diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2018-04-16 21:35:59 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2018-04-16 21:35:59 +0300 |
commit | c7d6aa4338527c4fe580bcbf7f8533f582583e13 (patch) | |
tree | e14c93d1f9cde421374db161b276d29dc4289bc7 /source | |
parent | 4ed21f13608901b10f8f4b37cee9a054a91da0bd (diff) | |
parent | 34ab90f546f097cada951b2c9ca22bf271996980 (diff) |
Merge branch 'blender2.8' into blender2.8-workbench
Diffstat (limited to 'source')
402 files changed, 9882 insertions, 7929 deletions
diff --git a/source/blender/alembic/intern/abc_camera.cc b/source/blender/alembic/intern/abc_camera.cc index aa5d77ce4ec..4c91b9a6252 100644 --- a/source/blender/alembic/intern/abc_camera.cc +++ b/source/blender/alembic/intern/abc_camera.cc @@ -49,13 +49,13 @@ using Alembic::AbcGeom::kWrapExisting; /* ************************************************************************** */ -AbcCameraWriter::AbcCameraWriter(EvaluationContext *eval_ctx, +AbcCameraWriter::AbcCameraWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, uint32_t time_sampling, ExportSettings &settings) - : AbcObjectWriter(eval_ctx, scene, ob, time_sampling, settings, parent) + : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent) { OCamera camera(parent->alembicXform(), m_name, m_time_sampling); m_camera_schema = camera.getSchema(); diff --git a/source/blender/alembic/intern/abc_camera.h b/source/blender/alembic/intern/abc_camera.h index 772b7a6aec6..a839ca947ca 100644 --- a/source/blender/alembic/intern/abc_camera.h +++ b/source/blender/alembic/intern/abc_camera.h @@ -35,7 +35,7 @@ class AbcCameraWriter : public AbcObjectWriter { Alembic::AbcGeom::OFloatProperty m_eye_separation; public: - AbcCameraWriter(EvaluationContext *eval_ctx, + AbcCameraWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, diff --git a/source/blender/alembic/intern/abc_curves.cc b/source/blender/alembic/intern/abc_curves.cc index 5328c471093..41c1dacabc0 100644 --- a/source/blender/alembic/intern/abc_curves.cc +++ b/source/blender/alembic/intern/abc_curves.cc @@ -71,13 +71,13 @@ using Alembic::AbcGeom::OV2fGeomParam; /* ************************************************************************** */ -AbcCurveWriter::AbcCurveWriter(EvaluationContext *eval_ctx, +AbcCurveWriter::AbcCurveWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, uint32_t time_sampling, ExportSettings &settings) - : AbcObjectWriter(eval_ctx, scene, ob, time_sampling, settings, parent) + : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent) { OCurves curves(parent->alembicXform(), m_name, m_time_sampling); m_schema = curves.getSchema(); diff --git a/source/blender/alembic/intern/abc_curves.h b/source/blender/alembic/intern/abc_curves.h index 73cc8b35e27..1e7180bbb1f 100644 --- a/source/blender/alembic/intern/abc_curves.h +++ b/source/blender/alembic/intern/abc_curves.h @@ -36,7 +36,7 @@ class AbcCurveWriter : public AbcObjectWriter { Alembic::AbcGeom::OCurvesSchema::Sample m_sample; public: - AbcCurveWriter(EvaluationContext *eval_ctx, + AbcCurveWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc index ed5b59d08e2..16c3f7f4e86 100644 --- a/source/blender/alembic/intern/abc_exporter.cc +++ b/source/blender/alembic/intern/abc_exporter.cc @@ -168,7 +168,7 @@ static bool export_object(const ExportSettings * const settings, const Base * co /* ************************************************************************** */ -AbcExporter::AbcExporter(Main *bmain, EvaluationContext *eval_ctx, Scene *scene, +AbcExporter::AbcExporter(Main *bmain, Scene *scene, ViewLayer *view_layer, Depsgraph *depsgraph, const char *filename, ExportSettings &settings) : m_bmain(bmain) @@ -176,8 +176,8 @@ AbcExporter::AbcExporter(Main *bmain, EvaluationContext *eval_ctx, Scene *scene, , m_filename(filename) , m_trans_sampling_index(0) , m_shape_sampling_index(0) - , m_eval_ctx(eval_ctx) , m_scene(scene) + , m_view_layer(view_layer) , m_depsgraph(depsgraph) , m_writer(NULL) {} @@ -253,13 +253,13 @@ void AbcExporter::getFrameSet(unsigned int nr_of_samples, } } -void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled) +void AbcExporter::operator()(float &progress, bool &was_canceled) { std::string scene_name; - if (bmain->name[0] != '\0') { + if (m_bmain->name[0] != '\0') { char scene_file_name[FILE_MAX]; - BLI_strncpy(scene_file_name, bmain->name, FILE_MAX); + BLI_strncpy(scene_file_name, m_bmain->name, FILE_MAX); scene_name = scene_file_name; } else { @@ -298,8 +298,8 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled) OBox3dProperty archive_bounds_prop = Alembic::AbcGeom::CreateOArchiveBounds(m_writer->archive(), m_trans_sampling_index); - createTransformWritersHierarchy(bmain->eval_ctx); - createShapeWriters(bmain->eval_ctx); + createTransformWritersHierarchy(m_depsgraph); + createShapeWriters(m_depsgraph); /* Make a list of frames to export. */ @@ -332,7 +332,7 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled) const double frame = *begin; /* 'frame' is offset by start frame, so need to cancel the offset. */ - setCurrentFrame(bmain, frame); + setCurrentFrame(m_bmain, frame); if (shape_frames.count(frame) != 0) { for (int i = 0, e = m_shapes.size(); i != e; ++i) { @@ -361,7 +361,7 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled) } } -void AbcExporter::createTransformWritersHierarchy(EvaluationContext *eval_ctx) +void AbcExporter::createTransformWritersHierarchy(Depsgraph *depsgraph) { for (Base *base = static_cast<Base *>(m_settings.view_layer->object_bases.first); base; base = base->next) { Object *ob = base->object; @@ -374,13 +374,13 @@ void AbcExporter::createTransformWritersHierarchy(EvaluationContext *eval_ctx) /* We do not export transforms for objects of these classes. */ break; default: - exploreTransform(eval_ctx, base, ob->parent, NULL); + exploreTransform(depsgraph, base, ob->parent, NULL); } } } } -void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, Object *parent, Object *dupliObParent) +void AbcExporter::exploreTransform(Depsgraph *depsgraph, Base *ob_base, Object *parent, Object *dupliObParent) { Object *ob = ob_base->object; @@ -391,10 +391,10 @@ void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, O } if (object_type_is_exportable(m_scene, ob)) { - createTransformWriter(eval_ctx, ob, parent, dupliObParent); + createTransformWriter(depsgraph, ob, parent, dupliObParent); } - ListBase *lb = object_duplilist(eval_ctx, m_scene, ob); + ListBase *lb = object_duplilist(depsgraph, m_scene, ob); if (lb) { Base fake_base = *ob_base; // copy flags (like selection state) from the real object. @@ -415,7 +415,7 @@ void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, O dupli_parent = (dupli_ob->parent) ? dupli_ob->parent : ob; fake_base.object = dupli_ob; - exploreTransform(eval_ctx, &fake_base, dupli_parent, ob); + exploreTransform(depsgraph, &fake_base, dupli_parent, ob); } } } @@ -423,7 +423,7 @@ void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, O free_object_duplilist(lb); } -AbcTransformWriter * AbcExporter::createTransformWriter(EvaluationContext *eval_ctx, Object *ob, Object *parent, Object *dupliObParent) +AbcTransformWriter * AbcExporter::createTransformWriter(Depsgraph *depsgraph, Object *ob, Object *parent, Object *dupliObParent) { /* An object should not be its own parent, or we'll get infinite loops. */ BLI_assert(ob != parent); @@ -458,29 +458,29 @@ AbcTransformWriter * AbcExporter::createTransformWriter(EvaluationContext *eval_ * return the parent's AbcTransformWriter pointer. */ if (parent->parent) { if (parent == dupliObParent) { - parent_writer = createTransformWriter(eval_ctx, parent, parent->parent, NULL); + parent_writer = createTransformWriter(depsgraph, parent, parent->parent, NULL); } else { - parent_writer = createTransformWriter(eval_ctx, parent, parent->parent, dupliObParent); + parent_writer = createTransformWriter(depsgraph, parent, parent->parent, dupliObParent); } } else if (parent == dupliObParent) { if (dupliObParent->parent == NULL) { - parent_writer = createTransformWriter(eval_ctx, parent, NULL, NULL); + parent_writer = createTransformWriter(depsgraph, parent, NULL, NULL); } else { - parent_writer = createTransformWriter(eval_ctx, parent, dupliObParent->parent, dupliObParent->parent); + parent_writer = createTransformWriter(depsgraph, parent, dupliObParent->parent, dupliObParent->parent); } } else { - parent_writer = createTransformWriter(eval_ctx, parent, dupliObParent, dupliObParent); + parent_writer = createTransformWriter(depsgraph, parent, dupliObParent, dupliObParent); } BLI_assert(parent_writer); alembic_parent = parent_writer->alembicXform(); } - my_writer = new AbcTransformWriter(eval_ctx, ob, alembic_parent, parent_writer, + my_writer = new AbcTransformWriter(depsgraph, ob, alembic_parent, parent_writer, m_trans_sampling_index, m_settings); /* When flattening, the matrix of the dupliobject has to be added. */ @@ -492,14 +492,14 @@ AbcTransformWriter * AbcExporter::createTransformWriter(EvaluationContext *eval_ return my_writer; } -void AbcExporter::createShapeWriters(EvaluationContext *eval_ctx) +void AbcExporter::createShapeWriters(Depsgraph *depsgraph) { for (Base *base = static_cast<Base *>(m_settings.view_layer->object_bases.first); base; base = base->next) { - exploreObject(eval_ctx, base, NULL); + exploreObject(depsgraph, base, NULL); } } -void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Object *dupliObParent) +void AbcExporter::exploreObject(Depsgraph *depsgraph, Base *ob_base, Object *dupliObParent) { /* If an object isn't exported itself, its duplilist shouldn't be * exported either. */ @@ -510,7 +510,7 @@ void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Obje createShapeWriter(ob_base, dupliObParent); Object *ob = ob_base->object; - ListBase *lb = object_duplilist(eval_ctx, m_scene, ob); + ListBase *lb = object_duplilist(depsgraph, m_scene, ob); if (lb) { Base fake_base = *ob_base; // copy flags (like selection state) from the real object. @@ -525,7 +525,7 @@ void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Obje } if (link->type == OB_DUPLIGROUP) { fake_base.object = link->ob; - exploreObject(eval_ctx, &fake_base, ob); + exploreObject(depsgraph, &fake_base, ob); } } } @@ -548,10 +548,10 @@ void AbcExporter::createParticleSystemsWriters(Object *ob, AbcTransformWriter *x if (m_settings.export_hair && psys->part->type == PART_HAIR) { m_settings.export_child_hairs = true; - m_shapes.push_back(new AbcHairWriter(m_eval_ctx, m_scene, ob, xform, m_shape_sampling_index, m_settings, psys)); + m_shapes.push_back(new AbcHairWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings, psys)); } else if (m_settings.export_particles && psys->part->type == PART_EMITTER) { - m_shapes.push_back(new AbcPointsWriter(m_eval_ctx, m_scene, ob, xform, m_shape_sampling_index, m_settings, psys)); + m_shapes.push_back(new AbcPointsWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings, psys)); } } } @@ -591,7 +591,7 @@ void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent) return; } - m_shapes.push_back(new AbcMeshWriter(m_eval_ctx, m_scene, ob, xform, m_shape_sampling_index, m_settings)); + m_shapes.push_back(new AbcMeshWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings)); break; } case OB_SURF: @@ -602,7 +602,7 @@ void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent) return; } - m_shapes.push_back(new AbcNurbsWriter(m_eval_ctx, m_scene, ob, xform, m_shape_sampling_index, m_settings)); + m_shapes.push_back(new AbcNurbsWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings)); break; } case OB_CURVE: @@ -613,7 +613,7 @@ void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent) return; } - m_shapes.push_back(new AbcCurveWriter(m_eval_ctx, m_scene, ob, xform, m_shape_sampling_index, m_settings)); + m_shapes.push_back(new AbcCurveWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings)); break; } case OB_CAMERA: @@ -621,7 +621,7 @@ void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent) Camera *cam = static_cast<Camera *>(ob->data); if (cam->type == CAM_PERSP) { - m_shapes.push_back(new AbcCameraWriter(m_eval_ctx, m_scene, ob, xform, m_shape_sampling_index, m_settings)); + m_shapes.push_back(new AbcCameraWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings)); } break; @@ -634,7 +634,7 @@ void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent) } m_shapes.push_back(new AbcMBallWriter( - m_bmain, m_eval_ctx, m_scene, ob, xform, + m_bmain, m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings)); break; } diff --git a/source/blender/alembic/intern/abc_exporter.h b/source/blender/alembic/intern/abc_exporter.h index 9c9c21af12f..0a32a28adca 100644 --- a/source/blender/alembic/intern/abc_exporter.h +++ b/source/blender/alembic/intern/abc_exporter.h @@ -34,7 +34,6 @@ class AbcObjectWriter; class AbcTransformWriter; class ArchiveWriter; -struct EvaluationContext; struct Depsgraph; struct Main; struct Object; @@ -93,8 +92,8 @@ class AbcExporter { unsigned int m_trans_sampling_index, m_shape_sampling_index; - EvaluationContext *m_eval_ctx; Scene *m_scene; + ViewLayer *m_view_layer; Depsgraph *m_depsgraph; ArchiveWriter *m_writer; @@ -106,12 +105,12 @@ class AbcExporter { std::vector<AbcObjectWriter *> m_shapes; public: - AbcExporter(Main *bmain, EvaluationContext *eval_ctx, Scene *scene, + AbcExporter(Main *bmain, Scene *scene, ViewLayer *view_layer, Depsgraph *depsgraph, const char *filename, ExportSettings &settings); ~AbcExporter(); - void operator()(Main *bmain, float &progress, bool &was_canceled); + void operator()(float &progress, bool &was_canceled); protected: void getShutterSamples(unsigned int nr_of_samples, @@ -122,11 +121,11 @@ protected: private: Alembic::Abc::TimeSamplingPtr createTimeSampling(double step); - void createTransformWritersHierarchy(EvaluationContext *eval_ctx); - AbcTransformWriter * createTransformWriter(EvaluationContext *eval_ctx, Object *ob, Object *parent, Object *dupliObParent); - void exploreTransform(EvaluationContext *eval_ctx, Base *ob_base, Object *parent, Object *dupliObParent); - void exploreObject(EvaluationContext *eval_ctx, Base *ob_base, Object *dupliObParent); - void createShapeWriters(EvaluationContext *eval_ctx); + void createTransformWritersHierarchy(Depsgraph *depsgraph); + AbcTransformWriter * createTransformWriter(Depsgraph *depsgraph, Object *ob, Object *parent, Object *dupliObParent); + void exploreTransform(Depsgraph *depsgraph, Base *ob_base, Object *parent, Object *dupliObParent); + void exploreObject(Depsgraph *depsgraph, Base *ob_base, Object *dupliObParent); + void createShapeWriters(Depsgraph *depsgraph); void createShapeWriter(Base *ob_base, Object *dupliObParent); void createParticleSystemsWriters(Object *ob, AbcTransformWriter *xform); diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc index 2579aa3cc36..70ca7a1a929 100644 --- a/source/blender/alembic/intern/abc_hair.cc +++ b/source/blender/alembic/intern/abc_hair.cc @@ -49,14 +49,14 @@ using Alembic::AbcGeom::OV2fGeomParam; /* ************************************************************************** */ -AbcHairWriter::AbcHairWriter(EvaluationContext *eval_ctx, +AbcHairWriter::AbcHairWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, uint32_t time_sampling, ExportSettings &settings, ParticleSystem *psys) - : AbcObjectWriter(eval_ctx, scene, ob, time_sampling, settings, parent) + : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent) , m_uv_warning_shown(false) { m_psys = psys; @@ -77,7 +77,7 @@ void AbcHairWriter::do_write() return; } - DerivedMesh *dm = mesh_create_derived_render(m_eval_ctx, m_scene, m_object, CD_MASK_MESH); + DerivedMesh *dm = mesh_create_derived_render(m_depsgraph, m_scene, m_object, CD_MASK_MESH); DM_ensure_tessface(dm); std::vector<Imath::V3f> verts; @@ -253,8 +253,9 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm, path = cache[p]; if (part->from == PART_FROM_FACE && - part->childtype != PART_CHILD_PARTICLES && - mtface) { + part->childtype != PART_CHILD_PARTICLES && + mtface) + { const int num = pc->num; if (num < 0) { ABC_LOG(m_settings.logger) diff --git a/source/blender/alembic/intern/abc_hair.h b/source/blender/alembic/intern/abc_hair.h index 8190c449205..5627f7726e6 100644 --- a/source/blender/alembic/intern/abc_hair.h +++ b/source/blender/alembic/intern/abc_hair.h @@ -40,7 +40,7 @@ class AbcHairWriter : public AbcObjectWriter { bool m_uv_warning_shown; public: - AbcHairWriter(EvaluationContext *eval_ctx, + AbcHairWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, diff --git a/source/blender/alembic/intern/abc_mball.cc b/source/blender/alembic/intern/abc_mball.cc index f1aa25c8f70..1df55712abe 100644 --- a/source/blender/alembic/intern/abc_mball.cc +++ b/source/blender/alembic/intern/abc_mball.cc @@ -42,13 +42,13 @@ extern "C" { AbcMBallWriter::AbcMBallWriter( Main *bmain, - EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, uint32_t time_sampling, ExportSettings &settings) - : AbcObjectWriter(eval_ctx, scene, ob, time_sampling, settings, parent) + : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent) , m_bmain(bmain) { m_is_animated = isAnimated(); @@ -58,7 +58,7 @@ AbcMBallWriter::AbcMBallWriter( sizeof(CurveCache), "CurveCache for AbcMBallWriter"); - m_mesh_writer = new AbcMeshWriter(eval_ctx, scene, m_mesh_ob, parent, + m_mesh_writer = new AbcMeshWriter(depsgraph, scene, m_mesh_ob, parent, time_sampling, settings); m_mesh_writer->setIsAnimated(m_is_animated); } @@ -97,13 +97,11 @@ void AbcMBallWriter::do_write() id_us_min(&tmpmesh->id); ListBase disp = {NULL, NULL}; - /* TODO(sergey): This is gonna to work for until EvaluationContext + /* TODO(sergey): This is gonna to work for until Depsgraph * only contains for_render flag. As soon as CoW is * implemented, this is to be rethinked. */ - EvaluationContext eval_ctx; - DEG_evaluation_context_init(&eval_ctx, DAG_EVAL_RENDER); - BKE_displist_make_mball_forRender(&eval_ctx, m_scene, m_object, &disp); + BKE_displist_make_mball_forRender(m_depsgraph, m_scene, m_object, &disp); BKE_mesh_from_metaball(&disp, tmpmesh); BKE_displist_free(&disp); diff --git a/source/blender/alembic/intern/abc_mball.h b/source/blender/alembic/intern/abc_mball.h index e657711059e..19bf7dc054d 100644 --- a/source/blender/alembic/intern/abc_mball.h +++ b/source/blender/alembic/intern/abc_mball.h @@ -42,7 +42,7 @@ class AbcMBallWriter : public AbcObjectWriter { public: AbcMBallWriter( Main *bmain, - EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc index c2c99e2b11f..52d14f84728 100644 --- a/source/blender/alembic/intern/abc_mesh.cc +++ b/source/blender/alembic/intern/abc_mesh.cc @@ -286,13 +286,13 @@ static ModifierData *get_liquid_sim_modifier(Scene *scene, Object *ob) /* ************************************************************************** */ -AbcMeshWriter::AbcMeshWriter(EvaluationContext *eval_ctx, +AbcMeshWriter::AbcMeshWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, uint32_t time_sampling, ExportSettings &settings) - : AbcObjectWriter(eval_ctx, scene, ob, time_sampling, settings, parent) + : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent) { m_is_animated = isAnimated(); m_subsurf_mod = NULL; @@ -525,7 +525,7 @@ DerivedMesh *AbcMeshWriter::getFinalMesh() m_subsurf_mod->mode |= eModifierMode_DisableTemporary; } - DerivedMesh *dm = mesh_create_derived_render(m_eval_ctx, m_scene, m_object, CD_MASK_MESH); + DerivedMesh *dm = mesh_create_derived_render(m_depsgraph, m_scene, m_object, CD_MASK_MESH); if (m_subsurf_mod) { m_subsurf_mod->mode &= ~eModifierMode_DisableTemporary; diff --git a/source/blender/alembic/intern/abc_mesh.h b/source/blender/alembic/intern/abc_mesh.h index a08b7352d16..c57123cda4c 100644 --- a/source/blender/alembic/intern/abc_mesh.h +++ b/source/blender/alembic/intern/abc_mesh.h @@ -50,7 +50,7 @@ class AbcMeshWriter : public AbcObjectWriter { bool m_is_subd; public: - AbcMeshWriter(EvaluationContext *eval_ctx, + AbcMeshWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, diff --git a/source/blender/alembic/intern/abc_nurbs.cc b/source/blender/alembic/intern/abc_nurbs.cc index 0532191a28d..1f042d0bafc 100644 --- a/source/blender/alembic/intern/abc_nurbs.cc +++ b/source/blender/alembic/intern/abc_nurbs.cc @@ -60,13 +60,13 @@ using Alembic::AbcGeom::ONuPatchSchema; /* ************************************************************************** */ -AbcNurbsWriter::AbcNurbsWriter(EvaluationContext *eval_ctx, +AbcNurbsWriter::AbcNurbsWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, uint32_t time_sampling, ExportSettings &settings) - : AbcObjectWriter(eval_ctx, scene, ob, time_sampling, settings, parent) + : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent) { m_is_animated = isAnimated(); diff --git a/source/blender/alembic/intern/abc_nurbs.h b/source/blender/alembic/intern/abc_nurbs.h index 3d20c5c60bb..d2422345c3f 100644 --- a/source/blender/alembic/intern/abc_nurbs.h +++ b/source/blender/alembic/intern/abc_nurbs.h @@ -32,7 +32,7 @@ class AbcNurbsWriter : public AbcObjectWriter { bool m_is_animated; public: - AbcNurbsWriter(EvaluationContext *eval_ctx, + AbcNurbsWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc index 98ebcf6debb..85bda9aa8eb 100644 --- a/source/blender/alembic/intern/abc_object.cc +++ b/source/blender/alembic/intern/abc_object.cc @@ -58,7 +58,7 @@ using Alembic::AbcGeom::OStringProperty; /* ************************************************************************** */ -AbcObjectWriter::AbcObjectWriter(EvaluationContext *eval_ctx, +AbcObjectWriter::AbcObjectWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, uint32_t time_sampling, @@ -66,7 +66,7 @@ AbcObjectWriter::AbcObjectWriter(EvaluationContext *eval_ctx, AbcObjectWriter *parent) : m_object(ob) , m_settings(settings) - , m_eval_ctx(eval_ctx) + , m_depsgraph(depsgraph) , m_scene(scene) , m_time_sampling(time_sampling) , m_first_frame(true) @@ -291,7 +291,8 @@ Alembic::AbcGeom::IXform AbcObjectReader::xform() /* The archive's top object can be recognised by not having a parent. */ if (abc_parent.getParent() - && IXform::matches(abc_parent.getMetaData())) { + && IXform::matches(abc_parent.getMetaData())) + { return IXform(abc_parent, Alembic::AbcGeom::kWrapExisting); } diff --git a/source/blender/alembic/intern/abc_object.h b/source/blender/alembic/intern/abc_object.h index 6aa6224f8d5..d41088bdcad 100644 --- a/source/blender/alembic/intern/abc_object.h +++ b/source/blender/alembic/intern/abc_object.h @@ -44,7 +44,7 @@ protected: Object *m_object; ExportSettings &m_settings; - EvaluationContext *m_eval_ctx; + Depsgraph *m_depsgraph; Scene *m_scene; uint32_t m_time_sampling; @@ -57,7 +57,7 @@ protected: std::string m_name; public: - AbcObjectWriter(EvaluationContext *eval_ctx, + AbcObjectWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, uint32_t time_sampling, diff --git a/source/blender/alembic/intern/abc_points.cc b/source/blender/alembic/intern/abc_points.cc index feb2eff5b9d..6f52ccec4a7 100644 --- a/source/blender/alembic/intern/abc_points.cc +++ b/source/blender/alembic/intern/abc_points.cc @@ -58,14 +58,14 @@ using Alembic::AbcGeom::OPointsSchema; /* ************************************************************************** */ -AbcPointsWriter::AbcPointsWriter(EvaluationContext *eval_ctx, +AbcPointsWriter::AbcPointsWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, uint32_t time_sampling, ExportSettings &settings, ParticleSystem *psys) - : AbcObjectWriter(eval_ctx, scene, ob, time_sampling, settings, parent) + : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent) { m_psys = psys; @@ -87,7 +87,7 @@ void AbcPointsWriter::do_write() ParticleKey state; ParticleSimulationData sim; - sim.eval_ctx = m_eval_ctx; + sim.depsgraph = m_depsgraph; sim.scene = m_scene; sim.ob = m_object; sim.psys = m_psys; diff --git a/source/blender/alembic/intern/abc_points.h b/source/blender/alembic/intern/abc_points.h index b60f1997aa8..1ac8792ede1 100644 --- a/source/blender/alembic/intern/abc_points.h +++ b/source/blender/alembic/intern/abc_points.h @@ -38,7 +38,7 @@ class AbcPointsWriter : public AbcObjectWriter { ParticleSystem *m_psys; public: - AbcPointsWriter(EvaluationContext *eval_ctx, + AbcPointsWriter(Depsgraph *depsgraph, Scene *scene, Object *ob, AbcTransformWriter *parent, diff --git a/source/blender/alembic/intern/abc_transform.cc b/source/blender/alembic/intern/abc_transform.cc index 0a1480e62b0..e5da367b9a9 100644 --- a/source/blender/alembic/intern/abc_transform.cc +++ b/source/blender/alembic/intern/abc_transform.cc @@ -57,13 +57,13 @@ static bool has_parent_camera(Object *ob) /* ************************************************************************** */ -AbcTransformWriter::AbcTransformWriter(EvaluationContext *eval_ctx, +AbcTransformWriter::AbcTransformWriter(Depsgraph *depsgraph, Object *ob, const OObject &abc_parent, AbcTransformWriter *parent, unsigned int time_sampling, ExportSettings &settings) - : AbcObjectWriter(eval_ctx, NULL, ob, time_sampling, settings, parent) + : AbcObjectWriter(depsgraph, NULL, ob, time_sampling, settings, parent) , m_proxy_from(NULL) { m_is_animated = hasAnimation(m_object); diff --git a/source/blender/alembic/intern/abc_transform.h b/source/blender/alembic/intern/abc_transform.h index e82765cb169..ce4b28ea236 100644 --- a/source/blender/alembic/intern/abc_transform.h +++ b/source/blender/alembic/intern/abc_transform.h @@ -44,7 +44,7 @@ public: Object *m_proxy_from; public: - AbcTransformWriter(EvaluationContext *eval_ctx, + AbcTransformWriter(Depsgraph *depsgraph, Object *ob, const Alembic::AbcGeom::OObject &abc_parent, AbcTransformWriter *parent, diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc index cb01efb2cf4..75b4063f3c4 100644 --- a/source/blender/alembic/intern/alembic_capi.cc +++ b/source/blender/alembic/intern/alembic_capi.cc @@ -230,7 +230,6 @@ static void find_iobject(const IObject &object, IObject &ret, } struct ExportJobData { - EvaluationContext eval_ctx; Scene *scene; ViewLayer *view_layer; Depsgraph *depsgraph; @@ -265,12 +264,13 @@ static void export_startjob(void *customdata, short *stop, short *do_update, flo try { Scene *scene = data->scene; - AbcExporter exporter(data->bmain, &data->eval_ctx, scene, data->depsgraph, data->filename, data->settings); + ViewLayer *view_layer = data->view_layer; + AbcExporter exporter(data->bmain, scene, view_layer, data->depsgraph, data->filename, data->settings); const int orig_frame = CFRA; data->was_canceled = false; - exporter(data->bmain, *data->progress, data->was_canceled); + exporter(*data->progress, data->was_canceled); if (CFRA != orig_frame) { CFRA = orig_frame; @@ -314,8 +314,6 @@ bool ABC_export( { ExportJobData *job = static_cast<ExportJobData *>(MEM_mallocN(sizeof(ExportJobData), "ExportJobData")); - CTX_data_eval_ctx(C, &job->eval_ctx); - job->scene = scene; job->view_layer = CTX_data_view_layer(C); job->depsgraph = CTX_data_depsgraph(C); diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 96854db66dd..d0589f6546e 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -100,8 +100,7 @@ KerningCacheBLF *blf_kerning_cache_new(FontBLF *font) GlyphBLF *g_prev = blf_glyph_search(font->glyph_cache, j); FT_Vector delta = {.x = 0, .y = 0}; - if (FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode, - &delta) == 0) { + if (FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode, &delta) == 0) { kc->table[i][j] = (int)delta.x >> 6; } else { diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 4ae11b5cca5..d269a2fb63b 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -95,10 +95,10 @@ struct KeyBlock; struct ModifierData; struct MCol; struct ColorBand; +struct Depsgraph; struct GPUVertexAttribs; struct GPUDrawObject; struct PBVH; -struct EvaluationContext; /* number of sub-elements each mesh element has (for interpolation) */ #define SUB_ELEMS_VERT 0 @@ -660,18 +660,18 @@ void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int /* */ DerivedMesh *mesh_get_derived_final( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, CustomDataMask dataMask); DerivedMesh *mesh_get_derived_deform( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, CustomDataMask dataMask); DerivedMesh *mesh_create_derived_for_modifier( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ModifierData *md, int build_shapekey_layers); DerivedMesh *mesh_create_derived_render( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, CustomDataMask dataMask); DerivedMesh *getEditDerivedBMesh( @@ -679,37 +679,37 @@ DerivedMesh *getEditDerivedBMesh( float (*vertexCos)[3]); DerivedMesh *mesh_create_derived_index_render( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, CustomDataMask dataMask, int index); /* same as above but wont use render settings */ DerivedMesh *mesh_create_derived(struct Mesh *me, float (*vertCos)[3]); DerivedMesh *mesh_create_derived_view( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, CustomDataMask dataMask); DerivedMesh *mesh_create_derived_no_deform( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float (*vertCos)[3], CustomDataMask dataMask); DerivedMesh *mesh_create_derived_no_deform_render( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float (*vertCos)[3], CustomDataMask dataMask); /* for gameengine */ DerivedMesh *mesh_create_derived_no_virtual( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float (*vertCos)[3], CustomDataMask dataMask); DerivedMesh *mesh_create_derived_physics( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float (*vertCos)[3], CustomDataMask dataMask); DerivedMesh *editbmesh_get_derived_base( struct Object *ob, struct BMEditMesh *em, CustomDataMask data_mask); DerivedMesh *editbmesh_get_derived_cage( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *, struct BMEditMesh *em, CustomDataMask dataMask); DerivedMesh *editbmesh_get_derived_cage_and_final( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *, struct BMEditMesh *em, CustomDataMask dataMask, DerivedMesh **r_final); @@ -718,7 +718,7 @@ DerivedMesh *object_get_derived_final(struct Object *ob, const bool for_render); float (*editbmesh_get_vertex_cos(struct BMEditMesh *em, int *r_numVerts))[3]; bool editbmesh_modifier_is_enabled(struct Scene *scene, struct ModifierData *md, DerivedMesh *dm); void makeDerivedMesh( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct BMEditMesh *em, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct BMEditMesh *em, CustomDataMask dataMask, const bool build_shapekey_layers); void weight_to_rgb(float r_rgb[3], const float weight); diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h index 30a7bdb0a27..0fb83162459 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_anim.h @@ -32,7 +32,7 @@ * \author nzc * \since March 2001 */ -struct EvaluationContext; +struct Depsgraph; struct Path; struct Object; struct Scene; @@ -54,7 +54,7 @@ void animviz_free_motionpath(struct bMotionPath *mpath); struct bMotionPath *animviz_verify_motionpaths(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan); void animviz_get_object_motionpaths(struct Object *ob, ListBase *targets); -void animviz_calc_motionpaths(struct EvaluationContext *eval_ctx, struct Main *bmain, struct Scene *scene, ListBase *targets); +void animviz_calc_motionpaths(struct Depsgraph *depsgraph, struct Main *bmain, struct Scene *scene, ListBase *targets); /* ---------------------------------------------------- */ /* Curve Paths */ @@ -66,8 +66,8 @@ int where_on_path(struct Object *ob, float ctime, float vec[4], float dir[3], fl /* ---------------------------------------------------- */ /* Dupli-Geometry */ -struct ListBase *object_duplilist_ex(const struct EvaluationContext *eval_ctx, struct Scene *sce, struct Object *ob, bool update); -struct ListBase *object_duplilist(const struct EvaluationContext *eval_ctx, struct Scene *sce, struct Object *ob); +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); @@ -81,7 +81,7 @@ typedef struct DupliApplyData { DupliExtraData *extra; } DupliApplyData; -DupliApplyData *duplilist_apply(const struct EvaluationContext *eval_ctx, struct Object *ob, struct Scene *scene, struct ListBase *duplilist); +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_animsys.h b/source/blender/blenkernel/BKE_animsys.h index d95b4a838b8..fe4a145b7b3 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -200,10 +200,10 @@ void animsys_evaluate_action_group(struct PointerRNA *ptr, struct bAction *act, /* ------------ Evaluation API --------------- */ -struct EvaluationContext; +struct Depsgraph; -void BKE_animsys_eval_animdata(const struct EvaluationContext *eval_ctx, struct ID *id); -void BKE_animsys_eval_driver(const struct EvaluationContext *eval_ctx, struct ID *id, struct FCurve *fcurve); +void BKE_animsys_eval_animdata(struct Depsgraph *depsgraph, struct ID *id); +void BKE_animsys_eval_driver(struct Depsgraph *depsgraph, struct ID *id, struct FCurve *fcurve); /* ************************************* */ diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index bf37224c85f..e286c1248c0 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -35,7 +35,7 @@ struct bPose; struct Bone; -struct EvaluationContext; +struct Depsgraph; struct GHash; struct Main; struct bArmature; @@ -100,8 +100,8 @@ void BKE_armature_where_is(struct bArmature *arm); void BKE_armature_where_is_bone(struct Bone *bone, struct Bone *prevbone, const bool use_recursion); void BKE_pose_clear_pointers(struct bPose *pose); void BKE_pose_rebuild(struct Object *ob, struct bArmature *arm); -void BKE_pose_where_is(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); -void BKE_pose_where_is_bone(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime, bool do_extra); +void BKE_pose_where_is(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); +void BKE_pose_where_is_bone(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime, bool do_extra); void BKE_pose_where_is_bone_tail(struct bPoseChannel *pchan); /* get_objectspace_bone_matrix has to be removed still */ @@ -118,7 +118,7 @@ void BKE_armature_loc_pose_to_bone(struct bPoseChannel *pchan, const float inloc void BKE_armature_mat_bone_to_pose(struct bPoseChannel *pchan, float inmat[4][4], float outmat[4][4]); void BKE_armature_mat_pose_to_delta(float delta_mat[4][4], float pose_mat[4][4], float arm_mat[4][4]); -void BKE_armature_mat_pose_to_bone_ex(const struct EvaluationContext *eval_ctx, struct Object *ob, struct bPoseChannel *pchan, float inmat[4][4], float outmat[4][4]); +void BKE_armature_mat_pose_to_bone_ex(struct Depsgraph *depsgraph, struct Object *ob, struct bPoseChannel *pchan, float inmat[4][4], float outmat[4][4]); void BKE_pchan_mat3_to_rot(struct bPoseChannel *pchan, float mat[3][3], bool use_compat); void BKE_pchan_apply_mat4(struct bPoseChannel *pchan, float mat[4][4], bool use_comat); @@ -166,46 +166,46 @@ struct bPoseChannel *BKE_armature_splineik_solver_find_root( void BKE_pose_splineik_init_tree(struct Scene *scene, struct Object *ob, float ctime); void BKE_splineik_execute_tree( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime); -void BKE_pose_eval_init(const struct EvaluationContext *eval_ctx, +void BKE_pose_eval_init(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); -void BKE_pose_eval_init_ik(const struct EvaluationContext *eval_ctx, +void BKE_pose_eval_init_ik(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); -void BKE_pose_eval_bone(const struct EvaluationContext *eval_ctx, +void BKE_pose_eval_bone(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int pchan_index); -void BKE_pose_constraints_evaluate(const struct EvaluationContext *eval_ctx, +void BKE_pose_constraints_evaluate(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int pchan_index); -void BKE_pose_bone_done(const struct EvaluationContext *eval_ctx, +void BKE_pose_bone_done(struct Depsgraph *depsgraph, struct Object *ob, int pchan_index); -void BKE_pose_iktree_evaluate(const struct EvaluationContext *eval_ctx, +void BKE_pose_iktree_evaluate(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int rootchan_index); -void BKE_pose_splineik_evaluate(const struct EvaluationContext *eval_ctx, +void BKE_pose_splineik_evaluate(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int rootchan_index); -void BKE_pose_eval_flush(const struct EvaluationContext *eval_ctx, +void BKE_pose_eval_flush(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); -void BKE_pose_eval_proxy_copy(const struct EvaluationContext *eval_ctx, +void BKE_pose_eval_proxy_copy(struct Depsgraph *depsgraph, struct Object *ob); #ifdef __cplusplus diff --git a/source/blender/blenkernel/BKE_camera.h b/source/blender/blenkernel/BKE_camera.h index d5bf2177f71..5e79f641c97 100644 --- a/source/blender/blenkernel/BKE_camera.h +++ b/source/blender/blenkernel/BKE_camera.h @@ -114,7 +114,7 @@ typedef struct CameraParams { void BKE_camera_params_init(CameraParams *params); void BKE_camera_params_from_object(CameraParams *params, const struct Object *camera); -void BKE_camera_params_from_view3d(CameraParams *params, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d); +void BKE_camera_params_from_view3d(CameraParams *params, struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d); void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy); void BKE_camera_params_compute_matrix(CameraParams *params); @@ -130,6 +130,7 @@ void BKE_camera_view_frame( float r_vec[4][3]); bool BKE_camera_view_frame_fit_to_scene( + struct Depsgraph *depsgraph, struct Scene *scene, struct ViewLayer *view_layer, struct Object *camera_ob, float r_co[3], float *r_scale); bool BKE_camera_view_frame_fit_to_coords( diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index 8923edacb07..94daf615054 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -41,7 +41,7 @@ struct MFace; struct DerivedMesh; struct ClothModifierData; struct CollisionModifierData; -struct EvaluationContext; +struct Depsgraph; #define DO_INLINE MALWAYS_INLINE @@ -227,7 +227,7 @@ void cloth_free_contacts(ColliderContacts *collider_contacts, int totcolliders); void cloth_free_modifier_extern (struct ClothModifierData *clmd ); void cloth_free_modifier (struct ClothModifierData *clmd ); void cloth_init (struct ClothModifierData *clmd ); -void clothModifier_do(struct ClothModifierData *clmd, const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]); +void clothModifier_do(struct ClothModifierData *clmd, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]); int cloth_uses_vgroup(struct ClothModifierData *clmd); diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h index cf7e2908360..54ddb61d922 100644 --- a/source/blender/blenkernel/BKE_constraint.h +++ b/source/blender/blenkernel/BKE_constraint.h @@ -40,7 +40,7 @@ struct ListBase; struct Object; struct Scene; struct bPoseChannel; -struct EvaluationContext; +struct Depsgraph; /* ---------------------------------------------------------------------------- */ #ifdef __cplusplus @@ -103,7 +103,7 @@ typedef struct bConstraintTypeInfo { /* evaluation */ /* set the ct->matrix for the given constraint target (at the given ctime) */ - void (*get_target_matrix)(const struct EvaluationContext *eval_ctx, struct bConstraint *con, struct bConstraintOb *cob, struct bConstraintTarget *ct, float ctime); + void (*get_target_matrix)(struct Depsgraph *depsgraph, struct bConstraint *con, struct bConstraintOb *cob, struct bConstraintTarget *ct, float ctime); /* evaluate the constraint for the given time */ void (*evaluate_constraint)(struct bConstraint *con, struct bConstraintOb *cob, struct ListBase *targets); } bConstraintTypeInfo; @@ -148,10 +148,10 @@ void BKE_constraints_clear_evalob(struct bConstraintOb *cob); void BKE_constraint_mat_convertspace( struct Object *ob, struct bPoseChannel *pchan, float mat[4][4], short from, short to, const bool keep_scale); -void BKE_constraint_target_matrix_get(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct bConstraint *con, +void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, struct Scene *scene, struct bConstraint *con, int n, short ownertype, void *ownerdata, float mat[4][4], float ctime); -void BKE_constraint_targets_for_solving_get(const struct EvaluationContext *eval_ctx, struct bConstraint *con, struct bConstraintOb *ob, struct ListBase *targets, float ctime); -void BKE_constraints_solve(const struct EvaluationContext *eval_ctx, struct ListBase *conlist, struct bConstraintOb *cob, float ctime); +void BKE_constraint_targets_for_solving_get(struct Depsgraph *depsgraph, struct bConstraint *con, struct bConstraintOb *ob, struct ListBase *targets, float ctime); +void BKE_constraints_solve(struct Depsgraph *depsgraph, struct ListBase *conlist, struct bConstraintOb *cob, float ctime); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index 34192db318e..5057168b9f6 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -75,7 +75,6 @@ struct SpaceText; struct SpaceImage; struct SpaceClip; struct ID; -struct EvaluationContext; #include "DNA_object_enums.h" @@ -245,6 +244,10 @@ void CTX_data_list_add(bContextDataResult *result, void *data); BLI_freelistN(&ctx_data_list); \ } (void)0 +#define CTX_DATA_BEGIN_WITH_ID(C, Type, instance, member, Type_id, instance_id) \ + CTX_DATA_BEGIN(C, Type, instance, member) \ + Type_id instance_id = ctx_link->ptr.id.data; \ + int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBase *)); #define CTX_DATA_COUNT(C, member) \ @@ -321,8 +324,6 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list); struct Depsgraph *CTX_data_depsgraph(const bContext *C); -void CTX_data_eval_ctx(const bContext *C, struct EvaluationContext *eval_ctx); - #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_crazyspace.h b/source/blender/blenkernel/BKE_crazyspace.h index 31542cd6f8a..e9745ed50fa 100644 --- a/source/blender/blenkernel/BKE_crazyspace.h +++ b/source/blender/blenkernel/BKE_crazyspace.h @@ -38,24 +38,24 @@ struct Scene; struct Object; struct BMEditMesh; struct Mesh; -struct EvaluationContext; +struct Depsgraph; /* crazyspace.c */ float (*BKE_crazyspace_get_mapped_editverts( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *obedit))[3]; + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *obedit))[3]; void BKE_crazyspace_set_quats_editmesh( struct BMEditMesh *em, float (*origcos)[3], float (*mappedcos)[3], float (*quats)[4], const bool use_select); void BKE_crazyspace_set_quats_mesh( struct Mesh *me, float (*origcos)[3], float (*mappedcos)[3], float (*quats)[4]); int BKE_crazyspace_get_first_deform_matrices_editbmesh( - const struct EvaluationContext *eval_ctx, struct Scene *, struct Object *, struct BMEditMesh *em, + struct Depsgraph *depsgraph, struct Scene *, struct Object *, struct BMEditMesh *em, float (**deformmats)[3][3], float (**deformcos)[3]); int BKE_sculpt_get_first_deform_matrices( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float (**deformmats)[3][3], float (**deformcos)[3]); void BKE_crazyspace_build_sculpt( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float (**deformmats)[3][3], float (**deformcos)[3]); #ifdef __cplusplus diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index fbd05552255..975cea7364d 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -36,7 +36,7 @@ struct BezTriple; struct Curve; struct EditNurb; -struct EvaluationContext; +struct Depsgraph; struct GHash; struct ListBase; struct Main; @@ -123,13 +123,13 @@ void BKE_curve_editNurb_keyIndex_free(struct GHash **keyindex); void BKE_curve_editNurb_free(struct Curve *cu); struct ListBase *BKE_curve_editNurbs_get(struct Curve *cu); -float *BKE_curve_make_orco(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, int *r_numVerts); +float *BKE_curve_make_orco(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int *r_numVerts); float *BKE_curve_surf_make_orco(struct Object *ob); void BKE_curve_bevelList_free(struct ListBase *bev); void BKE_curve_bevelList_make(struct Object *ob, struct ListBase *nurbs, bool for_render); void BKE_curve_bevel_make( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct ListBase *disp, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *disp, const bool for_render, const bool use_render_resolution); void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride); @@ -218,7 +218,7 @@ void BKE_nurb_handles_test(struct Nurb *nu, const bool use_handles); /* **** Depsgraph evaluation **** */ void BKE_curve_eval_geometry( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Curve *curve); /* Draw Cache */ diff --git a/source/blender/blenkernel/BKE_data_transfer.h b/source/blender/blenkernel/BKE_data_transfer.h index d5f0313ca64..6559f9a954f 100644 --- a/source/blender/blenkernel/BKE_data_transfer.h +++ b/source/blender/blenkernel/BKE_data_transfer.h @@ -38,11 +38,11 @@ extern "C" { #include "BKE_customdata.h" +struct Depsgraph; struct Object; struct Scene; struct SpaceTransform; struct ReportList; -struct EvaluationContext; /* Warning, those def are stored in files (TransferData modifier), *DO NOT* modify those values. */ enum { @@ -130,12 +130,12 @@ enum { }; void BKE_object_data_transfer_layout( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob_src, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst, const int data_types, const bool use_delete, const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX]); bool BKE_object_data_transfer_mesh( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst, const int data_types, const bool use_create, const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode, struct SpaceTransform *space_transform, const bool auto_transform, @@ -144,7 +144,7 @@ bool BKE_object_data_transfer_mesh( const int mix_mode, const float mix_factor, const char *vgroup_name, const bool invert_vgroup, struct ReportList *reports); bool BKE_object_data_transfer_dm( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst, struct DerivedMesh *dm_dst, const int data_types, bool use_create, const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode, diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index c2229976dd9..09e9b667369 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -60,8 +60,8 @@ enum { struct Scene; struct Object; struct ListBase; +struct Depsgraph; struct DerivedMesh; -struct EvaluationContext; /* used for curves, nurbs, mball, importing */ typedef struct DispList { @@ -87,28 +87,28 @@ void BKE_displist_free(struct ListBase *lb); bool BKE_displist_has_faces(struct ListBase *lb); void BKE_displist_make_surf( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct ListBase *dispbase, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase, struct DerivedMesh **r_dm_final, const bool for_render, const bool for_orco, const bool use_render_resolution); void BKE_displist_make_curveTypes( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, const bool for_orco); + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, const bool for_orco); void BKE_displist_make_curveTypes_forRender( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct ListBase *dispbase, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase, struct DerivedMesh **r_dm_final, const bool for_orco, const bool use_render_resolution); void BKE_displist_make_curveTypes_forOrco( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct ListBase *dispbase); + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase); void BKE_displist_make_mball( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void BKE_displist_make_mball_forRender( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct ListBase *dispbase); + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase); bool BKE_displist_surfindex_get(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4); void BKE_displist_fill(struct ListBase *dispbase, struct ListBase *to, const float normal_proj[3], const bool flipnormal); -float BKE_displist_calc_taper(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *taperobj, int cur, int tot); +float BKE_displist_calc_taper(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *taperobj, int cur, int tot); /* add Orco layer to the displist object which has got derived mesh and return orco */ float *BKE_displist_make_orco( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm_final, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm_final, const bool for_render, const bool use_render_resolution); void BKE_displist_minmax(struct ListBase *dispbase, float min[3], float max[3]); diff --git a/source/blender/blenkernel/BKE_dynamicpaint.h b/source/blender/blenkernel/BKE_dynamicpaint.h index 21c900a7f0d..8f795bc7535 100644 --- a/source/blender/blenkernel/BKE_dynamicpaint.h +++ b/source/blender/blenkernel/BKE_dynamicpaint.h @@ -27,9 +27,9 @@ * \ingroup bke */ +struct Depsgraph; struct Scene; struct ViewLayer; -struct EvaluationContext; /* Actual surface point */ typedef struct PaintSurfaceData { @@ -62,7 +62,7 @@ typedef struct PaintWavePoint { short state; } PaintWavePoint; -struct DerivedMesh *dynamicPaint_Modifier_do(struct DynamicPaintModifierData *pmd, const struct EvaluationContext *eval_ctx, struct Scene *scene, +struct DerivedMesh *dynamicPaint_Modifier_do(struct DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm); void dynamicPaint_Modifier_free(struct DynamicPaintModifierData *pmd); void dynamicPaint_Modifier_copy(struct DynamicPaintModifierData *pmd, struct DynamicPaintModifierData *tsmd); @@ -86,7 +86,7 @@ struct DynamicPaintSurface *get_activeSurface(struct DynamicPaintCanvasSettings /* image sequence baking */ int dynamicPaint_createUVSurface(struct Scene *scene, struct DynamicPaintSurface *surface, float *progress, short *do_update); -int dynamicPaint_calculateFrame(struct DynamicPaintSurface *surface, const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *cObject, int frame); +int dynamicPaint_calculateFrame(struct DynamicPaintSurface *surface, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *cObject, int frame); void dynamicPaint_outputSurfaceImage(struct DynamicPaintSurface *surface, char *filename, short output_layer); /* PaintPoint state */ diff --git a/source/blender/blenkernel/BKE_editmesh.h b/source/blender/blenkernel/BKE_editmesh.h index af1aeff230f..5e456fea64f 100644 --- a/source/blender/blenkernel/BKE_editmesh.h +++ b/source/blender/blenkernel/BKE_editmesh.h @@ -40,7 +40,7 @@ struct Mesh; struct Scene; struct DerivedMesh; struct MeshStatVis; -struct EvaluationContext; +struct Depsgraph; /** * This structure is used for mesh edit-mode. @@ -100,6 +100,6 @@ void BKE_editmesh_statvis_calc(BMEditMesh *em, struct DerivedMesh *dm, const struct MeshStatVis *statvis); float (*BKE_editmesh_vertexCos_get( - const struct EvaluationContext *eval_ctx, struct BMEditMesh *em, struct Scene *scene, int *r_numVerts))[3]; + struct Depsgraph *depsgraph, struct BMEditMesh *em, struct Scene *scene, int *r_numVerts))[3]; #endif /* __BKE_EDITMESH_H__ */ diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h index 6fa19d4aaf6..914dd650493 100644 --- a/source/blender/blenkernel/BKE_effect.h +++ b/source/blender/blenkernel/BKE_effect.h @@ -44,7 +44,7 @@ struct Group; struct ParticleSimulationData; struct ParticleData; struct ParticleKey; -struct EvaluationContext; +struct Depsgraph; struct EffectorWeights *BKE_add_effector_weights(struct Group *group); struct PartDeflect *object_add_collision_fields(int type); @@ -94,7 +94,7 @@ typedef struct EffectorData { typedef struct EffectorCache { struct EffectorCache *next, *prev; - const struct EvaluationContext *eval_ctx; + struct Depsgraph *depsgraph; struct Scene *scene; struct Object *ob; struct ParticleSystem *psys; @@ -113,10 +113,10 @@ typedef struct EffectorCache { void free_partdeflect(struct PartDeflect *pd); struct ListBase *pdInitEffectors( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob_src, struct ParticleSystem *psys_src, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool for_simulation); void pdEndEffectors(struct ListBase **effectors); -void pdPrecalculateEffectors(const struct EvaluationContext *eval_ctx, struct ListBase *effectors); +void pdPrecalculateEffectors(struct Depsgraph *depsgraph, struct ListBase *effectors); void pdDoEffectors(struct ListBase *effectors, struct ListBase *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *impulse); void pd_point_from_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, struct EffectedPoint *point); diff --git a/source/blender/blenkernel/BKE_fluidsim.h b/source/blender/blenkernel/BKE_fluidsim.h index 4ec58b2a0e5..8e04fe2c23a 100644 --- a/source/blender/blenkernel/BKE_fluidsim.h +++ b/source/blender/blenkernel/BKE_fluidsim.h @@ -36,11 +36,11 @@ struct Object; struct Scene; struct FluidsimSettings; struct MVert; -struct EvaluationContext; +struct Depsgraph; /* old interface */ -void initElbeemMesh(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, +void initElbeemMesh(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int *numVertices, float **vertices, int *numTriangles, int **triangles, int useGlobalCoords, int modifierIndex); diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h index a842bec7609..0195d1f1243 100644 --- a/source/blender/blenkernel/BKE_group.h +++ b/source/blender/blenkernel/BKE_group.h @@ -34,7 +34,7 @@ */ struct Base; -struct EvaluationContext; +struct Depsgraph; struct Group; struct Main; struct Object; @@ -53,11 +53,11 @@ bool BKE_group_object_exists(struct Group *group, struct Object *ob); bool BKE_group_object_cyclic_check(struct Main *bmain, struct Object *object, struct Group *group); bool BKE_group_is_animated(struct Group *group, struct Object *parent); -void BKE_group_handle_recalc_and_update(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *parent, struct Group *group); +void BKE_group_handle_recalc_and_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *parent, struct Group *group); /* Dependency graph evaluation. */ -void BKE_group_eval_view_layers(const struct EvaluationContext *eval_ctx, +void BKE_group_eval_view_layers(struct Depsgraph *depsgraph, struct Group *group); /* Helper macros. */ diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h index 1cdf193f054..1e3921747a5 100644 --- a/source/blender/blenkernel/BKE_lattice.h +++ b/source/blender/blenkernel/BKE_lattice.h @@ -43,7 +43,7 @@ struct Scene; struct DerivedMesh; struct BPoint; struct MDeformVert; -struct EvaluationContext; +struct Depsgraph; void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct Object *ltOb); void BKE_lattice_init(struct Lattice *lt); @@ -79,7 +79,7 @@ void armature_deform_verts(struct Object *armOb, struct Object *target, float (*BKE_lattice_vertexcos_get(struct Object *ob, int *r_numVerts))[3]; void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]); -void BKE_lattice_modifiers_calc(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); +void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *lattice); struct BPoint *BKE_lattice_active_point_get(struct Lattice *lt); @@ -101,9 +101,9 @@ void BKE_lattice_bitmap_from_flag(struct Lattice *lt, unsigned int *bitmap, cons /* **** Depsgraph evaluation **** */ -struct EvaluationContext; +struct Depsgraph; -void BKE_lattice_eval_geometry(const struct EvaluationContext *eval_ctx, +void BKE_lattice_eval_geometry(struct Depsgraph *depsgraph, struct Lattice *latt); /* Draw Cache */ diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index 9c06ae4f40d..8d141a2548b 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -42,7 +42,7 @@ extern "C" { #define ROOT_PROP "root" struct Base; -struct EvaluationContext; +struct Depsgraph; struct Group; struct ID; struct IDProperty; @@ -169,11 +169,11 @@ void BKE_collection_engine_property_value_set_bool(struct IDProperty *props, con /* evaluation */ -void BKE_layer_eval_view_layer(const struct EvaluationContext *eval_ctx, +void BKE_layer_eval_view_layer(struct Depsgraph *depsgraph, struct ID *owner_id, struct ViewLayer *view_layer); -void BKE_layer_eval_view_layer_indexed(const struct EvaluationContext *eval_ctx, +void BKE_layer_eval_view_layer_indexed(struct Depsgraph *depsgraph, struct ID *owner_id, int view_layer_index); @@ -187,10 +187,20 @@ void BKE_visible_objects_iterator_begin(BLI_Iterator *iter, void *data_in); void BKE_visible_objects_iterator_next(BLI_Iterator *iter); void BKE_visible_objects_iterator_end(BLI_Iterator *iter); +struct ObjectsInModeIteratorData { + int object_mode; + struct ViewLayer *view_layer; + struct Base *base_active; +}; + void BKE_renderable_objects_iterator_begin(BLI_Iterator *iter, void *data_in); void BKE_renderable_objects_iterator_next(BLI_Iterator *iter); void BKE_renderable_objects_iterator_end(BLI_Iterator *iter); +void BKE_view_layer_objects_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in); +void BKE_view_layer_objects_in_mode_iterator_next(BLI_Iterator *iter); +void BKE_view_layer_objects_in_mode_iterator_end(BLI_Iterator *iter); + void BKE_selected_bases_iterator_begin(BLI_Iterator *iter, void *data_in); void BKE_selected_bases_iterator_next(BLI_Iterator *iter); void BKE_selected_bases_iterator_end(BLI_Iterator *iter); @@ -217,6 +227,43 @@ void BKE_visible_bases_iterator_end(BLI_Iterator *iter); #define FOREACH_VISIBLE_OBJECT_END \ ITER_END + +#define FOREACH_BASE_IN_MODE_BEGIN(_view_layer, _object_mode, _instance) \ +{ \ + struct ObjectsInModeIteratorData data_ = { \ + .object_mode = _object_mode, \ + .view_layer = _view_layer, \ + .base_active = _view_layer->basact, \ + }; \ + ITER_BEGIN(BKE_view_layer_objects_in_mode_iterator_begin, \ + BKE_view_layer_objects_in_mode_iterator_next, \ + BKE_view_layer_objects_in_mode_iterator_end, \ + &data_, Base *, _instance) + +#define FOREACH_BASE_IN_MODE_END \ + ITER_END; \ +} ((void)0) + +#define FOREACH_BASE_IN_EDIT_MODE_BEGIN(_view_layer, _instance) \ + FOREACH_BASE_IN_MODE_BEGIN(_view_layer, OB_MODE_EDIT, _instance) + +#define FOREACH_BASE_IN_EDIT_MODE_END \ + FOREACH_BASE_IN_MODE_END + +#define FOREACH_OBJECT_IN_MODE_BEGIN(_view_layer, _object_mode, _instance) \ + FOREACH_BASE_IN_MODE_BEGIN(_view_layer, _object_mode, _base) { \ + Object *_instance = _base->object; + +#define FOREACH_OBJECT_IN_MODE_END \ + } FOREACH_BASE_IN_MODE_END + +#define FOREACH_OBJECT_IN_EDIT_MODE_BEGIN(_view_layer, _instance) \ + FOREACH_BASE_IN_EDIT_MODE_BEGIN(_view_layer, _base) { \ + Object *_instance = _base->object; + +#define FOREACH_OBJECT_IN_EDIT_MODE_END \ + } FOREACH_BASE_IN_EDIT_MODE_END + #define FOREACH_SELECTED_BASE_BEGIN(view_layer, _instance) \ ITER_BEGIN(BKE_selected_bases_iterator_begin, \ BKE_selected_bases_iterator_next, \ @@ -299,6 +346,70 @@ struct ObjectsRenderableIteratorData { ITER_END; \ } ((void)0) + +/* layer_utils.c */ + +struct ObjectsInModeParams { + int object_mode; + uint no_dup_data : 1; + + bool (*filter_fn)(struct Object *ob, void *user_data); + void *filter_userdata; +}; + +Base **BKE_view_layer_array_from_bases_in_mode_params( + struct ViewLayer *view_layer, uint *r_len, + const struct ObjectsInModeParams *params); + +struct Object **BKE_view_layer_array_from_objects_in_mode_params( + struct ViewLayer *view_layer, uint *len, + const struct ObjectsInModeParams *params); + +#define BKE_view_layer_array_from_objects_in_mode(view_layer, r_len, ...) \ + BKE_view_layer_array_from_objects_in_mode_params( \ + view_layer, r_len, \ + &(const struct ObjectsInModeParams)__VA_ARGS__) + +#define BKE_view_layer_array_from_bases_in_mode(view_layer, r_len, ...) \ + BKE_view_layer_array_from_bases_in_mode_params( \ + view_layer, r_len, \ + &(const struct ObjectsInModeParams)__VA_ARGS__) + +bool BKE_view_layer_filter_edit_mesh_has_uvs(struct Object *ob, void *user_data); +bool BKE_view_layer_filter_edit_mesh_has_edges(struct Object *ob, void *user_data); + +/* Utility macros that wrap common args (add more as needed). */ + +#define BKE_view_layer_array_from_objects_in_edit_mode(view_layer, r_len) \ + BKE_view_layer_array_from_objects_in_mode( \ + view_layer, r_len, { \ + .object_mode = OB_MODE_EDIT}); + +#define BKE_view_layer_array_from_bases_in_edit_mode(view_layer, r_len) \ + BKE_view_layer_array_from_bases_in_mode( \ + view_layer, r_len, { \ + .object_mode = OB_MODE_EDIT}); + +#define BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, r_len) \ + BKE_view_layer_array_from_objects_in_mode( \ + view_layer, r_len, { \ + .object_mode = OB_MODE_EDIT, \ + .no_dup_data = true}); + +#define BKE_view_layer_array_from_bases_in_edit_mode_unique_data(view_layer, r_len) \ + BKE_view_layer_array_from_bases_in_mode( \ + view_layer, r_len, { \ + .object_mode = OB_MODE_EDIT, \ + .no_dup_data = true}); + +#define BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, r_len) \ + BKE_view_layer_array_from_objects_in_mode( \ + view_layer, r_len, { \ + .object_mode = OB_MODE_EDIT, \ + .no_dup_data = true, \ + .filter_fn = BKE_view_layer_filter_edit_mesh_has_uvs}); + + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index aac43768acf..647af88d980 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -48,7 +48,7 @@ extern "C" { #endif -struct EvaluationContext; +struct Depsgraph; struct Library; struct MainLock; struct GHash; @@ -130,9 +130,6 @@ typedef struct Main { char id_tag_update[MAX_LIBARRAY]; - /* Evaluation context used by viewport */ - struct EvaluationContext *eval_ctx; - /* Must be generated, used and freed by same code - never assume this is valid data unless you know * when, who and how it was created. * Used by code doing a lot of remapping etc. at once to speed things up. */ diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 8b9fea071b0..976ee5b2691 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -32,7 +32,7 @@ * \ingroup bke */ -struct EvaluationContext; +struct Depsgraph; struct ImageUser; struct Image; struct ListBase; @@ -236,8 +236,8 @@ float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct Mas void BKE_mask_layer_evaluate_animation(struct MaskLayer *masklay, const float ctime); void BKE_mask_layer_evaluate_deform(struct MaskLayer *masklay, const float ctime); -void BKE_mask_eval_animation(struct EvaluationContext *eval_ctx, struct Mask *mask); -void BKE_mask_eval_update(struct EvaluationContext *eval_ctx, struct Mask *mask); +void BKE_mask_eval_animation(struct Depsgraph *depsgraph, struct Mask *mask); +void BKE_mask_eval_update(struct Depsgraph *depsgraph, struct Mask *mask); /* mask_rasterize.c */ struct MaskRasterHandle; diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index f4c98fc0aea..d57d0ea1a97 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -118,9 +118,9 @@ void paste_matcopybuf(struct Material *ma); /* Evaluation. */ -struct EvaluationContext; +struct Depsgraph; -void BKE_material_eval(const struct EvaluationContext *eval_ctx, struct Material *material); +void BKE_material_eval(struct Depsgraph *depsgraph, struct Material *material); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h index d4776d890d2..b05a35e614f 100644 --- a/source/blender/blenkernel/BKE_mball.h +++ b/source/blender/blenkernel/BKE_mball.h @@ -32,6 +32,7 @@ * \since March 2001 * \author nzc */ +struct Depsgraph; struct Main; struct MetaBall; struct Object; @@ -71,9 +72,9 @@ void BKE_mball_select_swap(struct MetaBall *mb); /* **** Depsgraph evaluation **** */ -struct EvaluationContext; +struct Depsgraph; -void BKE_mball_eval_geometry(const struct EvaluationContext *eval_ctx, +void BKE_mball_eval_geometry(struct Depsgraph *depsgraph, struct MetaBall *mball); /* Draw Cache */ diff --git a/source/blender/blenkernel/BKE_mball_tessellate.h b/source/blender/blenkernel/BKE_mball_tessellate.h index 40cdc80e280..df652df177d 100644 --- a/source/blender/blenkernel/BKE_mball_tessellate.h +++ b/source/blender/blenkernel/BKE_mball_tessellate.h @@ -23,12 +23,12 @@ /** \file BKE_mball_tessellate.h * \ingroup bke */ -struct EvaluationContext; +struct Depsgraph; struct Object; struct Scene; void BKE_mball_polygonize( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase); void BKE_mball_cubeTable_free(void); diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 79d72206903..e2265ae855e 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -34,8 +34,8 @@ struct ID; struct BMeshCreateParams; struct BoundBox; +struct Depsgraph; struct EdgeHash; -struct EvaluationContext; struct ListBase; struct LinkNode; struct BLI_Stack; @@ -119,7 +119,7 @@ void BKE_mesh_from_nurbs_displist( struct Object *ob, struct ListBase *dispbase, const bool use_orco_uv, const char *obdata_name); void BKE_mesh_from_nurbs(struct Object *ob); void BKE_mesh_to_curve_nurblist(struct DerivedMesh *dm, struct ListBase *nurblist, const int edge_users_test); -void BKE_mesh_to_curve(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); +void BKE_mesh_to_curve(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void BKE_mesh_material_index_remove(struct Mesh *me, short index); void BKE_mesh_material_index_clear(struct Mesh *me); void BKE_mesh_material_remap(struct Mesh *me, const unsigned int *remap, unsigned int remap_len); @@ -140,7 +140,7 @@ float (*BKE_mesh_vertexCos_get(const struct Mesh *me, int *r_numVerts))[3]; void BKE_mesh_split_faces(struct Mesh *mesh, bool free_loop_normals); -struct Mesh *BKE_mesh_new_from_object(const struct EvaluationContext *eval_ctx, struct Main *bmain, struct Scene *sce, struct Object *ob, +struct Mesh *BKE_mesh_new_from_object(struct Depsgraph *depsgraph, struct Main *bmain, struct Scene *sce, struct Object *ob, int apply_modifiers, int calc_tessface, int calc_undeformed); /* vertex level transformations & checks (no derived mesh) */ @@ -442,7 +442,7 @@ void BKE_mesh_calc_edges(struct Mesh *mesh, bool update, const bool select); /* **** Depsgraph evaluation **** */ -void BKE_mesh_eval_geometry(const struct EvaluationContext *eval_ctx, +void BKE_mesh_eval_geometry(struct Depsgraph *depsgraph, struct Mesh *mesh); /* Draw Cache */ diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 329defbc77c..c81c0f7c4c0 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -33,8 +33,8 @@ #include "BKE_customdata.h" struct ID; +struct Depsgraph; struct DerivedMesh; -struct EvaluationContext; struct Object; struct Scene; struct ViewLayer; @@ -163,25 +163,25 @@ typedef struct ModifierTypeInfo { * the object it can obtain it from the derivedData argument if non-NULL, * and otherwise the ob argument. */ - void (*deformVerts)(struct ModifierData *md, const struct EvaluationContext *eval_ctx, + void (*deformVerts)(struct ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, ModifierApplyFlag flag); /* Like deformMatricesEM but called from object mode (for supporting modifiers in sculpt mode) */ - void (*deformMatrices)(struct ModifierData *md, const struct EvaluationContext *eval_ctx, + void (*deformMatrices)(struct ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct DerivedMesh *derivedData, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts); /* Like deformVerts but called during editmode (for supporting modifiers) */ - void (*deformVertsEM)(struct ModifierData *md, const struct EvaluationContext *eval_ctx, + void (*deformVertsEM)(struct ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct BMEditMesh *editData, struct DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts); /* Set deform matrix per vertex for crazyspace correction */ - void (*deformMatricesEM)(struct ModifierData *md, const struct EvaluationContext *eval_ctx, + void (*deformMatricesEM)(struct ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct BMEditMesh *editData, struct DerivedMesh *derivedData, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts); @@ -207,7 +207,7 @@ typedef struct ModifierTypeInfo { * The modifier may reuse the derivedData argument (i.e. return it in * modified form), but must not release it. */ - struct DerivedMesh *(*applyModifier)(struct ModifierData *md, const struct EvaluationContext *eval_ctx, + struct DerivedMesh *(*applyModifier)(struct ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct DerivedMesh *derivedData, ModifierApplyFlag flag); @@ -218,7 +218,7 @@ typedef struct ModifierTypeInfo { * are expected from editmode objects. The same qualifications regarding * derivedData apply as for applyModifier. */ - struct DerivedMesh *(*applyModifierEM)(struct ModifierData *md, const struct EvaluationContext *eval_ctx, + struct DerivedMesh *(*applyModifierEM)(struct ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct BMEditMesh *editData, struct DerivedMesh *derivedData, ModifierApplyFlag flag); @@ -422,24 +422,24 @@ const char *modifier_path_relbase(struct Object *ob); /* wrappers for modifier callbacks */ struct DerivedMesh *modwrap_applyModifier( - ModifierData *md, const struct EvaluationContext *eval_ctx, + ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct DerivedMesh *dm, ModifierApplyFlag flag); struct DerivedMesh *modwrap_applyModifierEM( - ModifierData *md, const struct EvaluationContext *eval_ctx, + ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct BMEditMesh *em, struct DerivedMesh *dm, ModifierApplyFlag flag); void modwrap_deformVerts( - ModifierData *md, const struct EvaluationContext *eval_ctx, + ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts, ModifierApplyFlag flag); void modwrap_deformVertsEM( - ModifierData *md, const struct EvaluationContext *eval_ctx, struct Object *ob, + ModifierData *md, struct Depsgraph *depsgraph, struct Object *ob, struct BMEditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts); diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index 818f79ad8ac..5b5ebbf035c 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -32,7 +32,7 @@ * \author Sergey Sharybin */ -struct EvaluationContext; +struct Depsgraph; struct ImBuf; struct Main; struct MovieClip; @@ -85,7 +85,7 @@ bool BKE_movieclip_has_cached_frame(struct MovieClip *clip, struct MovieClipUser bool BKE_movieclip_put_frame_if_possible(struct MovieClip *clip, struct MovieClipUser *user, struct ImBuf *ibuf); /* Evaluaiton. */ -void BKE_movieclip_eval_update(struct EvaluationContext *eval_ctx, struct MovieClip *clip); +void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, struct MovieClip *clip); /* cacheing flags */ #define MOVIECLIP_CACHE_SKIP (1 << 0) diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h index 761bb7e8acb..10bc367e909 100644 --- a/source/blender/blenkernel/BKE_multires.h +++ b/source/blender/blenkernel/BKE_multires.h @@ -33,8 +33,8 @@ */ enum MultiresModifiedFlags; +struct Depsgraph; struct DerivedMesh; -struct EvaluationContext; struct MDisps; struct Mesh; struct ModifierData; @@ -81,18 +81,18 @@ struct DerivedMesh *multires_make_derived_from_derived(struct DerivedMesh *dm, struct MultiresModifierData *find_multires_modifier_before(struct Scene *scene, struct ModifierData *lastmd); struct MultiresModifierData *get_multires_modifier(struct Scene *scene, struct Object *ob, bool use_first); -struct DerivedMesh *get_multires_dm(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct MultiresModifierData *mmd, +struct DerivedMesh *get_multires_dm(struct Depsgraph *depsgraph, struct Scene *scene, struct MultiresModifierData *mmd, struct Object *ob); void multiresModifier_del_levels(struct MultiresModifierData *, struct Object *, int direction); void multiresModifier_base_apply(struct MultiresModifierData *mmd, struct Object *ob); void multiresModifier_subdivide(struct MultiresModifierData *mmd, struct Object *ob, int updateblock, int simple); void multiresModifier_sync_levels_ex( struct Object *ob_dst, struct MultiresModifierData *mmd_src, struct MultiresModifierData *mmd_dst); -int multiresModifier_reshape(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct MultiresModifierData *mmd, +int multiresModifier_reshape(struct Depsgraph *depsgraph, struct Scene *scene, struct MultiresModifierData *mmd, struct Object *dst, struct Object *src); -int multiresModifier_reshapeFromDM(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct MultiresModifierData *mmd, +int multiresModifier_reshapeFromDM(struct Depsgraph *depsgraph, struct Scene *scene, struct MultiresModifierData *mmd, struct Object *ob, struct DerivedMesh *srcdm); -int multiresModifier_reshapeFromDeformMod(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct MultiresModifierData *mmd, +int multiresModifier_reshapeFromDeformMod(struct Depsgraph *depsgraph, struct Scene *scene, struct MultiresModifierData *mmd, struct Object *ob, struct ModifierData *md); void multires_stitch_grids(struct Object *); @@ -110,8 +110,8 @@ void multires_free(struct Multires *mr); void multires_load_old(struct Object *ob, struct Mesh *me); void multires_load_old_250(struct Mesh *); -void multiresModifier_scale_disp(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); -void multiresModifier_prepare_join(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct Object *to_ob); +void multiresModifier_scale_disp(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); +void multiresModifier_prepare_join(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *to_ob); int multires_mdisp_corners(struct MDisps *s); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 6427a87a182..aa09e2fd5c3 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1060,12 +1060,12 @@ void free_nodesystem(void); /* -------------------------------------------------------------------- */ /* evaluation support, */ -struct EvaluationContext; +struct Depsgraph; void BKE_nodetree_copy_default_values(struct bNodeTree *ntree_dst, const struct bNodeTree *ntree_src); -void BKE_nodetree_shading_params_eval(const struct EvaluationContext *eval_ctx, +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 c698db2e8f5..d2d90801ade 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -36,7 +36,7 @@ extern "C" { #include "BLI_compiler_attrs.h" struct Base; -struct EvaluationContext; +struct Depsgraph; struct Scene; struct ViewLayer; struct Object; @@ -53,7 +53,7 @@ struct ModifierData; #include "DNA_object_enums.h" void BKE_object_workob_clear(struct Object *workob); -void BKE_object_workob_calc_parent(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct Object *workob); +void BKE_object_workob_calc_parent(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *workob); void BKE_object_transform_copy(struct Object *ob_tar, const struct Object *ob_src); struct SoftBody *copy_softbody(const struct SoftBody *sb, const int flag); @@ -83,7 +83,9 @@ void BKE_object_copy_proxy_drivers(struct Object *ob, struct Object *target); bool BKE_object_exists_check(const struct Object *obtest); bool BKE_object_is_in_editmode(const struct Object *ob); bool BKE_object_is_in_editmode_vgroup(const struct Object *ob); +bool BKE_object_is_in_editmode_and_selected(const struct Object *ob); bool BKE_object_is_in_wpaint_select_vert(const struct Object *ob); +bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode); typedef enum eObjectVisibilityCheck { OB_VISIBILITY_CHECK_FOR_VIEWPORT, @@ -144,14 +146,14 @@ void BKE_object_get_parent_matrix( struct Scene *scene, struct Object *ob, struct Object *par, float parentmat[4][4]); void BKE_object_where_is_calc( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void BKE_object_where_is_calc_ex( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct RigidBodyWorld *rbw, + struct Depsgraph *depsgraph, struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, float r_originmat[3][3]); void BKE_object_where_is_calc_time( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, float ctime); + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); void BKE_object_where_is_calc_time_ex( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, float ctime, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime, struct RigidBodyWorld *rbw, float r_originmat[3][3]); void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float obmat[4][4]); @@ -169,13 +171,15 @@ void BKE_object_empty_draw_type_set(struct Object *ob, const int value); void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set); void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden); bool BKE_object_minmax_dupli( - struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden); + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, + float r_min[3], float r_max[3], const bool use_hidden); /* sometimes min-max isn't enough, we need to loop over each point */ void BKE_object_foreach_display_point( struct Object *ob, float obmat[4][4], void (*func_cb)(const float[3], void *), void *user_data); void BKE_scene_foreach_display_point( + struct Depsgraph *depsgraph, struct Scene *scene, struct ViewLayer *view_layer, void (*func_cb)(const float[3], void *), void *user_data); @@ -205,60 +209,60 @@ void BKE_object_tfm_protected_restore( /* Dependency graph evaluation callbacks. */ void BKE_object_eval_local_transform( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Object *ob); void BKE_object_eval_parent( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void BKE_object_eval_constraints( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); -void BKE_object_eval_done(const struct EvaluationContext *eval_ctx, struct Object *ob); +void BKE_object_eval_done(struct Depsgraph *depsgraph, struct Object *ob); bool BKE_object_eval_proxy_copy( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Object *object); void BKE_object_eval_uber_transform( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Object *ob); void BKE_object_eval_uber_data( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void BKE_object_eval_cloth( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *object); void BKE_object_eval_transform_all( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *object); void BKE_object_eval_update_shading( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Object *object); void BKE_object_data_select_update( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct ID *object_data); void BKE_object_eval_flush_base_flags( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Object *object, int base_index, const bool is_from_set); void BKE_object_handle_data_update( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void BKE_object_handle_update( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void BKE_object_handle_update_ex( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct RigidBodyWorld *rbw, const bool do_proxy_update); @@ -314,7 +318,7 @@ struct KDTree *BKE_object_as_kdtree(struct Object *ob, int *r_tot); bool BKE_object_modifier_use_time(struct Object *ob, struct ModifierData *md); bool BKE_object_modifier_update_subframe( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, bool update_mesh, int parent_recursion, float frame, int type); #ifdef __cplusplus diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index fa67c07395d..717f4c4f6e8 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -58,7 +58,7 @@ struct StrokeCache; struct Tex; struct ImagePool; struct UnifiedPaintSettings; -struct EvaluationContext; +struct Depsgraph; enum eOverlayFlags; @@ -236,9 +236,8 @@ typedef struct SculptSession { struct MDeformVert *dvert_prev; } wpaint; - //struct { - //ToDo: identify sculpt-only fields - //} sculpt; + /* TODO: identify sculpt-only fields */ + // struct { ... } sculpt; } mode; int mode_type; @@ -252,7 +251,7 @@ void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss); void BKE_sculptsession_bm_to_me(struct Object *ob, bool reorder); void BKE_sculptsession_bm_to_me_for_render(struct Object *object); void BKE_sculpt_update_mesh_elements( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Sculpt *sd, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Sculpt *sd, struct Object *ob, bool need_pmap, bool need_mask); struct MultiresModifierData *BKE_sculpt_multires_active(struct Scene *scene, struct Object *ob); int BKE_sculpt_mask_layers_ensure(struct Object *ob, diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index 8cd76097401..05082ed1a70 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -63,7 +63,7 @@ struct RNG; struct BVHTreeRay; struct BVHTreeRayHit; struct EdgeHash; -struct EvaluationContext; +struct Depsgraph; struct ViewLayer; #define PARTICLE_COLLISION_MAX_COLLISIONS 10 @@ -80,7 +80,7 @@ struct ViewLayer; /* common stuff that many particle functions need */ typedef struct ParticleSimulationData { - const struct EvaluationContext *eval_ctx; + struct Depsgraph *depsgraph; struct Scene *scene; struct Object *ob; struct ParticleSystem *psys; @@ -341,9 +341,9 @@ void psys_reset(struct ParticleSystem *psys, int mode); void psys_find_parents(struct ParticleSimulationData *sim, const bool use_render_params); void psys_cache_paths(struct ParticleSimulationData *sim, float cfra, const bool use_render_params); -void psys_cache_edit_paths(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct PTCacheEdit *edit, float cfra, const bool use_render_params); +void psys_cache_edit_paths(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct PTCacheEdit *edit, float cfra, const bool use_render_params); void psys_cache_child_paths(struct ParticleSimulationData *sim, float cfra, const bool editupdate, const bool use_render_params); -int do_guides(const struct EvaluationContext *eval_ctx, struct ParticleSettings *part, struct ListBase *effectors, ParticleKey *state, int pa_num, float time); +int do_guides(struct Depsgraph *depsgraph, struct ParticleSettings *part, struct ListBase *effectors, ParticleKey *state, int pa_num, float time); void precalc_guides(struct ParticleSimulationData *sim, struct ListBase *effectors); float psys_get_timestep(struct ParticleSimulationData *sim); float psys_get_child_time(struct ParticleSystem *psys, struct ChildParticle *cpa, float cfra, float *birthtime, float *dietime); @@ -376,7 +376,7 @@ void psys_tasks_create(struct ParticleThreadContext *ctx, int startpart, int end void psys_tasks_free(struct ParticleTask *tasks, int numtasks); void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]); -void psys_apply_hair_lattice(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys); +void psys_apply_hair_lattice(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys); /* particle_system.c */ struct ParticleSystem *psys_get_target_system(struct Object *ob, struct ParticleTarget *pt); @@ -391,7 +391,7 @@ void psys_check_boid_data(struct ParticleSystem *psys); void psys_get_birth_coords(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, float dtime, float cfra); -void particle_system_update(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, const bool use_render_params); +void particle_system_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, const bool use_render_params); /* Callback format for performing operations on ID-pointers for particle systems */ typedef void (*ParticleSystemIDFunc)(struct ParticleSystem *psys, struct ID **idpoin, void *userdata, int cb_flag); @@ -454,9 +454,9 @@ float psys_get_current_display_percentage(struct ParticleSystem *psys, const boo /* **** Depsgraph evaluation **** */ -struct EvaluationContext; +struct Depsgraph; -void BKE_particle_system_eval_init(const struct EvaluationContext *eval_ctx, +void BKE_particle_system_eval_init(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h index 6aa43665427..016a531db95 100644 --- a/source/blender/blenkernel/BKE_rigidbody.h +++ b/source/blender/blenkernel/BKE_rigidbody.h @@ -37,7 +37,7 @@ struct RigidBodyWorld; struct RigidBodyOb; -struct EvaluationContext; +struct Depsgraph; struct Scene; struct Object; @@ -100,19 +100,19 @@ void BKE_rigidbody_aftertrans_update(struct Object *ob, float loc[3], float rot[ void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime); bool BKE_rigidbody_check_sim_running(struct RigidBodyWorld *rbw, float ctime); void BKE_rigidbody_cache_reset(struct RigidBodyWorld *rbw); -void BKE_rigidbody_rebuild_world(const struct EvaluationContext *eval_ctx, struct Scene *scene, float ctime); -void BKE_rigidbody_do_simulation(const struct EvaluationContext *eval_ctx, struct Scene *scene, float ctime); +void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, struct Scene *scene, float ctime); +void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, struct Scene *scene, float ctime); /* -------------------- */ /* Depsgraph evaluation */ -void BKE_rigidbody_rebuild_sim(const struct EvaluationContext *eval_ctx, +void BKE_rigidbody_rebuild_sim(struct Depsgraph *depsgraph, struct Scene *scene); -void BKE_rigidbody_eval_simulation(const struct EvaluationContext *eval_ctx, +void BKE_rigidbody_eval_simulation(struct Depsgraph *depsgraph, struct Scene *scene); -void BKE_rigidbody_object_sync_transforms(const struct EvaluationContext *eval_ctx, +void BKE_rigidbody_object_sync_transforms(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 4a97cb763dc..8c7c3fb15de 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -39,7 +39,6 @@ extern "C" { struct AviCodecData; struct Depsgraph; -struct EvaluationContext; struct Main; struct Object; struct RenderData; @@ -100,7 +99,7 @@ typedef struct SceneBaseIter { } SceneBaseIter; int BKE_scene_base_iter_next( - const struct EvaluationContext *eval_ctx, struct SceneBaseIter *iter, + struct Depsgraph *depsgraph, struct SceneBaseIter *iter, struct Scene **scene, int val, struct Base **base, struct Object **ob); void BKE_scene_base_flag_to_objects(struct ViewLayer *view_layer); diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index fd6b3d20fb7..984e3fb2a03 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -41,6 +41,7 @@ struct Menu; struct Panel; struct Scene; struct ScrArea; +struct ScrVert; struct SpaceType; struct TransformOrientation; struct View3D; @@ -338,5 +339,12 @@ float BKE_screen_view3d_zoom_from_fac(float zoomfac); void BKE_screen_free(struct bScreen *sc); unsigned int BKE_screen_visible_layers(struct bScreen *screen, struct Scene *scene); +struct ScrEdge *BKE_screen_find_edge(struct bScreen *sc, struct ScrVert *v1, struct ScrVert *v2); +void BKE_screen_sort_scrvert(struct ScrVert **v1, struct ScrVert **v2); +void BKE_screen_remove_double_scrverts(struct bScreen *sc); +void BKE_screen_remove_double_scredges(struct bScreen *sc); +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_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 21f3f344e64..1a0e61b0dd6 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -31,7 +31,7 @@ */ struct bContext; -struct EvaluationContext; +struct Depsgraph; struct StripColorBalance; struct Editing; struct GSet; @@ -93,12 +93,12 @@ void BKE_sequence_iterator_end(SeqIterator *iter); } typedef struct SeqRenderData { - struct EvaluationContext *eval_ctx; struct Main *bmain; struct Scene *scene; int rectx; int recty; int preview_render_size; + int for_render; int motion_blur_samples; float motion_blur_shutter; bool skip_cache; @@ -113,8 +113,9 @@ typedef struct SeqRenderData { } SeqRenderData; void BKE_sequencer_new_render_data( - struct EvaluationContext *eval_ctx, struct Main *bmain, struct Scene *scene, + struct Main *bmain, struct Scene *scene, int rectx, int recty, int preview_render_size, + int for_render, SeqRenderData *r_context); int BKE_sequencer_cmp_time_startdisp(const void *a, const void *b); @@ -435,7 +436,7 @@ enum { }; typedef struct ImBuf *(*SequencerDrawView)( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct ViewLayer *view_layer, struct RenderEngineType *engine_type, struct Object *camera, int width, int height, unsigned int flag, unsigned int draw_flags, int drawtype, int alpha_mode, diff --git a/source/blender/blenkernel/BKE_smoke.h b/source/blender/blenkernel/BKE_smoke.h index 64d70e8e209..82bfe56b0ab 100644 --- a/source/blender/blenkernel/BKE_smoke.h +++ b/source/blender/blenkernel/BKE_smoke.h @@ -35,7 +35,7 @@ typedef float (*bresenham_callback)(float *result, float *input, int res[3], int *pixel, float *tRay, float correct); -struct DerivedMesh *smokeModifier_do(struct SmokeModifierData *smd, const struct EvaluationContext *eval_ctx, +struct DerivedMesh *smokeModifier_do(struct SmokeModifierData *smd, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm); diff --git a/source/blender/blenkernel/BKE_softbody.h b/source/blender/blenkernel/BKE_softbody.h index e2255bdb779..c7bf876a414 100644 --- a/source/blender/blenkernel/BKE_softbody.h +++ b/source/blender/blenkernel/BKE_softbody.h @@ -31,10 +31,10 @@ * \ingroup bke */ +struct Depsgraph; struct Object; struct Scene; struct SoftBody; -struct EvaluationContext; typedef struct BodyPoint { float origS[3], origE[3], origT[3], pos[3], vec[3], force[3]; @@ -60,7 +60,7 @@ extern void sbFree(struct SoftBody *sb); extern void sbFreeSimulation(struct SoftBody *sb); /* do one simul step, reading and writing vertex locs from given array */ -extern void sbObjectStep(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, +extern void sbObjectStep(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float framnr, float (*vertexCos)[3], int numVerts); /* makes totally fresh start situation, resets time */ diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index 5da87de1cc9..13302caa09d 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -47,7 +47,6 @@ struct MovieDistortion; struct Camera; struct Object; struct Scene; -struct EvaluationContext; struct rcti; /* **** Common functions **** */ diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h index 32a9bcbec61..c4de9d134b7 100644 --- a/source/blender/blenkernel/BKE_workspace.h +++ b/source/blender/blenkernel/BKE_workspace.h @@ -28,7 +28,6 @@ #include "BLI_compiler_attrs.h" struct bScreen; -struct EvaluationContext; struct Main; struct Scene; struct TransformOrientation; diff --git a/source/blender/blenkernel/BKE_world.h b/source/blender/blenkernel/BKE_world.h index b45d7a7e6ec..fe8aa8694af 100644 --- a/source/blender/blenkernel/BKE_world.h +++ b/source/blender/blenkernel/BKE_world.h @@ -46,9 +46,9 @@ void BKE_world_make_local(struct Main *bmain, struct World *wrld, const bool lib /* Evaluation. */ -struct EvaluationContext; +struct Depsgraph; -void BKE_world_eval(const struct EvaluationContext *eval_ctx, struct World *world); +void BKE_world_eval(struct Depsgraph *depsgraph, struct World *world); #endif diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 6a1c3ea883c..e8fd71c2b2d 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -167,6 +167,7 @@ set(SRC intern/pointcache.c intern/property.c intern/layer.c + intern/layer_utils.c intern/lightprobe.c intern/report.c intern/rigidbody.c diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 916e11dbd46..132f247f0a1 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1148,7 +1148,7 @@ DerivedMesh *mesh_create_derived(Mesh *me, float (*vertCos)[3]) } DerivedMesh *mesh_create_derived_for_modifier( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md, int build_shapekey_layers) { Mesh *me = ob->data; @@ -1174,7 +1174,7 @@ DerivedMesh *mesh_create_derived_for_modifier( int numVerts; float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, &numVerts); - modwrap_deformVerts(md, eval_ctx, ob, NULL, deformedVerts, numVerts, 0); + modwrap_deformVerts(md, depsgraph, ob, NULL, deformedVerts, numVerts, 0); dm = mesh_create_derived(me, deformedVerts); if (build_shapekey_layers) @@ -1188,7 +1188,7 @@ DerivedMesh *mesh_create_derived_for_modifier( if (build_shapekey_layers) add_shapekey_layers(tdm, me, ob); - dm = modwrap_applyModifier(md, eval_ctx, ob, tdm, 0); + dm = modwrap_applyModifier(md, depsgraph, ob, tdm, 0); ASSERT_IS_VALID_DM(dm); if (tdm != dm) tdm->release(tdm); @@ -1753,7 +1753,7 @@ static void dm_ensure_display_normals(DerivedMesh *dm) * - apply deform modifiers and input vertexco */ static void mesh_calc_modifiers( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float (*inputVertexCos)[3], + struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*inputVertexCos)[3], const bool useRenderParams, int useDeform, const bool need_mapping, CustomDataMask dataMask, const int index, const bool useCache, const bool build_shapekey_layers, @@ -1864,7 +1864,7 @@ static void mesh_calc_modifiers( if (!deformedVerts) deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts); - modwrap_deformVerts(md, eval_ctx, ob, NULL, deformedVerts, numVerts, deform_app_flags); + modwrap_deformVerts(md, depsgraph, ob, NULL, deformedVerts, numVerts, deform_app_flags); } else { break; @@ -2005,7 +2005,7 @@ static void mesh_calc_modifiers( } } - modwrap_deformVerts(md, eval_ctx, ob, dm, deformedVerts, numVerts, deform_app_flags); + modwrap_deformVerts(md, depsgraph, ob, dm, deformedVerts, numVerts, deform_app_flags); } else { DerivedMesh *ndm; @@ -2080,7 +2080,7 @@ static void mesh_calc_modifiers( } } - ndm = modwrap_applyModifier(md, eval_ctx, ob, dm, app_flags); + ndm = modwrap_applyModifier(md, depsgraph, ob, dm, app_flags); ASSERT_IS_VALID_DM(ndm); if (ndm) { @@ -2107,7 +2107,7 @@ static void mesh_calc_modifiers( (mti->requiredDataMask ? mti->requiredDataMask(ob, md) : 0)); - ndm = modwrap_applyModifier(md, eval_ctx, ob, orcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO); + ndm = modwrap_applyModifier(md, depsgraph, ob, orcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO); ASSERT_IS_VALID_DM(ndm); if (ndm) { @@ -2125,7 +2125,7 @@ static void mesh_calc_modifiers( nextmask &= ~CD_MASK_CLOTH_ORCO; DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX); - ndm = modwrap_applyModifier(md, eval_ctx, ob, clothorcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO); + ndm = modwrap_applyModifier(md, depsgraph, ob, clothorcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO); ASSERT_IS_VALID_DM(ndm); if (ndm) { @@ -2308,7 +2308,7 @@ bool editbmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh * } static void editbmesh_calc_modifiers( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, BMEditMesh *em, CustomDataMask dataMask, /* return args */ DerivedMesh **r_cage, DerivedMesh **r_final) @@ -2396,9 +2396,9 @@ static void editbmesh_calc_modifiers( } if (mti->deformVertsEM) - modwrap_deformVertsEM(md, eval_ctx, ob, em, dm, deformedVerts, numVerts); + modwrap_deformVertsEM(md, depsgraph, ob, em, dm, deformedVerts, numVerts); else - modwrap_deformVerts(md, eval_ctx, ob, dm, deformedVerts, numVerts, 0); + modwrap_deformVerts(md, depsgraph, ob, dm, deformedVerts, numVerts, 0); } else { DerivedMesh *ndm; @@ -2443,10 +2443,10 @@ static void editbmesh_calc_modifiers( DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX); if (mti->applyModifierEM) { - ndm = modwrap_applyModifierEM(md, eval_ctx, ob, em, orcodm, MOD_APPLY_ORCO); + ndm = modwrap_applyModifierEM(md, depsgraph, ob, em, orcodm, MOD_APPLY_ORCO); } else { - ndm = modwrap_applyModifier(md, eval_ctx, ob, orcodm, MOD_APPLY_ORCO); + ndm = modwrap_applyModifier(md, depsgraph, ob, orcodm, MOD_APPLY_ORCO); } ASSERT_IS_VALID_DM(ndm); @@ -2471,9 +2471,9 @@ static void editbmesh_calc_modifiers( } if (mti->applyModifierEM) - ndm = modwrap_applyModifierEM(md, eval_ctx, ob, em, dm, MOD_APPLY_USECACHE | MOD_APPLY_ALLOW_GPU); + ndm = modwrap_applyModifierEM(md, depsgraph, ob, em, dm, MOD_APPLY_USECACHE | MOD_APPLY_ALLOW_GPU); else - ndm = modwrap_applyModifier(md, eval_ctx, ob, dm, MOD_APPLY_USECACHE | MOD_APPLY_ALLOW_GPU); + ndm = modwrap_applyModifier(md, depsgraph, ob, dm, MOD_APPLY_USECACHE | MOD_APPLY_ALLOW_GPU); ASSERT_IS_VALID_DM(ndm); if (ndm) { @@ -2609,7 +2609,7 @@ static void editbmesh_calc_modifiers( * we'll be using GPU backend of OpenSubdiv. This is so * playback performance is kept as high as possible. */ -static bool calc_modifiers_skip_orco(const EvaluationContext *eval_ctx, +static bool calc_modifiers_skip_orco(Depsgraph *depsgraph, Scene *scene, Object *ob, bool use_render_params) @@ -2626,7 +2626,7 @@ static bool calc_modifiers_skip_orco(const EvaluationContext *eval_ctx, else if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) { return false; } - else if ((DEG_get_eval_flags_for_id(eval_ctx->depsgraph, &ob->id) & DAG_EVAL_NEED_CPU) != 0) { + else if ((DEG_get_eval_flags_for_id(depsgraph, &ob->id) & DAG_EVAL_NEED_CPU) != 0) { return false; } SubsurfModifierData *smd = (SubsurfModifierData *)last_md; @@ -2638,7 +2638,7 @@ static bool calc_modifiers_skip_orco(const EvaluationContext *eval_ctx, #endif static void mesh_build_data( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, CustomDataMask dataMask, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask, const bool build_shapekey_layers, const bool need_mapping) { BLI_assert(ob->type == OB_MESH); @@ -2647,13 +2647,13 @@ static void mesh_build_data( BKE_object_sculpt_modifiers_changed(ob); #ifdef WITH_OPENSUBDIV - if (calc_modifiers_skip_orco(eval_ctx, scene, ob, false)) { + if (calc_modifiers_skip_orco(depsgraph, scene, ob, false)) { dataMask &= ~(CD_MASK_ORCO | CD_MASK_PREVIEW_MCOL); } #endif mesh_calc_modifiers( - eval_ctx, scene, ob, NULL, false, 1, need_mapping, dataMask, -1, true, build_shapekey_layers, + depsgraph, scene, ob, NULL, false, 1, need_mapping, dataMask, -1, true, build_shapekey_layers, true, &ob->derivedDeform, &ob->derivedFinal); @@ -2668,14 +2668,14 @@ static void mesh_build_data( /* create PBVH immediately (would be created on the fly too, * but this avoids waiting on first stroke) */ - BKE_sculpt_update_mesh_elements(eval_ctx, scene, scene->toolsettings->sculpt, ob, false, false); + BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, false, false); } BLI_assert(!(ob->derivedFinal->dirty & DM_DIRTY_NORMALS)); } static void editbmesh_build_data( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask) { BKE_object_free_derived_caches(obedit); @@ -2684,13 +2684,13 @@ static void editbmesh_build_data( BKE_editmesh_free_derivedmesh(em); #ifdef WITH_OPENSUBDIV - if (calc_modifiers_skip_orco(eval_ctx, scene, obedit, false)) { + if (calc_modifiers_skip_orco(depsgraph, scene, obedit, false)) { dataMask &= ~(CD_MASK_ORCO | CD_MASK_PREVIEW_MCOL); } #endif editbmesh_calc_modifiers( - eval_ctx, scene, obedit, em, dataMask, + depsgraph, scene, obedit, em, dataMask, &em->derivedCage, &em->derivedFinal); DM_set_object_boundbox(obedit, em->derivedFinal); @@ -2702,10 +2702,9 @@ static void editbmesh_build_data( BLI_assert(!(em->derivedFinal->dirty & DM_DIRTY_NORMALS)); } -static CustomDataMask object_get_datamask(const Scene *scene, Object *ob, bool *r_need_mapping) +static CustomDataMask object_get_datamask(const Depsgraph *depsgraph, Object *ob, bool *r_need_mapping) { - /* TODO(sergey): Avoid this linear list lookup. */ - ViewLayer *view_layer = BKE_view_layer_context_active_PLACEHOLDER(scene); + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); Object *actob = view_layer->basact ? view_layer->basact->object : NULL; CustomDataMask mask = ob->customdata_mask; @@ -2743,85 +2742,85 @@ static CustomDataMask object_get_datamask(const Scene *scene, Object *ob, bool * } void makeDerivedMesh( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, BMEditMesh *em, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, BMEditMesh *em, CustomDataMask dataMask, const bool build_shapekey_layers) { bool need_mapping; - dataMask |= object_get_datamask(scene, ob, &need_mapping); + dataMask |= object_get_datamask(depsgraph, ob, &need_mapping); if (em) { - editbmesh_build_data(eval_ctx, scene, ob, em, dataMask); + editbmesh_build_data(depsgraph, scene, ob, em, dataMask); } else { - mesh_build_data(eval_ctx, scene, ob, dataMask, build_shapekey_layers, need_mapping); + mesh_build_data(depsgraph, scene, ob, dataMask, build_shapekey_layers, need_mapping); } } /***/ DerivedMesh *mesh_get_derived_final( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, CustomDataMask dataMask) + struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask) { /* if there's no derived mesh or the last data mask used doesn't include * the data we need, rebuild the derived mesh */ bool need_mapping; - dataMask |= object_get_datamask(scene, ob, &need_mapping); + dataMask |= object_get_datamask(depsgraph, ob, &need_mapping); if (!ob->derivedFinal || ((dataMask & ob->lastDataMask) != dataMask) || (need_mapping != ob->lastNeedMapping)) { - mesh_build_data(eval_ctx, scene, ob, dataMask, false, need_mapping); + mesh_build_data(depsgraph, scene, ob, dataMask, false, need_mapping); } if (ob->derivedFinal) { BLI_assert(!(ob->derivedFinal->dirty & DM_DIRTY_NORMALS)); } return ob->derivedFinal; } -DerivedMesh *mesh_get_derived_deform(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, CustomDataMask dataMask) +DerivedMesh *mesh_get_derived_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 * the data we need, rebuild the derived mesh */ bool need_mapping; - dataMask |= object_get_datamask(scene, ob, &need_mapping); + dataMask |= object_get_datamask(depsgraph, ob, &need_mapping); if (!ob->derivedDeform || ((dataMask & ob->lastDataMask) != dataMask) || (need_mapping != ob->lastNeedMapping)) { - mesh_build_data(eval_ctx, scene, ob, dataMask, false, need_mapping); + mesh_build_data(depsgraph, scene, ob, dataMask, false, need_mapping); } return ob->derivedDeform; } -DerivedMesh *mesh_create_derived_render(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, CustomDataMask dataMask) +DerivedMesh *mesh_create_derived_render(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask) { DerivedMesh *final; mesh_calc_modifiers( - eval_ctx, scene, ob, NULL, true, 1, false, dataMask, -1, false, false, false, + depsgraph, scene, ob, NULL, true, 1, false, dataMask, -1, false, false, false, NULL, &final); return final; } -DerivedMesh *mesh_create_derived_index_render(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, CustomDataMask dataMask, int index) +DerivedMesh *mesh_create_derived_index_render(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask, int index) { DerivedMesh *final; mesh_calc_modifiers( - eval_ctx, scene, ob, NULL, true, 1, false, dataMask, index, false, false, false, + depsgraph, scene, ob, NULL, true, 1, false, dataMask, index, false, false, false, NULL, &final); return final; } DerivedMesh *mesh_create_derived_view( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask) { DerivedMesh *final; @@ -2833,7 +2832,7 @@ DerivedMesh *mesh_create_derived_view( ob->transflag |= OB_NO_PSYS_UPDATE; mesh_calc_modifiers( - eval_ctx, scene, ob, NULL, false, 1, false, dataMask, -1, false, false, false, + depsgraph, scene, ob, NULL, false, 1, false, dataMask, -1, false, false, false, NULL, &final); ob->transflag &= ~OB_NO_PSYS_UPDATE; @@ -2842,53 +2841,53 @@ DerivedMesh *mesh_create_derived_view( } DerivedMesh *mesh_create_derived_no_deform( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*vertCos)[3], CustomDataMask dataMask) { DerivedMesh *final; mesh_calc_modifiers( - eval_ctx, scene, ob, vertCos, false, 0, false, dataMask, -1, false, false, false, + depsgraph, scene, ob, vertCos, false, 0, false, dataMask, -1, false, false, false, NULL, &final); return final; } DerivedMesh *mesh_create_derived_no_virtual( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*vertCos)[3], CustomDataMask dataMask) { DerivedMesh *final; mesh_calc_modifiers( - eval_ctx, scene, ob, vertCos, false, -1, false, dataMask, -1, false, false, false, + depsgraph, scene, ob, vertCos, false, -1, false, dataMask, -1, false, false, false, NULL, &final); return final; } DerivedMesh *mesh_create_derived_physics( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*vertCos)[3], CustomDataMask dataMask) { DerivedMesh *final; mesh_calc_modifiers( - eval_ctx, scene, ob, vertCos, false, -1, true, dataMask, -1, false, false, false, + depsgraph, scene, ob, vertCos, false, -1, true, dataMask, -1, false, false, false, NULL, &final); return final; } DerivedMesh *mesh_create_derived_no_deform_render( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*vertCos)[3], CustomDataMask dataMask) { DerivedMesh *final; mesh_calc_modifiers( - eval_ctx, scene, ob, vertCos, true, 0, false, dataMask, -1, false, false, false, + depsgraph, scene, ob, vertCos, true, 0, false, dataMask, -1, false, false, false, NULL, &final); return final; @@ -2897,7 +2896,7 @@ DerivedMesh *mesh_create_derived_no_deform_render( /***/ DerivedMesh *editbmesh_get_derived_cage_and_final( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *obedit, BMEditMesh *em, + struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask, /* return args */ DerivedMesh **r_final) @@ -2905,12 +2904,12 @@ DerivedMesh *editbmesh_get_derived_cage_and_final( /* if there's no derived mesh or the last data mask used doesn't include * the data we need, rebuild the derived mesh */ - dataMask |= object_get_datamask(scene, obedit, NULL); + dataMask |= object_get_datamask(depsgraph, obedit, NULL); if (!em->derivedCage || (em->lastDataMask & dataMask) != dataMask) { - editbmesh_build_data(eval_ctx, scene, obedit, em, dataMask); + editbmesh_build_data(depsgraph, scene, obedit, em, dataMask); } *r_final = em->derivedFinal; @@ -2919,18 +2918,18 @@ DerivedMesh *editbmesh_get_derived_cage_and_final( } DerivedMesh *editbmesh_get_derived_cage( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *obedit, BMEditMesh *em, + struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask) { /* if there's no derived mesh or the last data mask used doesn't include * the data we need, rebuild the derived mesh */ - dataMask |= object_get_datamask(scene, obedit, NULL); + dataMask |= object_get_datamask(depsgraph, obedit, NULL); if (!em->derivedCage || (em->lastDataMask & dataMask) != dataMask) { - editbmesh_build_data(eval_ctx, scene, obedit, em, dataMask); + editbmesh_build_data(depsgraph, scene, obedit, em, dataMask); } return em->derivedCage; diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 0b964145c7f..1541d39938d 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -340,7 +340,7 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets) * - recalc: whether we need to */ /* TODO: include reports pointer? */ - void animviz_calc_motionpaths(EvaluationContext *eval_ctx, Main *bmain, Scene *scene, ListBase *targets) + void animviz_calc_motionpaths(Depsgraph *depsgraph, Main *bmain, Scene *scene, ListBase *targets) { MPathTarget *mpt; int sfra, efra; @@ -367,7 +367,7 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets) /* calculate path over requested range */ for (CFRA = sfra; CFRA <= efra; CFRA++) { /* update relevant data for new frame */ - motionpaths_calc_update_scene(bmain, eval_ctx->depsgraph); + motionpaths_calc_update_scene(bmain, depsgraph); /* perform baking for targets */ motionpaths_calc_bake_targets(scene, targets); @@ -375,7 +375,7 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets) /* reset original environment */ CFRA = cfra; - motionpaths_calc_update_scene(bmain, eval_ctx->depsgraph); + motionpaths_calc_update_scene(bmain, depsgraph); /* clear recalc flags from targets */ for (mpt = targets->first; mpt; mpt = mpt->next) { diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index ecdb180d2ed..aa8fd6f3870 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -70,6 +70,7 @@ #include "BKE_texture.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "RNA_access.h" @@ -77,8 +78,6 @@ #include "atomic_ops.h" -#include "DEG_depsgraph.h" - /* ***************************************** */ /* AnimData API */ @@ -2881,14 +2880,15 @@ void BKE_animsys_evaluate_all_animation(Main *main, Scene *scene, float ctime) /* ************** */ /* Evaluation API */ -void BKE_animsys_eval_animdata(const EvaluationContext *eval_ctx, ID *id) +void BKE_animsys_eval_animdata(Depsgraph *depsgraph, ID *id) { + float ctime = DEG_get_ctime(depsgraph); AnimData *adt = BKE_animdata_from_id(id); Scene *scene = NULL; /* XXX: this is only needed for flushing RNA updates, * which should get handled as part of the dependency graph instead... */ - DEG_debug_print_eval_time(__func__, id->name, id, eval_ctx->ctime); - BKE_animsys_evaluate_animdata(scene, id, adt, eval_ctx->ctime, ADT_RECALC_ANIM); + DEG_debug_print_eval_time(__func__, id->name, id, ctime); + BKE_animsys_evaluate_animdata(scene, id, adt, ctime, ADT_RECALC_ANIM); } /* TODO(sergey): This is slow lookup of driver from CoW datablock. @@ -2909,7 +2909,7 @@ static FCurve *find_driver_from_evaluated_id(ID *id, FCurve *fcu) return BLI_findlink(&adt_cow->drivers, fcu_index); } -void BKE_animsys_eval_driver(const EvaluationContext *eval_ctx, +void BKE_animsys_eval_driver(Depsgraph *depsgraph, ID *id, FCurve *fcu) { @@ -2937,7 +2937,8 @@ void BKE_animsys_eval_driver(const EvaluationContext *eval_ctx, PathResolvedRNA anim_rna; if (animsys_store_rna_setting(&id_ptr, NULL, fcu->rna_path, fcu->array_index, &anim_rna)) { - const float curval = calculate_fcurve(&anim_rna, fcu, eval_ctx->ctime); + const float ctime = DEG_get_ctime(depsgraph); + const float curval = calculate_fcurve(&anim_rna, fcu, ctime); ok = animsys_write_rna_setting(&anim_rna, curval); } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 0a8c97ff175..6daaa10f227 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1462,13 +1462,13 @@ void BKE_armature_loc_pose_to_bone(bPoseChannel *pchan, const float inloc[3], fl copy_v3_v3(outloc, nLocMat[3]); } -void BKE_armature_mat_pose_to_bone_ex(const struct EvaluationContext *eval_ctx, Object *ob, bPoseChannel *pchan, float inmat[4][4], float outmat[4][4]) +void BKE_armature_mat_pose_to_bone_ex(struct Depsgraph *depsgraph, Object *ob, bPoseChannel *pchan, float inmat[4][4], float outmat[4][4]) { bPoseChannel work_pchan = *pchan; /* recalculate pose matrix with only parent transformations, * bone loc/sca/rot is ignored, scene and frame are not used. */ - BKE_pose_where_is_bone(eval_ctx, NULL, ob, &work_pchan, 0.0f, false); + BKE_pose_where_is_bone(depsgraph, NULL, ob, &work_pchan, 0.0f, false); /* find the matrix, need to remove the bone transforms first so this is * calculated as a matrix to set rather then a difference ontop of whats @@ -2196,7 +2196,7 @@ void BKE_pose_where_is_bone_tail(bPoseChannel *pchan) * 'do_extra': when zero skips loc/size/rot, constraints and strip modifiers. */ void BKE_pose_where_is_bone( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, bool do_extra) { /* This gives a chan_mat with actions (ipos) results. */ @@ -2236,7 +2236,7 @@ void BKE_pose_where_is_bone( cob = BKE_constraints_make_evalob(scene, ob, pchan, CONSTRAINT_OBTYPE_BONE); /* Solve PoseChannel's Constraints */ - BKE_constraints_solve(eval_ctx, &pchan->constraints, cob, ctime); /* ctime doesnt alter objects */ + BKE_constraints_solve(depsgraph, &pchan->constraints, cob, ctime); /* ctime doesnt alter objects */ /* cleanup after Constraint Solving * - applies matrix back to pchan, and frees temporary struct used @@ -2258,7 +2258,7 @@ void BKE_pose_where_is_bone( /* This only reads anim data from channels, and writes to channels */ /* This is the only function adding poses */ -void BKE_pose_where_is(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob) +void BKE_pose_where_is(struct Depsgraph *depsgraph, Scene *scene, Object *ob) { bArmature *arm; Bone *bone; @@ -2297,7 +2297,7 @@ void BKE_pose_where_is(const struct EvaluationContext *eval_ctx, Scene *scene, O } /* 2a. construct the IK tree (standard IK) */ - BIK_initialize_tree(eval_ctx, scene, ob, ctime); + BIK_initialize_tree(depsgraph, scene, ob, ctime); /* 2b. construct the Spline IK trees * - this is not integrated as an IK plugin, since it should be able @@ -2309,15 +2309,15 @@ void BKE_pose_where_is(const struct EvaluationContext *eval_ctx, Scene *scene, O for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { /* 4a. if we find an IK root, we handle it separated */ if (pchan->flag & POSE_IKTREE) { - BIK_execute_tree(eval_ctx, scene, ob, pchan, ctime); + BIK_execute_tree(depsgraph, scene, ob, pchan, ctime); } /* 4b. if we find a Spline IK root, we handle it separated too */ else if (pchan->flag & POSE_IKSPLINE) { - BKE_splineik_execute_tree(eval_ctx, scene, ob, pchan, ctime); + BKE_splineik_execute_tree(depsgraph, scene, ob, pchan, ctime); } /* 5. otherwise just call the normal solver */ else if (!(pchan->flag & POSE_DONE)) { - BKE_pose_where_is_bone(eval_ctx, scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1); } } /* 6. release the IK tree */ diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c index 29baaff32ba..e626ed42062 100644 --- a/source/blender/blenkernel/intern/armature_update.c +++ b/source/blender/blenkernel/intern/armature_update.c @@ -116,7 +116,7 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos #if 0 /* only happens on reload file, but violates depsgraph still... fix! */ if (ELEM(NULL, ikData->tar->curve_cache, ikData->tar->curve_cache->path, ikData->tar->curve_cache->path->data)) { - BKE_displist_make_curveTypes(eval_ctx, scene, ikData->tar, 0); + BKE_displist_make_curveTypes(depsgraph, scene, ikData->tar, 0); /* path building may fail in EditMode after removing verts [#33268]*/ if (ELEM(NULL, ikData->tar->curve_cache->path, ikData->tar->curve_cache->path->data)) { @@ -266,7 +266,7 @@ static void splineik_init_tree(Scene *scene, Object *ob, float UNUSED(ctime)) /* Evaluate spline IK for a given bone */ static void splineik_evaluate_bone( - const struct EvaluationContext *eval_ctx, tSplineIK_Tree *tree, Scene *scene, Object *ob, bPoseChannel *pchan, + struct Depsgraph *depsgraph, tSplineIK_Tree *tree, Scene *scene, Object *ob, bPoseChannel *pchan, int index, float ctime) { bSplineIKConstraint *ikData = tree->ikData; @@ -274,7 +274,7 @@ static void splineik_evaluate_bone( float splineVec[3], scaleFac, radius = 1.0f; /* firstly, calculate the bone matrix the standard way, since this is needed for roll control */ - BKE_pose_where_is_bone(eval_ctx, scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1); copy_v3_v3(poseHead, pchan->pose_head); copy_v3_v3(poseTail, pchan->pose_tail); @@ -516,7 +516,7 @@ static void splineik_evaluate_bone( } /* Evaluate the chain starting from the nominated bone */ -static void splineik_execute_tree(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) +static void splineik_execute_tree(struct Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) { tSplineIK_Tree *tree; @@ -530,7 +530,7 @@ static void splineik_execute_tree(const struct EvaluationContext *eval_ctx, Scen */ for (i = tree->chainlen - 1; i >= 0; i--) { bPoseChannel *pchan = tree->chain[i]; - splineik_evaluate_bone(eval_ctx, tree, scene, ob, pchan, i, ctime); + splineik_evaluate_bone(depsgraph, tree, scene, ob, pchan, i, ctime); } /* free the tree info specific to SplineIK trees now */ @@ -550,10 +550,10 @@ void BKE_pose_splineik_init_tree(Scene *scene, Object *ob, float ctime) } void BKE_splineik_execute_tree( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) { - splineik_execute_tree(eval_ctx, scene, ob, pchan_root, ctime); + splineik_execute_tree(depsgraph, scene, ob, pchan_root, ctime); } /* *************** Depsgraph evaluation callbacks ************ */ @@ -567,7 +567,7 @@ BLI_INLINE bPoseChannel *pose_pchan_get_indexed(Object *ob, int pchan_index) return pose->chan_array[pchan_index]; } -void BKE_pose_eval_init(const struct EvaluationContext *UNUSED(eval_ctx), +void BKE_pose_eval_init(struct Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene), Object *ob) { @@ -597,7 +597,7 @@ void BKE_pose_eval_init(const struct EvaluationContext *UNUSED(eval_ctx), } } -void BKE_pose_eval_init_ik(const struct EvaluationContext *eval_ctx, +void BKE_pose_eval_init_ik(struct Depsgraph *depsgraph, Scene *scene, Object *ob) { @@ -609,7 +609,7 @@ void BKE_pose_eval_init_ik(const struct EvaluationContext *eval_ctx, return; } /* construct the IK tree (standard IK) */ - BIK_initialize_tree(eval_ctx, scene, ob, ctime); + BIK_initialize_tree(depsgraph, scene, ob, ctime); /* construct the Spline IK trees * - this is not integrated as an IK plugin, since it should be able * to function in conjunction with standard IK @@ -617,7 +617,7 @@ void BKE_pose_eval_init_ik(const struct EvaluationContext *eval_ctx, BKE_pose_splineik_init_tree(scene, ob, ctime); } -void BKE_pose_eval_bone(const struct EvaluationContext *eval_ctx, +void BKE_pose_eval_bone(struct Depsgraph *depsgraph, Scene *scene, Object *ob, int pchan_index) @@ -647,14 +647,14 @@ void BKE_pose_eval_bone(const struct EvaluationContext *eval_ctx, if ((pchan->flag & POSE_DONE) == 0) { /* TODO(sergey): Use time source node for time. */ float ctime = BKE_scene_frame_get(scene); /* not accurate... */ - BKE_pose_where_is_bone(eval_ctx, scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1); } } } } } -void BKE_pose_constraints_evaluate(const struct EvaluationContext *eval_ctx, +void BKE_pose_constraints_evaluate(struct Depsgraph *depsgraph, Scene *scene, Object *ob, int pchan_index) @@ -672,12 +672,12 @@ void BKE_pose_constraints_evaluate(const struct EvaluationContext *eval_ctx, else { if ((pchan->flag & POSE_DONE) == 0) { float ctime = BKE_scene_frame_get(scene); /* not accurate... */ - BKE_pose_where_is_bone(eval_ctx, scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1); } } } -void BKE_pose_bone_done(const struct EvaluationContext *UNUSED(eval_ctx), +void BKE_pose_bone_done(struct Depsgraph *UNUSED(depsgraph), struct Object *ob, int pchan_index) { @@ -690,7 +690,7 @@ void BKE_pose_bone_done(const struct EvaluationContext *UNUSED(eval_ctx), } } -void BKE_pose_iktree_evaluate(const struct EvaluationContext *eval_ctx, +void BKE_pose_iktree_evaluate(struct Depsgraph *depsgraph, Scene *scene, Object *ob, int rootchan_index) @@ -704,10 +704,10 @@ void BKE_pose_iktree_evaluate(const struct EvaluationContext *eval_ctx, if (arm->flag & ARM_RESTPOS) { return; } - BIK_execute_tree(eval_ctx, scene, ob, rootchan, ctime); + BIK_execute_tree(depsgraph, scene, ob, rootchan, ctime); } -void BKE_pose_splineik_evaluate(const struct EvaluationContext *eval_ctx, +void BKE_pose_splineik_evaluate(struct Depsgraph *depsgraph, Scene *scene, Object *ob, int rootchan_index) @@ -722,10 +722,10 @@ void BKE_pose_splineik_evaluate(const struct EvaluationContext *eval_ctx, if (arm->flag & ARM_RESTPOS) { return; } - BKE_splineik_execute_tree(eval_ctx, scene, ob, rootchan, ctime); + BKE_splineik_execute_tree(depsgraph, scene, ob, rootchan, ctime); } -void BKE_pose_eval_flush(const struct EvaluationContext *UNUSED(eval_ctx), +void BKE_pose_eval_flush(struct Depsgraph *UNUSED(depsgraph), Scene *scene, Object *ob) { @@ -744,7 +744,7 @@ void BKE_pose_eval_flush(const struct EvaluationContext *UNUSED(eval_ctx), pose->chan_array = NULL; } -void BKE_pose_eval_proxy_copy(const struct EvaluationContext *UNUSED(eval_ctx), Object *ob) +void BKE_pose_eval_proxy_copy(struct Depsgraph *UNUSED(depsgraph), Object *ob) { BLI_assert(ID_IS_LINKED(ob) && ob->proxy_from != NULL); DEG_debug_print_eval(__func__, ob->id.name, ob); diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index f440ce711ff..eb5cdd02fe5 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -132,7 +132,7 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, if (eff == NULL && gabr->ob) { memset(&temp_eff, 0, sizeof(EffectorCache)); temp_eff.ob = gabr->ob; - temp_eff.eval_ctx = bbd->sim->eval_ctx; + temp_eff.depsgraph = bbd->sim->depsgraph; temp_eff.scene = bbd->sim->scene; eff = &temp_eff; get_effector_data(eff, &efd, &epoint, 0); @@ -162,8 +162,10 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val, copy_v3_v3(bbd->goal_nor, efd.nor); } } - else if (rule->type == eBoidRuleType_Avoid && bpa->data.mode == eBoidMode_Climbing && - priority > 2.0f * gabr->fear_factor) { + else if ((rule->type == eBoidRuleType_Avoid) && + (bpa->data.mode == eBoidMode_Climbing) && + (priority > 2.0f * gabr->fear_factor)) + { /* detach from surface and try to fly away from danger */ negate_v3_v3(efd.vec_to_point, bpa->gravity); } @@ -1107,7 +1109,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) /* jump to go faster */ if (jump == 0 && val.jump_speed > val.max_speed && bbd->wanted_speed > val.max_speed) { - + /* pass */ } if (jump) { diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 8c4bced1563..7676baa9dba 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -259,7 +259,7 @@ void BKE_camera_params_from_object(CameraParams *params, const Object *ob) } } -void BKE_camera_params_from_view3d(CameraParams *params, const Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d) +void BKE_camera_params_from_view3d(CameraParams *params, Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d) { /* common */ params->lens = v3d->lens; @@ -664,7 +664,7 @@ static bool camera_frame_fit_calc_from_data( /* don't move the camera, just yield the fit location */ /* r_scale only valid/useful for ortho cameras */ bool BKE_camera_view_frame_fit_to_scene( - Scene *scene, ViewLayer *view_layer, Object *camera_ob, float r_co[3], float *r_scale) + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Object *camera_ob, float r_co[3], float *r_scale) { CameraParams params; CameraViewFrameData data_cb; @@ -675,7 +675,7 @@ bool BKE_camera_view_frame_fit_to_scene( camera_frame_fit_data_init(scene, camera_ob, ¶ms, &data_cb); /* run callback on all visible points */ - BKE_scene_foreach_display_point(scene, view_layer, camera_to_frame_view_cb, &data_cb); + BKE_scene_foreach_display_point(depsgraph, scene, view_layer, camera_to_frame_view_cb, &data_cb); return camera_frame_fit_calc_from_data(¶ms, &data_cb, r_co, r_scale); } diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 339dcc4a62e..976b8965fa2 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -347,7 +347,7 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul return 1; } -static int do_step_cloth(const struct EvaluationContext *eval_ctx, Object *ob, ClothModifierData *clmd, DerivedMesh *result, int framenr) +static int do_step_cloth(struct Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, DerivedMesh *result, int framenr) { ClothVertex *verts = NULL; Cloth *cloth; @@ -372,7 +372,7 @@ static int do_step_cloth(const struct EvaluationContext *eval_ctx, Object *ob, C mul_m4_v3(ob->obmat, verts->xconst); } - effectors = pdInitEffectors(eval_ctx, clmd->scene, ob, NULL, clmd->sim_parms->effector_weights, true); + effectors = pdInitEffectors(depsgraph, clmd->scene, ob, NULL, clmd->sim_parms->effector_weights, true); if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH ) cloth_update_verts ( ob, clmd, result ); @@ -402,7 +402,7 @@ static int do_step_cloth(const struct EvaluationContext *eval_ctx, Object *ob, C /************************************************ * clothModifier_do - main simulation function ************************************************/ -void clothModifier_do(ClothModifierData *clmd, const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3]) +void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3]) { PointCache *cache; PTCacheID pid; @@ -458,7 +458,8 @@ void clothModifier_do(ClothModifierData *clmd, const struct EvaluationContext *e cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe, can_simulate); if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED || - (!can_simulate && cache_result == PTCACHE_READ_OLD)) { + (!can_simulate && cache_result == PTCACHE_READ_OLD)) + { BKE_cloth_solver_set_positions(clmd); cloth_to_object (ob, clmd, vertexCos); @@ -489,7 +490,7 @@ void clothModifier_do(ClothModifierData *clmd, const struct EvaluationContext *e /* do simulation */ BKE_ptcache_validate(cache, framenr); - if (!do_step_cloth(eval_ctx, ob, clmd, dm, framenr)) { + if (!do_step_cloth(depsgraph, ob, clmd, dm, framenr)) { BKE_ptcache_invalidate(cache); } else diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index b070ccdd4eb..eca789b0f87 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -684,7 +684,7 @@ static bConstraintTypeInfo CTI_CONSTRNAME = { /* This function should be used for the get_target_matrix member of all * constraints that are not picky about what happens to their target matrix. */ -static void default_get_tarmat(const struct EvaluationContext *UNUSED(eval_ctx), bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime)) +static void default_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime)) { if (VALID_CONS_TARGET(ct)) constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->flag, con->headtail); @@ -1153,7 +1153,7 @@ static void kinematic_flush_tars(bConstraint *con, ListBase *list, bool no_copy) } } -static void kinematic_get_tarmat(const struct EvaluationContext *UNUSED(eval_ctx), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void kinematic_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { bKinematicConstraint *data = con->data; @@ -1240,7 +1240,7 @@ static void followpath_flush_tars(bConstraint *con, ListBase *list, bool no_copy } } -static void followpath_get_tarmat(const struct EvaluationContext *UNUSED(eval_ctx), +static void followpath_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime)) { @@ -2019,7 +2019,7 @@ static void pycon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userd } /* Whether this approach is maintained remains to be seen (aligorith) */ -static void pycon_get_tarmat(const struct EvaluationContext *UNUSED(eval_ctx), +static void pycon_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime)) { @@ -2135,7 +2135,7 @@ static void actcon_flush_tars(bConstraint *con, ListBase *list, bool no_copy) } } -static void actcon_get_tarmat(const struct EvaluationContext *UNUSED(eval_ctx), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void actcon_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { bActionConstraint *data = con->data; @@ -2630,7 +2630,7 @@ static void distlimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t /* if soft-distance is enabled, start fading once owner is dist+softdist from the target */ else if (data->flag & LIMITDIST_USESOFT) { if (dist <= (data->dist + data->soft)) { - + /* pass */ } } } @@ -3124,7 +3124,7 @@ static void clampto_flush_tars(bConstraint *con, ListBase *list, bool no_copy) } } -static void clampto_get_tarmat(const struct EvaluationContext *UNUSED(eval_ctx), +static void clampto_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *UNUSED(con), bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime)) { @@ -3461,7 +3461,7 @@ static void shrinkwrap_flush_tars(bConstraint *con, ListBase *list, bool no_copy } -static void shrinkwrap_get_tarmat(const struct EvaluationContext *UNUSED(eval_ctx), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) +static void shrinkwrap_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime)) { bShrinkwrapConstraint *scon = (bShrinkwrapConstraint *) con->data; @@ -3793,7 +3793,7 @@ static void splineik_flush_tars(bConstraint *con, ListBase *list, bool no_copy) } } -static void splineik_get_tarmat(const struct EvaluationContext *UNUSED(eval_ctx), +static void splineik_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *UNUSED(con), bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime)) { @@ -4845,7 +4845,7 @@ bool BKE_constraints_proxylocked_owner(Object *ob, bPoseChannel *pchan) * None of the actual calculations of the matrices should be done here! Also, this function is * not to be used by any new constraints, particularly any that have multiple targets. */ -void BKE_constraint_target_matrix_get(const struct EvaluationContext *eval_ctx, Scene *scene, bConstraint *con, int index, short ownertype, void *ownerdata, float mat[4][4], float ctime) +void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, Scene *scene, bConstraint *con, int index, short ownertype, void *ownerdata, float mat[4][4], float ctime) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); ListBase targets = {NULL, NULL}; @@ -4896,7 +4896,7 @@ void BKE_constraint_target_matrix_get(const struct EvaluationContext *eval_ctx, if (ct) { if (cti->get_target_matrix) - cti->get_target_matrix(eval_ctx, con, cob, ct, ctime); + cti->get_target_matrix(depsgraph, con, cob, ct, ctime); copy_m4_m4(mat, ct->matrix); } @@ -4912,7 +4912,7 @@ void BKE_constraint_target_matrix_get(const struct EvaluationContext *eval_ctx, } /* Get the list of targets required for solving a constraint */ -void BKE_constraint_targets_for_solving_get(const struct EvaluationContext *eval_ctx, bConstraint *con, bConstraintOb *cob, ListBase *targets, float ctime) +void BKE_constraint_targets_for_solving_get(struct Depsgraph *depsgraph, bConstraint *con, bConstraintOb *cob, ListBase *targets, float ctime) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); @@ -4930,7 +4930,7 @@ void BKE_constraint_targets_for_solving_get(const struct EvaluationContext *eval */ if (cti->get_target_matrix) { for (ct = targets->first; ct; ct = ct->next) - cti->get_target_matrix(eval_ctx, con, cob, ct, ctime); + cti->get_target_matrix(depsgraph, con, cob, ct, ctime); } else { for (ct = targets->first; ct; ct = ct->next) @@ -4947,7 +4947,7 @@ void BKE_constraint_targets_for_solving_get(const struct EvaluationContext *eval * BKE_constraints_make_evalob and BKE_constraints_clear_evalob should be called before and * after running this function, to sort out cob */ -void BKE_constraints_solve(const struct EvaluationContext *eval_ctx, ListBase *conlist, bConstraintOb *cob, float ctime) +void BKE_constraints_solve(struct Depsgraph *depsgraph, ListBase *conlist, bConstraintOb *cob, float ctime) { bConstraint *con; float oldmat[4][4]; @@ -4982,7 +4982,7 @@ void BKE_constraints_solve(const struct EvaluationContext *eval_ctx, ListBase *c BKE_constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace, false); /* prepare targets for constraint solving */ - BKE_constraint_targets_for_solving_get(eval_ctx, con, cob, &targets, ctime); + BKE_constraint_targets_for_solving_get(depsgraph, con, cob, &targets, ctime); /* Solve the constraint and put result in cob->matrix */ cti->evaluate_constraint(con, cob, &targets); diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index d550f1945db..2bb12725940 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -1266,15 +1266,3 @@ Depsgraph *CTX_data_depsgraph(const bContext *C) ViewLayer *view_layer = CTX_data_view_layer(C); return BKE_scene_get_depsgraph(scene, view_layer, true); } - -void CTX_data_eval_ctx(const bContext *C, EvaluationContext *eval_ctx) -{ - BLI_assert(C != NULL); - - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - DEG_evaluation_context_init_from_scene( - eval_ctx, - scene, view_layer, - DAG_EVAL_VIEWPORT); -} diff --git a/source/blender/blenkernel/intern/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c index d2ffbbcf27b..f5795444b7d 100644 --- a/source/blender/blenkernel/intern/crazyspace.c +++ b/source/blender/blenkernel/intern/crazyspace.c @@ -100,7 +100,7 @@ static int modifiers_disable_subsurf_temporary(Object *ob) /* disable subsurf temporal, get mapped cos, and enable it */ float (*BKE_crazyspace_get_mapped_editverts( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *obedit))[3] + struct Depsgraph *depsgraph, Scene *scene, Object *obedit))[3] { Mesh *me = obedit->data; DerivedMesh *dm; @@ -110,13 +110,13 @@ float (*BKE_crazyspace_get_mapped_editverts( /* disable subsurf temporal, get mapped cos, and enable it */ if (modifiers_disable_subsurf_temporary(obedit)) { /* need to make new derivemesh */ - makeDerivedMesh(eval_ctx, scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH, false); + makeDerivedMesh(depsgraph, scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH, false); } /* now get the cage */ vertexcos = MEM_mallocN(sizeof(*vertexcos) * nverts, "vertexcos map"); - dm = editbmesh_get_derived_cage(eval_ctx, scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH); + dm = editbmesh_get_derived_cage(depsgraph, scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH); mesh_get_mapped_verts_coords(dm, vertexcos, nverts); @@ -252,7 +252,7 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me, float (*origcos)[3], float (*mapped /** returns an array of deform matrices for crazyspace correction, and the * number of modifiers left */ int BKE_crazyspace_get_first_deform_matrices_editbmesh( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, BMEditMesh *em, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, BMEditMesh *em, float (**deformmats)[3][3], float (**deformcos)[3]) { ModifierData *md; @@ -292,7 +292,7 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh( unit_m3(defmats[a]); } - mti->deformMatricesEM(md, eval_ctx, ob, em, dm, deformedVerts, defmats, + mti->deformMatricesEM(md, depsgraph, ob, em, dm, deformedVerts, defmats, numVerts); } else @@ -313,7 +313,7 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh( } int BKE_sculpt_get_first_deform_matrices( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (**deformmats)[3][3], float (**deformcos)[3]) { ModifierData *md; @@ -350,7 +350,7 @@ int BKE_sculpt_get_first_deform_matrices( unit_m3(defmats[a]); } - if (mti->deformMatrices) mti->deformMatrices(md, eval_ctx, ob, dm, deformedVerts, defmats, numVerts); + if (mti->deformMatrices) mti->deformMatrices(md, depsgraph, ob, dm, deformedVerts, defmats, numVerts); else break; } } @@ -373,9 +373,9 @@ int BKE_sculpt_get_first_deform_matrices( return numleft; } -void BKE_crazyspace_build_sculpt(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float (**deformmats)[3][3], float (**deformcos)[3]) +void BKE_crazyspace_build_sculpt(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (**deformmats)[3][3], float (**deformcos)[3]) { - int totleft = BKE_sculpt_get_first_deform_matrices(eval_ctx, scene, ob, deformmats, deformcos); + int totleft = BKE_sculpt_get_first_deform_matrices(depsgraph, scene, ob, deformmats, deformcos); if (totleft) { /* there are deformation modifier which doesn't support deformation matrices @@ -400,7 +400,7 @@ void BKE_crazyspace_build_sculpt(const struct EvaluationContext *eval_ctx, Scene if (mti->deformMatrices && !deformed) continue; - mti->deformVerts(md, eval_ctx, ob, NULL, deformedVerts, me->totvert, 0); + mti->deformVerts(md, depsgraph, ob, NULL, deformedVerts, me->totvert, 0); deformed = 1; } } diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 0c4dbdf7763..661ffdbcd27 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -1624,7 +1624,7 @@ float *BKE_curve_surf_make_orco(Object *ob) /* NOTE: This routine is tied to the order of vertex * built by displist and as passed to the renderer. */ -float *BKE_curve_make_orco(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, int *r_numVerts) +float *BKE_curve_make_orco(Depsgraph *depsgraph, Scene *scene, Object *ob, int *r_numVerts) { Curve *cu = ob->data; DispList *dl; @@ -1632,7 +1632,7 @@ float *BKE_curve_make_orco(const EvaluationContext *eval_ctx, Scene *scene, Obje float *fp, *coord_array; ListBase disp = {NULL, NULL}; - BKE_displist_make_curveTypes_forOrco(eval_ctx, scene, ob, &disp); + BKE_displist_make_curveTypes_forOrco(depsgraph, scene, ob, &disp); numVerts = 0; for (dl = disp.first; dl; dl = dl->next) { @@ -1724,7 +1724,7 @@ float *BKE_curve_make_orco(const EvaluationContext *eval_ctx, Scene *scene, Obje /* ***************** BEVEL ****************** */ void BKE_curve_bevel_make( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *disp, + Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *disp, const bool for_render, const bool use_render_resolution) { DispList *dl, *dlnew; @@ -1749,7 +1749,7 @@ void BKE_curve_bevel_make( facy = cu->bevobj->size[1]; if (for_render) { - BKE_displist_make_curveTypes_forRender(eval_ctx, scene, cu->bevobj, &bevdisp, NULL, false, use_render_resolution); + BKE_displist_make_curveTypes_forRender(depsgraph, scene, cu->bevobj, &bevdisp, NULL, false, use_render_resolution); dl = bevdisp.first; } else if (cu->bevobj->curve_cache) { @@ -5255,7 +5255,7 @@ void BKE_curve_rect_from_textbox(const struct Curve *cu, const struct TextBox *t /* **** Depsgraph evaluation **** */ -void BKE_curve_eval_geometry(const EvaluationContext *UNUSED(eval_ctx), +void BKE_curve_eval_geometry(Depsgraph *UNUSED(depsgraph), Curve *curve) { DEG_debug_print_eval(__func__, curve->id.name, curve); diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c index 00b8063110d..0451031c5b8 100644 --- a/source/blender/blenkernel/intern/data_transfer.c +++ b/source/blender/blenkernel/intern/data_transfer.c @@ -107,7 +107,7 @@ bool BKE_object_data_transfer_get_dttypes_capacity( } switch (dtdata_type) { - /* Vertex data */ + /* Vertex data */ case DT_TYPE_MDEFORMVERT: *r_advanced_mixing = true; *r_threshold = true; @@ -120,7 +120,7 @@ bool BKE_object_data_transfer_get_dttypes_capacity( case DT_TYPE_BWEIGHT_VERT: ret = true; break; - /* Edge data */ + /* Edge data */ case DT_TYPE_SHARP_EDGE: *r_threshold = true; ret = true; @@ -139,7 +139,7 @@ bool BKE_object_data_transfer_get_dttypes_capacity( *r_threshold = true; ret = true; break; - /* Loop/Poly data */ + /* Loop/Poly data */ case DT_TYPE_UV: ret = true; break; @@ -1010,7 +1010,7 @@ static bool data_transfer_layersmapping_generate( * to get (as much as possible) exact copy of source data layout. */ void BKE_object_data_transfer_layout( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, const bool use_delete, const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX]) { @@ -1028,7 +1028,7 @@ void BKE_object_data_transfer_layout( /* Get source DM.*/ dm_src_mask |= BKE_object_data_transfer_dttypes_to_cdmask(data_types); - dm_src = mesh_get_derived_final(eval_ctx, scene, ob_src, dm_src_mask); + dm_src = mesh_get_derived_final(depsgraph, scene, ob_src, dm_src_mask); if (!dm_src) { return; } @@ -1086,7 +1086,7 @@ void BKE_object_data_transfer_layout( } bool BKE_object_data_transfer_dm( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob_src, Object *ob_dst, DerivedMesh *dm_dst, + struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, DerivedMesh *dm_dst, const int data_types, bool use_create, const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode, SpaceTransform *space_transform, const bool auto_transform, const float max_distance, const float ray_radius, const float islands_handling_precision, @@ -1150,7 +1150,7 @@ bool BKE_object_data_transfer_dm( * Also, we need to make a local copy of dm_src, otherwise we may end with concurrent creation * of data in it (multi-threaded evaluation of the modifier stack, see T46672). */ - dm_src = dm_dst ? ob_src->derivedFinal : mesh_get_derived_final(eval_ctx, scene, ob_src, dm_src_mask); + dm_src = dm_dst ? ob_src->derivedFinal : mesh_get_derived_final(depsgraph, scene, ob_src, dm_src_mask); if (!dm_src) { return changed; } @@ -1458,7 +1458,7 @@ bool BKE_object_data_transfer_dm( } bool BKE_object_data_transfer_mesh( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, + struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, const bool use_create, const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode, SpaceTransform *space_transform, const bool auto_transform, const float max_distance, const float ray_radius, const float islands_handling_precision, @@ -1467,7 +1467,7 @@ bool BKE_object_data_transfer_mesh( ReportList *reports) { return BKE_object_data_transfer_dm( - eval_ctx, scene, ob_src, ob_dst, NULL, data_types, use_create, + depsgraph, scene, ob_src, ob_dst, NULL, data_types, use_create, map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode, space_transform, auto_transform, max_distance, ray_radius, islands_handling_precision, diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index ffa4e652056..e74e540fab9 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -681,7 +681,7 @@ static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dis * - first point left, last point right * - based on subdivided points in original curve, not on points in taper curve (still) */ -static float displist_calc_taper(const EvaluationContext *eval_ctx, Scene *scene, Object *taperobj, float fac) +static float displist_calc_taper(Depsgraph *depsgraph, Scene *scene, Object *taperobj, float fac) { DispList *dl; @@ -690,7 +690,7 @@ static float displist_calc_taper(const EvaluationContext *eval_ctx, Scene *scene dl = taperobj->curve_cache ? taperobj->curve_cache->disp.first : NULL; if (dl == NULL) { - BKE_displist_make_curveTypes(eval_ctx, scene, taperobj, 0); + BKE_displist_make_curveTypes(depsgraph, scene, taperobj, 0); dl = taperobj->curve_cache->disp.first; } if (dl) { @@ -721,14 +721,14 @@ static float displist_calc_taper(const EvaluationContext *eval_ctx, Scene *scene return 1.0; } -float BKE_displist_calc_taper(const EvaluationContext *eval_ctx, Scene *scene, Object *taperobj, int cur, int tot) +float BKE_displist_calc_taper(Depsgraph *depsgraph, Scene *scene, Object *taperobj, int cur, int tot) { float fac = ((float)cur) / (float)(tot - 1); - return displist_calc_taper(eval_ctx, scene, taperobj, fac); + return displist_calc_taper(depsgraph, scene, taperobj, fac); } -void BKE_displist_make_mball(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +void BKE_displist_make_mball(Depsgraph *depsgraph, Scene *scene, Object *ob) { if (!ob || ob->type != OB_MBALL) return; @@ -741,7 +741,7 @@ void BKE_displist_make_mball(const EvaluationContext *eval_ctx, Scene *scene, Ob ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for MBall"); } - BKE_mball_polygonize(eval_ctx, scene, ob, &ob->curve_cache->disp); + BKE_mball_polygonize(depsgraph, scene, ob, &ob->curve_cache->disp); BKE_mball_texspace_calc(ob); object_deform_mball(ob, &ob->curve_cache->disp); @@ -751,9 +751,9 @@ void BKE_displist_make_mball(const EvaluationContext *eval_ctx, Scene *scene, Ob } } -void BKE_displist_make_mball_forRender(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *dispbase) +void BKE_displist_make_mball_forRender(Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase) { - BKE_mball_polygonize(eval_ctx, scene, ob, dispbase); + BKE_mball_polygonize(depsgraph, scene, ob, dispbase); BKE_mball_texspace_calc(ob); object_deform_mball(ob, dispbase); @@ -802,7 +802,7 @@ static ModifierData *curve_get_tessellate_point(Scene *scene, Object *ob, } static void curve_calc_modifiers_pre( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *nurb, + Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *nurb, const bool for_render, const bool use_render_resolution) { VirtualModifierData virtualModifierData; @@ -860,7 +860,7 @@ static void curve_calc_modifiers_pre( deformedVerts = BKE_curve_nurbs_vertexCos_get(nurb, &numVerts); } - mti->deformVerts(md, eval_ctx, ob, NULL, deformedVerts, numVerts, app_flag); + mti->deformVerts(md, depsgraph, ob, NULL, deformedVerts, numVerts, app_flag); if (md == pretessellatePoint) break; @@ -913,7 +913,7 @@ static void displist_apply_allverts(ListBase *dispbase, float (*allverts)[3]) } static void curve_calc_modifiers_post( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *nurb, + Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *nurb, ListBase *dispbase, DerivedMesh **r_dm_final, const bool for_render, const bool use_render_resolution) { @@ -969,14 +969,14 @@ static void curve_calc_modifiers_post( dm->getVertCos(dm, vertCos); } - mti->deformVerts(md, eval_ctx, ob, dm, vertCos, totvert, appf); + mti->deformVerts(md, depsgraph, ob, dm, vertCos, totvert, appf); } else { if (!vertCos) { vertCos = displist_get_allverts(dispbase, &totvert); } - mti->deformVerts(md, eval_ctx, ob, NULL, vertCos, totvert, appf); + mti->deformVerts(md, depsgraph, ob, NULL, vertCos, totvert, appf); } } else { @@ -1018,7 +1018,7 @@ static void curve_calc_modifiers_post( if (useCache) appf |= MOD_APPLY_USECACHE; - ndm = modwrap_applyModifier(md, eval_ctx, ob, dm, appf); + ndm = modwrap_applyModifier(md, depsgraph, ob, dm, appf); if (ndm) { /* Modifier returned a new derived mesh */ @@ -1095,13 +1095,13 @@ static void displist_surf_indices(DispList *dl) } } -static DerivedMesh *create_orco_dm(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +static DerivedMesh *create_orco_dm(Depsgraph *depsgraph, Scene *scene, Object *ob) { DerivedMesh *dm; ListBase disp = {NULL, NULL}; /* OrcoDM should be created from underformed disp lists */ - BKE_displist_make_curveTypes_forOrco(eval_ctx, scene, ob, &disp); + BKE_displist_make_curveTypes_forOrco(depsgraph, scene, ob, &disp); dm = CDDM_from_curve_displist(ob, &disp); BKE_displist_free(&disp); @@ -1140,7 +1140,7 @@ static void add_orco_dm(Object *ob, DerivedMesh *dm, DerivedMesh *orcodm) } static void curve_calc_orcodm( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, DerivedMesh *dm_final, + Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm_final, const bool for_render, const bool use_render_resolution) { /* this function represents logic of mesh's orcodm calculation @@ -1178,7 +1178,7 @@ static void curve_calc_orcodm( * This means we can create ORCO DM in advance and assume it's * never NULL. */ - orcodm = create_orco_dm(eval_ctx, scene, ob); + orcodm = create_orco_dm(depsgraph, scene, ob); for (; md; md = md->next) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -1190,7 +1190,7 @@ static void curve_calc_orcodm( if (mti->type != eModifierTypeType_Constructive) continue; - ndm = modwrap_applyModifier(md, eval_ctx, ob, orcodm, app_flag); + ndm = modwrap_applyModifier(md, depsgraph, ob, orcodm, app_flag); if (ndm) { /* if the modifier returned a new dm, release the old one */ @@ -1208,7 +1208,7 @@ static void curve_calc_orcodm( } void BKE_displist_make_surf( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *dispbase, + Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase, DerivedMesh **r_dm_final, const bool for_render, const bool for_orco, const bool use_render_resolution) { @@ -1227,7 +1227,7 @@ void BKE_displist_make_surf( } if (!for_orco) - curve_calc_modifiers_pre(eval_ctx, scene, ob, &nubase, for_render, use_render_resolution); + curve_calc_modifiers_pre(depsgraph, scene, ob, &nubase, for_render, use_render_resolution); for (nu = nubase.first; nu; nu = nu->next) { if ((for_render || nu->hide == 0) && BKE_nurb_check_valid_uv(nu)) { @@ -1294,7 +1294,7 @@ void BKE_displist_make_surf( if (!for_orco) { BKE_nurbList_duplicate(&ob->curve_cache->deformed_nurbs, &nubase); - curve_calc_modifiers_post(eval_ctx, scene, ob, &nubase, dispbase, r_dm_final, + curve_calc_modifiers_post(depsgraph, scene, ob, &nubase, dispbase, r_dm_final, for_render, use_render_resolution); } @@ -1521,7 +1521,7 @@ static void calc_bevfac_mapping(Curve *cu, BevList *bl, Nurb *nu, } static void do_makeDispListCurveTypes( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *dispbase, + Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase, DerivedMesh **r_dm_final, const bool for_render, const bool for_orco, const bool use_render_resolution) { @@ -1531,7 +1531,7 @@ static void do_makeDispListCurveTypes( if (!ELEM(ob->type, OB_SURF, OB_CURVE, OB_FONT)) return; if (ob->type == OB_SURF) { - BKE_displist_make_surf(eval_ctx, scene, ob, dispbase, r_dm_final, for_render, for_orco, use_render_resolution); + BKE_displist_make_surf(depsgraph, scene, ob, dispbase, r_dm_final, for_render, for_orco, use_render_resolution); } else if (ELEM(ob->type, OB_CURVE, OB_FONT)) { ListBase dlbev; @@ -1556,12 +1556,12 @@ static void do_makeDispListCurveTypes( } if (!for_orco) - curve_calc_modifiers_pre(eval_ctx, scene, ob, &nubase, for_render, use_render_resolution); + curve_calc_modifiers_pre(depsgraph, scene, ob, &nubase, for_render, use_render_resolution); BKE_curve_bevelList_make(ob, &nubase, for_render != false); /* If curve has no bevel will return nothing */ - BKE_curve_bevel_make(eval_ctx, scene, ob, &dlbev, for_render, use_render_resolution); + BKE_curve_bevel_make(depsgraph, scene, ob, &dlbev, for_render, use_render_resolution); /* no bevel or extrude, and no width correction? */ if (!dlbev.first && cu->width == 1.0f) { @@ -1696,7 +1696,7 @@ static void do_makeDispListCurveTypes( taper_fac -= (1.0f - lastblend) / len; } - fac = displist_calc_taper(eval_ctx, scene, cu->taperobj, taper_fac); + fac = displist_calc_taper(depsgraph, scene, cu->taperobj, taper_fac); } if (bevp->split_tag) { @@ -1749,7 +1749,7 @@ static void do_makeDispListCurveTypes( if (!for_orco) { if ((cu->flag & CU_PATH) || - DEG_get_eval_flags_for_id(eval_ctx->depsgraph, &ob->id) & DAG_EVAL_NEED_CURVE_PATH) + DEG_get_eval_flags_for_id(depsgraph, &ob->id) & DAG_EVAL_NEED_CURVE_PATH) { calc_curvepath(ob, &nubase); } @@ -1757,7 +1757,7 @@ static void do_makeDispListCurveTypes( if (!for_orco) { BKE_nurbList_duplicate(&ob->curve_cache->deformed_nurbs, &nubase); - curve_calc_modifiers_post(eval_ctx, scene, ob, &nubase, dispbase, r_dm_final, for_render, use_render_resolution); + curve_calc_modifiers_post(depsgraph, scene, ob, &nubase, dispbase, r_dm_final, for_render, use_render_resolution); } if (cu->flag & CU_DEFORM_FILL && !ob->derivedFinal) { @@ -1768,7 +1768,7 @@ static void do_makeDispListCurveTypes( } } -void BKE_displist_make_curveTypes(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, const bool for_orco) +void BKE_displist_make_curveTypes(Depsgraph *depsgraph, Scene *scene, Object *ob, const bool for_orco) { ListBase *dispbase; @@ -1786,13 +1786,13 @@ void BKE_displist_make_curveTypes(const EvaluationContext *eval_ctx, Scene *scen dispbase = &(ob->curve_cache->disp); - do_makeDispListCurveTypes(eval_ctx, scene, ob, dispbase, &ob->derivedFinal, 0, for_orco, 0); + do_makeDispListCurveTypes(depsgraph, scene, ob, dispbase, &ob->derivedFinal, 0, for_orco, 0); boundbox_displist_object(ob); } void BKE_displist_make_curveTypes_forRender( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *dispbase, + Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase, DerivedMesh **r_dm_final, const bool for_orco, const bool use_render_resolution) { @@ -1800,22 +1800,22 @@ void BKE_displist_make_curveTypes_forRender( ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve"); } - do_makeDispListCurveTypes(eval_ctx, scene, ob, dispbase, r_dm_final, true, for_orco, use_render_resolution); + do_makeDispListCurveTypes(depsgraph, scene, ob, dispbase, r_dm_final, true, for_orco, use_render_resolution); } void BKE_displist_make_curveTypes_forOrco( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *dispbase) + Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase) { if (ob->curve_cache == NULL) { ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve"); } - do_makeDispListCurveTypes(eval_ctx, scene, ob, dispbase, NULL, 1, 1, 1); + do_makeDispListCurveTypes(depsgraph, scene, ob, dispbase, NULL, 1, 1, 1); } /* add Orco layer to the displist object which has got derived mesh and return orco */ float *BKE_displist_make_orco( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, DerivedMesh *dm_final, + Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm_final, const bool for_render, const bool use_render_resolution) { @@ -1825,7 +1825,7 @@ float *BKE_displist_make_orco( dm_final = ob->derivedFinal; if (!dm_final->getVertDataArray(dm_final, CD_ORCO)) { - curve_calc_orcodm(eval_ctx, scene, ob, dm_final, for_render, use_render_resolution); + curve_calc_orcodm(depsgraph, scene, ob, dm_final, for_render, use_render_resolution); } orco = dm_final->getVertDataArray(dm_final, CD_ORCO); diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index ee678dd4c41..6f0135616f0 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -75,6 +75,7 @@ #include "BKE_scene.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" /* for image output */ #include "IMB_imbuf_types.h" @@ -2065,7 +2066,7 @@ static void canvas_copyDerivedMesh(DynamicPaintCanvasSettings *canvas, DerivedMe * Updates derived mesh copy and processes dynamic paint step / caches. */ static void dynamicPaint_frameUpdate( - DynamicPaintModifierData *pmd, const struct EvaluationContext *eval_ctx, Scene *scene, + DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm) { if (pmd->canvas) { @@ -2129,7 +2130,7 @@ static void dynamicPaint_frameUpdate( else if (can_simulate) { /* calculate surface frame */ canvas->flags |= MOD_DPAINT_BAKING; - dynamicPaint_calculateFrame(surface, eval_ctx, scene, ob, current_frame); + dynamicPaint_calculateFrame(surface, depsgraph, scene, ob, current_frame); canvas->flags &= ~MOD_DPAINT_BAKING; /* restore canvas derivedmesh if required */ @@ -2149,14 +2150,14 @@ static void dynamicPaint_frameUpdate( /* Modifier call. Processes dynamic paint modifier step. */ DerivedMesh *dynamicPaint_Modifier_do( - DynamicPaintModifierData *pmd, const struct EvaluationContext *eval_ctx, Scene *scene, + DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm) { if (pmd->canvas) { DerivedMesh *ret; /* Update canvas data for a new frame */ - dynamicPaint_frameUpdate(pmd, eval_ctx, scene, ob, dm); + dynamicPaint_frameUpdate(pmd, depsgraph, scene, ob, dm); /* Return output mesh */ ret = dynamicPaint_Modifier_apply(pmd, ob, dm); @@ -2165,7 +2166,7 @@ DerivedMesh *dynamicPaint_Modifier_do( } else { /* Update canvas data for a new frame */ - dynamicPaint_frameUpdate(pmd, eval_ctx, scene, ob, dm); + dynamicPaint_frameUpdate(pmd, depsgraph, scene, ob, dm); /* Return output mesh */ return dynamicPaint_Modifier_apply(pmd, ob, dm); @@ -3348,7 +3349,7 @@ typedef struct BrushMaterials { /* Initialize materials for brush object: * Calculates inverse matrices for linked objects, updates * volume caches etc. */ -static void dynamicPaint_updateBrushMaterials(const EvaluationContext *eval_ctx, Object *brushOb, Material *ui_mat, Scene *scene, BrushMaterials *bMats) +static void dynamicPaint_updateBrushMaterials(Depsgraph *depsgraph, Object *brushOb, Material *ui_mat, Scene *scene, BrushMaterials *bMats) { /* Calculate inverse transformation matrix * for this object */ @@ -3363,13 +3364,13 @@ static void dynamicPaint_updateBrushMaterials(const EvaluationContext *eval_ctx, if (tot) { bMats->ob_mats = MEM_callocN(sizeof(Material *) * (tot), "BrushMaterials"); for (i = 0; i < tot; i++) { - bMats->ob_mats[i] = RE_sample_material_init(eval_ctx, give_current_material(brushOb, (i + 1)), scene); + bMats->ob_mats[i] = RE_sample_material_init(depsgraph, give_current_material(brushOb, (i + 1)), scene); } } bMats->tot = tot; } else { - bMats->mat = RE_sample_material_init(eval_ctx, ui_mat, scene); + bMats->mat = RE_sample_material_init(depsgraph, ui_mat, scene); } } @@ -3740,7 +3741,7 @@ static void dynamic_paint_brush_velocity_compute_cb( } static void dynamicPaint_brushMeshCalculateVelocity( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, DynamicPaintBrushSettings *brush, Vec3f **brushVel, float timescale) { float prev_obmat[4][4]; @@ -3763,7 +3764,7 @@ static void dynamicPaint_brushMeshCalculateVelocity( scene->r.subframe = prev_sfra; BKE_object_modifier_update_subframe( - eval_ctx, scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + depsgraph, scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); dm_p = CDDM_copy(brush->dm); numOfVerts_p = dm_p->getNumVerts(dm_p); mvert_p = dm_p->getVertArray(dm_p); @@ -3774,7 +3775,7 @@ static void dynamicPaint_brushMeshCalculateVelocity( scene->r.subframe = cur_sfra; BKE_object_modifier_update_subframe( - eval_ctx, scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + depsgraph, scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); dm_c = brush->dm; numOfVerts_c = dm_c->getNumVerts(dm_c); mvert_c = dm_p->getVertArray(dm_c); @@ -3805,7 +3806,7 @@ static void dynamicPaint_brushMeshCalculateVelocity( } /* calculate velocity for object center point */ -static void dynamicPaint_brushObjectCalculateVelocity(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, Vec3f *brushVel, float timescale) +static void dynamicPaint_brushObjectCalculateVelocity(struct Depsgraph *depsgraph, Scene *scene, Object *ob, Vec3f *brushVel, float timescale) { float prev_obmat[4][4]; float cur_loc[3] = {0.0f}, prev_loc[3] = {0.0f}; @@ -3824,14 +3825,14 @@ static void dynamicPaint_brushObjectCalculateVelocity(const struct EvaluationCon scene->r.cfra = prev_fra; scene->r.subframe = prev_sfra; BKE_object_modifier_update_subframe( - eval_ctx, scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + depsgraph, scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); copy_m4_m4(prev_obmat, ob->obmat); /* current frame dm */ scene->r.cfra = cur_fra; scene->r.subframe = cur_sfra; BKE_object_modifier_update_subframe( - eval_ctx, scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); + depsgraph, scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); /* calculate speed */ mul_m4_v3(prev_obmat, prev_loc); @@ -4203,7 +4204,7 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex( } } -static int dynamicPaint_paintMesh(const struct EvaluationContext *eval_ctx, DynamicPaintSurface *surface, +static int dynamicPaint_paintMesh(struct Depsgraph *depsgraph, DynamicPaintSurface *surface, DynamicPaintBrushSettings *brush, Object *brushOb, BrushMaterials *bMats, @@ -4219,7 +4220,7 @@ static int dynamicPaint_paintMesh(const struct EvaluationContext *eval_ctx, Dyna const MLoop *mloop = NULL; if (brush->flags & MOD_DPAINT_USES_VELOCITY) - dynamicPaint_brushMeshCalculateVelocity(eval_ctx, scene, brushOb, brush, &brushVelocity, timescale); + dynamicPaint_brushMeshCalculateVelocity(depsgraph, scene, brushOb, brush, &brushVelocity, timescale); if (!brush->dm) return 0; @@ -4709,7 +4710,7 @@ static void dynamic_paint_paint_single_point_cb_ex( } static int dynamicPaint_paintSinglePoint( - const struct EvaluationContext *eval_ctx, DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush, + struct Depsgraph *depsgraph, DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush, Object *brushOb, BrushMaterials *bMats, Scene *scene, float timescale) { PaintSurfaceData *sData = surface->data; @@ -4717,7 +4718,7 @@ static int dynamicPaint_paintSinglePoint( Vec3f brushVel; if (brush->flags & MOD_DPAINT_USES_VELOCITY) - dynamicPaint_brushObjectCalculateVelocity(eval_ctx, scene, brushOb, &brushVel, timescale); + dynamicPaint_brushObjectCalculateVelocity(depsgraph, scene, brushOb, &brushVel, timescale); const MVert *mvert = brush->dm->getVertArray(brush->dm); @@ -5039,7 +5040,7 @@ static void dynamic_paint_prepare_effect_cb( } static int dynamicPaint_prepareEffectStep( - const struct EvaluationContext *eval_ctx, DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale) + struct Depsgraph *depsgraph, DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale) { double average_force = 0.0f; float shrink_speed = 0.0f, spread_speed = 0.0f; @@ -5050,7 +5051,7 @@ static int dynamicPaint_prepareEffectStep( /* Init force data if required */ if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) { - ListBase *effectors = pdInitEffectors(eval_ctx, scene, ob, NULL, surface->effector_weights, true); + ListBase *effectors = pdInitEffectors(depsgraph, scene, ob, NULL, surface->effector_weights, true); /* allocate memory for force data (dir vector + strength) */ *force = MEM_mallocN(sData->total_points * 4 * sizeof(float), "PaintEffectForces"); @@ -6007,7 +6008,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Vie /* * Do Dynamic Paint step. Paints scene brush objects of current state/frame to the surface. */ -static int dynamicPaint_doStep(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, DynamicPaintSurface *surface, float timescale, float subframe) +static int dynamicPaint_doStep(struct Depsgraph *depsgraph, Scene *scene, Object *ob, DynamicPaintSurface *surface, float timescale, float subframe) { PaintSurfaceData *sData = surface->data; PaintBakeData *bData = sData->bData; @@ -6035,7 +6036,7 @@ static int dynamicPaint_doStep(const struct EvaluationContext *eval_ctx, Scene * Base *base = NULL; Object *brushObj = NULL; ModifierData *md = NULL; - ViewLayer *view_layer = eval_ctx->view_layer; + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); /* backup current scene frame */ int scene_frame = scene->r.cfra; @@ -6082,12 +6083,12 @@ static int dynamicPaint_doStep(const struct EvaluationContext *eval_ctx, Scene * /* update object data on this subframe */ if (subframe) { scene_setSubframe(scene, subframe); - BKE_object_modifier_update_subframe(eval_ctx, scene, brushObj, true, SUBFRAME_RECURSION, + BKE_object_modifier_update_subframe(depsgraph, scene, brushObj, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); } /* Prepare materials if required */ if (brush_usesMaterial(brush, scene)) - dynamicPaint_updateBrushMaterials(eval_ctx, brushObj, brush->mat, scene, &bMats); + dynamicPaint_updateBrushMaterials(depsgraph, brushObj, brush->mat, scene, &bMats); /* Apply brush on the surface depending on it's collision type */ if (brush->psys && brush->psys->part && @@ -6101,11 +6102,11 @@ static int dynamicPaint_doStep(const struct EvaluationContext *eval_ctx, Scene * } /* Object center distance: */ if (brush->collision == MOD_DPAINT_COL_POINT && brushObj != ob) { - dynamicPaint_paintSinglePoint(eval_ctx, surface, brushObj->loc, brush, brushObj, &bMats, scene, timescale); + dynamicPaint_paintSinglePoint(depsgraph, surface, brushObj->loc, brush, brushObj, &bMats, scene, timescale); } /* Mesh volume/proximity: */ else if (brushObj != ob) { - dynamicPaint_paintMesh(eval_ctx, surface, brush, brushObj, &bMats, scene, timescale); + dynamicPaint_paintMesh(depsgraph, surface, brush, brushObj, &bMats, scene, timescale); } /* free temp material data */ @@ -6115,7 +6116,7 @@ static int dynamicPaint_doStep(const struct EvaluationContext *eval_ctx, Scene * if (subframe) { scene->r.cfra = scene_frame; scene->r.subframe = scene_subframe; - BKE_object_modifier_update_subframe(eval_ctx, scene, brushObj, true, SUBFRAME_RECURSION, + BKE_object_modifier_update_subframe(depsgraph, scene, brushObj, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint); } @@ -6150,7 +6151,7 @@ static int dynamicPaint_doStep(const struct EvaluationContext *eval_ctx, Scene * return setError(canvas, N_("Not enough free memory")); /* Prepare effects and get number of required steps */ - steps = dynamicPaint_prepareEffectStep(eval_ctx, surface, scene, ob, &force, timescale); + steps = dynamicPaint_prepareEffectStep(depsgraph, surface, scene, ob, &force, timescale); for (s = 0; s < steps; s++) { dynamicPaint_doEffectStep(surface, force, prevPoint, timescale, (float)steps); } @@ -6175,7 +6176,7 @@ static int dynamicPaint_doStep(const struct EvaluationContext *eval_ctx, Scene * * Calculate a single frame and included subframes for surface */ int dynamicPaint_calculateFrame( - DynamicPaintSurface *surface, const struct EvaluationContext *eval_ctx, + DynamicPaintSurface *surface, struct Depsgraph *depsgraph, Scene *scene, Object *cObject, int frame) { float timescale = 1.0f; @@ -6185,7 +6186,8 @@ int dynamicPaint_calculateFrame( dynamicPaint_applySurfaceDisplace(surface, surface->canvas->dm); /* update bake data */ - dynamicPaint_generateBakeData(surface, eval_ctx->view_layer, cObject); + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); + dynamicPaint_generateBakeData(surface, view_layer, cObject); /* don't do substeps for first frame */ if (surface->substeps && (frame != surface->start_frame)) { @@ -6194,10 +6196,10 @@ int dynamicPaint_calculateFrame( for (st = 1; st <= surface->substeps; st++) { float subframe = ((float) st) / (surface->substeps + 1); - if (!dynamicPaint_doStep(eval_ctx, scene, cObject, surface, timescale, subframe)) + if (!dynamicPaint_doStep(depsgraph, scene, cObject, surface, timescale, subframe)) return 0; } } - return dynamicPaint_doStep(eval_ctx, scene, cObject, surface, timescale, 0.0f); + return dynamicPaint_doStep(depsgraph, scene, cObject, surface, timescale, 0.0f); } diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 2018962eb62..4281443220d 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -2176,14 +2176,14 @@ static void cage_mapped_verts_callback( } } -float (*BKE_editmesh_vertexCos_get(const struct EvaluationContext *eval_ctx, BMEditMesh *em, Scene *scene, int *r_numVerts))[3] +float (*BKE_editmesh_vertexCos_get(struct Depsgraph *depsgraph, BMEditMesh *em, Scene *scene, int *r_numVerts))[3] { DerivedMesh *cage, *final; BLI_bitmap *visit_bitmap; struct CageUserData data; float (*cos_cage)[3]; - cage = editbmesh_get_derived_cage_and_final(eval_ctx, scene, em->ob, em, CD_MASK_BAREMESH, &final); + cage = editbmesh_get_derived_cage_and_final(depsgraph, scene, em->ob, em, CD_MASK_BAREMESH, &final); cos_cage = MEM_callocN(sizeof(*cos_cage) * em->bm->totvert, "bmbvh cos_cage"); /* when initializing cage verts, we only want the first cage coordinate for each vertex, diff --git a/source/blender/blenkernel/intern/editmesh.c b/source/blender/blenkernel/intern/editmesh.c index c95da3b2569..b63ab276b14 100644 --- a/source/blender/blenkernel/intern/editmesh.c +++ b/source/blender/blenkernel/intern/editmesh.c @@ -89,11 +89,13 @@ BMEditMesh *BKE_editmesh_from_object(Object *ob) { BLI_assert(ob->type == OB_MESH); /* sanity check */ +#if 0 /* disable in mutlti-object edit. */ #ifndef NDEBUG if (((Mesh *)ob->data)->edit_btmesh) { BLI_assert(((Mesh *)ob->data)->edit_btmesh->ob == ob); } #endif +#endif return ((Mesh *)ob->data)->edit_btmesh; } diff --git a/source/blender/blenkernel/intern/editmesh_bvh.c b/source/blender/blenkernel/intern/editmesh_bvh.c index 2927354241c..e68f11f6274 100644 --- a/source/blender/blenkernel/intern/editmesh_bvh.c +++ b/source/blender/blenkernel/intern/editmesh_bvh.c @@ -547,4 +547,4 @@ BVHTreeOverlap *BKE_bmbvh_overlap(const BMBVHTree *bmtree_a, const BMBVHTree *bm data.epsilon = max_ff(BLI_bvhtree_get_epsilon(bmtree_a->tree), BLI_bvhtree_get_epsilon(bmtree_b->tree)); return BLI_bvhtree_overlap(bmtree_a->tree, bmtree_b->tree, r_overlap_tot, bmbvh_overlap_cb, &data); -}
\ No newline at end of file +} diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c index f725a1793b4..9e8b4fa8782 100644 --- a/source/blender/blenkernel/intern/editmesh_tangent.c +++ b/source/blender/blenkernel/intern/editmesh_tangent.c @@ -428,4 +428,4 @@ void BKE_editmesh_loop_tangent_calc( } /* else tangent has been built from orco */ } -/** \} */
\ No newline at end of file +/** \} */ diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index b54093555f5..8bdc74edffd 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -74,6 +74,7 @@ #include "BKE_smoke.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "RE_render_ext.h" #include "RE_shader_ext.h" @@ -148,10 +149,10 @@ void free_partdeflect(PartDeflect *pd) MEM_freeN(pd); } -static EffectorCache *new_effector_cache(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, ParticleSystem *psys, PartDeflect *pd) +static EffectorCache *new_effector_cache(struct Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, PartDeflect *pd) { EffectorCache *eff = MEM_callocN(sizeof(EffectorCache), "EffectorCache"); - eff->eval_ctx = eval_ctx; + eff->depsgraph = depsgraph; eff->scene = scene; eff->ob = ob; eff->psys = psys; @@ -159,7 +160,7 @@ static EffectorCache *new_effector_cache(const struct EvaluationContext *eval_ct eff->frame = -1; return eff; } -static void add_object_to_effectors(ListBase **effectors, const struct EvaluationContext *eval_ctx, Scene *scene, EffectorWeights *weights, Object *ob, Object *ob_src, bool for_simulation) +static void add_object_to_effectors(ListBase **effectors, struct Depsgraph *depsgraph, Scene *scene, EffectorWeights *weights, Object *ob, Object *ob_src, bool for_simulation) { EffectorCache *eff = NULL; @@ -177,14 +178,14 @@ static void add_object_to_effectors(ListBase **effectors, const struct Evaluatio if (*effectors == NULL) *effectors = MEM_callocN(sizeof(ListBase), "effectors list"); - eff = new_effector_cache(eval_ctx, scene, ob, NULL, ob->pd); + eff = new_effector_cache(depsgraph, scene, ob, NULL, ob->pd); /* make sure imat is up to date */ invert_m4_m4(ob->imat, ob->obmat); BLI_addtail(*effectors, eff); } -static void add_particles_to_effectors(ListBase **effectors, const struct EvaluationContext *eval_ctx, Scene *scene, EffectorWeights *weights, Object *ob, ParticleSystem *psys, ParticleSystem *psys_src, bool for_simulation) +static void add_particles_to_effectors(ListBase **effectors, struct Depsgraph *depsgraph, Scene *scene, EffectorWeights *weights, Object *ob, ParticleSystem *psys, ParticleSystem *psys_src, bool for_simulation) { ParticleSettings *part= psys->part; @@ -198,20 +199,20 @@ static void add_particles_to_effectors(ListBase **effectors, const struct Evalua if (*effectors == NULL) *effectors = MEM_callocN(sizeof(ListBase), "effectors list"); - BLI_addtail(*effectors, new_effector_cache(eval_ctx, scene, ob, psys, part->pd)); + BLI_addtail(*effectors, new_effector_cache(depsgraph, scene, ob, psys, part->pd)); } if (part->pd2 && part->pd2->forcefield && (!for_simulation || weights->weight[part->pd2->forcefield] != 0.0f)) { if (*effectors == NULL) *effectors = MEM_callocN(sizeof(ListBase), "effectors list"); - BLI_addtail(*effectors, new_effector_cache(eval_ctx, scene, ob, psys, part->pd2)); + BLI_addtail(*effectors, new_effector_cache(depsgraph, scene, ob, psys, part->pd2)); } } /* returns ListBase handle with objects taking part in the effecting */ ListBase *pdInitEffectors( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob_src, ParticleSystem *psys_src, + struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, ParticleSystem *psys_src, EffectorWeights *weights, bool for_simulation) { ViewLayer *view_layer; @@ -222,11 +223,11 @@ ListBase *pdInitEffectors( view_layer = weights->group->view_layer; } /* TODO(mai): the check for view_layer shouldnt be needed, remove when render engine api is updated for this */ - else if (eval_ctx && eval_ctx->view_layer) { - view_layer = eval_ctx->view_layer; + else if (depsgraph && DEG_get_evaluated_view_layer(depsgraph)) { + view_layer = DEG_get_evaluated_view_layer(depsgraph); } else { - /* eval_ctx is NULL during deg build */ + /* depsgraph is NULL during deg build */ view_layer = BKE_view_layer_context_active_PLACEHOLDER(scene); } @@ -236,20 +237,20 @@ ListBase *pdInitEffectors( } if (base->object->pd && base->object->pd->forcefield) { - add_object_to_effectors(&effectors, eval_ctx, scene, weights, base->object, ob_src, for_simulation); + add_object_to_effectors(&effectors, depsgraph, scene, weights, base->object, ob_src, for_simulation); } if (base->object->particlesystem.first) { ParticleSystem *psys= base->object->particlesystem.first; for (; psys; psys=psys->next) { - add_particles_to_effectors(&effectors, eval_ctx, scene, weights, base->object, psys, psys_src, for_simulation); + add_particles_to_effectors(&effectors, depsgraph, scene, weights, base->object, psys, psys_src, for_simulation); } } } if (for_simulation) { - pdPrecalculateEffectors(eval_ctx, effectors); + pdPrecalculateEffectors(depsgraph, effectors); } return effectors; @@ -271,7 +272,7 @@ void pdEndEffectors(ListBase **effectors) } } -static void precalculate_effector(const struct EvaluationContext *eval_ctx, EffectorCache *eff) +static void precalculate_effector(struct Depsgraph *depsgraph, EffectorCache *eff) { unsigned int cfra = (unsigned int)(eff->scene->r.cfra >= 0 ? eff->scene->r.cfra : -eff->scene->r.cfra); if (!eff->pd->rng) @@ -283,7 +284,7 @@ static void precalculate_effector(const struct EvaluationContext *eval_ctx, Effe Curve *cu= eff->ob->data; if (cu->flag & CU_PATH) { if (eff->ob->curve_cache == NULL || eff->ob->curve_cache->path==NULL || eff->ob->curve_cache->path->data==NULL) - BKE_displist_make_curveTypes(eval_ctx, eff->scene, eff->ob, 0); + BKE_displist_make_curveTypes(depsgraph, eff->scene, eff->ob, 0); if (eff->ob->curve_cache->path && eff->ob->curve_cache->path->data) { where_on_path(eff->ob, 0.0, eff->guide_loc, eff->guide_dir, NULL, &eff->guide_radius, NULL); @@ -304,19 +305,19 @@ static void precalculate_effector(const struct EvaluationContext *eval_ctx, Effe if (eff->ob) { float old_vel[3]; - BKE_object_where_is_calc_time(eval_ctx, eff->scene, eff->ob, cfra - 1.0f); + BKE_object_where_is_calc_time(depsgraph, eff->scene, eff->ob, cfra - 1.0f); copy_v3_v3(old_vel, eff->ob->obmat[3]); - BKE_object_where_is_calc_time(eval_ctx, eff->scene, eff->ob, cfra); + BKE_object_where_is_calc_time(depsgraph, eff->scene, eff->ob, cfra); sub_v3_v3v3(eff->velocity, eff->ob->obmat[3], old_vel); } } -void pdPrecalculateEffectors(const struct EvaluationContext *eval_ctx, ListBase *effectors) +void pdPrecalculateEffectors(struct Depsgraph *depsgraph, ListBase *effectors) { if (effectors) { EffectorCache *eff = effectors->first; for (; eff; eff=eff->next) - precalculate_effector(eval_ctx, eff); + precalculate_effector(depsgraph, eff); } } @@ -507,28 +508,28 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNU falloff=0.0f; else { switch (eff->pd->falloff) { - case PFIELD_FALL_SPHERE: - falloff*= falloff_func_dist(eff->pd, efd->distance); - break; - - case PFIELD_FALL_TUBE: - falloff*= falloff_func_dist(eff->pd, ABS(fac)); - if (falloff == 0.0f) + case PFIELD_FALL_SPHERE: + falloff*= falloff_func_dist(eff->pd, efd->distance); break; - madd_v3_v3v3fl(temp, efd->vec_to_point2, efd->nor, -fac); - r_fac= len_v3(temp); - falloff*= falloff_func_rad(eff->pd, r_fac); - break; - case PFIELD_FALL_CONE: - falloff*= falloff_func_dist(eff->pd, ABS(fac)); - if (falloff == 0.0f) + case PFIELD_FALL_TUBE: + falloff*= falloff_func_dist(eff->pd, ABS(fac)); + if (falloff == 0.0f) + break; + + madd_v3_v3v3fl(temp, efd->vec_to_point2, efd->nor, -fac); + r_fac= len_v3(temp); + falloff*= falloff_func_rad(eff->pd, r_fac); break; + case PFIELD_FALL_CONE: + falloff*= falloff_func_dist(eff->pd, ABS(fac)); + if (falloff == 0.0f) + break; - r_fac= RAD2DEGF(saacos(fac/len_v3(efd->vec_to_point))); - falloff*= falloff_func_rad(eff->pd, r_fac); + r_fac= RAD2DEGF(saacos(fac/len_v3(efd->vec_to_point))); + falloff*= falloff_func_rad(eff->pd, r_fac); - break; + break; } } @@ -615,7 +616,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin } else { ParticleSimulationData sim= {NULL}; - sim.eval_ctx = eff->eval_ctx; + sim.depsgraph = eff->depsgraph; sim.scene= eff->scene; sim.ob= eff->ob; sim.psys= eff->psys; diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index d0d3317b477..c79b2bb4aee 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -64,7 +64,7 @@ // file handling //------------------------------------------------------------------------------- -void initElbeemMesh(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, +void initElbeemMesh(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int *numVertices, float **vertices, int *numTriangles, int **triangles, int useGlobalCoords, int modifierIndex) @@ -77,7 +77,7 @@ void initElbeemMesh(const struct EvaluationContext *eval_ctx, struct Scene *scen float *verts; int *tris; - dm = mesh_create_derived_index_render(eval_ctx, scene, ob, CD_MASK_BAREMESH, modifierIndex); + dm = mesh_create_derived_index_render(depsgraph, scene, ob, CD_MASK_BAREMESH, modifierIndex); mvert = dm->getVertArray(dm); mloop = dm->getLoopArray(dm); diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index 7566d370c45..ae031d21b88 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -334,7 +334,7 @@ static void group_replaces_nla(Object *parent, Object *target, char mode) * 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_group_handle_recalc_and_update(const struct EvaluationContext *eval_ctx, Scene *scene, Object *UNUSED(parent), Group *group) +void BKE_group_handle_recalc_and_update(struct Depsgraph *depsgraph, Scene *scene, Object *UNUSED(parent), Group *group) { #if 0 /* warning, isn't clearing the recalc flag on the object which causes it to run all the time, * not just on frame change. @@ -354,7 +354,7 @@ void BKE_group_handle_recalc_and_update(const struct EvaluationContext *eval_ctx go->ob->recalc = go->recalc; group_replaces_nla(parent, go->ob, 's'); - BKE_object_handle_update(eval_ctx, scene, go->ob); + BKE_object_handle_update(depsgraph, scene, go->ob); group_replaces_nla(parent, go->ob, 'e'); /* leave recalc tags in case group members are in normal scene */ @@ -372,7 +372,7 @@ void BKE_group_handle_recalc_and_update(const struct EvaluationContext *eval_ctx FOREACH_GROUP_OBJECT_BEGIN(group, object) { if (object->id.recalc & ID_RECALC_ALL) { - BKE_object_handle_update(eval_ctx, scene, object); + BKE_object_handle_update(depsgraph, scene, object); } } FOREACH_GROUP_OBJECT_END; @@ -381,9 +381,9 @@ void BKE_group_handle_recalc_and_update(const struct EvaluationContext *eval_ctx /* ******** Dependency graph evaluation ******** */ -void BKE_group_eval_view_layers(const struct EvaluationContext *eval_ctx, +void BKE_group_eval_view_layers(struct Depsgraph *depsgraph, Group *group) { DEG_debug_print_eval(__func__, group->id.name, group); - BKE_layer_eval_view_layer(eval_ctx, &group->id, group->view_layer); + BKE_layer_eval_view_layer(depsgraph, &group->id, group->view_layer); } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index c41ad78977e..b9e6e0e8fa9 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -1026,7 +1026,7 @@ void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]) } } -void BKE_lattice_modifiers_calc(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob) +void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob) { Lattice *lt = ob->data; VirtualModifierData virtualModifierData; @@ -1053,7 +1053,7 @@ void BKE_lattice_modifiers_calc(const struct EvaluationContext *eval_ctx, Scene if (mti->type != eModifierTypeType_OnlyDeform) continue; if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts); - mti->deformVerts(md, eval_ctx, ob, NULL, vertexCos, numVerts, 0); + mti->deformVerts(md, depsgraph, ob, NULL, vertexCos, numVerts, 0); } /* always displist to make this work like derivedmesh */ @@ -1227,7 +1227,7 @@ void BKE_lattice_translate(Lattice *lt, float offset[3], bool do_keys) /* **** Depsgraph evaluation **** */ -void BKE_lattice_eval_geometry(const struct EvaluationContext *UNUSED(eval_ctx), +void BKE_lattice_eval_geometry(struct Depsgraph *UNUSED(depsgraph), Lattice *UNUSED(latt)) { } diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 50c7dc0c02f..2e4dd1b0d62 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -26,6 +26,7 @@ #include <string.h> +#include "BLI_array.h" #include "BLI_listbase.h" #include "BLI_string.h" #include "BLI_string_utf8.h" @@ -41,8 +42,7 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_workspace.h" - -#include "DEG_depsgraph.h" +#include "BKE_object.h" #include "DNA_group_types.h" #include "DNA_ID.h" @@ -53,6 +53,9 @@ #include "DNA_windowmanager_types.h" #include "DNA_workspace_types.h" +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" + #include "DRW_engine.h" #include "MEM_guardedalloc.h" @@ -2235,6 +2238,61 @@ void BKE_renderable_objects_iterator_end(BLI_Iterator *UNUSED(iter)) /* Do nothing - iter->data was static allocated, we can't free it. */ } +/* -------------------------------------------------------------------- */ +/** \name BKE_view_layer_objects_in_mode_iterator + * \{ */ + +void BKE_view_layer_objects_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in) +{ + struct ObjectsInModeIteratorData *data = data_in; + Base *base = data->base_active; + + /* when there are no objects */ + if (base == NULL) { + iter->valid = false; + return; + } + iter->data = data_in; + iter->current = base; +} + +void BKE_view_layer_objects_in_mode_iterator_next(BLI_Iterator *iter) +{ + struct ObjectsInModeIteratorData *data = iter->data; + Base *base = iter->current; + + if (base == data->base_active) { + /* first step */ + base = data->view_layer->object_bases.first; + if (base == data->base_active) { + base = base->next; + } + } + else { + base = base->next; + } + + while (base) { + if ((base->flag & BASE_SELECTED) != 0 && + (base->object->type == data->base_active->object->type) && + (base != data->base_active) && + (base->object->mode & data->object_mode)) + { + iter->current = base; + return; + } + base = base->next; + } + iter->valid = false; +} + +void BKE_view_layer_objects_in_mode_iterator_end(BLI_Iterator *UNUSED(iter)) +{ + /* do nothing */ +} + +/** \} */ + /* Evaluation */ /** @@ -2285,13 +2343,13 @@ static const char *collection_type_lookup[] = * \note We can't use layer_collection->flag because of 3 level nesting (where parent is visible, but not grand-parent) * So layer_collection->flag_evaluated is expected to be up to date with layer_collection->flag. */ -static bool layer_collection_visible_get(const EvaluationContext *eval_ctx, LayerCollection *layer_collection) +static bool layer_collection_visible_get(Depsgraph *depsgraph, LayerCollection *layer_collection) { if (layer_collection->flag_evaluated & COLLECTION_DISABLED) { return false; } - if (eval_ctx->mode == DAG_EVAL_VIEWPORT) { + if (DEG_get_mode(depsgraph) == DAG_EVAL_VIEWPORT) { return (layer_collection->flag_evaluated & COLLECTION_VIEWPORT) != 0; } else { @@ -2299,7 +2357,7 @@ static bool layer_collection_visible_get(const EvaluationContext *eval_ctx, Laye } } -static void layer_eval_layer_collection(const EvaluationContext *eval_ctx, +static void layer_eval_layer_collection(Depsgraph *depsgraph, LayerCollection *layer_collection, LayerCollection *parent_layer_collection) { @@ -2320,7 +2378,7 @@ static void layer_eval_layer_collection(const EvaluationContext *eval_ctx, layer_collection->flag_evaluated = layer_collection->flag; if (parent_layer_collection != NULL) { - if (layer_collection_visible_get(eval_ctx, parent_layer_collection) == false) { + if (layer_collection_visible_get(depsgraph, parent_layer_collection) == false) { layer_collection->flag_evaluated |= COLLECTION_DISABLED; } @@ -2331,7 +2389,7 @@ static void layer_eval_layer_collection(const EvaluationContext *eval_ctx, } } - const bool is_visible = layer_collection_visible_get(eval_ctx, layer_collection); + const bool is_visible = layer_collection_visible_get(depsgraph, layer_collection); const bool is_selectable = is_visible && ((layer_collection->flag_evaluated & COLLECTION_SELECTABLE) != 0); /* overrides */ @@ -2378,7 +2436,7 @@ static void layer_eval_layer_collection_post(ViewLayer *view_layer) } } -static void layer_eval_collections_recurse(const EvaluationContext *eval_ctx, +static void layer_eval_collections_recurse(Depsgraph *depsgraph, ListBase *layer_collections, LayerCollection *parent_layer_collection) { @@ -2386,27 +2444,27 @@ static void layer_eval_collections_recurse(const EvaluationContext *eval_ctx, layer_collection != NULL; layer_collection = layer_collection->next) { - layer_eval_layer_collection(eval_ctx, + layer_eval_layer_collection(depsgraph, layer_collection, parent_layer_collection); - layer_eval_collections_recurse(eval_ctx, + layer_eval_collections_recurse(depsgraph, &layer_collection->layer_collections, layer_collection); } } -void BKE_layer_eval_view_layer(const struct EvaluationContext *eval_ctx, +void BKE_layer_eval_view_layer(struct Depsgraph *depsgraph, struct ID *owner_id, ViewLayer *view_layer) { layer_eval_layer_collection_pre(owner_id, view_layer); - layer_eval_collections_recurse(eval_ctx, + layer_eval_collections_recurse(depsgraph, &view_layer->layer_collections, NULL); layer_eval_layer_collection_post(view_layer); } -void BKE_layer_eval_view_layer_indexed(const struct EvaluationContext *eval_ctx, +void BKE_layer_eval_view_layer_indexed(struct Depsgraph *depsgraph, struct ID *owner_id, int view_layer_index) { @@ -2415,7 +2473,7 @@ void BKE_layer_eval_view_layer_indexed(const struct EvaluationContext *eval_ctx, Scene *scene = (Scene *)owner_id; ViewLayer *view_layer = BLI_findlink(&scene->view_layers, view_layer_index); BLI_assert(view_layer != NULL); - BKE_layer_eval_view_layer(eval_ctx, owner_id, view_layer); + BKE_layer_eval_view_layer(depsgraph, owner_id, view_layer); } /** diff --git a/source/blender/blenkernel/intern/layer_utils.c b/source/blender/blenkernel/intern/layer_utils.c new file mode 100644 index 00000000000..94bac8a33d6 --- /dev/null +++ b/source/blender/blenkernel/intern/layer_utils.c @@ -0,0 +1,125 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/layer_utils.c + * \ingroup bke + */ + +#include <string.h> + +#include "BLI_array.h" +#include "BLI_listbase.h" + +#include "BKE_collection.h" +#include "BKE_editmesh.h" +#include "BKE_layer.h" + +#include "DNA_ID.h" +#include "DNA_layer_types.h" +#include "DNA_object_types.h" +#include "DNA_mesh_types.h" +#include "DNA_scene_types.h" + +#include "MEM_guardedalloc.h" + +Base **BKE_view_layer_array_from_bases_in_mode_params( + ViewLayer *view_layer, uint *r_len, + const struct ObjectsInModeParams *params) +{ + if (params->no_dup_data) { + FOREACH_BASE_IN_MODE_BEGIN(view_layer, params->object_mode, base_iter) { + ID *id = base_iter->object->data; + if (id) { + id->tag |= LIB_TAG_DOIT; + } + } FOREACH_BASE_IN_MODE_END; + } + + Base **base_array = NULL; + BLI_array_declare(base_array); + + FOREACH_BASE_IN_MODE_BEGIN(view_layer, params->object_mode, base_iter) { + if (params->filter_fn) { + if (!params->filter_fn(base_iter->object, params->filter_userdata)) { + continue; + } + } + if (params->no_dup_data) { + ID *id = base_iter->object->data; + if (id) { + if (id->tag & LIB_TAG_DOIT) { + id->tag &= ~LIB_TAG_DOIT; + } + else { + continue; + } + } + } + BLI_array_append(base_array, base_iter); + } FOREACH_BASE_IN_MODE_END; + + if (base_array != NULL) { + base_array = MEM_reallocN(base_array, sizeof(*base_array) * BLI_array_len(base_array)); + } + *r_len = BLI_array_len(base_array); + return base_array; +} + +Object **BKE_view_layer_array_from_objects_in_mode_params( + ViewLayer *view_layer, uint *r_len, + const struct ObjectsInModeParams *params) +{ + Base **base_array = BKE_view_layer_array_from_bases_in_mode_params( + view_layer, r_len, params); + if (base_array != NULL) { + for (uint i = 0; i < *r_len; i++) { + ((Object **)base_array)[i] = base_array[i]->object; + } + } + return (Object **)base_array; +} + +bool BKE_view_layer_filter_edit_mesh_has_uvs(Object *ob, void *UNUSED(user_data)) +{ + if (ob->type == OB_MESH) { + Mesh *me = ob->data; + BMEditMesh *em = me->edit_btmesh; + if (em != NULL) { + if (CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV) != -1) { + return true; + } + } + } + return false; +} + +bool BKE_view_layer_filter_edit_mesh_has_edges(Object *ob, void *UNUSED(user_data)) +{ + if (ob->type == OB_MESH) { + Mesh *me = ob->data; + BMEditMesh *em = me->edit_btmesh; + if (em != NULL) { + if (em->bm->totedge != 0) { + return true; + } + } + } + return false; +} diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 6ec2d223e84..c0eb9e77087 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1466,7 +1466,6 @@ void BKE_library_free(Library *lib) Main *BKE_main_new(void) { Main *bmain = MEM_callocN(sizeof(Main), "new main"); - bmain->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_VIEWPORT); bmain->lock = MEM_mallocN(sizeof(SpinLock), "main lock"); BLI_spin_init((SpinLock *)bmain->lock); return bmain; @@ -1541,7 +1540,6 @@ void BKE_main_free(Main *mainvar) BLI_spin_end((SpinLock *)mainvar->lock); MEM_freeN(mainvar->lock); - DEG_evaluation_context_free(mainvar->eval_ctx); MEM_freeN(mainvar); } diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index 61c136d2c4f..651bcddc84a 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -40,11 +40,13 @@ #include "BLI_math.h" #include "DNA_mask_types.h" +#include "DNA_object_types.h" #include "BKE_curve.h" #include "BKE_mask.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" unsigned int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) { @@ -896,24 +898,26 @@ void BKE_mask_layer_evaluate_deform(MaskLayer *masklay, const float ctime) } } -void BKE_mask_eval_animation(struct EvaluationContext *eval_ctx, Mask *mask) +void BKE_mask_eval_animation(struct Depsgraph *depsgraph, Mask *mask) { + float ctime = DEG_get_ctime(depsgraph); DEG_debug_print_eval(__func__, mask->id.name, mask); for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer != NULL; mask_layer = mask_layer->next) { - BKE_mask_layer_evaluate_animation(mask_layer, eval_ctx->ctime); + BKE_mask_layer_evaluate_animation(mask_layer, ctime); } } -void BKE_mask_eval_update(struct EvaluationContext *eval_ctx, Mask *mask) +void BKE_mask_eval_update(struct Depsgraph *depsgraph, Mask *mask) { + float ctime = DEG_get_ctime(depsgraph); DEG_debug_print_eval(__func__, mask->id.name, mask); for (MaskLayer *mask_layer = mask->masklayers.first; mask_layer != NULL; mask_layer = mask_layer->next) { - BKE_mask_layer_evaluate_deform(mask_layer, eval_ctx->ctime); + BKE_mask_layer_evaluate_deform(mask_layer, ctime); } } diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 2971f56c775..f80f726607b 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1777,7 +1777,7 @@ bool BKE_object_material_edit_image_set(Object *ob, short mat_nr, Image *image) return false; } -void BKE_material_eval(const struct EvaluationContext *UNUSED(eval_ctx), Material *material) +void BKE_material_eval(struct Depsgraph *UNUSED(depsgraph), Material *material) { DEG_debug_print_eval(__func__, material->id.name, material); if ((BLI_listbase_is_empty(&material->gpumaterial) == false)) { diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index cc801b2d8c3..47f15e99b5f 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -329,12 +329,14 @@ void BKE_mball_properties_copy(Scene *scene, Object *active_object) int basisnr, obnr; char basisname[MAX_ID_NAME], obname[MAX_ID_NAME]; SceneBaseIter iter; - struct EvaluationContext *eval_ctx = G.main->eval_ctx; BLI_split_name_num(basisname, &basisnr, active_object->id.name + 2, '.'); - BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 0, NULL, NULL); - while (BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 1, &base, &ob)) { + /* Pass depsgraph as NULL, which means we will not expand into + * duplis unlike when we generate the mball. Expanding duplis + * would not be compatible when editing multiple view layers. */ + BKE_scene_base_iter_next(NULL, &iter, &sce_iter, 0, NULL, NULL); + while (BKE_scene_base_iter_next(NULL, &iter, &sce_iter, 1, &base, &ob)) { if (ob->type == OB_MBALL) { if (ob != active_object) { BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); @@ -541,7 +543,7 @@ void BKE_mball_select_swap(struct MetaBall *mb) /* **** Depsgraph evaluation **** */ -void BKE_mball_eval_geometry(const struct EvaluationContext *UNUSED(eval_ctx), +void BKE_mball_eval_geometry(struct Depsgraph *UNUSED(depsgraph), MetaBall *UNUSED(mball)) { } diff --git a/source/blender/blenkernel/intern/mball_tessellate.c b/source/blender/blenkernel/intern/mball_tessellate.c index 5e63b5c1607..0f13618c76a 100644 --- a/source/blender/blenkernel/intern/mball_tessellate.c +++ b/source/blender/blenkernel/intern/mball_tessellate.c @@ -53,6 +53,7 @@ #include "BKE_mball_tessellate.h" /* own include */ #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "BLI_strict_flags.h" @@ -1056,7 +1057,7 @@ static void polygonize(PROCESS *process) * Iterates over ALL objects in the scene and all of its sets, including * making all duplis(not only metas). Copies metas to mainb array. * Computes bounding boxes for building BVH. */ -static void init_meta(const EvaluationContext *eval_ctx, PROCESS *process, Scene *scene, Object *ob) +static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Object *ob) { Scene *sce_iter = scene; Base *base; @@ -1075,8 +1076,8 @@ static void init_meta(const EvaluationContext *eval_ctx, PROCESS *process, Scene BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); /* make main array */ - BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 0, NULL, NULL); - while (BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 1, &base, &bob)) { + BKE_scene_base_iter_next(depsgraph, &iter, &sce_iter, 0, NULL, NULL); + while (BKE_scene_base_iter_next(depsgraph, &iter, &sce_iter, 1, &base, &bob)) { if (bob->type == OB_MBALL) { zero_size = 0; ml = NULL; @@ -1233,12 +1234,13 @@ static void init_meta(const EvaluationContext *eval_ctx, PROCESS *process, Scene } } -void BKE_mball_polygonize(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *dispbase) +void BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase) { MetaBall *mb; DispList *dl; unsigned int a; PROCESS process = {0}; + bool is_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER; mb = ob->data; @@ -1249,10 +1251,10 @@ void BKE_mball_polygonize(const EvaluationContext *eval_ctx, Scene *scene, Objec else if (process.thresh < 0.1f) process.converge_res = 4; else process.converge_res = 2; - if ((eval_ctx->mode != DAG_EVAL_RENDER) && (mb->flag == MB_UPDATE_NEVER)) return; + if (is_render && (mb->flag == MB_UPDATE_NEVER)) return; if ((G.moving & (G_TRANSFORM_OBJ | G_TRANSFORM_EDIT)) && mb->flag == MB_UPDATE_FAST) return; - if (eval_ctx->mode == DAG_EVAL_RENDER) { + if (is_render) { process.size = mb->rendersize; } else { @@ -1267,7 +1269,7 @@ void BKE_mball_polygonize(const EvaluationContext *eval_ctx, Scene *scene, Objec process.pgn_elements = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "Metaball memarena"); /* initialize all mainb (MetaElems) */ - init_meta(eval_ctx, &process, scene, ob); + init_meta(depsgraph, &process, scene, ob); if (process.totelem > 0) { build_bvh_spatial(&process, &process.metaball_bvh, 0, process.totelem, &process.allbb); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index af92422f4c3..bbe5fd9765e 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1643,10 +1643,10 @@ void BKE_mesh_to_curve_nurblist(DerivedMesh *dm, ListBase *nurblist, const int e } } -void BKE_mesh_to_curve(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +void BKE_mesh_to_curve(Depsgraph *depsgraph, Scene *scene, Object *ob) { /* make new mesh data from the original copy */ - DerivedMesh *dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_MESH); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_MESH); ListBase nurblist = {NULL, NULL}; bool needsFree = false; @@ -2428,13 +2428,13 @@ void BKE_mesh_split_faces(Mesh *mesh, bool free_loop_normals) /* settings: 1 - preview, 2 - render */ Mesh *BKE_mesh_new_from_object( - const EvaluationContext *eval_ctx, Main *bmain, Scene *sce, Object *ob, + Depsgraph *depsgraph, Main *bmain, Scene *sce, Object *ob, int apply_modifiers, int calc_tessface, int calc_undeformed) { Mesh *tmpmesh; Curve *tmpcu = NULL, *copycu; int i; - const bool render = (DEG_get_mode(eval_ctx->depsgraph) == DAG_EVAL_RENDER); + const bool render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); const bool cage = !apply_modifiers; bool do_mat_id_data_us = true; @@ -2487,7 +2487,7 @@ Mesh *BKE_mesh_new_from_object( copycu->editnurb = tmpcu->editnurb; /* get updated display list, and convert to a mesh */ - BKE_displist_make_curveTypes_forRender(eval_ctx, sce, tmpobj, &dispbase, &derivedFinal, false, render); + BKE_displist_make_curveTypes_forRender(depsgraph, sce, tmpobj, &dispbase, &derivedFinal, false, render); copycu->editfont = NULL; copycu->editnurb = NULL; @@ -2536,7 +2536,7 @@ Mesh *BKE_mesh_new_from_object( if (render) { ListBase disp = {NULL, NULL}; - BKE_displist_make_mball_forRender(eval_ctx, sce, ob, &disp); + BKE_displist_make_mball_forRender(depsgraph, sce, ob, &disp); BKE_mesh_from_metaball(&disp, tmpmesh); BKE_displist_free(&disp); } @@ -2575,9 +2575,9 @@ Mesh *BKE_mesh_new_from_object( /* Write the display mesh into the dummy mesh */ if (render) - dm = mesh_create_derived_render(eval_ctx, sce, ob, mask); + dm = mesh_create_derived_render(depsgraph, sce, ob, mask); else - dm = mesh_create_derived_view(eval_ctx, sce, ob, mask); + dm = mesh_create_derived_view(depsgraph, sce, ob, mask); tmpmesh = BKE_mesh_add(bmain, ((ID *)ob->data)->name + 2); DM_to_mesh(dm, tmpmesh, ob, mask, true); @@ -2668,7 +2668,7 @@ Mesh *BKE_mesh_new_from_object( /* **** Depsgraph evaluation **** */ -void BKE_mesh_eval_geometry(const EvaluationContext *UNUSED(eval_ctx), +void BKE_mesh_eval_geometry(Depsgraph *UNUSED(depsgraph), Mesh *mesh) { DEG_debug_print_eval(__func__, mesh->id.name, mesh); diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c index 77288bd672e..05a5a5e8703 100644 --- a/source/blender/blenkernel/intern/mesh_tangent.c +++ b/source/blender/blenkernel/intern/mesh_tangent.c @@ -472,7 +472,8 @@ void BKE_mesh_calc_loop_tangent_step_0( const CustomData *loopData, bool calc_active_tangent, const char (*tangent_names)[MAX_NAME], int tangent_names_count, bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n, - char *ract_uv_name, char *rren_uv_name, short *rtangent_mask) { + char *ract_uv_name, char *rren_uv_name, short *rtangent_mask) +{ /* Active uv in viewport */ int layer_index = CustomData_get_layer_index(loopData, CD_MLOOPUV); *ract_uv_n = CustomData_get_active_layer(loopData, CD_MLOOPUV); diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 5eb5272f3e5..c15ae9e4a7c 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -786,7 +786,7 @@ void modifier_path_init(char *path, int path_maxlen, const char *name) /* wrapper around ModifierTypeInfo.applyModifier that ensures valid normals */ struct DerivedMesh *modwrap_applyModifier( - ModifierData *md, const struct EvaluationContext *eval_ctx, + ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct DerivedMesh *dm, ModifierApplyFlag flag) { @@ -796,11 +796,11 @@ struct DerivedMesh *modwrap_applyModifier( if (mti->dependsOnNormals && mti->dependsOnNormals(md)) { DM_ensure_normals(dm); } - return mti->applyModifier(md, eval_ctx, ob, dm, flag); + return mti->applyModifier(md, depsgraph, ob, dm, flag); } struct DerivedMesh *modwrap_applyModifierEM( - ModifierData *md, const struct EvaluationContext *eval_ctx, + ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct BMEditMesh *em, DerivedMesh *dm, ModifierApplyFlag flag) @@ -811,11 +811,11 @@ struct DerivedMesh *modwrap_applyModifierEM( if (mti->dependsOnNormals && mti->dependsOnNormals(md)) { DM_ensure_normals(dm); } - return mti->applyModifierEM(md, eval_ctx, ob, em, dm, flag); + return mti->applyModifierEM(md, depsgraph, ob, em, dm, flag); } void modwrap_deformVerts( - ModifierData *md, const struct EvaluationContext *eval_ctx, + ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *dm, float (*vertexCos)[3], int numVerts, ModifierApplyFlag flag) @@ -826,11 +826,11 @@ void modwrap_deformVerts( if (dm && mti->dependsOnNormals && mti->dependsOnNormals(md)) { DM_ensure_normals(dm); } - mti->deformVerts(md, eval_ctx, ob, dm, vertexCos, numVerts, flag); + mti->deformVerts(md, depsgraph, ob, dm, vertexCos, numVerts, flag); } void modwrap_deformVertsEM( - ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, + ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct BMEditMesh *em, DerivedMesh *dm, float (*vertexCos)[3], int numVerts) { @@ -840,6 +840,6 @@ void modwrap_deformVertsEM( if (dm && mti->dependsOnNormals && mti->dependsOnNormals(md)) { DM_ensure_normals(dm); } - mti->deformVertsEM(md, eval_ctx, ob, em, dm, vertexCos, numVerts); + mti->deformVertsEM(md, depsgraph, ob, em, dm, vertexCos, numVerts); } /* end modifier callback wrappers */ diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 9ed715d7591..36a5a60635a 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -1609,7 +1609,7 @@ bool BKE_movieclip_put_frame_if_possible(MovieClip *clip, return result; } -void BKE_movieclip_eval_update(struct EvaluationContext *UNUSED(eval_ctx), MovieClip *clip) +void BKE_movieclip_eval_update(struct Depsgraph *UNUSED(depsgraph), MovieClip *clip) { DEG_debug_print_eval(__func__, clip->id.name, clip); BKE_tracking_dopesheet_tag_update(&clip->tracking); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 55f11604710..edba03dd707 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -277,14 +277,14 @@ static MDisps *multires_mdisps_initialize_hidden(Mesh *me, int level) return mdisps; } -DerivedMesh *get_multires_dm(const struct EvaluationContext *eval_ctx, Scene *scene, MultiresModifierData *mmd, Object *ob) +DerivedMesh *get_multires_dm(struct Depsgraph *depsgraph, Scene *scene, MultiresModifierData *mmd, Object *ob) { ModifierData *md = (ModifierData *)mmd; const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - DerivedMesh *tdm = mesh_get_derived_deform(eval_ctx, scene, ob, CD_MASK_BAREMESH); + DerivedMesh *tdm = mesh_get_derived_deform(depsgraph, scene, ob, CD_MASK_BAREMESH); DerivedMesh *dm; - dm = mti->applyModifier(md, eval_ctx, ob, tdm, MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY); + dm = mti->applyModifier(md, depsgraph, ob, tdm, MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY); if (dm == tdm) { dm = CDDM_copy(tdm); } @@ -398,10 +398,10 @@ void multires_force_render_update(Object *ob) multires_force_update(ob); } -int multiresModifier_reshapeFromDM(const struct EvaluationContext *eval_ctx, Scene *scene, MultiresModifierData *mmd, +int multiresModifier_reshapeFromDM(struct Depsgraph *depsgraph, Scene *scene, MultiresModifierData *mmd, Object *ob, DerivedMesh *srcdm) { - DerivedMesh *mrdm = get_multires_dm(eval_ctx, scene, mmd, ob); + DerivedMesh *mrdm = get_multires_dm(depsgraph, scene, mmd, ob); if (mrdm && srcdm && mrdm->getNumVerts(mrdm) == srcdm->getNumVerts(srcdm)) { multires_mvert_to_ss(mrdm, srcdm->getVertArray(srcdm)); @@ -420,13 +420,13 @@ int multiresModifier_reshapeFromDM(const struct EvaluationContext *eval_ctx, Sce } /* Returns 1 on success, 0 if the src's totvert doesn't match */ -int multiresModifier_reshape(const struct EvaluationContext *eval_ctx, Scene *scene, MultiresModifierData *mmd, Object *dst, Object *src) +int multiresModifier_reshape(struct Depsgraph *depsgraph, Scene *scene, MultiresModifierData *mmd, Object *dst, Object *src) { - DerivedMesh *srcdm = mesh_get_derived_final(eval_ctx, scene, src, CD_MASK_BAREMESH); - return multiresModifier_reshapeFromDM(eval_ctx, scene, mmd, dst, srcdm); + DerivedMesh *srcdm = mesh_get_derived_final(depsgraph, scene, src, CD_MASK_BAREMESH); + return multiresModifier_reshapeFromDM(depsgraph, scene, mmd, dst, srcdm); } -int multiresModifier_reshapeFromDeformMod(const struct EvaluationContext *eval_ctx, Scene *scene, MultiresModifierData *mmd, +int multiresModifier_reshapeFromDeformMod(struct Depsgraph *depsgraph, Scene *scene, MultiresModifierData *mmd, Object *ob, ModifierData *md) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -438,12 +438,12 @@ int multiresModifier_reshapeFromDeformMod(const struct EvaluationContext *eval_c return 0; /* Create DerivedMesh for deformation modifier */ - dm = get_multires_dm(eval_ctx, scene, mmd, ob); + dm = get_multires_dm(depsgraph, scene, mmd, ob); numVerts = dm->getNumVerts(dm); deformedVerts = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "multiresReshape_deformVerts"); dm->getVertCos(dm, deformedVerts); - mti->deformVerts(md, eval_ctx, ob, dm, deformedVerts, numVerts, 0); + mti->deformVerts(md, depsgraph, ob, dm, deformedVerts, numVerts, 0); ndm = CDDM_copy(dm); CDDM_apply_vert_coords(ndm, deformedVerts); @@ -452,7 +452,7 @@ int multiresModifier_reshapeFromDeformMod(const struct EvaluationContext *eval_c dm->release(dm); /* Reshaping */ - result = multiresModifier_reshapeFromDM(eval_ctx, scene, mmd, ob, ndm); + result = multiresModifier_reshapeFromDM(depsgraph, scene, mmd, ob, ndm); /* Cleanup */ ndm->release(ndm); @@ -2275,7 +2275,7 @@ static void multires_apply_smat_cb( } } -static void multires_apply_smat(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float smat[3][3]) +static void multires_apply_smat(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float smat[3][3]) { DerivedMesh *dm = NULL, *cddm = NULL, *subdm = NULL; CCGElem **gridData, **subGridData; @@ -2300,10 +2300,10 @@ static void multires_apply_smat(const struct EvaluationContext *eval_ctx, Scene high_mmd.lvl = high_mmd.totlvl; /* unscaled multires with applied displacement */ - subdm = get_multires_dm(eval_ctx, scene, &high_mmd, ob); + subdm = get_multires_dm(depsgraph, scene, &high_mmd, ob); /* prepare scaled CDDM to create ccgDN */ - cddm = mesh_get_derived_deform(eval_ctx, scene, ob, CD_MASK_BAREMESH); + cddm = mesh_get_derived_deform(depsgraph, scene, ob, CD_MASK_BAREMESH); totvert = cddm->getNumVerts(cddm); vertCos = MEM_malloc_arrayN(totvert, sizeof(*vertCos), "multiresScale vertCos"); @@ -2364,17 +2364,17 @@ int multires_mdisp_corners(MDisps *s) return 0; } -void multiresModifier_scale_disp(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob) +void multiresModifier_scale_disp(struct Depsgraph *depsgraph, Scene *scene, Object *ob) { float smat[3][3]; /* object's scale matrix */ BKE_object_scale_to_mat3(ob, smat); - multires_apply_smat(eval_ctx, scene, ob, smat); + multires_apply_smat(depsgraph, scene, ob, smat); } -void multiresModifier_prepare_join(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, Object *to_ob) +void multiresModifier_prepare_join(struct Depsgraph *depsgraph, Scene *scene, Object *ob, Object *to_ob) { float smat[3][3], tmat[3][3], mat[3][3]; multires_sync_levels(scene, to_ob, ob); @@ -2385,7 +2385,7 @@ void multiresModifier_prepare_join(const struct EvaluationContext *eval_ctx, Sce BKE_object_scale_to_mat3(ob, smat); mul_m3_m3m3(mat, smat, tmat); - multires_apply_smat(eval_ctx, scene, ob, mat); + multires_apply_smat(depsgraph, scene, ob, mat); } /* update multires data after topology changing */ diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 41b7cd1f48e..845880fb60d 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -3869,7 +3869,7 @@ void BKE_nodetree_copy_default_values(bNodeTree *ntree_dst, } } -void BKE_nodetree_shading_params_eval(const struct EvaluationContext *UNUSED(eval_ctx), +void BKE_nodetree_shading_params_eval(struct Depsgraph *UNUSED(depsgraph), bNodeTree *ntree_dst, const bNodeTree *ntree_src) { diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 875d716305f..f59a942c683 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -530,6 +530,15 @@ bool BKE_object_is_in_editmode(const Object *ob) return false; } +bool BKE_object_is_in_editmode_and_selected(const Object *ob) +{ + if ((ob->flag & SELECT) && (BKE_object_is_in_editmode(ob))) { + return true; + } + return false; +} + + bool BKE_object_is_in_editmode_vgroup(const Object *ob) { return (OB_TYPE_SUPPORT_VGROUP(ob->type) && @@ -548,6 +557,36 @@ bool BKE_object_is_in_wpaint_select_vert(const Object *ob) return false; } +bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode) +{ + if (object_mode & OB_MODE_EDIT) { + if (BKE_object_is_in_editmode(ob)) { + return true; + } + } + else if (object_mode & OB_MODE_VERTEX_PAINT) { + if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT)) { + return true; + } + } + else if (object_mode & OB_MODE_WEIGHT_PAINT) { + if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT)) { + return true; + } + } + else if (object_mode & OB_MODE_SCULPT) { + if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_SCULPT)) { + return true; + } + } + else if (object_mode & OB_MODE_POSE) { + if (ob->pose != NULL) { + return true; + } + } + return false; +} + /** * Return if the object is visible, as evaluated by depsgraph */ @@ -1787,7 +1826,7 @@ static bool ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[4][4]) if (scene == NULL) { return false; } - BKE_displist_make_curveTypes(eval_ctx, scene, par, 0); + BKE_displist_make_curveTypes(depsgraph, scene, par, 0); } #endif @@ -2171,7 +2210,7 @@ static bool where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat /* note, scene is the active scene while actual_scene is the scene the object resides in */ void BKE_object_where_is_calc_time_ex( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, float ctime, + Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime, RigidBodyWorld *rbw, float r_originmat[3][3]) { if (ob == NULL) return; @@ -2207,7 +2246,7 @@ void BKE_object_where_is_calc_time_ex( if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) { bConstraintOb *cob; cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); - BKE_constraints_solve(eval_ctx, &ob->constraints, cob, ctime); + BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime); BKE_constraints_clear_evalob(cob); } @@ -2216,9 +2255,9 @@ void BKE_object_where_is_calc_time_ex( else ob->transflag &= ~OB_NEG_SCALE; } -void BKE_object_where_is_calc_time(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, float ctime) +void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime) { - BKE_object_where_is_calc_time_ex(eval_ctx, scene, ob, ctime, NULL, NULL); + BKE_object_where_is_calc_time_ex(depsgraph, scene, ob, ctime, NULL, NULL); } /* get object transformation matrix without recalculating dependencies and @@ -2243,17 +2282,17 @@ void BKE_object_where_is_calc_mat4(Scene *scene, Object *ob, float obmat[4][4]) } } -void BKE_object_where_is_calc_ex(const EvaluationContext *eval_ctx, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3]) +void BKE_object_where_is_calc_ex(Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3]) { - BKE_object_where_is_calc_time_ex(eval_ctx, scene, ob, BKE_scene_frame_get(scene), rbw, r_originmat); + BKE_object_where_is_calc_time_ex(depsgraph, scene, ob, BKE_scene_frame_get(scene), rbw, r_originmat); } -void BKE_object_where_is_calc(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob) { - BKE_object_where_is_calc_time_ex(eval_ctx, scene, ob, BKE_scene_frame_get(scene), NULL, NULL); + BKE_object_where_is_calc_time_ex(depsgraph, scene, ob, BKE_scene_frame_get(scene), NULL, NULL); } /* for calculation of the inverse parent transform, only used for editor */ -void BKE_object_workob_calc_parent(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, Object *workob) +void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob, Object *workob) { BKE_object_workob_clear(workob); @@ -2275,7 +2314,7 @@ void BKE_object_workob_calc_parent(const EvaluationContext *eval_ctx, Scene *sce BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr)); - BKE_object_where_is_calc(eval_ctx, scene, workob); + BKE_object_where_is_calc(depsgraph, scene, workob); } /* see BKE_pchan_apply_mat4() for the equivalent 'pchan' function */ @@ -2531,7 +2570,7 @@ void BKE_object_empty_draw_type_set(Object *ob, const int value) } } -bool BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_max[3], const bool use_hidden) +bool BKE_object_minmax_dupli(Depsgraph *depsgraph, Scene *scene, Object *ob, float r_min[3], float r_max[3], const bool use_hidden) { bool ok = false; if ((ob->transflag & OB_DUPLI) == 0) { @@ -2540,7 +2579,7 @@ bool BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_m else { ListBase *lb; DupliObject *dob; - lb = object_duplilist(G.main->eval_ctx, scene, ob); + lb = object_duplilist(depsgraph, scene, ob); for (dob = lb->first; dob; dob = dob->next) { if ((use_hidden == false) && (dob->no_draw != 0)) { /* pass */ @@ -2600,7 +2639,7 @@ void BKE_object_foreach_display_point( } void BKE_scene_foreach_display_point( - Scene *scene, ViewLayer *view_layer, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, void (*func_cb)(const float[3], void *), void *user_data) { Base *base; @@ -2617,7 +2656,7 @@ void BKE_scene_foreach_display_point( ListBase *lb; DupliObject *dob; - lb = object_duplilist(G.main->eval_ctx, scene, ob); + lb = object_duplilist(depsgraph, scene, ob); for (dob = lb->first; dob; dob = dob->next) { if (dob->no_draw == 0) { BKE_object_foreach_display_point(dob->ob, dob->mat, func_cb, user_data); @@ -2697,7 +2736,7 @@ bool BKE_object_parent_loop_check(const Object *par, const Object *ob) return BKE_object_parent_loop_check(par->parent, ob); } -static void object_handle_update_proxy(const EvaluationContext *eval_ctx, +static void object_handle_update_proxy(Depsgraph *depsgraph, Scene *scene, Object *object, const bool do_proxy_update) @@ -2714,7 +2753,7 @@ static void object_handle_update_proxy(const EvaluationContext *eval_ctx, if (object->proxy_group == NULL) { if (do_proxy_update) { // printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name); - BKE_object_handle_update(eval_ctx, scene, object->proxy); + BKE_object_handle_update(depsgraph, scene, object->proxy); } } } @@ -2727,7 +2766,7 @@ static void object_handle_update_proxy(const EvaluationContext *eval_ctx, /* the main object update call, for object matrix, constraints, keys and displist (modifiers) */ /* requires flags to be set! */ /* Ideally we shouldn't have to pass the rigid body world, but need bigger restructuring to avoid id */ -void BKE_object_handle_update_ex(const EvaluationContext *eval_ctx, +void BKE_object_handle_update_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, RigidBodyWorld *rbw, const bool do_proxy_update) @@ -2738,7 +2777,7 @@ void BKE_object_handle_update_ex(const EvaluationContext *eval_ctx, (object_data != NULL) ? ((object_data->recalc & ID_RECALC_ALL) != 0) : 0; if (!recalc_object && ! recalc_data) { - object_handle_update_proxy(eval_ctx, scene, ob, do_proxy_update); + object_handle_update_proxy(depsgraph, scene, ob, do_proxy_update); return; } /* Speed optimization for animation lookups. */ @@ -2766,18 +2805,18 @@ void BKE_object_handle_update_ex(const EvaluationContext *eval_ctx, printf("recalcob %s\n", ob->id.name + 2); } /* Handle proxy copy for target. */ - if (!BKE_object_eval_proxy_copy(eval_ctx, ob)) { - BKE_object_where_is_calc_ex(eval_ctx, scene, rbw, ob, NULL); + if (!BKE_object_eval_proxy_copy(depsgraph, ob)) { + BKE_object_where_is_calc_ex(depsgraph, scene, rbw, ob, NULL); } } if (recalc_data) { - BKE_object_handle_data_update(eval_ctx, scene, ob); + BKE_object_handle_data_update(depsgraph, scene, ob); } ob->id.recalc &= ID_RECALC_ALL; - object_handle_update_proxy(eval_ctx, scene, ob, do_proxy_update); + object_handle_update_proxy(depsgraph, scene, ob, do_proxy_update); } /* WARNING: "scene" here may not be the scene object actually resides in. @@ -2785,9 +2824,9 @@ void BKE_object_handle_update_ex(const EvaluationContext *eval_ctx, * e.g. "scene" <-- set 1 <-- set 2 ("ob" lives here) <-- set 3 <-- ... <-- set n * rigid bodies depend on their world so use BKE_object_handle_update_ex() to also pass along the corrent rigid body world */ -void BKE_object_handle_update(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +void BKE_object_handle_update(Depsgraph *depsgraph, Scene *scene, Object *ob) { - BKE_object_handle_update_ex(eval_ctx, scene, ob, NULL, true); + BKE_object_handle_update_ex(depsgraph, scene, ob, NULL, true); } void BKE_object_sculpt_modifiers_changed(Object *ob) @@ -3705,7 +3744,7 @@ static void object_cacheIgnoreClear(Object *ob, int state) * Avoid calling this in new code unless there is a very good reason for it! */ bool BKE_object_modifier_update_subframe( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, bool update_mesh, + Depsgraph *depsgraph, Scene *scene, Object *ob, bool update_mesh, int parent_recursion, float frame, int type) { ModifierData *md = modifiers_findByType(ob, (ModifierType)type); @@ -3729,8 +3768,8 @@ bool BKE_object_modifier_update_subframe( if (parent_recursion) { int recursion = parent_recursion - 1; bool no_update = false; - if (ob->parent) no_update |= BKE_object_modifier_update_subframe(eval_ctx, scene, ob->parent, 0, recursion, frame, type); - if (ob->track) no_update |= BKE_object_modifier_update_subframe(eval_ctx, scene, ob->track, 0, recursion, frame, type); + if (ob->parent) no_update |= BKE_object_modifier_update_subframe(depsgraph, scene, ob->parent, 0, recursion, frame, type); + if (ob->track) no_update |= BKE_object_modifier_update_subframe(depsgraph, scene, ob->track, 0, recursion, frame, type); /* skip subframe if object is parented * to vertex of a dynamic paint canvas */ @@ -3747,7 +3786,7 @@ bool BKE_object_modifier_update_subframe( cti->get_constraint_targets(con, &targets); for (ct = targets.first; ct; ct = ct->next) { if (ct->tar) - BKE_object_modifier_update_subframe(eval_ctx, scene, ct->tar, 0, recursion, frame, type); + BKE_object_modifier_update_subframe(depsgraph, scene, ct->tar, 0, recursion, frame, type); } /* free temp targets */ if (cti->flush_constraint_targets) @@ -3764,11 +3803,11 @@ bool BKE_object_modifier_update_subframe( /* ignore cache clear during subframe updates * to not mess up cache validity */ object_cacheIgnoreClear(ob, 1); - BKE_object_handle_update(G.main->eval_ctx, scene, ob); + BKE_object_handle_update(depsgraph, scene, ob); object_cacheIgnoreClear(ob, 0); } else - BKE_object_where_is_calc_time(eval_ctx, scene, ob, frame); + BKE_object_where_is_calc_time(depsgraph, scene, ob, frame); /* for curve following objects, parented curve has to be updated too */ if (ob->type == OB_CURVE) { @@ -3779,7 +3818,7 @@ bool BKE_object_modifier_update_subframe( if (ob->type == OB_ARMATURE) { bArmature *arm = ob->data; BKE_animsys_evaluate_animdata(scene, &arm->id, arm->adt, frame, ADT_RECALC_ANIM); - BKE_pose_where_is(eval_ctx, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); } return false; diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c index 1b976fef166..35f86cd0c81 100644 --- a/source/blender/blenkernel/intern/object_dupli.c +++ b/source/blender/blenkernel/intern/object_dupli.c @@ -63,6 +63,7 @@ #include "BKE_anim.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "BLI_strict_flags.h" #include "BLI_hash.h" @@ -70,7 +71,7 @@ /* Dupli-Geometry */ typedef struct DupliContext { - const EvaluationContext *eval_ctx; + Depsgraph *depsgraph; bool do_update; bool animated; Group *group; /* XXX child objects are selected from this group if set, could be nicer */ @@ -98,13 +99,13 @@ 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, const EvaluationContext *eval_ctx, 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], bool update) { - r_ctx->eval_ctx = eval_ctx; + r_ctx->depsgraph = depsgraph; r_ctx->scene = scene; - r_ctx->view_layer = eval_ctx->view_layer; + 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 && eval_ctx->mode != DAG_EVAL_RENDER); + r_ctx->do_update = update && !(G.is_rendering && DEG_get_mode(depsgraph) != DAG_EVAL_RENDER); r_ctx->animated = false; r_ctx->group = NULL; @@ -310,7 +311,7 @@ static void make_duplis_group(const DupliContext *ctx) if (ctx->do_update) { /* note: update is optional because we don't always need object * transformations to be correct. Also fixes bug [#29616]. */ - BKE_group_handle_recalc_and_update(ctx->eval_ctx, ctx->scene, ob, group); + BKE_group_handle_recalc_and_update(ctx->depsgraph, ctx->scene, ob, group); } animated = BKE_group_is_animated(group, ob); @@ -383,7 +384,7 @@ static void make_duplis_frames(const DupliContext *ctx) * However, this has always been the way that this worked (i.e. pre 2.5), so I guess that it'll be fine! */ BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */ - BKE_object_where_is_calc_time(ctx->eval_ctx, scene, ob, (float)scene->r.cfra); + BKE_object_where_is_calc_time(ctx->depsgraph, scene, ob, (float)scene->r.cfra); make_dupli(ctx, ob, ob->obmat, scene->r.cfra, false, false, NULL); } @@ -397,7 +398,7 @@ static void make_duplis_frames(const DupliContext *ctx) scene->r.cfra = cfrao; BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */ - BKE_object_where_is_calc_time(ctx->eval_ctx, scene, ob, (float)scene->r.cfra); + BKE_object_where_is_calc_time(ctx->depsgraph, scene, ob, (float)scene->r.cfra); /* but, to make sure unkeyed object transforms are still sane, * let's copy object's original data back over @@ -519,7 +520,7 @@ static void make_duplis_verts(const DupliContext *ctx) { Scene *scene = ctx->scene; Object *parent = ctx->object; - bool use_texcoords = ELEM(ctx->eval_ctx->mode, DAG_EVAL_RENDER, DAG_EVAL_PREVIEW); + bool use_texcoords = ELEM(DEG_get_mode(ctx->depsgraph), DAG_EVAL_RENDER, DAG_EVAL_PREVIEW); VertexDupliData vdd; vdd.ctx = ctx; @@ -531,14 +532,14 @@ static void make_duplis_verts(const DupliContext *ctx) BMEditMesh *em = BKE_editmesh_from_object(parent); CustomDataMask dm_mask = (use_texcoords ? CD_MASK_BAREMESH | CD_MASK_ORCO : CD_MASK_BAREMESH); - if (ctx->eval_ctx->mode == DAG_EVAL_RENDER) { - vdd.dm = mesh_create_derived_render(ctx->eval_ctx, scene, parent, dm_mask); + if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER) { + vdd.dm = mesh_create_derived_render(ctx->depsgraph, scene, parent, dm_mask); } else if (em) { - vdd.dm = editbmesh_get_derived_cage(ctx->eval_ctx, scene, parent, em, dm_mask); + vdd.dm = editbmesh_get_derived_cage(ctx->depsgraph, scene, parent, em, dm_mask); } else { - vdd.dm = mesh_get_derived_final(ctx->eval_ctx, scene, parent, dm_mask); + vdd.dm = mesh_get_derived_final(ctx->depsgraph, scene, parent, dm_mask); } vdd.edit_btmesh = me->edit_btmesh; @@ -723,7 +724,7 @@ static void make_child_duplis_faces(const DupliContext *ctx, void *userdata, Obj float (*orco)[3] = fdd->orco; MLoopUV *mloopuv = fdd->mloopuv; int a, totface = fdd->totface; - bool use_texcoords = ELEM(ctx->eval_ctx->mode, DAG_EVAL_RENDER, DAG_EVAL_PREVIEW); + bool use_texcoords = ELEM(DEG_get_mode(ctx->depsgraph), DAG_EVAL_RENDER, DAG_EVAL_PREVIEW); float child_imat[4][4]; DupliObject *dob; @@ -789,7 +790,7 @@ static void make_duplis_faces(const DupliContext *ctx) { Scene *scene = ctx->scene; Object *parent = ctx->object; - bool use_texcoords = ELEM(ctx->eval_ctx->mode, DAG_EVAL_RENDER, DAG_EVAL_PREVIEW); + bool use_texcoords = ELEM(DEG_get_mode(ctx->depsgraph), DAG_EVAL_RENDER, DAG_EVAL_PREVIEW); FaceDupliData fdd; fdd.use_scale = ((parent->transflag & OB_DUPLIFACES_SCALE) != 0); @@ -799,14 +800,14 @@ static void make_duplis_faces(const DupliContext *ctx) BMEditMesh *em = BKE_editmesh_from_object(parent); CustomDataMask dm_mask = (use_texcoords ? CD_MASK_BAREMESH | CD_MASK_ORCO | CD_MASK_MLOOPUV : CD_MASK_BAREMESH); - if (ctx->eval_ctx->mode == DAG_EVAL_RENDER) { - fdd.dm = mesh_create_derived_render(ctx->eval_ctx, scene, parent, dm_mask); + if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER) { + fdd.dm = mesh_create_derived_render(ctx->depsgraph, scene, parent, dm_mask); } else if (em) { - fdd.dm = editbmesh_get_derived_cage(ctx->eval_ctx, scene, parent, em, dm_mask); + fdd.dm = editbmesh_get_derived_cage(ctx->depsgraph, scene, parent, em, dm_mask); } else { - fdd.dm = mesh_get_derived_final(ctx->eval_ctx, scene, parent, dm_mask); + fdd.dm = mesh_get_derived_final(ctx->depsgraph, scene, parent, dm_mask); } if (use_texcoords) { @@ -841,8 +842,8 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem { Scene *scene = ctx->scene; Object *par = ctx->object; - bool for_render = ctx->eval_ctx->mode == DAG_EVAL_RENDER; - bool use_texcoords = ELEM(ctx->eval_ctx->mode, DAG_EVAL_RENDER, DAG_EVAL_PREVIEW); + bool for_render = DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER; + bool use_texcoords = ELEM(DEG_get_mode(ctx->depsgraph), DAG_EVAL_RENDER, DAG_EVAL_PREVIEW); Object *ob = NULL, **oblist = NULL, obcopy, *obcopylist = NULL; DupliObject *dob; @@ -868,7 +869,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem if (part == NULL) return; - if (!psys_check_enabled(par, psys, (ctx->eval_ctx->mode == DAG_EVAL_RENDER))) + if (!psys_check_enabled(par, psys, (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER))) return; if (!for_render) @@ -883,7 +884,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem if ((for_render || part->draw_as == PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) { ParticleSimulationData sim = {NULL}; - sim.eval_ctx = ctx->eval_ctx; + sim.depsgraph = ctx->depsgraph; sim.scene = scene; sim.ob = par; sim.psys = psys; @@ -924,7 +925,7 @@ 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_group_handle_recalc_and_update(ctx->eval_ctx, scene, par, part->dup_group); + BKE_group_handle_recalc_and_update(ctx->depsgraph, scene, par, part->dup_group); } if (part->draw & PART_DRAW_COUNT_GR) { @@ -1086,7 +1087,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem } else { /* to give ipos in object correct offset */ - BKE_object_where_is_calc_time(ctx->eval_ctx, scene, ob, ctime - pa_time); + BKE_object_where_is_calc_time(ctx->depsgraph, scene, ob, ctime - pa_time); copy_v3_v3(vec, obmat[3]); obmat[3][0] = obmat[3][1] = obmat[3][2] = 0.0f; @@ -1190,7 +1191,7 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx) return NULL; /* Should the dupli's be generated for this object? - Respect restrict flags */ - if (ctx->eval_ctx->mode == DAG_EVAL_RENDER ? (restrictflag & OB_RESTRICT_RENDER) : (restrictflag & OB_RESTRICT_VIEW)) + if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER ? (restrictflag & OB_RESTRICT_RENDER) : (restrictflag & OB_RESTRICT_VIEW)) return NULL; if (transflag & OB_DUPLIPARTS) { @@ -1222,11 +1223,11 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx) /* ---- ListBase dupli container implementation ---- */ /* Returns a list of DupliObject */ -ListBase *object_duplilist_ex(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, bool update) +ListBase *object_duplilist_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, bool update) { ListBase *duplilist = MEM_callocN(sizeof(ListBase), "duplilist"); DupliContext ctx; - init_context(&ctx, eval_ctx, scene, ob, NULL, update); + init_context(&ctx, depsgraph, scene, ob, NULL, update); if (ctx.gen) { ctx.duplilist = duplilist; ctx.gen->make_duplis(&ctx); @@ -1237,9 +1238,9 @@ ListBase *object_duplilist_ex(const EvaluationContext *eval_ctx, Scene *scene, O /* 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(const EvaluationContext *eval_ctx, Scene *sce, Object *ob) +ListBase *object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *ob) { - return object_duplilist_ex(eval_ctx, sce, ob, true); + return object_duplilist_ex(depsgraph, sce, ob, true); } void free_object_duplilist(ListBase *lb) @@ -1286,7 +1287,7 @@ int count_duplilist(Object *ob) return 1; } -DupliApplyData *duplilist_apply(const EvaluationContext *eval_ctx, Object *ob, Scene *scene, ListBase *duplilist) +DupliApplyData *duplilist_apply(Depsgraph *depsgraph, Object *ob, Scene *scene, ListBase *duplilist) { DupliApplyData *apply_data = NULL; int num_objects = BLI_listbase_count(duplilist); @@ -1302,7 +1303,7 @@ DupliApplyData *duplilist_apply(const EvaluationContext *eval_ctx, Object *ob, S for (dob = duplilist->first, i = 0; dob; dob = dob->next, ++i) { /* make sure derivedmesh is calculated once, before drawing */ if (scene && !(dob->ob->transflag & OB_DUPLICALCDERIVED) && dob->ob->type == OB_MESH) { - mesh_get_derived_final(eval_ctx, scene, dob->ob, scene->customdata_mask); + mesh_get_derived_final(depsgraph, scene, dob->ob, scene->customdata_mask); dob->ob->transflag |= OB_DUPLICALCDERIVED; } } diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index c70e07e6c4c..81f15d265a2 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -63,10 +63,12 @@ #include "BKE_image.h" #include "MEM_guardedalloc.h" + #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" -void BKE_object_eval_local_transform(const EvaluationContext *UNUSED(eval_ctx), +void BKE_object_eval_local_transform(Depsgraph *UNUSED(depsgraph), Object *ob) { DEG_debug_print_eval(__func__, ob->id.name, ob); @@ -77,7 +79,7 @@ void BKE_object_eval_local_transform(const EvaluationContext *UNUSED(eval_ctx), /* Evaluate parent */ /* NOTE: based on solve_parenting(), but with the cruft stripped out */ -void BKE_object_eval_parent(const EvaluationContext *UNUSED(eval_ctx), +void BKE_object_eval_parent(Depsgraph *UNUSED(depsgraph), Scene *scene, Object *ob) { @@ -109,7 +111,7 @@ void BKE_object_eval_parent(const EvaluationContext *UNUSED(eval_ctx), } } -void BKE_object_eval_constraints(const EvaluationContext *eval_ctx, +void BKE_object_eval_constraints(Depsgraph *depsgraph, Scene *scene, Object *ob) { @@ -128,11 +130,11 @@ void BKE_object_eval_constraints(const EvaluationContext *eval_ctx, * */ cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT); - BKE_constraints_solve(eval_ctx, &ob->constraints, cob, ctime); + BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime); BKE_constraints_clear_evalob(cob); } -void BKE_object_eval_done(const EvaluationContext *UNUSED(eval_ctx), Object *ob) +void BKE_object_eval_done(Depsgraph *UNUSED(depsgraph), Object *ob) { DEG_debug_print_eval(__func__, ob->id.name, ob); @@ -142,7 +144,7 @@ void BKE_object_eval_done(const EvaluationContext *UNUSED(eval_ctx), Object *ob) } void BKE_object_handle_data_update( - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob) { @@ -172,19 +174,27 @@ void BKE_object_handle_data_update( switch (ob->type) { case OB_MESH: { +#if 0 BMEditMesh *em = (ob->mode & OB_MODE_EDIT) ? BKE_editmesh_from_object(ob) : NULL; +#else + BMEditMesh *em = (ob->mode & OB_MODE_EDIT) ? ((Mesh *)ob->data)->edit_btmesh : NULL; + if (em && em->ob != ob) { + em = NULL; + } +#endif + uint64_t data_mask = scene->customdata_mask | CD_MASK_BAREMESH; #ifdef WITH_FREESTYLE /* make sure Freestyle edge/face marks appear in DM for render (see T40315) */ - if (eval_ctx->mode != DAG_EVAL_VIEWPORT) { + if (DEG_get_mode(depsgraph) != DAG_EVAL_VIEWPORT) { data_mask |= CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE; } #endif if (em) { - makeDerivedMesh(eval_ctx, scene, ob, em, data_mask, false); /* was CD_MASK_BAREMESH */ + makeDerivedMesh(depsgraph, scene, ob, em, data_mask, false); /* was CD_MASK_BAREMESH */ } else { - makeDerivedMesh(eval_ctx, scene, ob, NULL, data_mask, false); + makeDerivedMesh(depsgraph, scene, ob, NULL, data_mask, false); } break; } @@ -196,22 +206,22 @@ void BKE_object_handle_data_update( } } else { - BKE_pose_where_is(eval_ctx, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); } break; case OB_MBALL: - BKE_displist_make_mball(eval_ctx, scene, ob); + BKE_displist_make_mball(depsgraph, scene, ob); break; case OB_CURVE: case OB_SURF: case OB_FONT: - BKE_displist_make_curveTypes(eval_ctx, scene, ob, 0); + BKE_displist_make_curveTypes(depsgraph, scene, ob, 0); break; case OB_LATTICE: - BKE_lattice_modifiers_calc(eval_ctx, scene, ob); + BKE_lattice_modifiers_calc(depsgraph, scene, ob); break; case OB_EMPTY: @@ -223,6 +233,7 @@ void BKE_object_handle_data_update( /* particles */ if (!(ob->mode & OB_MODE_EDIT) && ob->particlesystem.first) { + const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); ParticleSystem *tpsys, *psys; DerivedMesh *dm; ob->transflag &= ~OB_DUPLIPARTS; @@ -233,16 +244,16 @@ void BKE_object_handle_data_update( psys_changed_type(ob, psys); } - if (psys_check_enabled(ob, psys, eval_ctx->mode == DAG_EVAL_RENDER)) { + if (psys_check_enabled(ob, psys, use_render_params)) { /* check use of dupli objects here */ - if (psys->part && (psys->part->draw_as == PART_DRAW_REND || eval_ctx->mode == DAG_EVAL_RENDER) && + if (psys->part && (psys->part->draw_as == PART_DRAW_REND || use_render_params) && ((psys->part->ren_as == PART_DRAW_OB && psys->part->dup_ob) || (psys->part->ren_as == PART_DRAW_GR && psys->part->dup_group))) { ob->transflag |= OB_DUPLIPARTS; } - particle_system_update(eval_ctx, scene, ob, psys, (eval_ctx->mode == DAG_EVAL_RENDER)); + particle_system_update(depsgraph, scene, ob, psys, use_render_params); psys = psys->next; } else if (psys->flag & PSYS_DELETE) { @@ -255,12 +266,12 @@ void BKE_object_handle_data_update( psys = psys->next; } - if (eval_ctx->mode == DAG_EVAL_RENDER && ob->transflag & OB_DUPLIPARTS) { + if (use_render_params && ob->transflag & OB_DUPLIPARTS) { /* this is to make sure we get render level duplis in groups: * the derivedmesh must be created before init_render_mesh, * since object_duplilist does dupliparticles before that */ CustomDataMask data_mask = CD_MASK_BAREMESH | CD_MASK_MFACE | CD_MASK_MTFACE | CD_MASK_MCOL; - dm = mesh_create_derived_render(eval_ctx, scene, ob, data_mask); + dm = mesh_create_derived_render(depsgraph, scene, ob, data_mask); dm->release(dm); for (psys = ob->particlesystem.first; psys; psys = psys->next) @@ -271,7 +282,7 @@ void BKE_object_handle_data_update( /* quick cache removed */ } -bool BKE_object_eval_proxy_copy(const EvaluationContext *UNUSED(eval_ctx), +bool BKE_object_eval_proxy_copy(Depsgraph *UNUSED(depsgraph), Object *object) { /* Handle proxy copy for target, */ @@ -295,18 +306,18 @@ bool BKE_object_eval_proxy_copy(const EvaluationContext *UNUSED(eval_ctx), return false; } -void BKE_object_eval_uber_transform(const EvaluationContext *eval_ctx, Object *object) +void BKE_object_eval_uber_transform(Depsgraph *depsgraph, Object *object) { - BKE_object_eval_proxy_copy(eval_ctx, object); + BKE_object_eval_proxy_copy(depsgraph, object); } -void BKE_object_eval_uber_data(const EvaluationContext *eval_ctx, +void BKE_object_eval_uber_data(Depsgraph *depsgraph, Scene *scene, Object *ob) { DEG_debug_print_eval(__func__, ob->id.name, ob); BLI_assert(ob->type != OB_ARMATURE); - BKE_object_handle_data_update(eval_ctx, scene, ob); + BKE_object_handle_data_update(depsgraph, scene, ob); switch (ob->type) { case OB_MESH: @@ -378,7 +389,7 @@ void BKE_object_eval_uber_data(const EvaluationContext *eval_ctx, } } -void BKE_object_eval_cloth(const EvaluationContext *UNUSED(eval_ctx), +void BKE_object_eval_cloth(Depsgraph *UNUSED(depsgraph), Scene *scene, Object *object) { @@ -386,23 +397,23 @@ void BKE_object_eval_cloth(const EvaluationContext *UNUSED(eval_ctx), BKE_ptcache_object_reset(scene, object, PTCACHE_RESET_DEPSGRAPH); } -void BKE_object_eval_transform_all(const EvaluationContext *eval_ctx, +void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *object) { /* This mimics full transform update chain from new depsgraph. */ - BKE_object_eval_local_transform(eval_ctx, object); + BKE_object_eval_local_transform(depsgraph, object); if (object->parent != NULL) { - BKE_object_eval_parent(eval_ctx, scene, object); + BKE_object_eval_parent(depsgraph, scene, object); } if (!BLI_listbase_is_empty(&object->constraints)) { - BKE_object_eval_constraints(eval_ctx, scene, object); + BKE_object_eval_constraints(depsgraph, scene, object); } - BKE_object_eval_uber_transform(eval_ctx, object); - BKE_object_eval_done(eval_ctx, object); + BKE_object_eval_uber_transform(depsgraph, object); + BKE_object_eval_done(depsgraph, object); } -void BKE_object_eval_update_shading(const EvaluationContext *UNUSED(eval_ctx), +void BKE_object_eval_update_shading(Depsgraph *UNUSED(depsgraph), Object *object) { DEG_debug_print_eval(__func__, object->id.name, object); @@ -411,7 +422,7 @@ void BKE_object_eval_update_shading(const EvaluationContext *UNUSED(eval_ctx), } } -void BKE_object_data_select_update(const EvaluationContext *UNUSED(eval_ctx), +void BKE_object_data_select_update(Depsgraph *UNUSED(depsgraph), struct ID *object_data) { DEG_debug_print_eval(__func__, object_data->name, object_data); @@ -433,10 +444,10 @@ void BKE_object_data_select_update(const EvaluationContext *UNUSED(eval_ctx), } } -void BKE_object_eval_flush_base_flags(const EvaluationContext *eval_ctx, +void BKE_object_eval_flush_base_flags(Depsgraph *depsgraph, Object *object, int base_index, bool is_from_set) { - ViewLayer *view_layer = eval_ctx->view_layer; + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); BLI_assert(view_layer->object_bases_array != NULL); BLI_assert(base_index >= 0); BLI_assert(base_index < MEM_allocN_len(view_layer->object_bases_array) / sizeof(Base *)); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 20375fe6953..ed1d9519046 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -881,7 +881,7 @@ static bool sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob) * \param need_mask So the DerivedMesh thats returned has mask data */ void BKE_sculpt_update_mesh_elements( - const EvaluationContext *eval_ctx, Scene *scene, Sculpt *sd, Object *ob, + Depsgraph *depsgraph, Scene *scene, Sculpt *sd, Object *ob, bool need_pmap, bool need_mask) { DerivedMesh *dm; @@ -921,7 +921,7 @@ void BKE_sculpt_update_mesh_elements( ss->kb = (mmd == NULL) ? BKE_keyblock_from_object(ob) : NULL; - dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(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) { @@ -956,7 +956,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(eval_ctx, scene, ob, &ss->deform_imats, &ss->deform_cos); + BKE_crazyspace_build_sculpt(depsgraph, scene, ob, &ss->deform_imats, &ss->deform_cos); BKE_pbvh_apply_vertCos(ss->pbvh, ss->deform_cos); for (a = 0; a < me->totvert; ++a) { diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 1917e370aa9..cbc3b17a5c2 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -252,7 +252,7 @@ struct LatticeDeformData *psys_create_lattice_deform_data(ParticleSimulationData { struct LatticeDeformData *lattice_deform_data = NULL; - if (psys_in_edit_mode(sim->eval_ctx->depsgraph, sim->psys) == 0) { + if (psys_in_edit_mode(sim->depsgraph, sim->psys) == 0) { Object *lattice = NULL; ModifierData *md = (ModifierData *)psys_get_modifier(sim->ob, sim->psys); int mode = G.is_rendering ? eModifierMode_Render : eModifierMode_Realtime; @@ -291,7 +291,7 @@ void psys_enable_all(Object *ob) bool psys_in_edit_mode(Depsgraph *depsgraph, ParticleSystem *psys) { - ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); return (view_layer->basact && @@ -1654,7 +1654,7 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors) } } -int do_guides(const EvaluationContext *eval_ctx, ParticleSettings *part, ListBase *effectors, ParticleKey *state, int index, float time) +int do_guides(Depsgraph *depsgraph, ParticleSettings *part, ListBase *effectors, ParticleKey *state, int index, float time) { CurveMapping *clumpcurve = (part->child_flag & PART_CHILD_USE_CLUMP_CURVE) ? part->clumpcurve : NULL; CurveMapping *roughcurve = (part->child_flag & PART_CHILD_USE_ROUGH_CURVE) ? part->roughcurve : NULL; @@ -1717,7 +1717,7 @@ int do_guides(const EvaluationContext *eval_ctx, ParticleSettings *part, ListBas /* curve taper */ if (cu->taperobj) - mul_v3_fl(vec_to_point, BKE_displist_calc_taper(eval_ctx, eff->scene, cu->taperobj, (int)(data->strength * guidetime * 100.0f), 100)); + mul_v3_fl(vec_to_point, BKE_displist_calc_taper(depsgraph, eff->scene, cu->taperobj, (int)(data->strength * guidetime * 100.0f), 100)); else { /* curve size*/ if (cu->flag & CU_PATH_RADIUS) { @@ -1900,7 +1900,7 @@ static bool psys_thread_context_init_path( psys_thread_context_init(ctx, sim); /*---start figuring out what is actually wanted---*/ - if (psys_in_edit_mode(sim->eval_ctx->depsgraph, psys)) { + if (psys_in_edit_mode(sim->depsgraph, psys)) { ParticleEditSettings *pset = &scene->toolsettings->particle; if ((use_render_params == 0) && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0) @@ -1997,7 +1997,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp ParticleSystem *psys = ctx->sim.psys; ParticleSettings *part = psys->part; ParticleCacheKey **cache = psys->childcache; - ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.eval_ctx->depsgraph, psys) && psys->edit ? psys->edit->pathcache : psys->pathcache; + ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.depsgraph, psys) && psys->edit ? psys->edit->pathcache : psys->pathcache; ParticleCacheKey *child, *key[4]; ParticleTexture ptex; float *cpa_fuv = 0, *par_rot = 0, rot[4]; @@ -2421,7 +2421,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re return; #if 0 /* TODO(mai): something is very wrong with these conditionals, they dont make sense and the cache isnt updating */ - if (psys_in_edit_mode(sim->eval_ctx->depsgraph, psys)) + if (psys_in_edit_mode(sim->depsgraph, psys)) if ((psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0) return; #endif @@ -2542,7 +2542,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re if (sim->psys->effectors && (psys->part->flag & PART_CHILD_EFFECT) == 0) { for (k = 0, ca = cache[p]; k <= segments; k++, ca++) /* ca is safe to cast, since only co and vel are used */ - do_guides(sim->eval_ctx, sim->psys->part, sim->psys->effectors, (ParticleKey *)ca, p, (float)k / (float)segments); + do_guides(sim->depsgraph, sim->psys->part, sim->psys->effectors, (ParticleKey *)ca, p, (float)k / (float)segments); } /* lattices have to be calculated separately to avoid mixups between effector calculations */ @@ -2590,7 +2590,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re if (vg_length) MEM_freeN(vg_length); } -void psys_cache_edit_paths(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, PTCacheEdit *edit, float cfra, const bool use_render_params) +void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCacheEdit *edit, float cfra, const bool use_render_params) { ParticleCacheKey *ca, **cache = edit->pathcache; ParticleEditSettings *pset = &scene->toolsettings->particle; @@ -2791,7 +2791,7 @@ void psys_cache_edit_paths(const EvaluationContext *eval_ctx, Scene *scene, Obje if (psys) { ParticleSimulationData sim = {0}; - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = ob; sim.psys = psys; @@ -3631,7 +3631,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * pind.bspline = (psys->part->flag & PART_HAIR_BSPLINE); /* pind.dm disabled in editmode means we don't get effectors taken into * account when subdividing for instance */ - pind.dm = psys_in_edit_mode(sim->eval_ctx->depsgraph, psys) ? NULL : psys->hair_out_dm; + pind.dm = psys_in_edit_mode(sim->depsgraph, psys) ? NULL : psys->hair_out_dm; init_particle_interpolation(sim->ob, psys, pa, &pind); do_particle_interpolation(psys, p, pa, t, &pind, state); @@ -3646,7 +3646,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey * mul_mat3_m4_v3(hairmat, state->vel); if (sim->psys->effectors && (part->flag & PART_CHILD_GUIDE) == 0) { - do_guides(sim->eval_ctx, sim->psys->part, sim->psys->effectors, state, p, state->time); + do_guides(sim->depsgraph, sim->psys->part, sim->psys->effectors, state, p, state->time); /* TODO: proper velocity handling */ } @@ -4196,10 +4196,10 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3] madd_v3_v3fl(center, yvec, bb->offset[1]); } -void psys_apply_hair_lattice(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ParticleSystem *psys) +void psys_apply_hair_lattice(Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys) { ParticleSimulationData sim = {0}; - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = ob; sim.psys = psys; diff --git a/source/blender/blenkernel/intern/particle_child.c b/source/blender/blenkernel/intern/particle_child.c index c2640e9b9e2..8d42f2a9b84 100644 --- a/source/blender/blenkernel/intern/particle_child.c +++ b/source/blender/blenkernel/intern/particle_child.c @@ -816,7 +816,7 @@ void do_child_modifiers(const ParticleChildModifierContext *modifier_ctx, if (part->flag & PART_CHILD_EFFECT) /* state is safe to cast, since only co and vel are used */ - guided = do_guides(sim->eval_ctx, sim->psys->part, sim->psys->effectors, (ParticleKey *)state, cpa->parent, t); + guided = do_guides(sim->depsgraph, sim->psys->part, sim->psys->effectors, (ParticleKey *)state, cpa->parent, t); if (guided == 0) { float orco_offset[3]; diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c index c261b0dc22c..87fa86977e6 100644 --- a/source/blender/blenkernel/intern/particle_distribute.c +++ b/source/blender/blenkernel/intern/particle_distribute.c @@ -240,10 +240,12 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) if (mface->v4 && (!intersects_tri || from==PART_FROM_VOLUME)) { copy_v3_v3(v4, mvert[mface->v4].co); - if (isect_ray_tri_watertight_v3(co1, - &isect_precalc, - v1, v3, v4, - &lambda, NULL)) { + if (isect_ray_tri_watertight_v3( + co1, + &isect_precalc, + v1, v3, v4, + &lambda, NULL)) + { if (from==PART_FROM_FACE) (pa+(int)(lambda*size[a])*a0mul)->flag &= ~PARS_UNEXIST; else @@ -772,7 +774,7 @@ static void distribute_invalid(ParticleSimulationData *sim, int from) { Scene *scene = sim->scene; ParticleSystem *psys = sim->psys; - const bool use_render_params = (DEG_get_mode(sim->eval_ctx->depsgraph) == DAG_EVAL_RENDER); + const bool use_render_params = (DEG_get_mode(sim->depsgraph) == DAG_EVAL_RENDER); if (from == PART_FROM_CHILD) { ChildParticle *cpa; @@ -840,7 +842,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti psys_thread_context_init(ctx, sim); - const bool use_render_params = (DEG_get_mode(sim->eval_ctx->depsgraph) == DAG_EVAL_RENDER); + const bool use_render_params = (DEG_get_mode(sim->depsgraph) == DAG_EVAL_RENDER); /* First handle special cases */ if (from == PART_FROM_CHILD) { diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index ffe6617d561..b9361f3499b 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -536,18 +536,20 @@ static void initialize_particle_texture(ParticleSimulationData *sim, ParticleDat psys_get_texture(sim, pa, &ptex, PAMAP_INIT, 0.f); switch (part->type) { - case PART_EMITTER: - if (ptex.exist < psys_frand(psys, p+125)) - pa->flag |= PARS_UNEXIST; - pa->time = part->sta + (part->end - part->sta)*ptex.time; - break; - case PART_HAIR: - if (ptex.exist < psys_frand(psys, p+125)) - pa->flag |= PARS_UNEXIST; - pa->time = 0.f; - break; - case PART_FLUID: - break; + case PART_EMITTER: + if (ptex.exist < psys_frand(psys, p + 125)) { + pa->flag |= PARS_UNEXIST; + } + pa->time = part->sta + (part->end - part->sta)*ptex.time; + break; + case PART_HAIR: + if (ptex.exist < psys_frand(psys, p + 125)) { + pa->flag |= PARS_UNEXIST; + } + pa->time = 0.f; + break; + case PART_FLUID: + break; } } @@ -986,14 +988,14 @@ void psys_get_birth_coords(ParticleSimulationData *sim, ParticleData *pa, Partic } /* recursively evaluate emitter parent anim at cfra */ -static void evaluate_emitter_anim(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float cfra) +static void evaluate_emitter_anim(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float cfra) { if (ob->parent) - evaluate_emitter_anim(eval_ctx, scene, ob->parent, cfra); + evaluate_emitter_anim(depsgraph, scene, ob->parent, cfra); /* we have to force RECALC_ANIM here since where_is_objec_time only does drivers */ BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, cfra, ADT_RECALC_ANIM); - BKE_object_where_is_calc_time(eval_ctx, scene, ob, cfra); + BKE_object_where_is_calc_time(depsgraph, scene, ob, cfra); } /* sets particle to the emitter surface with initial velocity & rotation */ @@ -1007,7 +1009,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, /* get precise emitter matrix if particle is born */ if (part->type != PART_HAIR && dtime > 0.f && pa->time < cfra && pa->time >= sim->psys->cfra) { - evaluate_emitter_anim(sim->eval_ctx, sim->scene, sim->ob, pa->time); + evaluate_emitter_anim(sim->depsgraph, sim->scene, sim->ob, pa->time); psys->flag |= PSYS_OB_ANIM_RESTORE; } @@ -1060,8 +1062,10 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime, pa->dietime = pa->time + pa->lifetime; - if (sim->psys->pointcache && sim->psys->pointcache->flag & PTCACHE_BAKED && - sim->psys->pointcache->mem_cache.first) { + if ((sim->psys->pointcache) && + (sim->psys->pointcache->flag & PTCACHE_BAKED) && + (sim->psys->pointcache->mem_cache.first)) + { float dietime = psys_get_dietime_from_cache(sim->psys->pointcache, p); pa->dietime = MIN2(pa->dietime, dietime); } @@ -1139,7 +1143,7 @@ static void set_keyed_keys(ParticleSimulationData *sim) int totpart = psys->totpart, k, totkeys = psys->totkeyed; int keyed_flag = 0; - ksim.eval_ctx = sim->eval_ctx; + ksim.depsgraph = sim->depsgraph; ksim.scene = sim->scene; /* no proper targets so let's clear and bail out */ @@ -1301,7 +1305,7 @@ void psys_update_particle_tree(ParticleSystem *psys, float cfra) static void psys_update_effectors(ParticleSimulationData *sim) { pdEndEffectors(&sim->psys->effectors); - sim->psys->effectors = pdInitEffectors(sim->eval_ctx, sim->scene, sim->ob, sim->psys, + sim->psys->effectors = pdInitEffectors(sim->depsgraph, sim->scene, sim->ob, sim->psys, sim->psys->part->effector_weights, true); precalc_guides(sim, sim->psys->effectors); } @@ -2122,7 +2126,7 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa tkey.time=pa->state.time; if (part->type != PART_HAIR) { - if (do_guides(sim->eval_ctx, sim->psys->part, sim->psys->effectors, &tkey, p, time)) { + if (do_guides(sim->depsgraph, sim->psys->part, sim->psys->effectors, &tkey, p, time)) { copy_v3_v3(pa->state.co,tkey.co); /* guides don't produce valid velocity */ sub_v3_v3v3(pa->state.vel, tkey.co, pa->prev_state.co); @@ -2941,7 +2945,7 @@ static void psys_update_path_cache(ParticleSimulationData *sim, float cfra, cons skip = 1; /* no need to cache paths while baking dynamics */ #if 0 /* TODO(mai): something is very wrong with these conditionals, they dont make sense and the cache isnt updating */ - else if (psys_in_edit_mode(sim->eval_ctx->depsgraph, psys)) { + else if (psys_in_edit_mode(sim->depsgraph, psys)) { if ((pset->flag & PE_DRAW_PART)==0) skip = 1; else if (part->childtype==0 && (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED)==0) @@ -3209,7 +3213,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim) psys->hair_out_dm = CDDM_copy(psys->hair_in_dm); psys->hair_out_dm->getVertCos(psys->hair_out_dm, deformedVerts); - clothModifier_do(psys->clmd, sim->eval_ctx, sim->scene, sim->ob, psys->hair_in_dm, deformedVerts); + clothModifier_do(psys->clmd, sim->depsgraph, sim->scene, sim->ob, psys->hair_in_dm, deformedVerts); CDDM_apply_vert_coords(psys->hair_out_dm, deformedVerts); @@ -3692,11 +3696,11 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) /* Note that we could avoid copying sphdata for each thread here (it's only read here), * but doubt this would gain us anything except confusion... */ { - ParallelRangeSettings settings; - BLI_parallel_range_settings_defaults(&settings); - settings.use_threading = (psys->totpart > 100); - settings.userdata_chunk = &sphdata; - settings.userdata_chunk_size = sizeof(sphdata); + ParallelRangeSettings settings; + BLI_parallel_range_settings_defaults(&settings); + settings.use_threading = (psys->totpart > 100); + settings.userdata_chunk = &sphdata; + settings.userdata_chunk_size = sizeof(sphdata); BLI_task_parallel_range( 0, psys->totpart, &task_data, @@ -3706,11 +3710,11 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) /* do global forces & effectors */ { - ParallelRangeSettings settings; - BLI_parallel_range_settings_defaults(&settings); - settings.use_threading = (psys->totpart > 100); - settings.userdata_chunk = &sphdata; - settings.userdata_chunk_size = sizeof(sphdata); + ParallelRangeSettings settings; + BLI_parallel_range_settings_defaults(&settings); + settings.use_threading = (psys->totpart > 100); + settings.userdata_chunk = &sphdata; + settings.userdata_chunk_size = sizeof(sphdata); BLI_task_parallel_range( 0, psys->totpart, &task_data, @@ -4209,7 +4213,7 @@ static int hair_needs_recalc(ParticleSystem *psys) /* main particle update call, checks that things are ok on the large scale and * then advances in to actual particle calculations depending on particle type */ -void particle_system_update(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, ParticleSystem *psys, const bool use_render_params) +void particle_system_update(struct Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, const bool use_render_params) { ParticleSimulationData sim= {0}; ParticleSettings *part = psys->part; @@ -4223,7 +4227,7 @@ void particle_system_update(const struct EvaluationContext *eval_ctx, Scene *sce cfra= BKE_scene_frame_get(scene); - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = ob; sim.psys = psys; @@ -4370,7 +4374,7 @@ void particle_system_update(const struct EvaluationContext *eval_ctx, Scene *sce /* make sure emitter is left at correct time (particle emission can change this) */ if (psys->flag & PSYS_OB_ANIM_RESTORE) { - evaluate_emitter_anim(eval_ctx, scene, ob, cfra); + evaluate_emitter_anim(depsgraph, scene, ob, cfra); psys->flag &= ~PSYS_OB_ANIM_RESTORE; } @@ -4411,7 +4415,7 @@ void BKE_particlesystem_id_loop(ParticleSystem *psys, ParticleSystemIDFunc func, /* **** Depsgraph evaluation **** */ -void BKE_particle_system_eval_init(const struct EvaluationContext *UNUSED(eval_ctx), +void BKE_particle_system_eval_init(struct Depsgraph *UNUSED(depsgraph), Scene *scene, Object *ob) { diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 50314daa014..3ab17b083db 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -441,9 +441,9 @@ static void ptcache_particle_extra_write(void *psys_v, PTCacheMem *pm, int UNUSE PTCacheExtra *extra = NULL; if (psys->part->phystype == PART_PHYS_FLUID && - psys->part->fluid && psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS && - psys->tot_fluidsprings && psys->fluid_springs) { - + psys->part->fluid && psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS && + psys->tot_fluidsprings && psys->fluid_springs) + { extra = MEM_callocN(sizeof(PTCacheExtra), "Point cache: fluid extra data"); extra->type = BPHYS_EXTRA_FLUID_SPRINGS; @@ -790,8 +790,9 @@ static int ptcache_smoke_read(PTCacheFile *pf, void *smoke_v) /* check if resolution has changed */ if (sds->res[0] != ch_res[0] || - sds->res[1] != ch_res[1] || - sds->res[2] != ch_res[2]) { + sds->res[1] != ch_res[1] || + sds->res[2] != ch_res[2]) + { if (sds->flags & MOD_SMOKE_ADAPTIVE_DOMAIN) reallocate = 1; else @@ -2214,8 +2215,8 @@ static void ptcache_data_copy(void *from[], void *to[]) { int i; for (i=0; i<BPHYS_TOT_DATA; i++) { - /* note, durian file 03.4b_comp crashes if to[i] is not tested - * its NULL, not sure if this should be fixed elsewhere but for now its needed */ + /* note, durian file 03.4b_comp crashes if to[i] is not tested + * its NULL, not sure if this should be fixed elsewhere but for now its needed */ if (from[i] && to[i]) memcpy(to[i], from[i], ptcache_data_size[i]); } diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index ff521260993..ab8f9dcb2e4 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1237,7 +1237,7 @@ static void rigidbody_update_sim_world(Scene *scene, RigidBodyWorld *rbw) rigidbody_update_ob_array(rbw); } -static void rigidbody_update_sim_ob(const struct EvaluationContext *eval_ctx, Scene *scene, RigidBodyWorld *rbw, Object *ob, RigidBodyOb *rbo) +static void rigidbody_update_sim_ob(struct Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, RigidBodyOb *rbo) { float loc[3]; float rot[4]; @@ -1285,7 +1285,7 @@ static void rigidbody_update_sim_ob(const struct EvaluationContext *eval_ctx, Sc ListBase *effectors; /* get effectors present in the group specified by effector_weights */ - effectors = pdInitEffectors(eval_ctx, scene, ob, NULL, effector_weights, true); + effectors = pdInitEffectors(depsgraph, scene, ob, NULL, effector_weights, true); if (effectors) { float eff_force[3] = {0.0f, 0.0f, 0.0f}; float eff_loc[3], eff_vel[3]; @@ -1326,7 +1326,7 @@ static void rigidbody_update_sim_ob(const struct EvaluationContext *eval_ctx, Sc * * \param rebuild Rebuild entire simulation */ -static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx, Scene *scene, RigidBodyWorld *rbw, bool rebuild) +static void rigidbody_update_simulation(struct Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, bool rebuild) { /* update world */ if (rebuild) @@ -1359,7 +1359,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx /* validate that we've got valid object set up here... */ RigidBodyOb *rbo = ob->rigidbody_object; /* update transformation matrix of the object so we don't get a frame of lag for simple animations */ - BKE_object_where_is_calc(eval_ctx, scene, ob); + BKE_object_where_is_calc(depsgraph, scene, ob); if (rbo == NULL) { /* Since this object is included in the sim group but doesn't have @@ -1393,7 +1393,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx } /* update simulation object... */ - rigidbody_update_sim_ob(eval_ctx, scene, rbw, ob, rbo); + rigidbody_update_sim_ob(depsgraph, scene, rbw, ob, rbo); } } FOREACH_GROUP_OBJECT_END; @@ -1407,7 +1407,7 @@ static void rigidbody_update_simulation(const struct EvaluationContext *eval_ctx /* validate that we've got valid object set up here... */ RigidBodyCon *rbc = ob->rigidbody_constraint; /* update transformation matrix of the object so we don't get a frame of lag for simple animations */ - BKE_object_where_is_calc(eval_ctx, scene, ob); + BKE_object_where_is_calc(depsgraph, scene, ob); if (rbc == NULL) { /* Since this object is included in the group but doesn't have @@ -1563,7 +1563,7 @@ void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) /* Rebuild rigid body world */ /* NOTE: this needs to be called before frame update to work correctly */ -void BKE_rigidbody_rebuild_world(const struct EvaluationContext *eval_ctx, Scene *scene, float ctime) +void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, float ctime) { RigidBodyWorld *rbw = scene->rigidbody_world; PointCache *cache; @@ -1582,7 +1582,7 @@ void BKE_rigidbody_rebuild_world(const struct EvaluationContext *eval_ctx, Scene if (ctime == startframe + 1 && rbw->ltime == startframe) { if (cache->flag & PTCACHE_OUTDATED) { BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); - rigidbody_update_simulation(eval_ctx, scene, rbw, true); + rigidbody_update_simulation(depsgraph, scene, rbw, true); BKE_ptcache_validate(cache, (int)ctime); cache->last_exact = 0; cache->flag &= ~PTCACHE_REDO_NEEDED; @@ -1591,7 +1591,7 @@ void BKE_rigidbody_rebuild_world(const struct EvaluationContext *eval_ctx, Scene } /* Run RigidBody simulation for the specified physics world */ -void BKE_rigidbody_do_simulation(const struct EvaluationContext *eval_ctx, Scene *scene, float ctime) +void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, Scene *scene, float ctime) { float timestep; RigidBodyWorld *rbw = scene->rigidbody_world; @@ -1636,7 +1636,7 @@ void BKE_rigidbody_do_simulation(const struct EvaluationContext *eval_ctx, Scene } /* update and validate simulation */ - rigidbody_update_simulation(eval_ctx, scene, rbw, false); + rigidbody_update_simulation(depsgraph, scene, rbw, false); /* calculate how much time elapsed since last step in seconds */ timestep = 1.0f / (float)FPS * (ctime - rbw->ltime) * rbw->time_scale; @@ -1680,8 +1680,8 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) {} bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime) { return false; } void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) {} -void BKE_rigidbody_rebuild_world(const struct EvaluationContext *eval_ctx, Scene *scene, float ctime) {} -void BKE_rigidbody_do_simulation(const struct EvaluationContext *eval_ctx, Scene *scene, float ctime) {} +void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, float ctime) {} +void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, Scene *scene, float ctime) {} #ifdef __GNUC__ # pragma GCC diagnostic pop @@ -1692,29 +1692,29 @@ void BKE_rigidbody_do_simulation(const struct EvaluationContext *eval_ctx, Scene /* -------------------- */ /* Depsgraph evaluation */ -void BKE_rigidbody_rebuild_sim(const struct EvaluationContext *eval_ctx, +void BKE_rigidbody_rebuild_sim(struct Depsgraph *depsgraph, Scene *scene) { float ctime = BKE_scene_frame_get(scene); DEG_debug_print_eval_time(__func__, scene->id.name, scene, ctime); /* rebuild sim data (i.e. after resetting to start of timeline) */ if (BKE_scene_check_rigidbody_active(scene)) { - BKE_rigidbody_rebuild_world(eval_ctx, scene, ctime); + BKE_rigidbody_rebuild_world(depsgraph, scene, ctime); } } -void BKE_rigidbody_eval_simulation(const struct EvaluationContext *eval_ctx, +void BKE_rigidbody_eval_simulation(struct Depsgraph *depsgraph, Scene *scene) { float ctime = BKE_scene_frame_get(scene); DEG_debug_print_eval_time(__func__, scene->id.name, scene, ctime); /* evaluate rigidbody sim */ if (BKE_scene_check_rigidbody_active(scene)) { - BKE_rigidbody_do_simulation(eval_ctx, scene, ctime); + BKE_rigidbody_do_simulation(depsgraph, scene, ctime); } } -void BKE_rigidbody_object_sync_transforms(const struct EvaluationContext *UNUSED(eval_ctx), +void BKE_rigidbody_object_sync_transforms(struct Depsgraph *UNUSED(depsgraph), Scene *scene, Object *ob) { diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 628d9584f0e..ee60a9b9f4d 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -996,7 +996,7 @@ Scene *BKE_scene_set_name(Main *bmain, const char *name) /* Used by metaballs, return *all* objects (including duplis) existing in the scene (including scene's sets) */ int BKE_scene_base_iter_next( - const EvaluationContext *eval_ctx, SceneBaseIter *iter, + Depsgraph *depsgraph, SceneBaseIter *iter, Scene **scene, int val, Base **base, Object **ob) { bool run_again = true; @@ -1015,7 +1015,9 @@ int BKE_scene_base_iter_next( /* the first base */ if (iter->phase == F_START) { - ViewLayer *view_layer = eval_ctx->view_layer; + ViewLayer *view_layer = (depsgraph) ? + DEG_get_evaluated_view_layer(depsgraph) : + BKE_view_layer_from_scene_get(*scene); *base = view_layer->object_bases.first; if (*base) { *ob = (*base)->object; @@ -1063,12 +1065,12 @@ int BKE_scene_base_iter_next( } else { if (iter->phase != F_DUPLI) { - if ( (*base)->object->transflag & OB_DUPLI) { + if (depsgraph && (*base)->object->transflag & OB_DUPLI) { /* groups cannot be duplicated for mballs yet, * this enters eternal loop because of * makeDispListMBall getting called inside of group_duplilist */ if ((*base)->object->dup_group == NULL) { - iter->duplilist = object_duplilist_ex(eval_ctx, (*scene), (*base)->object, false); + iter->duplilist = object_duplilist_ex(depsgraph, (*scene), (*base)->object, false); iter->dupob = iter->duplilist->first; @@ -1351,7 +1353,7 @@ static bool check_rendered_viewport_visible(Main *bmain) return false; } -/* TODO(campbell): shouldn't we be able to use 'eval_ctx->view_layer' here? +/* TODO(campbell): shouldn't we be able to use 'DEG_get_view_layer' here? * Currently this is NULL on load, so don't. */ static void prepare_mesh_for_viewport_render( Main *bmain, const ViewLayer *view_layer) diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index c1b3a4ae0c8..35055a59243 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -451,6 +451,174 @@ unsigned int BKE_screen_visible_layers(bScreen *screen, Scene *scene) return layer; } + +/* ***************** Screen edges & verts ***************** */ + +ScrEdge *BKE_screen_find_edge(bScreen *sc, ScrVert *v1, ScrVert *v2) +{ + ScrEdge *se; + + BKE_screen_sort_scrvert(&v1, &v2); + for (se = sc->edgebase.first; se; se = se->next) { + if (se->v1 == v1 && se->v2 == v2) { + return se; + } + } + + return NULL; +} + +void BKE_screen_sort_scrvert(ScrVert **v1, ScrVert **v2) +{ + ScrVert *tmp; + + if (*v1 > *v2) { + tmp = *v1; + *v1 = *v2; + *v2 = tmp; + } +} + +void BKE_screen_remove_double_scrverts(bScreen *sc) +{ + ScrVert *v1, *verg; + ScrEdge *se; + ScrArea *sa; + + verg = sc->vertbase.first; + while (verg) { + if (verg->newv == NULL) { /* !!! */ + v1 = verg->next; + while (v1) { + if (v1->newv == NULL) { /* !?! */ + if (v1->vec.x == verg->vec.x && v1->vec.y == verg->vec.y) { + /* printf("doublevert\n"); */ + v1->newv = verg; + } + } + v1 = v1->next; + } + } + verg = verg->next; + } + + /* replace pointers in edges and faces */ + se = sc->edgebase.first; + while (se) { + if (se->v1->newv) se->v1 = se->v1->newv; + if (se->v2->newv) se->v2 = se->v2->newv; + /* edges changed: so.... */ + BKE_screen_sort_scrvert(&(se->v1), &(se->v2)); + se = se->next; + } + sa = sc->areabase.first; + while (sa) { + if (sa->v1->newv) sa->v1 = sa->v1->newv; + if (sa->v2->newv) sa->v2 = sa->v2->newv; + if (sa->v3->newv) sa->v3 = sa->v3->newv; + if (sa->v4->newv) sa->v4 = sa->v4->newv; + sa = sa->next; + } + + /* remove */ + verg = sc->vertbase.first; + while (verg) { + v1 = verg->next; + if (verg->newv) { + BLI_remlink(&sc->vertbase, verg); + MEM_freeN(verg); + } + verg = v1; + } + +} + +void BKE_screen_remove_double_scredges(bScreen *sc) +{ + ScrEdge *verg, *se, *sn; + + /* compare */ + verg = sc->edgebase.first; + while (verg) { + se = verg->next; + while (se) { + sn = se->next; + if (verg->v1 == se->v1 && verg->v2 == se->v2) { + BLI_remlink(&sc->edgebase, se); + MEM_freeN(se); + } + se = sn; + } + verg = verg->next; + } +} + +void BKE_screen_remove_unused_scredges(bScreen *sc) +{ + ScrEdge *se, *sen; + ScrArea *sa; + int a = 0; + + /* sets flags when edge is used in area */ + sa = sc->areabase.first; + while (sa) { + se = BKE_screen_find_edge(sc, sa->v1, sa->v2); + if (se == NULL) printf("error: area %d edge 1 doesn't exist\n", a); + else se->flag = 1; + se = BKE_screen_find_edge(sc, sa->v2, sa->v3); + if (se == NULL) printf("error: area %d edge 2 doesn't exist\n", a); + else se->flag = 1; + se = BKE_screen_find_edge(sc, sa->v3, sa->v4); + if (se == NULL) printf("error: area %d edge 3 doesn't exist\n", a); + else se->flag = 1; + se = BKE_screen_find_edge(sc, sa->v4, sa->v1); + if (se == NULL) printf("error: area %d edge 4 doesn't exist\n", a); + else se->flag = 1; + sa = sa->next; + a++; + } + se = sc->edgebase.first; + while (se) { + sen = se->next; + if (se->flag == 0) { + BLI_remlink(&sc->edgebase, se); + MEM_freeN(se); + } + else { + se->flag = 0; + } + se = sen; + } +} + +void BKE_screen_remove_unused_scrverts(bScreen *sc) +{ + ScrVert *sv, *svn; + ScrEdge *se; + + /* we assume edges are ok */ + + se = sc->edgebase.first; + while (se) { + se->v1->flag = 1; + se->v2->flag = 1; + se = se->next; + } + + sv = sc->vertbase.first; + while (sv) { + svn = sv->next; + if (sv->flag == 0) { + BLI_remlink(&sc->vertbase, sv); + MEM_freeN(sv); + } + else { + sv->flag = 0; + } + sv = svn; + } +} + /* ***************** Utilities ********************** */ /* Find a region of the specified type from the given area */ diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 58b83a754d8..4f8e4b0b842 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -76,6 +76,7 @@ #include "BKE_idprop.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "RNA_access.h" @@ -592,17 +593,16 @@ void BKE_sequencer_pixel_from_sequencer_space_v4(struct Scene *scene, float pixe /*********************** sequencer pipeline functions *************************/ void BKE_sequencer_new_render_data( - EvaluationContext *eval_ctx, Main *bmain, Scene *scene, int rectx, int recty, - int preview_render_size, + int preview_render_size, int for_render, SeqRenderData *r_context) { - r_context->eval_ctx = eval_ctx; r_context->bmain = bmain; r_context->scene = scene; r_context->rectx = rectx; r_context->recty = recty; r_context->preview_render_size = preview_render_size; + r_context->for_render = for_render; r_context->motion_blur_samples = 0; r_context->motion_blur_shutter = 0; r_context->skip_cache = false; @@ -2035,9 +2035,10 @@ void BKE_sequencer_proxy_rebuild(SeqIndexBuildContext *context, short *stop, sho /* fail safe code */ BKE_sequencer_new_render_data( - bmain->eval_ctx, bmain, context->scene, + bmain, context->scene, (scene->r.size * (float) scene->r.xsch) / 100.0f + 0.5f, (scene->r.size * (float) scene->r.ysch) / 100.0f + 0.5f, 100, + false, &render_context); render_context.skip_cache = true; @@ -3337,7 +3338,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq BKE_scene_graph_update_for_newframe(depsgraph, context->bmain); ibuf = sequencer_view3d_cb( /* set for OpenGL render (NULL when scrubbing) */ - context->eval_ctx, scene, view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, camera, width, height, IB_rect, draw_flags, context->scene->r.seq_prev_type, scene->r.alphamode, context->gpu_samples, viewname, @@ -3362,7 +3363,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq * When rendering from command line renderer is called from main thread, in this * case it's always safe to render scene here */ - if (!is_thread_main || is_rendering == false || is_background || context->eval_ctx->mode == DAG_EVAL_RENDER) { + if (!is_thread_main || is_rendering == false || is_background || context->for_render) { if (re == NULL) re = RE_NewSceneRender(scene); diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 9215d56eb30..f99bd773ebc 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -83,6 +83,7 @@ #include "BKE_texture.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "RE_shader_ext.h" @@ -127,7 +128,7 @@ void smoke_initWaveletBlenderRNA(struct WTURBULENCE *UNUSED(wt), float *UNUSED(s void smoke_initBlenderRNA(struct FLUID_3D *UNUSED(fluid), float *UNUSED(alpha), float *UNUSED(beta), float *UNUSED(dt_factor), float *UNUSED(vorticity), int *UNUSED(border_colli), float *UNUSED(burning_rate), float *UNUSED(flame_smoke), float *UNUSED(flame_smoke_color), float *UNUSED(flame_vorticity), float *UNUSED(flame_ignition_temp), float *UNUSED(flame_max_temp)) {} -struct DerivedMesh *smokeModifier_do(SmokeModifierData *UNUSED(smd), const struct EvaluationContext *UNUSED(eval_ctx), Scene *UNUSED(scene), Object *UNUSED(ob), DerivedMesh *UNUSED(dm)) { return NULL; } +struct DerivedMesh *smokeModifier_do(SmokeModifierData *UNUSED(smd), struct Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene), Object *UNUSED(ob), DerivedMesh *UNUSED(dm)) { return NULL; } float smoke_get_velocity_at(struct Object *UNUSED(ob), float UNUSED(position[3]), float UNUSED(velocity[3])) { return 0.0f; } #endif /* WITH_SMOKE */ @@ -1107,8 +1108,9 @@ static void em_combineMaps(EmissionMap *output, EmissionMap *em2, int hires_mult /* initialize with first input if in range */ if (x >= em1.min[0] && x < em1.max[0] && - y >= em1.min[1] && y < em1.max[1] && - z >= em1.min[2] && z < em1.max[2]) { + y >= em1.min[1] && y < em1.max[1] && + z >= em1.min[2] && z < em1.max[2]) + { int index_in = smoke_get_index(x - em1.min[0], em1.res[0], y - em1.min[1], em1.res[1], z - em1.min[2]); /* values */ @@ -1120,8 +1122,9 @@ static void em_combineMaps(EmissionMap *output, EmissionMap *em2, int hires_mult /* apply second input if in range */ if (x >= em2->min[0] && x < em2->max[0] && - y >= em2->min[1] && y < em2->max[1] && - z >= em2->min[2] && z < em2->max[2]) { + y >= em2->min[1] && y < em2->max[1] && + z >= em2->min[2] && z < em2->max[2]) + { int index_in = smoke_get_index(x - em2->min[0], em2->res[0], y - em2->min[1], em2->res[1], z - em2->min[2]); /* values */ @@ -1151,8 +1154,9 @@ static void em_combineMaps(EmissionMap *output, EmissionMap *em2, int hires_mult /* initialize with first input if in range */ if (x >= em1.hmin[0] && x < em1.hmax[0] && - y >= em1.hmin[1] && y < em1.hmax[1] && - z >= em1.hmin[2] && z < em1.hmax[2]) { + y >= em1.hmin[1] && y < em1.hmax[1] && + z >= em1.hmin[2] && z < em1.hmax[2]) + { int index_in = smoke_get_index(x - em1.hmin[0], em1.hres[0], y - em1.hmin[1], em1.hres[1], z - em1.hmin[2]); /* values */ output->influence_high[index_out] = em1.influence_high[index_in]; @@ -1160,8 +1164,9 @@ static void em_combineMaps(EmissionMap *output, EmissionMap *em2, int hires_mult /* apply second input if in range */ if (x >= em2->hmin[0] && x < em2->hmax[0] && - y >= em2->hmin[1] && y < em2->hmax[1] && - z >= em2->hmin[2] && z < em2->hmax[2]) { + y >= em2->hmin[1] && y < em2->hmax[1] && + z >= em2->hmin[2] && z < em2->hmax[2]) + { int index_in = smoke_get_index(x - em2->hmin[0], em2->hres[0], y - em2->hmin[1], em2->hres[1], z - em2->hmin[2]); /* values */ @@ -2102,7 +2107,7 @@ BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value } } -static void update_flowsfluids(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt) +static void update_flowsfluids(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt) { Object **flowobjs = NULL; EmissionMap *emaps = NULL; @@ -2209,7 +2214,7 @@ static void update_flowsfluids(const struct EvaluationContext *eval_ctx, Scene * else { /* MOD_SMOKE_FLOW_SOURCE_MESH */ /* update flow object frame */ BLI_mutex_lock(&object_update_lock); - BKE_object_modifier_update_subframe(eval_ctx, scene, collob, true, 5, BKE_scene_frame_get(scene), eModifierType_Smoke); + BKE_object_modifier_update_subframe(depsgraph, scene, collob, true, 5, BKE_scene_frame_get(scene), eModifierType_Smoke); BLI_mutex_unlock(&object_update_lock); /* apply flow */ @@ -2521,12 +2526,12 @@ static void update_effectors_task_cb( } } -static void update_effectors(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, SmokeDomainSettings *sds, float UNUSED(dt)) +static void update_effectors(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float UNUSED(dt)) { ListBase *effectors; /* make sure smoke flow influence is 0.0f */ sds->effector_weights->weight[PFIELD_SMOKEFLOW] = 0.0f; - effectors = pdInitEffectors(eval_ctx, scene, ob, NULL, sds->effector_weights, true); + effectors = pdInitEffectors(depsgraph, scene, ob, NULL, sds->effector_weights, true); if (effectors) { // precalculate wind forces @@ -2556,7 +2561,7 @@ static void update_effectors(const struct EvaluationContext *eval_ctx, Scene *sc pdEndEffectors(&effectors); } -static void step(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh *domain_dm, float fps) +static void step(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh *domain_dm, float fps) { SmokeDomainSettings *sds = smd->domain; /* stability values copied from wturbulence.cpp */ @@ -2626,11 +2631,11 @@ static void step(const struct EvaluationContext *eval_ctx, Scene *scene, Object for (substep = 0; substep < totalSubsteps; substep++) { // calc animated obstacle velocities - update_flowsfluids(eval_ctx, scene, ob, sds, dtSubdiv); + update_flowsfluids(depsgraph, scene, ob, sds, dtSubdiv); update_obstacles(scene, ob, sds, dtSubdiv, substep, totalSubsteps); if (sds->total_cells > 1) { - update_effectors(eval_ctx, scene, ob, sds, dtSubdiv); // DG TODO? problem --> uses forces instead of velocity, need to check how they need to be changed with variable dt + update_effectors(depsgraph, scene, ob, sds, dtSubdiv); // DG TODO? problem --> uses forces instead of velocity, need to check how they need to be changed with variable dt smoke_step(sds->fluid, gravity, dtSubdiv); } } @@ -2724,7 +2729,7 @@ static DerivedMesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob) } static void smokeModifier_process( - SmokeModifierData *smd, const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, DerivedMesh *dm) + SmokeModifierData *smd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm) { if ((smd->type & MOD_SMOKE_TYPE_FLOW)) { @@ -2845,11 +2850,11 @@ static void smokeModifier_process( } - step(eval_ctx, scene, ob, smd, dm, scene->r.frs_sec / scene->r.frs_sec_base); + step(depsgraph, scene, ob, smd, dm, scene->r.frs_sec / scene->r.frs_sec_base); } // create shadows before writing cache so they get stored - smoke_calc_transparency(sds, eval_ctx->view_layer); + smoke_calc_transparency(sds, DEG_get_evaluated_view_layer(depsgraph)); if (sds->wt && sds->total_cells > 1) { smoke_turbulence_step(sds->wt, sds->fluid); @@ -2867,13 +2872,13 @@ static void smokeModifier_process( } struct DerivedMesh *smokeModifier_do( - SmokeModifierData *smd, const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, DerivedMesh *dm) + SmokeModifierData *smd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm) { /* lock so preview render does not read smoke data while it gets modified */ if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) BLI_rw_mutex_lock(smd->domain->fluid_mutex, THREAD_LOCK_WRITE); - smokeModifier_process(smd, eval_ctx, scene, ob, dm); + smokeModifier_process(smd, depsgraph, scene, ob, dm); if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) BLI_rw_mutex_unlock(smd->domain->fluid_mutex); diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 1fb95bd3115..0af400796a4 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -83,6 +83,7 @@ variables on the UI for now #include "BKE_scene.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "PIL_time.h" @@ -662,11 +663,13 @@ static void add_2nd_order_roller(Object *ob, float UNUSED(stiffness), int *count notthis = bs->v2; } else { - if (v0 == bs->v2) { - bpo = sb->bpoint+bs->v1; - notthis = bs->v1; - } - else {printf("oops we should not get here - add_2nd_order_springs");} + if (v0 == bs->v2) { + bpo = sb->bpoint+bs->v1; + notthis = bs->v1; + } + else { + printf("oops we should not get here - add_2nd_order_springs"); + } } if (bpo) {/* so now we have a 2nd order humpdidump */ for (c=bpo->nofsprings;c>0;c--) { @@ -1522,12 +1525,12 @@ static void _scan_for_ext_spring_forces(Scene *scene, Object *ob, float timenow, } -static void scan_for_ext_spring_forces(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float timenow) +static void scan_for_ext_spring_forces(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float timenow) { SoftBody *sb = ob->soft; ListBase *do_effector = NULL; - do_effector = pdInitEffectors(eval_ctx, scene, ob, NULL, sb->effector_weights, true); + do_effector = pdInitEffectors(depsgraph, scene, ob, NULL, sb->effector_weights, true); _scan_for_ext_spring_forces(scene, ob, timenow, 0, sb->totspring, do_effector); pdEndEffectors(&do_effector); } @@ -1539,7 +1542,7 @@ static void *exec_scan_for_ext_spring_forces(void *data) return NULL; } -static void sb_sfesf_threads_run(const struct EvaluationContext *eval_ctx, Scene *scene, struct Object *ob, float timenow, int totsprings, int *UNUSED(ptr_to_break_func(void))) +static void sb_sfesf_threads_run(struct Depsgraph *depsgraph, Scene *scene, struct Object *ob, float timenow, int totsprings, int *UNUSED(ptr_to_break_func(void))) { ListBase *do_effector = NULL; ListBase threads; @@ -1547,7 +1550,7 @@ static void sb_sfesf_threads_run(const struct EvaluationContext *eval_ctx, Scene int i, totthread, left, dec; int lowsprings =100; /* wild guess .. may increase with better thread management 'above' or even be UI option sb->spawn_cf_threads_nopts */ - do_effector= pdInitEffectors(eval_ctx, scene, ob, NULL, ob->soft->effector_weights, true); + do_effector= pdInitEffectors(depsgraph, scene, ob, NULL, ob->soft->effector_weights, true); /* figure the number of threads while preventing pretty pointless threading overhead */ totthread= BKE_scene_num_threads(scene); @@ -1955,12 +1958,12 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo /* intitialize */ if (sb) { - /* check conditions for various options */ - /* +++ could be done on object level to squeeze out the last bits of it */ - do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF)); - do_springcollision=do_deflector && (ob->softflag & OB_SB_EDGES) &&(ob->softflag & OB_SB_EDGECOLL); - do_aero=((sb->aeroedge)&& (ob->softflag & OB_SB_EDGES)); - /* --- could be done on object level to squeeze out the last bits of it */ + /* check conditions for various options */ + /* +++ could be done on object level to squeeze out the last bits of it */ + do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF)); + do_springcollision=do_deflector && (ob->softflag & OB_SB_EDGES) &&(ob->softflag & OB_SB_EDGECOLL); + do_aero=((sb->aeroedge)&& (ob->softflag & OB_SB_EDGES)); + /* --- could be done on object level to squeeze out the last bits of it */ } else { printf("Error expected a SB here\n"); @@ -2205,7 +2208,7 @@ static void sb_cf_threads_run(Scene *scene, Object *ob, float forcetime, float t MEM_freeN(sb_threads); } -static void softbody_calc_forcesEx(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float forcetime, float timenow) +static void softbody_calc_forcesEx(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow) { /* rule we never alter free variables :bp->vec bp->pos in here ! * this will ruin adaptive stepsize AKA heun! (BM) @@ -2221,7 +2224,7 @@ static void softbody_calc_forcesEx(const struct EvaluationContext *eval_ctx, Sce /* gravity = sb->grav * sb_grav_force_scale(ob); */ /* UNUSED */ /* check conditions for various options */ - do_deflector= query_external_colliders(eval_ctx->view_layer, sb->collision_group); + do_deflector= query_external_colliders(DEG_get_evaluated_view_layer(depsgraph), sb->collision_group); /* do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF)); */ /* UNUSED */ do_springcollision=do_deflector && (ob->softflag & OB_SB_EDGES) &&(ob->softflag & OB_SB_EDGECOLL); do_aero=((sb->aeroedge)&& (ob->softflag & OB_SB_EDGES)); @@ -2230,10 +2233,10 @@ static void softbody_calc_forcesEx(const struct EvaluationContext *eval_ctx, Sce /* bproot= sb->bpoint; */ /* need this for proper spring addressing */ /* UNUSED */ if (do_springcollision || do_aero) - sb_sfesf_threads_run(eval_ctx, scene, ob, timenow, sb->totspring, NULL); + sb_sfesf_threads_run(depsgraph, scene, ob, timenow, sb->totspring, NULL); /* after spring scan because it uses Effoctors too */ - do_effector= pdInitEffectors(eval_ctx, scene, ob, NULL, sb->effector_weights, true); + do_effector= pdInitEffectors(depsgraph, scene, ob, NULL, sb->effector_weights, true); if (do_deflector) { float defforce[3]; @@ -2250,11 +2253,11 @@ static void softbody_calc_forcesEx(const struct EvaluationContext *eval_ctx, Sce } -static void softbody_calc_forces(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float forcetime, float timenow) +static void softbody_calc_forces(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow) { /* redirection to the new threaded Version */ if (!(G.debug_value & 0x10)) { // 16 - softbody_calc_forcesEx(eval_ctx, scene, ob, forcetime, timenow); + softbody_calc_forcesEx(depsgraph, scene, ob, forcetime, timenow); return; } else { @@ -2285,7 +2288,7 @@ static void softbody_calc_forces(const struct EvaluationContext *eval_ctx, Scene } /* check conditions for various options */ - do_deflector= query_external_colliders(eval_ctx->view_layer, sb->collision_group); + do_deflector= query_external_colliders(DEG_get_evaluated_view_layer(depsgraph), sb->collision_group); do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF)); do_springcollision=do_deflector && (ob->softflag & OB_SB_EDGES) &&(ob->softflag & OB_SB_EDGECOLL); do_aero=((sb->aeroedge)&& (ob->softflag & OB_SB_EDGES)); @@ -2293,9 +2296,9 @@ static void softbody_calc_forces(const struct EvaluationContext *eval_ctx, Scene iks = 1.0f/(1.0f-sb->inspring)-1.0f ;/* inner spring constants function */ /* bproot= sb->bpoint; */ /* need this for proper spring addressing */ /* UNUSED */ - if (do_springcollision || do_aero) scan_for_ext_spring_forces(eval_ctx, scene, ob, timenow); + if (do_springcollision || do_aero) scan_for_ext_spring_forces(depsgraph, scene, ob, timenow); /* after spring scan because it uses Effoctors too */ - do_effector= pdInitEffectors(eval_ctx, scene, ob, NULL, ob->soft->effector_weights, true); + do_effector= pdInitEffectors(depsgraph, scene, ob, NULL, ob->soft->effector_weights, true); if (do_deflector) { float defforce[3]; @@ -2755,7 +2758,7 @@ static void apply_spring_memory(Object *ob) l = len_v3v3(bp1->pos, bp2->pos); r = bs->len/l; if (( r > 1.05f) || (r < 0.95f)) { - bs->len = ((100.0f - b) * bs->len + b*l)/100.0f; + bs->len = ((100.0f - b) * bs->len + b*l)/100.0f; } } } @@ -2803,10 +2806,10 @@ static void springs_from_mesh(Object *ob) sb= ob->soft; if (me && sb) { - /* using bp->origS as a container for spring calcualtions here - * will be overwritten sbObjectStep() to receive - * actual modifier stack positions - */ + /* using bp->origS as a container for spring calcualtions here + * will be overwritten sbObjectStep() to receive + * actual modifier stack positions + */ if (me->totvert) { bp= ob->soft->bpoint; for (a=0; a<me->totvert; a++, bp++) { @@ -3469,20 +3472,20 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int SB_estimate_transform(ob, NULL, NULL, NULL); } switch (ob->type) { - case OB_MESH: - if (ob->softflag & OB_SB_FACECOLL) mesh_faces_to_scratch(ob); - break; - case OB_LATTICE: - break; - case OB_CURVE: - case OB_SURF: - break; - default: - break; + case OB_MESH: + if (ob->softflag & OB_SB_FACECOLL) mesh_faces_to_scratch(ob); + break; + case OB_LATTICE: + break; + case OB_CURVE: + case OB_SURF: + break; + default: + break; } } -static void softbody_step(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, SoftBody *sb, float dtime) +static void softbody_step(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SoftBody *sb, float dtime) { /* the simulator */ float forcetime; @@ -3496,11 +3499,13 @@ static void softbody_step(const struct EvaluationContext *eval_ctx, Scene *scene */ if (dtime < 0 || dtime > 10.5f) return; - ccd_update_deflector_hash(eval_ctx->view_layer, sb->collision_group, ob, sb->scratch->colliderhash); + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); + + ccd_update_deflector_hash(view_layer, sb->collision_group, ob, sb->scratch->colliderhash); if (sb->scratch->needstobuildcollider) { - if (query_external_colliders(eval_ctx->view_layer, sb->collision_group)) { - ccd_build_deflector_hash(eval_ctx->view_layer, sb->collision_group, ob, sb->scratch->colliderhash); + if (query_external_colliders(view_layer, sb->collision_group)) { + ccd_build_deflector_hash(view_layer, sb->collision_group, ob, sb->scratch->colliderhash); } sb->scratch->needstobuildcollider=0; } @@ -3530,12 +3535,12 @@ static void softbody_step(const struct EvaluationContext *eval_ctx, Scene *scene sb->scratch->flag &= ~SBF_DOFUZZY; /* do predictive euler step */ - softbody_calc_forces(eval_ctx, scene, ob, forcetime, timedone/dtime); + softbody_calc_forces(depsgraph, scene, ob, forcetime, timedone/dtime); softbody_apply_forces(ob, forcetime, 1, NULL, mid_flags); /* crop new slope values to do averaged slope step */ - softbody_calc_forces(eval_ctx, scene, ob, forcetime, timedone/dtime); + softbody_calc_forces(depsgraph, scene, ob, forcetime, timedone/dtime); softbody_apply_forces(ob, forcetime, 2, &err, mid_flags); softbody_apply_goalsnap(ob); @@ -3616,7 +3621,7 @@ static void softbody_step(const struct EvaluationContext *eval_ctx, Scene *scene } /* simulates one step. framenr is in frames */ -void sbObjectStep(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], int numVerts) +void sbObjectStep(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], int numVerts) { SoftBody *sb= ob->soft; PointCache *cache; @@ -3697,7 +3702,8 @@ void sbObjectStep(const struct EvaluationContext *eval_ctx, Scene *scene, Object cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe, can_simulate); if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED || - (!can_simulate && cache_result == PTCACHE_READ_OLD)) { + (!can_simulate && cache_result == PTCACHE_READ_OLD)) + { softbody_to_object(ob, vertexCos, numVerts, sb->local); BKE_ptcache_validate(cache, framenr); @@ -3731,7 +3737,7 @@ void sbObjectStep(const struct EvaluationContext *eval_ctx, Scene *scene, Object dtime = framedelta*timescale; /* do simulation */ - softbody_step(eval_ctx, scene, ob, sb, dtime); + softbody_step(depsgraph, scene, ob, sb, dtime); softbody_to_object(ob, vertexCos, numVerts, 0); diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index e87e84736c8..167ee6b4018 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -195,7 +195,7 @@ 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(const struct EvaluationContext *UNUSED(eval_ctx), World *world) +void BKE_world_eval(struct Depsgraph *UNUSED(depsgraph), World *world) { if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s on %s (%p)\n", __func__, world->id.name, world); diff --git a/source/blender/blenlib/BLI_utildefines_stack.h b/source/blender/blenlib/BLI_utildefines_stack.h index 15b0029e727..224add91504 100644 --- a/source/blender/blenlib/BLI_utildefines_stack.h +++ b/source/blender/blenlib/BLI_utildefines_stack.h @@ -77,13 +77,13 @@ SWAP(typeof(stack_a), stack_a, stack_b); \ SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \ _STACK_SWAP_TOTALLOC(stack_a, stack_b); \ - } ((void)0) +} ((void)0) #else #define STACK_SWAP(stack_a, stack_b) { \ SWAP(void *, stack_a, stack_b); \ SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \ _STACK_SWAP_TOTALLOC(stack_a, stack_b); \ - } ((void)0) +} ((void)0) #endif #endif /* __BLI_UTILDEFINES_STACK_H__ */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 4308fe0fee3..f2f5dd2d27b 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3873,8 +3873,8 @@ static void direct_link_text(FileData *fd, Text *text) #if 0 if (text->flags & TXT_ISEXT) { BKE_text_reload(text); - } - /* else { */ + } + /* else { */ #endif link_list(fd, &text->lines); @@ -6516,6 +6516,588 @@ static void direct_link_scene(FileData *fd, Scene *sce, Main *bmain) direct_link_workspace_link_scene_data(fd, sce, &bmain->workspaces); } +/* ****************** READ GREASE PENCIL ***************** */ + +/* relink's grease pencil data's refs */ +static void lib_link_gpencil(FileData *fd, Main *main) +{ + for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) { + if (gpd->id.tag & LIB_TAG_NEED_LINK) { + IDP_LibLinkProperty(gpd->id.properties, fd); + lib_link_animdata(fd, &gpd->id, gpd->adt); + + gpd->id.tag &= ~LIB_TAG_NEED_LINK; + } + } +} + +/* relinks grease-pencil data - used for direct_link and old file linkage */ +static void direct_link_gpencil(FileData *fd, bGPdata *gpd) +{ + bGPDlayer *gpl; + bGPDframe *gpf; + bGPDstroke *gps; + bGPDpalette *palette; + + /* we must firstly have some grease-pencil data to link! */ + if (gpd == NULL) + return; + + /* relink animdata */ + gpd->adt = newdataadr(fd, gpd->adt); + direct_link_animdata(fd, gpd->adt); + + /* relink palettes */ + link_list(fd, &gpd->palettes); + for (palette = gpd->palettes.first; palette; palette = palette->next) { + link_list(fd, &palette->colors); + } + + /* relink layers */ + link_list(fd, &gpd->layers); + + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { + /* parent */ + gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent); + /* relink frames */ + link_list(fd, &gpl->frames); + gpl->actframe = newdataadr(fd, gpl->actframe); + + for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { + /* relink strokes (and their points) */ + link_list(fd, &gpf->strokes); + + for (gps = gpf->strokes.first; gps; gps = gps->next) { + gps->points = newdataadr(fd, gps->points); + + /* the triangulation is not saved, so need to be recalculated */ + gps->triangles = NULL; + gps->tot_triangles = 0; + gps->flag |= GP_STROKE_RECALC_CACHES; + /* the color pointer is not saved, so need to be recalculated using the color name */ + gps->palcolor = NULL; + gps->flag |= GP_STROKE_RECALC_COLOR; + } + } + } +} + +/* *********** READ AREA **************** */ + +static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) +{ + Panel *pa; + uiList *ui_list; + + link_list(fd, &ar->panels); + + for (pa = ar->panels.first; pa; pa = pa->next) { + pa->paneltab = newdataadr(fd, pa->paneltab); + pa->runtime_flag = 0; + pa->activedata = NULL; + pa->type = NULL; + } + + link_list(fd, &ar->panels_category_active); + + link_list(fd, &ar->ui_lists); + + for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { + ui_list->type = NULL; + ui_list->dyn_data = NULL; + ui_list->properties = newdataadr(fd, ui_list->properties); + IDP_DirectLinkGroup_OrFree(&ui_list->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + } + + link_list(fd, &ar->ui_previews); + + if (spacetype == SPACE_EMPTY) { + /* unkown space type, don't leak regiondata */ + ar->regiondata = NULL; + } + else { + ar->regiondata = newdataadr(fd, ar->regiondata); + if (ar->regiondata) { + if (spacetype == SPACE_VIEW3D) { + RegionView3D *rv3d = ar->regiondata; + + rv3d->localvd = newdataadr(fd, rv3d->localvd); + rv3d->clipbb = newdataadr(fd, rv3d->clipbb); + + rv3d->depths = NULL; + rv3d->gpuoffscreen = NULL; + rv3d->render_engine = NULL; + rv3d->sms = NULL; + rv3d->smooth_timer = NULL; + rv3d->compositor = NULL; + rv3d->viewport = NULL; + } + } + } + + ar->v2d.tab_offset = NULL; + ar->v2d.tab_num = 0; + ar->v2d.tab_cur = 0; + ar->v2d.sms = NULL; + BLI_listbase_clear(&ar->panels_category); + BLI_listbase_clear(&ar->handlers); + BLI_listbase_clear(&ar->uiblocks); + ar->headerstr = NULL; + ar->visible = 0; + ar->type = NULL; + ar->swap = 0; + ar->do_draw = 0; + ar->manipulator_map = NULL; + ar->regiontimer = NULL; + memset(&ar->drawrct, 0, sizeof(ar->drawrct)); +} + +static void direct_link_area(FileData *fd, ScrArea *area) +{ + SpaceLink *sl; + ARegion *ar; + + link_list(fd, &(area->spacedata)); + link_list(fd, &(area->regionbase)); + + BLI_listbase_clear(&area->handlers); + area->type = NULL; /* spacetype callbacks */ + area->region_active_win = -1; + + /* if we do not have the spacetype registered (game player), we cannot + * free it, so don't allocate any new memory for such spacetypes. */ + if (!BKE_spacetype_exists(area->spacetype)) { + area->spacetype = SPACE_EMPTY; + } + + for (ar = area->regionbase.first; ar; ar = ar->next) { + direct_link_region(fd, ar, area->spacetype); + } + + /* accident can happen when read/save new file with older version */ + /* 2.50: we now always add spacedata for info */ + if (area->spacedata.first == NULL) { + SpaceInfo *sinfo= MEM_callocN(sizeof(SpaceInfo), "spaceinfo"); + area->spacetype= sinfo->spacetype= SPACE_INFO; + BLI_addtail(&area->spacedata, sinfo); + } + /* add local view3d too */ + else if (area->spacetype == SPACE_VIEW3D) { + blo_do_versions_view3d_split_250(area->spacedata.first, &area->regionbase); + } + + /* incase we set above */ + area->butspacetype = area->spacetype; + + for (sl = area->spacedata.first; sl; sl = sl->next) { + link_list(fd, &(sl->regionbase)); + + /* if we do not have the spacetype registered (game player), we cannot + * free it, so don't allocate any new memory for such spacetypes. */ + if (!BKE_spacetype_exists(sl->spacetype)) + sl->spacetype = SPACE_EMPTY; + + for (ar = sl->regionbase.first; ar; ar = ar->next) + direct_link_region(fd, ar, sl->spacetype); + + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d= (View3D*) sl; + + v3d->flag |= V3D_INVALID_BACKBUF; + + if (v3d->gpd) { + v3d->gpd = newdataadr(fd, v3d->gpd); + direct_link_gpencil(fd, v3d->gpd); + } + v3d->localvd = newdataadr(fd, v3d->localvd); + BLI_listbase_clear(&v3d->afterdraw_transp); + BLI_listbase_clear(&v3d->afterdraw_xray); + BLI_listbase_clear(&v3d->afterdraw_xraytransp); + v3d->properties_storage = NULL; + v3d->defmaterial = NULL; + + /* render can be quite heavy, set to solid on load */ + if (v3d->drawtype == OB_RENDER) + v3d->drawtype = OB_SOLID; + v3d->prev_drawtype = OB_SOLID; + + if (v3d->fx_settings.dof) + v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof); + if (v3d->fx_settings.ssao) + v3d->fx_settings.ssao = newdataadr(fd, v3d->fx_settings.ssao); + + blo_do_versions_view3d_split_250(v3d, &sl->regionbase); + } + else if (sl->spacetype == SPACE_IPO) { + SpaceIpo *sipo = (SpaceIpo *)sl; + + sipo->ads = newdataadr(fd, sipo->ads); + BLI_listbase_clear(&sipo->ghostCurves); + } + else if (sl->spacetype == SPACE_NLA) { + SpaceNla *snla = (SpaceNla *)sl; + + snla->ads = newdataadr(fd, snla->ads); + } + else if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *soops = (SpaceOops *) sl; + + /* use newdataadr_no_us and do not free old memory avoiding double + * frees and use of freed memory. this could happen because of a + * bug fixed in revision 58959 where the treestore memory address + * was not unique */ + TreeStore *ts = newdataadr_no_us(fd, soops->treestore); + soops->treestore = NULL; + if (ts) { + TreeStoreElem *elems = newdataadr_no_us(fd, ts->data); + + soops->treestore = BLI_mempool_create(sizeof(TreeStoreElem), ts->usedelem, + 512, BLI_MEMPOOL_ALLOW_ITER); + if (ts->usedelem && elems) { + int i; + for (i = 0; i < ts->usedelem; i++) { + TreeStoreElem *new_elem = BLI_mempool_alloc(soops->treestore); + *new_elem = elems[i]; + } + } + /* we only saved what was used */ + soops->storeflag |= SO_TREESTORE_CLEANUP; // at first draw + } + soops->treehash = NULL; + soops->tree.first = soops->tree.last= NULL; + } + else if (sl->spacetype == SPACE_IMAGE) { + SpaceImage *sima = (SpaceImage *)sl; + + sima->iuser.scene = NULL; + sima->iuser.ok = 1; + sima->scopes.waveform_1 = NULL; + sima->scopes.waveform_2 = NULL; + sima->scopes.waveform_3 = NULL; + sima->scopes.vecscope = NULL; + sima->scopes.ok = 0; + + /* WARNING: gpencil data is no longer stored directly in sima after 2.5 + * so sacrifice a few old files for now to avoid crashes with new files! + * committed: r28002 */ +#if 0 + sima->gpd = newdataadr(fd, sima->gpd); + if (sima->gpd) + direct_link_gpencil(fd, sima->gpd); +#endif + } + else if (sl->spacetype == SPACE_NODE) { + SpaceNode *snode = (SpaceNode *)sl; + + if (snode->gpd) { + snode->gpd = newdataadr(fd, snode->gpd); + direct_link_gpencil(fd, snode->gpd); + } + + link_list(fd, &snode->treepath); + snode->edittree = NULL; + snode->iofsd = NULL; + BLI_listbase_clear(&snode->linkdrag); + } + else if (sl->spacetype == SPACE_TEXT) { + SpaceText *st= (SpaceText *)sl; + + st->drawcache = NULL; + st->scroll_accum[0] = 0.0f; + st->scroll_accum[1] = 0.0f; + } + else if (sl->spacetype == SPACE_TIME) { + SpaceTime *stime = (SpaceTime *)sl; + BLI_listbase_clear(&stime->caches); + } + else if (sl->spacetype == SPACE_LOGIC) { + SpaceLogic *slogic = (SpaceLogic *)sl; + + /* XXX: this is new stuff, which shouldn't be directly linking to gpd... */ + if (slogic->gpd) { + slogic->gpd = newdataadr(fd, slogic->gpd); + direct_link_gpencil(fd, slogic->gpd); + } + } + else if (sl->spacetype == SPACE_SEQ) { + SpaceSeq *sseq = (SpaceSeq *)sl; + + /* grease pencil data is not a direct data and can't be linked from direct_link* + * functions, it should be linked from lib_link* functions instead + * + * otherwise it'll lead to lost grease data on open because it'll likely be + * read from file after all other users of grease pencil and newdataadr would + * simple return NULL here (sergey) + */ +#if 0 + if (sseq->gpd) { + sseq->gpd = newdataadr(fd, sseq->gpd); + direct_link_gpencil(fd, sseq->gpd); + } +#endif + sseq->scopes.reference_ibuf = NULL; + sseq->scopes.zebra_ibuf = NULL; + sseq->scopes.waveform_ibuf = NULL; + sseq->scopes.sep_waveform_ibuf = NULL; + sseq->scopes.vector_ibuf = NULL; + sseq->scopes.histogram_ibuf = NULL; + sseq->compositor = NULL; + } + else if (sl->spacetype == SPACE_BUTS) { + SpaceButs *sbuts = (SpaceButs *)sl; + + sbuts->path= NULL; + sbuts->texuser= NULL; + sbuts->mainbo = sbuts->mainb; + sbuts->mainbuser = sbuts->mainb; + } + else if (sl->spacetype == SPACE_CONSOLE) { + SpaceConsole *sconsole = (SpaceConsole *)sl; + ConsoleLine *cl, *cl_next; + + link_list(fd, &sconsole->scrollback); + link_list(fd, &sconsole->history); + + //for (cl= sconsole->scrollback.first; cl; cl= cl->next) + // cl->line= newdataadr(fd, cl->line); + + /* comma expressions, (e.g. expr1, expr2, expr3) evaluate each expression, + * from left to right. the right-most expression sets the result of the comma + * expression as a whole*/ + for (cl = sconsole->history.first; cl; cl = cl_next) { + cl_next = cl->next; + cl->line = newdataadr(fd, cl->line); + if (cl->line) { + /* the allocted length is not written, so reset here */ + cl->len_alloc = cl->len + 1; + } + else { + BLI_remlink(&sconsole->history, cl); + MEM_freeN(cl); + } + } + } + else if (sl->spacetype == SPACE_FILE) { + SpaceFile *sfile = (SpaceFile *)sl; + + /* this sort of info is probably irrelevant for reloading... + * plus, it isn't saved to files yet! + */ + sfile->folders_prev = sfile->folders_next = NULL; + sfile->files = NULL; + sfile->layout = NULL; + sfile->op = NULL; + sfile->previews_timer = NULL; + sfile->params = newdataadr(fd, sfile->params); + } + else if (sl->spacetype == SPACE_CLIP) { + SpaceClip *sclip = (SpaceClip *)sl; + + sclip->scopes.track_search = NULL; + sclip->scopes.track_preview = NULL; + sclip->scopes.ok = 0; + } + } + + BLI_listbase_clear(&area->actionzones); + + area->v1 = newdataadr(fd, area->v1); + area->v2 = newdataadr(fd, area->v2); + area->v3 = newdataadr(fd, area->v3); + area->v4 = newdataadr(fd, area->v4); +} + +static void lib_link_area(FileData *fd, bScreen *sc, ScrArea *area) +{ + area->full = newlibadr(fd, sc->id.lib, area->full); + + for (SpaceLink *sl = area->spacedata.first; sl; sl= sl->next) { + switch (sl->spacetype) { + case SPACE_VIEW3D: + { + View3D *v3d = (View3D*) sl; + + v3d->camera= newlibadr(fd, sc->id.lib, v3d->camera); + v3d->ob_centre= newlibadr(fd, sc->id.lib, v3d->ob_centre); + + if (v3d->localvd) { + v3d->localvd->camera = newlibadr(fd, sc->id.lib, v3d->localvd->camera); + } + break; + } + case SPACE_IPO: + { + SpaceIpo *sipo = (SpaceIpo *)sl; + bDopeSheet *ads = sipo->ads; + + if (ads) { + ads->source = newlibadr(fd, sc->id.lib, ads->source); + ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); + } + break; + } + case SPACE_BUTS: + { + SpaceButs *sbuts = (SpaceButs *)sl; + sbuts->pinid = newlibadr(fd, sc->id.lib, sbuts->pinid); + if (sbuts->pinid == NULL) { + sbuts->flag &= ~SB_PIN_CONTEXT; + } + break; + } + case SPACE_FILE: + break; + case SPACE_ACTION: + { + SpaceAction *saction = (SpaceAction *)sl; + bDopeSheet *ads = &saction->ads; + + if (ads) { + ads->source = newlibadr(fd, sc->id.lib, ads->source); + ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); + } + + saction->action = newlibadr(fd, sc->id.lib, saction->action); + break; + } + case SPACE_IMAGE: + { + SpaceImage *sima = (SpaceImage *)sl; + + sima->image = newlibadr_real_us(fd, sc->id.lib, sima->image); + sima->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sima->mask_info.mask); + + /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data + * so fingers crossed this works fine! + */ + sima->gpd = newlibadr_us(fd, sc->id.lib, sima->gpd); + break; + } + case SPACE_SEQ: + { + SpaceSeq *sseq = (SpaceSeq *)sl; + + /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data + * so fingers crossed this works fine! + */ + sseq->gpd = newlibadr_us(fd, sc->id.lib, sseq->gpd); + break; + } + case SPACE_NLA: + { + SpaceNla *snla= (SpaceNla *)sl; + bDopeSheet *ads= snla->ads; + + if (ads) { + ads->source = newlibadr(fd, sc->id.lib, ads->source); + ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); + } + break; + } + case SPACE_TEXT: + { + SpaceText *st= (SpaceText *)sl; + + st->text= newlibadr(fd, sc->id.lib, st->text); + break; + } + case SPACE_SCRIPT: + { + SpaceScript *scpt = (SpaceScript *)sl; + /*scpt->script = NULL; - 2.45 set to null, better re-run the script */ + if (scpt->script) { + scpt->script = newlibadr(fd, sc->id.lib, scpt->script); + if (scpt->script) { + SCRIPT_SET_NULL(scpt->script); + } + } + break; + } + case SPACE_OUTLINER: + { + SpaceOops *so= (SpaceOops *)sl; + so->search_tse.id = newlibadr(fd, NULL, so->search_tse.id); + + if (so->treestore) { + TreeStoreElem *tselem; + BLI_mempool_iter iter; + + BLI_mempool_iternew(so->treestore, &iter); + while ((tselem = BLI_mempool_iterstep(&iter))) { + tselem->id = newlibadr(fd, NULL, tselem->id); + } + if (so->treehash) { + /* rebuild hash table, because it depends on ids too */ + so->storeflag |= SO_TREESTORE_REBUILD; + } + } + break; + } + case SPACE_NODE: + { + SpaceNode *snode = (SpaceNode *)sl; + bNodeTreePath *path, *path_next; + bNodeTree *ntree; + + /* node tree can be stored locally in id too, link this first */ + snode->id = newlibadr(fd, sc->id.lib, snode->id); + snode->from = newlibadr(fd, sc->id.lib, snode->from); + + ntree = snode->id ? ntreeFromID(snode->id) : NULL; + snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree); + + for (path = snode->treepath.first; path; path = path->next) { + if (path == snode->treepath.first) { + /* first nodetree in path is same as snode->nodetree */ + path->nodetree = snode->nodetree; + } + else + path->nodetree = newlibadr_us(fd, sc->id.lib, path->nodetree); + + if (!path->nodetree) + break; + } + + /* remaining path entries are invalid, remove */ + for (; path; path = path_next) { + path_next = path->next; + + BLI_remlink(&snode->treepath, path); + MEM_freeN(path); + } + + /* edittree is just the last in the path, + * set this directly since the path may have been shortened above */ + if (snode->treepath.last) { + path = snode->treepath.last; + snode->edittree = path->nodetree; + } + else { + snode->edittree = NULL; + } + break; + } + case SPACE_CLIP: + { + SpaceClip *sclip = (SpaceClip *)sl; + + sclip->clip = newlibadr_real_us(fd, sc->id.lib, sclip->clip); + sclip->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sclip->mask_info.mask); + break; + } + case SPACE_LOGIC: + { + SpaceLogic *slogic = (SpaceLogic *)sl; + + slogic->gpd = newlibadr_us(fd, sc->id.lib, slogic->gpd); + break; + } + default: + break; + } + } +} + /* ************ READ WM ***************** */ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm) @@ -6604,74 +7186,8 @@ static void lib_link_windowmanager(FileData *fd, Main *main) /* deprecated, but needed for versioning (will be NULL'ed then) */ win->screen = newlibadr(fd, NULL, win->screen); } - - wm->id.tag &= ~LIB_TAG_NEED_LINK; - } - } -} - -/* ****************** READ GREASE PENCIL ***************** */ - -/* relink's grease pencil data's refs */ -static void lib_link_gpencil(FileData *fd, Main *main) -{ - for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) { - if (gpd->id.tag & LIB_TAG_NEED_LINK) { - IDP_LibLinkProperty(gpd->id.properties, fd); - lib_link_animdata(fd, &gpd->id, gpd->adt); - - gpd->id.tag &= ~LIB_TAG_NEED_LINK; - } - } -} - -/* relinks grease-pencil data - used for direct_link and old file linkage */ -static void direct_link_gpencil(FileData *fd, bGPdata *gpd) -{ - bGPDlayer *gpl; - bGPDframe *gpf; - bGPDstroke *gps; - bGPDpalette *palette; - - /* we must firstly have some grease-pencil data to link! */ - if (gpd == NULL) - return; - - /* relink animdata */ - gpd->adt = newdataadr(fd, gpd->adt); - direct_link_animdata(fd, gpd->adt); - /* relink palettes */ - link_list(fd, &gpd->palettes); - for (palette = gpd->palettes.first; palette; palette = palette->next) { - link_list(fd, &palette->colors); - } - - /* relink layers */ - link_list(fd, &gpd->layers); - - for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { - /* parent */ - gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent); - /* relink frames */ - link_list(fd, &gpl->frames); - gpl->actframe = newdataadr(fd, gpl->actframe); - - for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { - /* relink strokes (and their points) */ - link_list(fd, &gpf->strokes); - - for (gps = gpf->strokes.first; gps; gps = gps->next) { - gps->points = newdataadr(fd, gps->points); - - /* the triangulation is not saved, so need to be recalculated */ - gps->triangles = NULL; - gps->tot_triangles = 0; - gps->flag |= GP_STROKE_RECALC_CACHES; - /* the color pointer is not saved, so need to be recalculated using the color name */ - gps->palcolor = NULL; - gps->flag |= GP_STROKE_RECALC_COLOR; - } + wm->id.tag &= ~LIB_TAG_NEED_LINK; } } } @@ -6694,194 +7210,8 @@ static void lib_link_screen(FileData *fd, Main *main) sc->tool_tip = NULL; sc->scrubbing = false; - for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { - sa->full = newlibadr(fd, sc->id.lib, sa->full); - - for (SpaceLink *sl = sa->spacedata.first; sl; sl= sl->next) { - switch (sl->spacetype) { - case SPACE_VIEW3D: - { - View3D *v3d = (View3D*) sl; - - v3d->camera= newlibadr(fd, sc->id.lib, v3d->camera); - v3d->ob_centre= newlibadr(fd, sc->id.lib, v3d->ob_centre); - - if (v3d->localvd) { - v3d->localvd->camera = newlibadr(fd, sc->id.lib, v3d->localvd->camera); - } - break; - } - case SPACE_IPO: - { - SpaceIpo *sipo = (SpaceIpo *)sl; - bDopeSheet *ads = sipo->ads; - - if (ads) { - ads->source = newlibadr(fd, sc->id.lib, ads->source); - ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); - } - break; - } - case SPACE_BUTS: - { - SpaceButs *sbuts = (SpaceButs *)sl; - sbuts->pinid = newlibadr(fd, sc->id.lib, sbuts->pinid); - if (sbuts->pinid == NULL) { - sbuts->flag &= ~SB_PIN_CONTEXT; - } - break; - } - case SPACE_FILE: - break; - case SPACE_ACTION: - { - SpaceAction *saction = (SpaceAction *)sl; - bDopeSheet *ads = &saction->ads; - - if (ads) { - ads->source = newlibadr(fd, sc->id.lib, ads->source); - ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); - } - - saction->action = newlibadr(fd, sc->id.lib, saction->action); - break; - } - case SPACE_IMAGE: - { - SpaceImage *sima = (SpaceImage *)sl; - - sima->image = newlibadr_real_us(fd, sc->id.lib, sima->image); - sima->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sima->mask_info.mask); - - /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data - * so fingers crossed this works fine! - */ - sima->gpd = newlibadr_us(fd, sc->id.lib, sima->gpd); - break; - } - case SPACE_SEQ: - { - SpaceSeq *sseq = (SpaceSeq *)sl; - - /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data - * so fingers crossed this works fine! - */ - sseq->gpd = newlibadr_us(fd, sc->id.lib, sseq->gpd); - break; - } - case SPACE_NLA: - { - SpaceNla *snla= (SpaceNla *)sl; - bDopeSheet *ads= snla->ads; - - if (ads) { - ads->source = newlibadr(fd, sc->id.lib, ads->source); - ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp); - } - break; - } - case SPACE_TEXT: - { - SpaceText *st= (SpaceText *)sl; - - st->text= newlibadr(fd, sc->id.lib, st->text); - break; - } - case SPACE_SCRIPT: - { - SpaceScript *scpt = (SpaceScript *)sl; - /*scpt->script = NULL; - 2.45 set to null, better re-run the script */ - if (scpt->script) { - scpt->script = newlibadr(fd, sc->id.lib, scpt->script); - if (scpt->script) { - SCRIPT_SET_NULL(scpt->script); - } - } - break; - } - case SPACE_OUTLINER: - { - SpaceOops *so= (SpaceOops *)sl; - so->search_tse.id = newlibadr(fd, NULL, so->search_tse.id); - - if (so->treestore) { - TreeStoreElem *tselem; - BLI_mempool_iter iter; - - BLI_mempool_iternew(so->treestore, &iter); - while ((tselem = BLI_mempool_iterstep(&iter))) { - tselem->id = newlibadr(fd, NULL, tselem->id); - } - if (so->treehash) { - /* rebuild hash table, because it depends on ids too */ - so->storeflag |= SO_TREESTORE_REBUILD; - } - } - break; - } - case SPACE_NODE: - { - SpaceNode *snode = (SpaceNode *)sl; - bNodeTreePath *path, *path_next; - bNodeTree *ntree; - - /* node tree can be stored locally in id too, link this first */ - snode->id = newlibadr(fd, sc->id.lib, snode->id); - snode->from = newlibadr(fd, sc->id.lib, snode->from); - - ntree = snode->id ? ntreeFromID(snode->id) : NULL; - snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree); - - for (path = snode->treepath.first; path; path = path->next) { - if (path == snode->treepath.first) { - /* first nodetree in path is same as snode->nodetree */ - path->nodetree = snode->nodetree; - } - else - path->nodetree = newlibadr_us(fd, sc->id.lib, path->nodetree); - - if (!path->nodetree) - break; - } - - /* remaining path entries are invalid, remove */ - for (; path; path = path_next) { - path_next = path->next; - - BLI_remlink(&snode->treepath, path); - MEM_freeN(path); - } - - /* edittree is just the last in the path, - * set this directly since the path may have been shortened above */ - if (snode->treepath.last) { - path = snode->treepath.last; - snode->edittree = path->nodetree; - } - else { - snode->edittree = NULL; - } - break; - } - case SPACE_CLIP: - { - SpaceClip *sclip = (SpaceClip *)sl; - - sclip->clip = newlibadr_real_us(fd, sc->id.lib, sclip->clip); - sclip->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sclip->mask_info.mask); - break; - } - case SPACE_LOGIC: - { - SpaceLogic *slogic = (SpaceLogic *)sl; - - slogic->gpd = newlibadr_us(fd, sc->id.lib, slogic->gpd); - break; - } - default: - break; - } - } + for (ScrArea *area = sc->areabase.first; area; area = area->next) { + lib_link_area(fd, sc, area); } sc->id.tag &= ~LIB_TAG_NEED_LINK; } @@ -7286,74 +7616,6 @@ void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene BKE_main_idmap_destroy(id_map); } -static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) -{ - Panel *pa; - uiList *ui_list; - - link_list(fd, &ar->panels); - - for (pa = ar->panels.first; pa; pa = pa->next) { - pa->paneltab = newdataadr(fd, pa->paneltab); - pa->runtime_flag = 0; - pa->activedata = NULL; - pa->type = NULL; - } - - link_list(fd, &ar->panels_category_active); - - link_list(fd, &ar->ui_lists); - - for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { - ui_list->type = NULL; - ui_list->dyn_data = NULL; - ui_list->properties = newdataadr(fd, ui_list->properties); - IDP_DirectLinkGroup_OrFree(&ui_list->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - } - - link_list(fd, &ar->ui_previews); - - if (spacetype == SPACE_EMPTY) { - /* unkown space type, don't leak regiondata */ - ar->regiondata = NULL; - } - else { - ar->regiondata = newdataadr(fd, ar->regiondata); - if (ar->regiondata) { - if (spacetype == SPACE_VIEW3D) { - RegionView3D *rv3d = ar->regiondata; - - rv3d->localvd = newdataadr(fd, rv3d->localvd); - rv3d->clipbb = newdataadr(fd, rv3d->clipbb); - - rv3d->depths = NULL; - rv3d->gpuoffscreen = NULL; - rv3d->render_engine = NULL; - rv3d->sms = NULL; - rv3d->smooth_timer = NULL; - rv3d->compositor = NULL; - rv3d->viewport = NULL; - } - } - } - - ar->v2d.tab_offset = NULL; - ar->v2d.tab_num = 0; - ar->v2d.tab_cur = 0; - ar->v2d.sms = NULL; - BLI_listbase_clear(&ar->panels_category); - BLI_listbase_clear(&ar->handlers); - BLI_listbase_clear(&ar->uiblocks); - ar->headerstr = NULL; - ar->visible = 0; - ar->type = NULL; - ar->swap = 0; - ar->do_draw = 0; - ar->manipulator_map = NULL; - ar->regiontimer = NULL; - memset(&ar->drawrct, 0, sizeof(ar->drawrct)); -} - /* for the saved 2.50 files without regiondata */ /* and as patch for 2.48 and older */ void blo_do_versions_view3d_split_250(View3D *v3d, ListBase *regions) @@ -7416,253 +7678,7 @@ static bool direct_link_screen(FileData *fd, bScreen *sc) /* areas */ for (sa = sc->areabase.first; sa; sa = sa->next) { - SpaceLink *sl; - ARegion *ar; - - link_list(fd, &(sa->spacedata)); - link_list(fd, &(sa->regionbase)); - - BLI_listbase_clear(&sa->handlers); - sa->type = NULL; /* spacetype callbacks */ - sa->region_active_win = -1; - - /* if we do not have the spacetype registered (game player), we cannot - * free it, so don't allocate any new memory for such spacetypes. */ - if (!BKE_spacetype_exists(sa->spacetype)) - sa->spacetype = SPACE_EMPTY; - - for (ar = sa->regionbase.first; ar; ar = ar->next) - direct_link_region(fd, ar, sa->spacetype); - - /* accident can happen when read/save new file with older version */ - /* 2.50: we now always add spacedata for info */ - if (sa->spacedata.first==NULL) { - SpaceInfo *sinfo= MEM_callocN(sizeof(SpaceInfo), "spaceinfo"); - sa->spacetype= sinfo->spacetype= SPACE_INFO; - BLI_addtail(&sa->spacedata, sinfo); - } - /* add local view3d too */ - else if (sa->spacetype == SPACE_VIEW3D) - blo_do_versions_view3d_split_250(sa->spacedata.first, &sa->regionbase); - - /* incase we set above */ - sa->butspacetype = sa->spacetype; - - for (sl = sa->spacedata.first; sl; sl = sl->next) { - link_list(fd, &(sl->regionbase)); - - /* if we do not have the spacetype registered (game player), we cannot - * free it, so don't allocate any new memory for such spacetypes. */ - if (!BKE_spacetype_exists(sl->spacetype)) - sl->spacetype = SPACE_EMPTY; - - for (ar = sl->regionbase.first; ar; ar = ar->next) - direct_link_region(fd, ar, sl->spacetype); - - if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d= (View3D*) sl; - v3d->flag |= V3D_INVALID_BACKBUF; - - if (v3d->gpd) { - v3d->gpd = newdataadr(fd, v3d->gpd); - direct_link_gpencil(fd, v3d->gpd); - } - v3d->localvd = newdataadr(fd, v3d->localvd); - BLI_listbase_clear(&v3d->afterdraw_transp); - BLI_listbase_clear(&v3d->afterdraw_xray); - BLI_listbase_clear(&v3d->afterdraw_xraytransp); - v3d->properties_storage = NULL; - v3d->defmaterial = NULL; - - /* render can be quite heavy, set to solid on load */ - if (v3d->drawtype == OB_RENDER) - v3d->drawtype = OB_SOLID; - v3d->prev_drawtype = OB_SOLID; - - if (v3d->fx_settings.dof) - v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof); - if (v3d->fx_settings.ssao) - v3d->fx_settings.ssao = newdataadr(fd, v3d->fx_settings.ssao); - - blo_do_versions_view3d_split_250(v3d, &sl->regionbase); - } - else if (sl->spacetype == SPACE_IPO) { - SpaceIpo *sipo = (SpaceIpo *)sl; - - sipo->ads = newdataadr(fd, sipo->ads); - BLI_listbase_clear(&sipo->ghostCurves); - } - else if (sl->spacetype == SPACE_NLA) { - SpaceNla *snla = (SpaceNla *)sl; - - snla->ads = newdataadr(fd, snla->ads); - } - else if (sl->spacetype == SPACE_OUTLINER) { - SpaceOops *soops = (SpaceOops *) sl; - - /* use newdataadr_no_us and do not free old memory avoiding double - * frees and use of freed memory. this could happen because of a - * bug fixed in revision 58959 where the treestore memory address - * was not unique */ - TreeStore *ts = newdataadr_no_us(fd, soops->treestore); - soops->treestore = NULL; - if (ts) { - TreeStoreElem *elems = newdataadr_no_us(fd, ts->data); - - soops->treestore = BLI_mempool_create(sizeof(TreeStoreElem), ts->usedelem, - 512, BLI_MEMPOOL_ALLOW_ITER); - if (ts->usedelem && elems) { - int i; - for (i = 0; i < ts->usedelem; i++) { - TreeStoreElem *new_elem = BLI_mempool_alloc(soops->treestore); - *new_elem = elems[i]; - } - } - /* we only saved what was used */ - soops->storeflag |= SO_TREESTORE_CLEANUP; // at first draw - } - soops->treehash = NULL; - soops->tree.first = soops->tree.last= NULL; - } - else if (sl->spacetype == SPACE_IMAGE) { - SpaceImage *sima = (SpaceImage *)sl; - - sima->iuser.scene = NULL; - sima->iuser.ok = 1; - sima->scopes.waveform_1 = NULL; - sima->scopes.waveform_2 = NULL; - sima->scopes.waveform_3 = NULL; - sima->scopes.vecscope = NULL; - sima->scopes.ok = 0; - - /* WARNING: gpencil data is no longer stored directly in sima after 2.5 - * so sacrifice a few old files for now to avoid crashes with new files! - * committed: r28002 */ -#if 0 - sima->gpd = newdataadr(fd, sima->gpd); - if (sima->gpd) - direct_link_gpencil(fd, sima->gpd); -#endif - } - else if (sl->spacetype == SPACE_NODE) { - SpaceNode *snode = (SpaceNode *)sl; - - if (snode->gpd) { - snode->gpd = newdataadr(fd, snode->gpd); - direct_link_gpencil(fd, snode->gpd); - } - - link_list(fd, &snode->treepath); - snode->edittree = NULL; - snode->iofsd = NULL; - BLI_listbase_clear(&snode->linkdrag); - } - else if (sl->spacetype == SPACE_TEXT) { - SpaceText *st= (SpaceText *)sl; - - st->drawcache = NULL; - st->scroll_accum[0] = 0.0f; - st->scroll_accum[1] = 0.0f; - } - else if (sl->spacetype == SPACE_TIME) { - SpaceTime *stime = (SpaceTime *)sl; - BLI_listbase_clear(&stime->caches); - } - else if (sl->spacetype == SPACE_LOGIC) { - SpaceLogic *slogic = (SpaceLogic *)sl; - - /* XXX: this is new stuff, which shouldn't be directly linking to gpd... */ - if (slogic->gpd) { - slogic->gpd = newdataadr(fd, slogic->gpd); - direct_link_gpencil(fd, slogic->gpd); - } - } - else if (sl->spacetype == SPACE_SEQ) { - SpaceSeq *sseq = (SpaceSeq *)sl; - - /* grease pencil data is not a direct data and can't be linked from direct_link* - * functions, it should be linked from lib_link* functions instead - * - * otherwise it'll lead to lost grease data on open because it'll likely be - * read from file after all other users of grease pencil and newdataadr would - * simple return NULL here (sergey) - */ -#if 0 - if (sseq->gpd) { - sseq->gpd = newdataadr(fd, sseq->gpd); - direct_link_gpencil(fd, sseq->gpd); - } -#endif - sseq->scopes.reference_ibuf = NULL; - sseq->scopes.zebra_ibuf = NULL; - sseq->scopes.waveform_ibuf = NULL; - sseq->scopes.sep_waveform_ibuf = NULL; - sseq->scopes.vector_ibuf = NULL; - sseq->scopes.histogram_ibuf = NULL; - sseq->compositor = NULL; - } - else if (sl->spacetype == SPACE_BUTS) { - SpaceButs *sbuts = (SpaceButs *)sl; - - sbuts->path= NULL; - sbuts->texuser= NULL; - sbuts->mainbo = sbuts->mainb; - sbuts->mainbuser = sbuts->mainb; - } - else if (sl->spacetype == SPACE_CONSOLE) { - SpaceConsole *sconsole = (SpaceConsole *)sl; - ConsoleLine *cl, *cl_next; - - link_list(fd, &sconsole->scrollback); - link_list(fd, &sconsole->history); - - //for (cl= sconsole->scrollback.first; cl; cl= cl->next) - // cl->line= newdataadr(fd, cl->line); - - /* comma expressions, (e.g. expr1, expr2, expr3) evaluate each expression, - * from left to right. the right-most expression sets the result of the comma - * expression as a whole*/ - for (cl = sconsole->history.first; cl; cl = cl_next) { - cl_next = cl->next; - cl->line = newdataadr(fd, cl->line); - if (cl->line) { - /* the allocted length is not written, so reset here */ - cl->len_alloc = cl->len + 1; - } - else { - BLI_remlink(&sconsole->history, cl); - MEM_freeN(cl); - } - } - } - else if (sl->spacetype == SPACE_FILE) { - SpaceFile *sfile = (SpaceFile *)sl; - - /* this sort of info is probably irrelevant for reloading... - * plus, it isn't saved to files yet! - */ - sfile->folders_prev = sfile->folders_next = NULL; - sfile->files = NULL; - sfile->layout = NULL; - sfile->op = NULL; - sfile->previews_timer = NULL; - sfile->params = newdataadr(fd, sfile->params); - } - else if (sl->spacetype == SPACE_CLIP) { - SpaceClip *sclip = (SpaceClip *)sl; - - sclip->scopes.track_search = NULL; - sclip->scopes.track_preview = NULL; - sclip->scopes.ok = 0; - } - } - - BLI_listbase_clear(&sa->actionzones); - - sa->v1 = newdataadr(fd, sa->v1); - sa->v2 = newdataadr(fd, sa->v2); - sa->v3 = newdataadr(fd, sa->v3); - sa->v4 = newdataadr(fd, sa->v4); + direct_link_area(fd, sa); } return wrong_id; diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c index f7301fe4664..023bd7fe809 100644 --- a/source/blender/blenloader/intern/versioning_260.c +++ b/source/blender/blenloader/intern/versioning_260.c @@ -944,7 +944,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main) } } { - /* Warn the user if he is using ["Text"] properties for Font objects */ + /* Warn the user if he is using ["Text"] properties for Font objects */ Object *ob; bProperty *prop; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 7f4e7fdc646..c1c165bb523 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2900,25 +2900,6 @@ static void write_gpencil(WriteData *wd, bGPdata *gpd) } } -static void write_windowmanager(WriteData *wd, wmWindowManager *wm) -{ - writestruct(wd, ID_WM, wmWindowManager, 1, wm); - write_iddata(wd, &wm->id); - - for (wmWindow *win = wm->windows.first; win; win = win->next) { - - /* update deprecated screen member (for so loading in 2.7x uses the correct screen) */ - win->screen = BKE_workspace_active_screen_get(win->workspace_hook); - - writestruct(wd, DATA, wmWindow, 1, win); - writestruct(wd, DATA, WorkSpaceInstanceHook, 1, win->workspace_hook); - writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format); - - /* data is written, clear deprecated data again */ - win->screen = NULL; - } -} - static void write_region(WriteData *wd, ARegion *ar, int spacetype) { writestruct(wd, DATA, ARegion, 1, ar); @@ -2999,166 +2980,184 @@ static void write_soops(WriteData *wd, SpaceOops *so) } } -static void write_screen(WriteData *wd, bScreen *sc) +static void write_area_regions(WriteData *wd, ScrArea *area) { - /* write LibData */ - /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ - writestruct(wd, ID_SCRN, bScreen, 1, sc); - write_iddata(wd, &sc->id); + for (ARegion *region = area->regionbase.first; region; region = region->next) { + write_region(wd, region, area->spacetype); - write_previews(wd, sc->preview); + for (Panel *pa = region->panels.first; pa; pa = pa->next) { + writestruct(wd, DATA, Panel, 1, pa); + } - /* direct data */ - for (ScrVert *sv = sc->vertbase.first; sv; sv = sv->next) { - writestruct(wd, DATA, ScrVert, 1, sv); - } + for (PanelCategoryStack *pc_act = region->panels_category_active.first; pc_act; pc_act = pc_act->next) { + writestruct(wd, DATA, PanelCategoryStack, 1, pc_act); + } - for (ScrEdge *se = sc->edgebase.first; se; se = se->next) { - writestruct(wd, DATA, ScrEdge, 1, se); + for (uiList *ui_list = region->ui_lists.first; ui_list; ui_list = ui_list->next) { + write_uilist(wd, ui_list); + } + + for (uiPreview *ui_preview = region->ui_previews.first; ui_preview; ui_preview = ui_preview->next) { + writestruct(wd, DATA, uiPreview, 1, ui_preview); + } } - for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { - SpaceLink *sl; - Panel *pa; - uiList *ui_list; - uiPreview *ui_preview; - PanelCategoryStack *pc_act; - ARegion *ar; + for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) { + for (ARegion *region = sl->regionbase.first; region; region = region->next) { + write_region(wd, region, sl->spacetype); + } - writestruct(wd, DATA, ScrArea, 1, sa); + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + writestruct(wd, DATA, View3D, 1, v3d); - for (ar = sa->regionbase.first; ar; ar = ar->next) { - write_region(wd, ar, sa->spacetype); + if (v3d->localvd) { + writestruct(wd, DATA, View3D, 1, v3d->localvd); + } - for (pa = ar->panels.first; pa; pa = pa->next) { - writestruct(wd, DATA, Panel, 1, pa); + if (v3d->fx_settings.ssao) { + writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao); + } + if (v3d->fx_settings.dof) { + writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof); } + } + else if (sl->spacetype == SPACE_IPO) { + SpaceIpo *sipo = (SpaceIpo *)sl; + ListBase tmpGhosts = sipo->ghostCurves; + + /* temporarily disable ghost curves when saving */ + sipo->ghostCurves.first = sipo->ghostCurves.last = NULL; - for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) { - writestruct(wd, DATA, PanelCategoryStack, 1, pc_act); + writestruct(wd, DATA, SpaceIpo, 1, sl); + if (sipo->ads) { + writestruct(wd, DATA, bDopeSheet, 1, sipo->ads); } - for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { - write_uilist(wd, ui_list); + /* reenable ghost curves */ + sipo->ghostCurves = tmpGhosts; + } + else if (sl->spacetype == SPACE_BUTS) { + writestruct(wd, DATA, SpaceButs, 1, sl); + } + else if (sl->spacetype == SPACE_FILE) { + SpaceFile *sfile = (SpaceFile *)sl; + + writestruct(wd, DATA, SpaceFile, 1, sl); + if (sfile->params) { + writestruct(wd, DATA, FileSelectParams, 1, sfile->params); } + } + else if (sl->spacetype == SPACE_SEQ) { + writestruct(wd, DATA, SpaceSeq, 1, sl); + } + else if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *so = (SpaceOops *)sl; + write_soops(wd, so); + } + else if (sl->spacetype == SPACE_IMAGE) { + writestruct(wd, DATA, SpaceImage, 1, sl); + } + else if (sl->spacetype == SPACE_TEXT) { + writestruct(wd, DATA, SpaceText, 1, sl); + } + else if (sl->spacetype == SPACE_SCRIPT) { + SpaceScript *scr = (SpaceScript *)sl; + scr->but_refs = NULL; + writestruct(wd, DATA, SpaceScript, 1, sl); + } + else if (sl->spacetype == SPACE_ACTION) { + writestruct(wd, DATA, SpaceAction, 1, sl); + } + else if (sl->spacetype == SPACE_NLA) { + SpaceNla *snla = (SpaceNla *)sl; - for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) { - writestruct(wd, DATA, uiPreview, 1, ui_preview); + writestruct(wd, DATA, SpaceNla, 1, snla); + if (snla->ads) { + writestruct(wd, DATA, bDopeSheet, 1, snla->ads); } } + else if (sl->spacetype == SPACE_TIME) { + writestruct(wd, DATA, SpaceTime, 1, sl); + } + else if (sl->spacetype == SPACE_NODE) { + SpaceNode *snode = (SpaceNode *)sl; + bNodeTreePath *path; + writestruct(wd, DATA, SpaceNode, 1, snode); - for (sl = sa->spacedata.first; sl; sl = sl->next) { - for (ar = sl->regionbase.first; ar; ar = ar->next) { - write_region(wd, ar, sl->spacetype); + for (path = snode->treepath.first; path; path = path->next) { + writestruct(wd, DATA, bNodeTreePath, 1, path); } + } + else if (sl->spacetype == SPACE_LOGIC) { + writestruct(wd, DATA, SpaceLogic, 1, sl); + } + else if (sl->spacetype == SPACE_CONSOLE) { + SpaceConsole *con = (SpaceConsole *)sl; + ConsoleLine *cl; - if (sl->spacetype == SPACE_VIEW3D) { - View3D *v3d = (View3D *)sl; - writestruct(wd, DATA, View3D, 1, v3d); + for (cl = con->history.first; cl; cl = cl->next) { + /* 'len_alloc' is invalid on write, set from 'len' on read */ + writestruct(wd, DATA, ConsoleLine, 1, cl); + writedata(wd, DATA, cl->len + 1, cl->line); + } + writestruct(wd, DATA, SpaceConsole, 1, sl); - if (v3d->localvd) { - writestruct(wd, DATA, View3D, 1, v3d->localvd); - } + } + else if (sl->spacetype == SPACE_USERPREF) { + writestruct(wd, DATA, SpaceUserPref, 1, sl); + } + else if (sl->spacetype == SPACE_CLIP) { + writestruct(wd, DATA, SpaceClip, 1, sl); + } + else if (sl->spacetype == SPACE_INFO) { + writestruct(wd, DATA, SpaceInfo, 1, sl); + } + } - if (v3d->fx_settings.ssao) { - writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao); - } - if (v3d->fx_settings.dof) { - writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof); - } - } - else if (sl->spacetype == SPACE_IPO) { - SpaceIpo *sipo = (SpaceIpo *)sl; - ListBase tmpGhosts = sipo->ghostCurves; +} - /* temporarily disable ghost curves when saving */ - sipo->ghostCurves.first = sipo->ghostCurves.last = NULL; +static void write_windowmanager(WriteData *wd, wmWindowManager *wm) +{ + writestruct(wd, ID_WM, wmWindowManager, 1, wm); + write_iddata(wd, &wm->id); - writestruct(wd, DATA, SpaceIpo, 1, sl); - if (sipo->ads) { - writestruct(wd, DATA, bDopeSheet, 1, sipo->ads); - } + for (wmWindow *win = wm->windows.first; win; win = win->next) { - /* reenable ghost curves */ - sipo->ghostCurves = tmpGhosts; - } - else if (sl->spacetype == SPACE_BUTS) { - writestruct(wd, DATA, SpaceButs, 1, sl); - } - else if (sl->spacetype == SPACE_FILE) { - SpaceFile *sfile = (SpaceFile *)sl; + /* update deprecated screen member (for so loading in 2.7x uses the correct screen) */ + win->screen = BKE_workspace_active_screen_get(win->workspace_hook); - writestruct(wd, DATA, SpaceFile, 1, sl); - if (sfile->params) { - writestruct(wd, DATA, FileSelectParams, 1, sfile->params); - } - } - else if (sl->spacetype == SPACE_SEQ) { - writestruct(wd, DATA, SpaceSeq, 1, sl); - } - else if (sl->spacetype == SPACE_OUTLINER) { - SpaceOops *so = (SpaceOops *)sl; - write_soops(wd, so); - } - else if (sl->spacetype == SPACE_IMAGE) { - writestruct(wd, DATA, SpaceImage, 1, sl); - } - else if (sl->spacetype == SPACE_TEXT) { - writestruct(wd, DATA, SpaceText, 1, sl); - } - else if (sl->spacetype == SPACE_SCRIPT) { - SpaceScript *scr = (SpaceScript *)sl; - scr->but_refs = NULL; - writestruct(wd, DATA, SpaceScript, 1, sl); - } - else if (sl->spacetype == SPACE_ACTION) { - writestruct(wd, DATA, SpaceAction, 1, sl); - } - else if (sl->spacetype == SPACE_NLA) { - SpaceNla *snla = (SpaceNla *)sl; + writestruct(wd, DATA, wmWindow, 1, win); + writestruct(wd, DATA, WorkSpaceInstanceHook, 1, win->workspace_hook); + writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format); - writestruct(wd, DATA, SpaceNla, 1, snla); - if (snla->ads) { - writestruct(wd, DATA, bDopeSheet, 1, snla->ads); - } - } - else if (sl->spacetype == SPACE_TIME) { - writestruct(wd, DATA, SpaceTime, 1, sl); - } - else if (sl->spacetype == SPACE_NODE) { - SpaceNode *snode = (SpaceNode *)sl; - bNodeTreePath *path; - writestruct(wd, DATA, SpaceNode, 1, snode); + /* data is written, clear deprecated data again */ + win->screen = NULL; + } +} - for (path = snode->treepath.first; path; path = path->next) { - writestruct(wd, DATA, bNodeTreePath, 1, path); - } - } - else if (sl->spacetype == SPACE_LOGIC) { - writestruct(wd, DATA, SpaceLogic, 1, sl); - } - else if (sl->spacetype == SPACE_CONSOLE) { - SpaceConsole *con = (SpaceConsole *)sl; - ConsoleLine *cl; - - for (cl = con->history.first; cl; cl = cl->next) { - /* 'len_alloc' is invalid on write, set from 'len' on read */ - writestruct(wd, DATA, ConsoleLine, 1, cl); - writedata(wd, DATA, cl->len + 1, cl->line); - } - writestruct(wd, DATA, SpaceConsole, 1, sl); +static void write_screen(WriteData *wd, bScreen *sc) +{ + /* write LibData */ + /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ + writestruct(wd, ID_SCRN, bScreen, 1, sc); + write_iddata(wd, &sc->id); - } - else if (sl->spacetype == SPACE_USERPREF) { - writestruct(wd, DATA, SpaceUserPref, 1, sl); - } - else if (sl->spacetype == SPACE_CLIP) { - writestruct(wd, DATA, SpaceClip, 1, sl); - } - else if (sl->spacetype == SPACE_INFO) { - writestruct(wd, DATA, SpaceInfo, 1, sl); - } - } + write_previews(wd, sc->preview); + + /* direct data */ + for (ScrVert *sv = sc->vertbase.first; sv; sv = sv->next) { + writestruct(wd, DATA, ScrVert, 1, sv); + } + + for (ScrEdge *se = sc->edgebase.first; se; se = se->next) { + writestruct(wd, DATA, ScrEdge, 1, se); + } + + for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) { + writestruct(wd, DATA, ScrArea, 1, sa); + + write_area_regions(wd, sa); } } diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 9e03c28ba1b..8071637d95e 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -1160,7 +1160,7 @@ void bmesh_edit_end(BMesh *bm, BMOpTypeFlag type_flag) } } -void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) +void BM_mesh_elem_index_ensure_ex(BMesh *bm, const char htype, int elem_offset[4]) { const char htype_needed = bm->elem_index_dirty & htype; @@ -1173,15 +1173,15 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) } if (htype & BM_VERT) { - if (bm->elem_index_dirty & BM_VERT) { + if ((bm->elem_index_dirty & BM_VERT) || (elem_offset && elem_offset[0])) { BMIter iter; BMElem *ele; - int index; - BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, index) { - BM_elem_index_set(ele, index); /* set_ok */ + int index = elem_offset ? elem_offset[0] : 0; + BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) { + BM_elem_index_set(ele, index++); /* set_ok */ } - BLI_assert(index == bm->totvert); + BLI_assert(elem_offset || index == bm->totvert); } else { // printf("%s: skipping vert index calc!\n", __func__); @@ -1189,15 +1189,15 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) } if (htype & BM_EDGE) { - if (bm->elem_index_dirty & BM_EDGE) { + if ((bm->elem_index_dirty & BM_EDGE) || (elem_offset && elem_offset[1])) { BMIter iter; BMElem *ele; - int index; - BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, index) { - BM_elem_index_set(ele, index); /* set_ok */ + int index = elem_offset ? elem_offset[1] : 0; + BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) { + BM_elem_index_set(ele, index++); /* set_ok */ } - BLI_assert(index == bm->totedge); + BLI_assert(elem_offset || index == bm->totedge); } else { // printf("%s: skipping edge index calc!\n", __func__); @@ -1205,19 +1205,19 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) } if (htype & (BM_FACE | BM_LOOP)) { - if (bm->elem_index_dirty & (BM_FACE | BM_LOOP)) { + if ((bm->elem_index_dirty & (BM_FACE | BM_LOOP)) || (elem_offset && (elem_offset[2] || elem_offset[3]))) { BMIter iter; BMElem *ele; const bool update_face = (htype & BM_FACE) && (bm->elem_index_dirty & BM_FACE); const bool update_loop = (htype & BM_LOOP) && (bm->elem_index_dirty & BM_LOOP); - int index; - int index_loop = 0; + int index_loop = elem_offset ? elem_offset[2] : 0; + int index = elem_offset ? elem_offset[3] : 0; - BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, index) { + BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) { if (update_face) { - BM_elem_index_set(ele, index); /* set_ok */ + BM_elem_index_set(ele, index++); /* set_ok */ } if (update_loop) { @@ -1230,9 +1230,9 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) } } - BLI_assert(index == bm->totface); + BLI_assert(elem_offset || !update_face || index == bm->totface); if (update_loop) { - BLI_assert(index_loop == bm->totloop); + BLI_assert(elem_offset || !update_loop || index_loop == bm->totloop); } } else { @@ -1242,6 +1242,37 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) finally: bm->elem_index_dirty &= ~htype; + if (elem_offset) { + if (htype & BM_VERT) { + elem_offset[0] += bm->totvert; + if (elem_offset[0] != bm->totvert) { + bm->elem_index_dirty |= BM_VERT; + } + } + if (htype & BM_EDGE) { + elem_offset[1] += bm->totedge; + if (elem_offset[1] != bm->totedge) { + bm->elem_index_dirty |= BM_EDGE; + } + } + if (htype & BM_LOOP) { + elem_offset[2] += bm->totloop; + if (elem_offset[2] != bm->totloop) { + bm->elem_index_dirty |= BM_LOOP; + } + } + if (htype & BM_FACE) { + elem_offset[3] += bm->totface; + if (elem_offset[3] != bm->totface) { + bm->elem_index_dirty |= BM_FACE; + } + } + } +} + +void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) +{ + BM_mesh_elem_index_ensure_ex(bm, htype, NULL); } diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h index 10f024423aa..3ebe6535a8b 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.h +++ b/source/blender/bmesh/intern/bmesh_mesh.h @@ -60,6 +60,7 @@ void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle); void bmesh_edit_begin(BMesh *bm, const BMOpTypeFlag type_flag); void bmesh_edit_end(BMesh *bm, const BMOpTypeFlag type_flag); +void BM_mesh_elem_index_ensure_ex(BMesh *bm, const char htype, int elem_offset[4]); void BM_mesh_elem_index_ensure(BMesh *bm, const char hflag); void BM_mesh_elem_index_validate( BMesh *bm, const char *location, const char *func, @@ -119,7 +120,7 @@ extern const BMAllocTemplate bm_mesh_chunksize_default; (dm)->getNumEdges(dm), \ (dm)->getNumLoops(dm), \ (dm)->getNumPolys(dm), \ - } +} #define _VA_BMALLOC_TEMPLATE_FROM_DM_2(dm_a, dm_b) { \ (CHECK_TYPE_INLINE(dm_a, DerivedMesh *), \ CHECK_TYPE_INLINE(dm_b, DerivedMesh *), \ @@ -127,7 +128,7 @@ extern const BMAllocTemplate bm_mesh_chunksize_default; (dm_a)->getNumEdges(dm_a) + (dm_b)->getNumEdges(dm_b), \ (dm_a)->getNumLoops(dm_a) + (dm_b)->getNumLoops(dm_b), \ (dm_a)->getNumPolys(dm_a) + (dm_b)->getNumPolys(dm_b), \ - } +} #define BMALLOC_TEMPLATE_FROM_DM(...) VA_NARGS_CALL_OVERLOAD(_VA_BMALLOC_TEMPLATE_FROM_DM_, __VA_ARGS__) diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 4847ae4be42..b5e6fe168e5 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -112,7 +112,7 @@ static BMOpDefine bmo_smooth_vert_def = { {"use_axis_x", BMO_OP_SLOT_BOOL}, /* smooth vertices along X axis */ {"use_axis_y", BMO_OP_SLOT_BOOL}, /* smooth vertices along Y axis */ {"use_axis_z", BMO_OP_SLOT_BOOL}, /* smooth vertices along Z axis */ - {{'\0'}}, + {{'\0'}}, }, {{{'\0'}}}, /* no output */ bmo_smooth_vert_exec, @@ -135,7 +135,7 @@ static BMOpDefine bmo_smooth_laplacian_vert_def = { {"use_y", BMO_OP_SLOT_BOOL}, /* Smooth object along Y axis */ {"use_z", BMO_OP_SLOT_BOOL}, /* Smooth object along Z axis */ {"preserve_volume", BMO_OP_SLOT_BOOL}, /* Apply volume preservation after smooth */ - {{'\0'}}, + {{'\0'}}, }, {{{'\0'}}}, /* no output */ bmo_smooth_laplacian_vert_exec, @@ -839,7 +839,7 @@ static BMOpDefine bmo_bmesh_to_mesh_def = { "bmesh_to_mesh", /* slots_in */ { - /* pointer to a mesh structure to fill in */ + /* pointer to a mesh structure to fill in */ {"mesh", BMO_OP_SLOT_PTR, {(int)BMO_OP_SLOT_SUBTYPE_PTR_MESH}}, /* pointer to an object structure */ {"object", BMO_OP_SLOT_PTR, {(int)BMO_OP_SLOT_SUBTYPE_PTR_OBJECT}}, @@ -860,7 +860,7 @@ static BMOpDefine bmo_mesh_to_bmesh_def = { "mesh_to_bmesh", /* slots_in */ { - /* pointer to a Mesh structure */ + /* pointer to a Mesh structure */ {"mesh", BMO_OP_SLOT_PTR, {(int)BMO_OP_SLOT_SUBTYPE_PTR_MESH}}, /* pointer to an Object structure */ {"object", BMO_OP_SLOT_PTR, {(int)BMO_OP_SLOT_SUBTYPE_PTR_OBJECT}}, @@ -1337,7 +1337,7 @@ static BMOpDefine bmo_duplicate_def = { {"face_map.out", BMO_OP_SLOT_MAPPING, {(int)BMO_OP_SLOT_SUBTYPE_MAP_ELEM}}, {"boundary_map.out", BMO_OP_SLOT_MAPPING, {(int)BMO_OP_SLOT_SUBTYPE_MAP_ELEM}}, {"isovert_map.out", BMO_OP_SLOT_MAPPING, {(int)BMO_OP_SLOT_SUBTYPE_MAP_ELEM}}, - {{'\0'}}, + {{'\0'}}, }, bmo_duplicate_exec, (BMO_OPTYPE_FLAG_NORMALS_CALC | diff --git a/source/blender/bmesh/operators/bmo_offset_edgeloops.c b/source/blender/bmesh/operators/bmo_offset_edgeloops.c index 269f933f27f..d54efc27124 100644 --- a/source/blender/bmesh/operators/bmo_offset_edgeloops.c +++ b/source/blender/bmesh/operators/bmo_offset_edgeloops.c @@ -242,6 +242,7 @@ void bmo_offset_edgeloops_exec(BMesh *bm, BMOperator *op) #if 0 else if (BM_elem_index_get(l->prev->v) == -1) { if (BM_elem_index_get(l->next->next->v) == -1) { + /* pass */ } } #endif diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index 2f692cb0f33..439f48897f6 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -38,7 +38,7 @@ bool AnimationExporter::exportAnimations(Scene *sce) { bool has_animations = hasAnimations(sce); if (has_animations) { - this->eval_ctx = eval_ctx; + this->depsgraph = depsgraph; this->scene = sce; openLibrary(); @@ -215,7 +215,7 @@ void AnimationExporter::export_sampled_matrix_animation(Object *ob, std::vector< for (std::vector<float>::iterator ctime = ctimes.begin(); ctime != ctimes.end(); ++ctime) { float fmat[4][4]; - bc_update_scene(eval_ctx, scene, *ctime); + bc_update_scene(depsgraph, scene, *ctime); BKE_object_matrix_local_get(ob, fmat); if (this->export_settings->limit_precision) bc_sanitize_mat(fmat, 6); @@ -247,7 +247,7 @@ void AnimationExporter::export_sampled_transrotloc_animation(Object *ob, std::ve float fsize[3]; float feul[3]; - bc_update_scene(eval_ctx, scene, *ctime); + bc_update_scene(depsgraph, scene, *ctime); BKE_object_matrix_local_get(ob, fmat); mat4_decompose(floc, fquat, fsize, fmat); quat_to_eul(feul, fquat); @@ -722,7 +722,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B if (flag & ARM_RESTPOS) { arm->flag &= ~ARM_RESTPOS; - BKE_pose_where_is(eval_ctx, scene, ob_arm); + BKE_pose_where_is(depsgraph, scene, ob_arm); } if (fra.size()) { @@ -731,7 +731,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B if (flag & ARM_RESTPOS) arm->flag = flag; - BKE_pose_where_is(eval_ctx, scene, ob_arm); + BKE_pose_where_is(depsgraph, scene, ob_arm); } void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_arm, Bone *bone) @@ -1022,7 +1022,7 @@ void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime) if (obtar) { BKE_animsys_evaluate_animdata(scene, &obtar->id, obtar->adt, ctime, ADT_RECALC_ANIM); - BKE_object_where_is_calc_time(this->eval_ctx, scene, obtar, ctime); + BKE_object_where_is_calc_time(this->depsgraph, scene, obtar, ctime); } } @@ -1030,7 +1030,7 @@ void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime) cti->flush_constraint_targets(con, &targets, 1); } } - BKE_object_where_is_calc_time(this->eval_ctx, scene, ob, ctime); + BKE_object_where_is_calc_time(this->depsgraph, scene, ob, ctime); } /* @@ -1316,16 +1316,16 @@ std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Obj float frame = *it; float ctime = BKE_scene_frame_get_from_ctime(scene, frame); - bc_update_scene(eval_ctx, scene, ctime); + bc_update_scene(depsgraph, scene, ctime); if (is_bone_animation) { if (pchan->flag & POSE_CHAIN) { enable_fcurves(ob->adt->action, NULL); BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL); - BKE_pose_where_is(eval_ctx, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); } else { - BKE_pose_where_is_bone(eval_ctx, scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1); } // compute bone local mat @@ -1843,7 +1843,7 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo // exit rest position if (flag & ARM_RESTPOS) { arm->flag &= ~ARM_RESTPOS; - BKE_pose_where_is(eval_ctx, scene, ob_arm); + BKE_pose_where_is(depsgraph, scene, ob_arm); } //v array will hold all values which will be exported. if (fra.size()) { @@ -1873,7 +1873,7 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo // restore restpos if (flag & ARM_RESTPOS) arm->flag = flag; - BKE_pose_where_is(eval_ctx, scene, ob_arm); + BKE_pose_where_is(depsgraph, scene, ob_arm); } void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan) @@ -1898,7 +1898,7 @@ void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, i BKE_animsys_evaluate_animdata(scene, &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM); - BKE_pose_where_is_bone(eval_ctx, scene, ob_arm, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob_arm, pchan, ctime, 1); // compute bone local mat if (bone->parent) { diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index d2216c04ee5..bbd7fdb9a63 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -79,19 +79,19 @@ extern "C" #include <vector> #include <algorithm> // std::find -struct EvaluationContext; +struct Depsgraph; class AnimationExporter: COLLADASW::LibraryAnimations { private: Scene *scene; - EvaluationContext *eval_ctx; + Depsgraph *depsgraph; COLLADASW::StreamWriter *sw; public: - AnimationExporter(EvaluationContext *eval_ctx, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): - eval_ctx(eval_ctx), + AnimationExporter(Depsgraph *depsgraph, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): + depsgraph(depsgraph), COLLADASW::LibraryAnimations(sw), export_settings(export_settings) { diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index b12ecb50e32..4ab6498af87 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -566,14 +566,16 @@ void AnimationImporter:: Assign_transform_animations(COLLADAFW::Transformation * } case COLLADAFW::Transformation::MATRIX: - /*{ - COLLADAFW::Matrix *mat = (COLLADAFW::Matrix*)transform; - COLLADABU::Math::Matrix4 mat4 = mat->getMatrix(); - switch (binding->animationClass) { - case COLLADAFW::AnimationList::TRANSFORM: - - } - }*/ +#if 0 + { + COLLADAFW::Matrix *mat = (COLLADAFW::Matrix*)transform; + COLLADABU::Math::Matrix4 mat4 = mat->getMatrix(); + switch (binding->animationClass) { + case COLLADAFW::AnimationList::TRANSFORM: + + } + } +#endif unused_fcurve(curves); break; case COLLADAFW::Transformation::SKEW: @@ -1751,7 +1753,8 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, float if (type != COLLADAFW::Transformation::ROTATE && type != COLLADAFW::Transformation::SCALE && type != COLLADAFW::Transformation::TRANSLATE && - type != COLLADAFW::Transformation::MATRIX) { + type != COLLADAFW::Transformation::MATRIX) + { fprintf(stderr, "animation of transformation %d is not supported yet\n", type); return false; } diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp index fbceb6e077f..5e349535610 100644 --- a/source/blender/collada/ArmatureExporter.cpp +++ b/source/blender/collada/ArmatureExporter.cpp @@ -62,7 +62,7 @@ ArmatureExporter::ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSett } // write bone nodes -void ArmatureExporter::add_armature_bones(const EvaluationContext *eval_ctx, Object *ob_arm, +void ArmatureExporter::add_armature_bones(Depsgraph *depsgraph, Object *ob_arm, Scene *sce, SceneExporter *se, std::list<Object *>& child_objects) { @@ -77,7 +77,7 @@ void ArmatureExporter::add_armature_bones(const EvaluationContext *eval_ctx, Obj for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) { // start from root bones if (!bone->parent) - add_bone_node(eval_ctx, bone, ob_arm, sce, se, child_objects); + add_bone_node(depsgraph, bone, ob_arm, sce, se, child_objects); } if (!is_edited) { @@ -157,7 +157,7 @@ void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vector<O #endif // parent_mat is armature-space -void ArmatureExporter::add_bone_node(const EvaluationContext *eval_ctx, Bone *bone, Object *ob_arm, Scene *sce, +void ArmatureExporter::add_bone_node(Depsgraph *depsgraph, Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, std::list<Object *>& child_objects) { @@ -231,7 +231,7 @@ void ArmatureExporter::add_bone_node(const EvaluationContext *eval_ctx, Bone *bo mul_m4_m4m4((*i)->parentinv, temp, (*i)->parentinv); } - se->writeNodes(eval_ctx, *i, sce); + se->writeNodes(depsgraph, *i, sce); copy_m4_m4((*i)->parentinv, backup_parinv); child_objects.erase(i++); @@ -240,13 +240,13 @@ void ArmatureExporter::add_bone_node(const EvaluationContext *eval_ctx, Bone *bo } for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - add_bone_node(eval_ctx, child, ob_arm, sce, se, child_objects); + add_bone_node(depsgraph, child, ob_arm, sce, se, child_objects); } node.end(); } else { for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - add_bone_node(eval_ctx, child, ob_arm, sce, se, child_objects); + add_bone_node(depsgraph, child, ob_arm, sce, se, child_objects); } } } diff --git a/source/blender/collada/ArmatureExporter.h b/source/blender/collada/ArmatureExporter.h index a3ed97c3a43..17c02d637e8 100644 --- a/source/blender/collada/ArmatureExporter.h +++ b/source/blender/collada/ArmatureExporter.h @@ -60,7 +60,7 @@ public: ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); // write bone nodes - void add_armature_bones(const struct EvaluationContext *eval_ctx, Object *ob_arm, Scene *sce, SceneExporter *se, + void add_armature_bones(struct Depsgraph *depsgraph, Object *ob_arm, Scene *sce, SceneExporter *se, std::list<Object *>& child_objects); bool add_instance_controller(Object *ob); @@ -85,7 +85,7 @@ private: // Scene, SceneExporter and the list of child_objects // are required for writing bone parented objects - void add_bone_node(const struct EvaluationContext *eval_ctx, Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, + void add_bone_node(struct Depsgraph *depsgraph, Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, std::list<Object *>& child_objects); void add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node& node); diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp index f32cb624f78..f6dbc965b42 100644 --- a/source/blender/collada/ControllerExporter.cpp +++ b/source/blender/collada/ControllerExporter.cpp @@ -104,9 +104,9 @@ bool ControllerExporter::add_instance_controller(Object *ob) return true; } -void ControllerExporter::export_controllers(const struct EvaluationContext *eval_ctx, Scene *sce) +void ControllerExporter::export_controllers(struct Depsgraph *depsgraph, Scene *sce) { - this->eval_ctx = eval_ctx; + this->depsgraph = depsgraph; scene = sce; openLibrary(); @@ -198,7 +198,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) bool use_instantiation = this->export_settings->use_object_instantiation; Mesh *me; - me = bc_get_mesh_copy(eval_ctx, scene, + me = bc_get_mesh_copy(depsgraph, scene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, @@ -300,7 +300,7 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key) bool use_instantiation = this->export_settings->use_object_instantiation; Mesh *me; - me = bc_get_mesh_copy(eval_ctx, scene, + me = bc_get_mesh_copy(depsgraph, scene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, @@ -495,7 +495,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas // put armature in rest position if (!(arm->flag & ARM_RESTPOS)) { arm->flag |= ARM_RESTPOS; - BKE_pose_where_is(eval_ctx, scene, ob_arm); + BKE_pose_where_is(depsgraph, scene, ob_arm); } for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) { @@ -543,7 +543,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas // back from rest positon if (!(flag & ARM_RESTPOS)) { arm->flag = flag; - BKE_pose_where_is(eval_ctx, scene, ob_arm); + BKE_pose_where_is(depsgraph, scene, ob_arm); } source.finish(); diff --git a/source/blender/collada/ControllerExporter.h b/source/blender/collada/ControllerExporter.h index a1d46c5aafb..e13d7c7ebea 100644 --- a/source/blender/collada/ControllerExporter.h +++ b/source/blender/collada/ControllerExporter.h @@ -54,7 +54,7 @@ #include "BKE_key.h" -struct EvaluationContext; +struct Depsgraph; class SceneExporter; class ControllerExporter : public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter @@ -66,12 +66,12 @@ public: bool add_instance_controller(Object *ob); - void export_controllers(const struct EvaluationContext *eval_ctx, Scene *sce); + void export_controllers(struct Depsgraph *depsgraph, Scene *sce); void operator()(Object *ob); private: - const struct EvaluationContext *eval_ctx; + struct Depsgraph *depsgraph; Scene *scene; UnitConverter converter; const ExportSettings *export_settings; diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index 04af73f2406..0b70b73887f 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -152,8 +152,8 @@ char *bc_CustomData_get_active_layer_name(const CustomData *data, int type) return data->layers[layer_index].name; } -DocumentExporter::DocumentExporter(EvaluationContext *eval_ctx, const ExportSettings *export_settings) : - eval_ctx(eval_ctx), +DocumentExporter::DocumentExporter(Depsgraph *depsgraph, const ExportSettings *export_settings) : + depsgraph(depsgraph), export_settings(export_settings) { } @@ -288,7 +288,7 @@ int DocumentExporter::exportCurrentScene(Scene *sce) // <library_geometries> if (bc_has_object_type(export_set, OB_MESH)) { GeometryExporter ge(writer, this->export_settings); - ge.exportGeom(eval_ctx, sce); + ge.exportGeom(depsgraph, sce); } // <library_controllers> @@ -296,7 +296,7 @@ int DocumentExporter::exportCurrentScene(Scene *sce) ControllerExporter controller_exporter(writer, this->export_settings); if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys) { - controller_exporter.export_controllers(eval_ctx, sce); + controller_exporter.export_controllers(depsgraph, sce); } // <library_visual_scenes> @@ -305,10 +305,10 @@ int DocumentExporter::exportCurrentScene(Scene *sce) if (this->export_settings->include_animations) { // <library_animations> - AnimationExporter ae(eval_ctx, writer, this->export_settings); + AnimationExporter ae(depsgraph, writer, this->export_settings); ae.exportAnimations(sce); } - se.exportScene(eval_ctx, sce); + se.exportScene(depsgraph, sce); // <scene> std::string scene_name(translate_id(id_name(sce))); diff --git a/source/blender/collada/DocumentExporter.h b/source/blender/collada/DocumentExporter.h index 68e1523fbee..b420140c3bf 100644 --- a/source/blender/collada/DocumentExporter.h +++ b/source/blender/collada/DocumentExporter.h @@ -39,13 +39,13 @@ struct Scene; class DocumentExporter { public: - DocumentExporter(EvaluationContext *eval_ctx, const ExportSettings *export_settings); + DocumentExporter(Depsgraph *depsgraph, const ExportSettings *export_settings); int exportCurrentScene(Scene *sce); void exportScenes(const char *filename); private: const ExportSettings *export_settings; - EvaluationContext *eval_ctx; + Depsgraph *depsgraph; }; #endif diff --git a/source/blender/collada/EffectExporter.cpp b/source/blender/collada/EffectExporter.cpp index 5e2b00be82a..66f3f81f71f 100644 --- a/source/blender/collada/EffectExporter.cpp +++ b/source/blender/collada/EffectExporter.cpp @@ -123,12 +123,13 @@ void EffectsExporter::writePhong(COLLADASW::EffectProfile &ep, Material *ma) ep.setSpecular(cot, false, "specular"); } -void EffectsExporter::writeTextures(COLLADASW::EffectProfile &ep, - std::string &key, - COLLADASW::Sampler *sampler, - MTex *t, Image *ima, - std::string &uvname ) { - +void EffectsExporter::writeTextures( + COLLADASW::EffectProfile &ep, + std::string &key, + COLLADASW::Sampler *sampler, + MTex *t, Image *ima, + std::string &uvname ) +{ // Image not set for texture if (!ima) return; diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index 8dbee607b01..87b47353596 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -57,11 +57,11 @@ GeometryExporter::GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSett { } -void GeometryExporter::exportGeom(const struct EvaluationContext *eval_ctx, Scene *sce) +void GeometryExporter::exportGeom(struct Depsgraph *depsgraph, Scene *sce) { openLibrary(); - mEvalCtx = eval_ctx; + mDepsgraph = depsgraph; mScene = sce; GeometryFunctor gf; gf.forEachMeshObjectInExportSet<GeometryExporter>(sce, *this, this->export_settings->export_set); @@ -77,7 +77,7 @@ void GeometryExporter::operator()(Object *ob) #endif bool use_instantiation = this->export_settings->use_object_instantiation; - Mesh *me = bc_get_mesh_copy(mEvalCtx, mScene, + Mesh *me = bc_get_mesh_copy(mDepsgraph, mScene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, diff --git a/source/blender/collada/GeometryExporter.h b/source/blender/collada/GeometryExporter.h index 7527195fdd8..88420b4ad2f 100644 --- a/source/blender/collada/GeometryExporter.h +++ b/source/blender/collada/GeometryExporter.h @@ -46,7 +46,7 @@ #include "BKE_key.h" -struct EvaluationContext; +struct Depsgraph; extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob); @@ -74,13 +74,13 @@ class GeometryExporter : COLLADASW::LibraryGeometries Normal n; - const struct EvaluationContext *mEvalCtx; + struct Depsgraph *mDepsgraph; Scene *mScene; public: GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); - void exportGeom(const struct EvaluationContext *eval_ctx, Scene *sce); + void exportGeom(struct Depsgraph *depsgraph, Scene *sce); void operator()(Object *ob); diff --git a/source/blender/collada/InstanceWriter.cpp b/source/blender/collada/InstanceWriter.cpp index 71371d280df..d96d590597a 100644 --- a/source/blender/collada/InstanceWriter.cpp +++ b/source/blender/collada/InstanceWriter.cpp @@ -32,9 +32,9 @@ #include "COLLADASWInstanceMaterial.h" extern "C" { - #include "BKE_customdata.h" - #include "BKE_material.h" - #include "DNA_mesh_types.h" +#include "BKE_customdata.h" +#include "BKE_material.h" +#include "DNA_mesh_types.h" } #include "InstanceWriter.h" diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index ec1b14a3855..339c8cec191 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -705,8 +705,9 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) } if (collada_meshtype == COLLADAFW::MeshPrimitive::POLYLIST || - collada_meshtype == COLLADAFW::MeshPrimitive::POLYGONS || - collada_meshtype == COLLADAFW::MeshPrimitive::TRIANGLES) { + collada_meshtype == COLLADAFW::MeshPrimitive::POLYGONS || + collada_meshtype == COLLADAFW::MeshPrimitive::TRIANGLES) + { COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp; unsigned int start_index = 0; diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp index f24c104892d..a1d542daa14 100644 --- a/source/blender/collada/SceneExporter.cpp +++ b/source/blender/collada/SceneExporter.cpp @@ -39,17 +39,17 @@ SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, { } -void SceneExporter::exportScene(const EvaluationContext *eval_ctx, Scene *sce) +void SceneExporter::exportScene(Depsgraph *depsgraph, Scene *sce) { // <library_visual_scenes> <visual_scene> std::string id_naming = id_name(sce); openVisualScene(translate_id(id_naming), id_naming); - exportHierarchy(eval_ctx, sce); + exportHierarchy(depsgraph, sce); closeVisualScene(); closeLibrary(); } -void SceneExporter::exportHierarchy(const EvaluationContext *eval_ctx, Scene *sce) +void SceneExporter::exportHierarchy(Depsgraph *depsgraph, Scene *sce) { LinkNode *node; std::vector<Object *> base_objects; @@ -81,13 +81,13 @@ void SceneExporter::exportHierarchy(const EvaluationContext *eval_ctx, Scene *sc Object *ob = base_objects[index]; if (bc_is_marked(ob)) { bc_remove_mark(ob); - writeNodes(eval_ctx, ob, sce); + writeNodes(depsgraph, ob, sce); } } } -void SceneExporter::writeNodes(const EvaluationContext *eval_ctx, Object *ob, Scene *sce) +void SceneExporter::writeNodes(Depsgraph *depsgraph, Object *ob, Scene *sce) { // Add associated armature first if available bool armature_exported = false; @@ -96,7 +96,7 @@ void SceneExporter::writeNodes(const EvaluationContext *eval_ctx, Object *ob, Sc armature_exported = bc_is_in_Export_set(this->export_settings->export_set, ob_arm); if (armature_exported && bc_is_marked(ob_arm)) { bc_remove_mark(ob_arm); - writeNodes(eval_ctx, ob_arm, sce); + writeNodes(depsgraph, ob_arm, sce); armature_exported = true; } } @@ -155,7 +155,7 @@ void SceneExporter::writeNodes(const EvaluationContext *eval_ctx, Object *ob, Sc // <instance_controller> else if (ob->type == OB_ARMATURE) { - arm_exporter->add_armature_bones(eval_ctx, ob, sce, this, child_objects); + arm_exporter->add_armature_bones(depsgraph, ob, sce, this, child_objects); } // <instance_camera> @@ -234,7 +234,7 @@ void SceneExporter::writeNodes(const EvaluationContext *eval_ctx, Object *ob, Sc for (std::list<Object *>::iterator i = child_objects.begin(); i != child_objects.end(); ++i) { if (bc_is_marked(*i)) { bc_remove_mark(*i); - writeNodes(eval_ctx, *i, sce); + writeNodes(depsgraph, *i, sce); } } diff --git a/source/blender/collada/SceneExporter.h b/source/blender/collada/SceneExporter.h index 3e3c15b836f..c330aa81e91 100644 --- a/source/blender/collada/SceneExporter.h +++ b/source/blender/collada/SceneExporter.h @@ -96,12 +96,12 @@ class SceneExporter: COLLADASW::LibraryVisualScenes, protected TransformWriter, { public: SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings); - void exportScene(const EvaluationContext *eval_ctx, Scene *sce); + void exportScene(Depsgraph *depsgraph, Scene *sce); private: friend class ArmatureExporter; - void exportHierarchy(const struct EvaluationContext *eval_ctx, Scene *sce); - void writeNodes(const struct EvaluationContext *eval_ctx, Object *ob, Scene *sce); + void exportHierarchy(struct Depsgraph *depsgraph, Scene *sce); + void writeNodes(struct Depsgraph *depsgraph, Object *ob, Scene *sce); ArmatureExporter *arm_exporter; const ExportSettings *export_settings; diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp index 64e3a4c36ce..5def6638df6 100644 --- a/source/blender/collada/collada.cpp +++ b/source/blender/collada/collada.cpp @@ -39,6 +39,7 @@ extern "C" #include "BKE_scene.h" #include "BKE_context.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" /* make dummy file */ #include "BLI_fileops.h" @@ -50,11 +51,11 @@ int collada_import(bContext *C, ImportSettings *import_settings) return (imp.import())? 1:0; } -int collada_export(EvaluationContext *eval_ctx, +int collada_export(Depsgraph *depsgraph, Scene *sce, ExportSettings *export_settings) { - ViewLayer *view_layer = eval_ctx->view_layer; + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); int includeFilter = OB_REL_NONE; if (export_settings->include_armatures) includeFilter |= OB_REL_MOD_ARMATURE; @@ -78,7 +79,7 @@ int collada_export(EvaluationContext *eval_ctx, bc_bubble_sort_by_Object_name(export_settings->export_set); } - DocumentExporter exporter(eval_ctx, export_settings); + DocumentExporter exporter(depsgraph, export_settings); int status = exporter.exportCurrentScene(sce); BLI_linklist_free(export_settings->export_set, NULL); diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h index f95fca03b65..5cf526af1f2 100644 --- a/source/blender/collada/collada.h +++ b/source/blender/collada/collada.h @@ -41,9 +41,9 @@ extern "C" { #include "RNA_types.h" struct bContext; +struct Depsgraph; struct Scene; struct ViewLayer; -struct EvaluationContext; /* * both return 1 on success, 0 on error @@ -52,7 +52,7 @@ int collada_import(struct bContext *C, ImportSettings *import_settings); -int collada_export(struct EvaluationContext *eval_ctx, +int collada_export(struct Depsgraph *depsgraph, struct Scene *sce, ExportSettings *export_settings); diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index 569e724b106..670dcba0a24 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -65,6 +65,7 @@ extern "C" { } #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "collada_utils.h" #include "ExportSettings.h" @@ -96,11 +97,9 @@ int bc_test_parent_loop(Object *par, Object *ob) int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) { Object workob; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *sce = CTX_data_scene(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - if (!par || bc_test_parent_loop(par, ob)) return false; @@ -112,7 +111,7 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) if (is_parent_space) { float mat[4][4]; // calc par->obmat - BKE_object_where_is_calc(&eval_ctx, sce, par); + BKE_object_where_is_calc(depsgraph, sce, par); // move child obmat into world space mul_m4_m4m4(mat, par->obmat, ob->obmat); @@ -123,7 +122,7 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) BKE_object_apply_mat4(ob, ob->obmat, 0, 0); // compute parentinv - BKE_object_workob_calc_parent(&eval_ctx, sce, ob, &workob); + BKE_object_workob_calc_parent(depsgraph, sce, ob, &workob); invert_m4_m4(ob->parentinv, workob.obmat); DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA); @@ -148,18 +147,12 @@ Main *bc_get_main() return G.main; } -EvaluationContext *bc_get_evaluation_context() -{ - Main *bmain = G.main; - return bmain->eval_ctx; -} - -void bc_update_scene(EvaluationContext *eval_ctx, Scene *scene, float ctime) +void bc_update_scene(Depsgraph *depsgraph, Scene *scene, float ctime) { BKE_scene_frame_set(scene, ctime); Main *bmain = bc_get_main(); - BKE_scene_graph_update_for_newframe(eval_ctx->depsgraph, bmain); + BKE_scene_graph_update_for_newframe(depsgraph, bmain); } Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char *name) @@ -179,7 +172,7 @@ Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char return ob; } -Mesh *bc_get_mesh_copy(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate) +Mesh *bc_get_mesh_copy(struct Depsgraph *depsgraph, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate) { Mesh *tmpmesh; CustomDataMask mask = CD_MASK_MESH; @@ -189,12 +182,12 @@ Mesh *bc_get_mesh_copy(const struct EvaluationContext *eval_ctx, Scene *scene, O switch (export_mesh_type) { case BC_MESH_TYPE_VIEW: { - dm = mesh_create_derived_view(eval_ctx, scene, ob, mask); + dm = mesh_create_derived_view(depsgraph, scene, ob, mask); break; } case BC_MESH_TYPE_RENDER: { - dm = mesh_create_derived_render(eval_ctx, scene, ob, mask); + dm = mesh_create_derived_render(depsgraph, scene, ob, mask); break; } } @@ -769,17 +762,17 @@ float bc_get_property(Bone *bone, std::string key, float def) IDProperty *property = bc_get_IDProperty(bone, key); if (property) { switch (property->type) { - case IDP_INT: - result = (float)(IDP_Int(property)); - break; - case IDP_FLOAT: - result = (float)(IDP_Float(property)); - break; - case IDP_DOUBLE: - result = (float)(IDP_Double(property)); - break; - default: - result = def; + case IDP_INT: + result = (float)(IDP_Int(property)); + break; + case IDP_FLOAT: + result = (float)(IDP_Float(property)); + break; + case IDP_DOUBLE: + result = (float)(IDP_Double(property)); + break; + default: + result = def; } } return result; diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h index 52767557397..89765375afb 100644 --- a/source/blender/collada/collada_utils.h +++ b/source/blender/collada/collada_utils.h @@ -60,20 +60,20 @@ extern "C" { #include "ExportSettings.h" #include "collada_internal.h" -struct EvaluationContext; +struct Depsgraph; typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureArrayMap; extern Scene *bc_get_scene(bContext *C); extern Main *bc_get_main(); -extern EvaluationContext *bc_get_evaluation_context(); -extern void bc_update_scene(EvaluationContext *eval_ctx, Scene *scene, float ctime); +extern Depsgraph *bc_get_depsgraph(); +extern void bc_update_scene(Depsgraph *depsgraph, Scene *scene, float ctime); extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index); extern int bc_test_parent_loop(Object *par, Object *ob); extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true); extern Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char *name); -extern Mesh *bc_get_mesh_copy(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate); +extern Mesh *bc_get_mesh_copy(struct Depsgraph *depsgraph, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate); extern Object *bc_get_assigned_armature(Object *ob); extern Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob); diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cpp b/source/blender/compositor/operations/COM_CompositorOperation.cpp index fe13f3d60a2..241ae20ce33 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.cpp +++ b/source/blender/compositor/operations/COM_CompositorOperation.cpp @@ -152,31 +152,31 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int /*tileNumber*/) const RenderData *rd = this->m_rd; if (rd->mode & R_BORDER && rd->mode & R_CROP) { - /*! - When using cropped render result, need to re-position area of interest, - so it'll natch bounds of render border within frame. By default, canvas - will be centered between full frame and cropped frame, so we use such - scheme to map cropped coordinates to full-frame coordinates - - ^ Y - | Width - +------------------------------------------------+ - | | - | | - | Centered canvas, we map coordinate from it | - | +------------------+ | - | | | | H - | | | | e - | +------------------+ . Center | | i - | | | | | | g - | | | | | | h - | |....dx.... +------|-----------+ | t - | | . dy | | - | +------------------+ | - | Render border, we map coordinates to it | - | | X - +------------------------------------------------+----> - Full frame + /** + * When using cropped render result, need to re-position area of interest, + * so it'll natch bounds of render border within frame. By default, canvas + * will be centered between full frame and cropped frame, so we use such + * scheme to map cropped coordinates to full-frame coordinates + * + * ^ Y + * | Width + * +------------------------------------------------+ + * | | + * | | + * | Centered canvas, we map coordinate from it | + * | +------------------+ | + * | | | | H + * | | | | e + * | +------------------+ . Center | | i + * | | | | | | g + * | | | | | | h + * | |....dx.... +------|-----------+ | t + * | | . dy | | + * | +------------------+ | + * | Render border, we map coordinates to it | + * | | X + * +------------------------------------------------+----> + * Full frame */ int full_width = rd->xsch * rd->size / 100; diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h index 4760c88cdbd..b30c99cbc0e 100644 --- a/source/blender/depsgraph/DEG_depsgraph.h +++ b/source/blender/depsgraph/DEG_depsgraph.h @@ -60,7 +60,6 @@ typedef struct Depsgraph Depsgraph; /* ------------------------------------------------ */ -struct EvaluationContext; struct Main; struct PointerRNA; @@ -75,19 +74,6 @@ typedef enum eEvaluationMode { DAG_EVAL_RENDER = 2, /* evaluate for render purposes */ } eEvaluationMode; -/* Dependency graph evaluation context - * - * This structure stores all the local dependency graph data, - * which is needed for it's evaluation, - */ -typedef struct EvaluationContext { - eEvaluationMode mode; - float ctime; - - struct Depsgraph *depsgraph; - struct ViewLayer *view_layer; -} EvaluationContext; - /* DagNode->eval_flags */ enum { /* Regardless to curve->path animation flag path is to be evaluated anyway, @@ -203,37 +189,6 @@ void DEG_ids_check_recalc(struct Main *bmain, /* ************************************************ */ /* Evaluation Engine API */ -/* Evaluation Context ---------------------------- */ - -/* Create new evaluation context. */ -struct EvaluationContext *DEG_evaluation_context_new(eEvaluationMode mode); - -/* Initialize evaluation context. - * Used by the areas which currently overrides the context or doesn't have - * access to a proper one. - */ -void DEG_evaluation_context_init(struct EvaluationContext *eval_ctx, - eEvaluationMode mode); -void DEG_evaluation_context_init_from_scene( - struct EvaluationContext *eval_ctx, - struct Scene *scene, - struct ViewLayer *view_layer, - eEvaluationMode mode); - -void DEG_evaluation_context_init_from_view_layer_for_render( - struct EvaluationContext *eval_ctx, - struct Depsgraph *depsgraph, - struct Scene *scene, - struct ViewLayer *view_layer); - -void DEG_evaluation_context_init_from_depsgraph( - struct EvaluationContext *eval_ctx, - struct Depsgraph *depsgraph, - eEvaluationMode mode); - -/* Free evaluation context. */ -void DEG_evaluation_context_free(struct EvaluationContext *eval_ctx); - /* Graph Evaluation ----------------------------- */ /* Frame changed recalculation entry point diff --git a/source/blender/depsgraph/DEG_depsgraph_build.h b/source/blender/depsgraph/DEG_depsgraph_build.h index 334b15cc638..3460cbf7c91 100644 --- a/source/blender/depsgraph/DEG_depsgraph_build.h +++ b/source/blender/depsgraph/DEG_depsgraph_build.h @@ -42,7 +42,6 @@ struct Depsgraph; struct CacheFile; struct EffectorWeights; -struct EvaluationContext; struct Group; struct Main; struct ModifierData; diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h index ceba87338a0..902a2ea3981 100644 --- a/source/blender/depsgraph/DEG_depsgraph_query.h +++ b/source/blender/depsgraph/DEG_depsgraph_query.h @@ -106,7 +106,6 @@ typedef struct DEGObjectIterData { int flag; struct Scene *scene; - struct EvaluationContext eval_ctx; int visibility_check; /* eObjectVisibilityCheck. */ diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index a5a28ce0a8c..ca31c1c15a1 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -170,7 +170,7 @@ IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id) ComponentDepsNode *comp_cow = id_node->add_component(DEG_NODE_TYPE_COPY_ON_WRITE); OperationDepsNode *op_cow = comp_cow->add_operation( - function_bind(deg_evaluate_copy_on_write, _1, graph_, id_node), + function_bind(deg_evaluate_copy_on_write, _1, id_node), DEG_OPCODE_COPY_ON_WRITE, "", -1); graph_->operations.push_back(op_cow); @@ -382,6 +382,43 @@ void DepsgraphNodeBuilder::end_build() } } +void DepsgraphNodeBuilder::build_id(ID* id) { + if (id == NULL) { + return; + } + switch (GS(id->name)) { + case ID_GR: + build_group((Group *)id); + break; + case ID_OB: + build_object(-1, (Object *)id, DEG_ID_LINKED_INDIRECTLY); + break; + case ID_NT: + build_nodetree((bNodeTree *)id); + break; + case ID_MA: + build_material((Material *)id); + break; + case ID_TE: + build_texture((Tex *)id); + break; + case ID_IM: + build_image((Image *)id); + break; + case ID_WO: + build_world((World *)id); + break; + case ID_MSK: + build_mask((Mask *)id); + break; + case ID_MC: + build_movieclip((MovieClip *)id); + break; + default: + fprintf(stderr, "Unhandled ID %s\n", id->name); + } +} + void DepsgraphNodeBuilder::build_group(Group *group) { if (built_map_.checkIsBuiltAndTag(group)) { @@ -698,6 +735,7 @@ void DepsgraphNodeBuilder::build_driver_variables(ID * id, FCurve *fcurve) LISTBASE_FOREACH (DriverVar *, dvar, &fcurve->driver->variables) { DRIVER_TARGETS_USED_LOOPER(dvar) { + build_id(dtar->id); build_driver_id_property(dtar->id, dtar->rna_path); } DRIVER_TARGETS_LOOPER_END diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h index df94671b4c6..757cacc6050 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h @@ -157,6 +157,7 @@ struct DepsgraphNodeBuilder { const char *name = "", int name_tag = -1); + void build_id(ID* id); void build_view_layer(Scene *scene, ViewLayer *view_layer, eDepsNode_LinkedState_Type linked_state); diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc index ac92d440bbe..edb6600f3e0 100644 --- a/source/blender/depsgraph/intern/depsgraph_eval.cc +++ b/source/blender/depsgraph/intern/depsgraph_eval.cc @@ -55,76 +55,6 @@ extern "C" { #include "intern/depsgraph.h" -/* ****************** */ -/* Evaluation Context */ - -/* Create new evaluation context. */ -EvaluationContext *DEG_evaluation_context_new(eEvaluationMode mode) -{ - EvaluationContext *eval_ctx = - (EvaluationContext *)MEM_callocN(sizeof(EvaluationContext), - "EvaluationContext"); - DEG_evaluation_context_init(eval_ctx, mode); - return eval_ctx; -} - -/** - * Initialize evaluation context. - * Used by the areas which currently overrides the context or doesn't have - * access to a proper one. - */ -void DEG_evaluation_context_init(EvaluationContext *eval_ctx, - eEvaluationMode mode) -{ - eval_ctx->mode = mode; -} - -void DEG_evaluation_context_init_from_scene( - EvaluationContext *eval_ctx, - Scene *scene, - ViewLayer *view_layer, - eEvaluationMode mode) -{ - DEG_evaluation_context_init(eval_ctx, mode); - eval_ctx->depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true); - eval_ctx->view_layer = view_layer; - eval_ctx->ctime = BKE_scene_frame_get(scene); -} - -void DEG_evaluation_context_init_from_view_layer_for_render( - EvaluationContext *eval_ctx, - Depsgraph *depsgraph, - Scene *scene, - ViewLayer *view_layer) -{ - /* ViewLayer may come from a copy of scene.viewlayers, we need to find the original though. */ - ViewLayer *view_layer_original = (ViewLayer *)BLI_findstring(&scene->view_layers, view_layer->name, offsetof(ViewLayer, name)); - BLI_assert(view_layer_original != NULL); - - DEG_evaluation_context_init(eval_ctx, DAG_EVAL_RENDER); - eval_ctx->ctime = BKE_scene_frame_get(scene); - eval_ctx->depsgraph = depsgraph; - eval_ctx->view_layer = view_layer_original; -} - -void DEG_evaluation_context_init_from_depsgraph( - EvaluationContext *eval_ctx, - Depsgraph *depsgraph, - eEvaluationMode mode) -{ - Scene *scene = DEG_get_evaluated_scene(depsgraph); - DEG_evaluation_context_init(eval_ctx, mode); - eval_ctx->ctime = (float)scene->r.cfra + scene->r.subframe; - eval_ctx->depsgraph = depsgraph; - eval_ctx->view_layer = DEG_get_evaluated_view_layer(depsgraph); -} - -/* Free evaluation context. */ -void DEG_evaluation_context_free(EvaluationContext *eval_ctx) -{ - MEM_freeN(eval_ctx); -} - /* Evaluate all nodes tagged for updating. */ void DEG_evaluate_on_refresh(Depsgraph *graph) { diff --git a/source/blender/depsgraph/intern/depsgraph_query_iter.cc b/source/blender/depsgraph/intern/depsgraph_query_iter.cc index 61f1ccdd2a0..c610e7fc500 100644 --- a/source/blender/depsgraph/intern/depsgraph_query_iter.cc +++ b/source/blender/depsgraph/intern/depsgraph_query_iter.cc @@ -187,7 +187,7 @@ static void DEG_iterator_objects_step(BLI_Iterator *iter, DEG::IDDepsNode *id_no (object->transflag & OB_DUPLI)) { data->dupli_parent = object; - data->dupli_list = object_duplilist(&data->eval_ctx, data->scene, object); + data->dupli_list = object_duplilist(data->graph, data->scene, object); data->dupli_object_next = (DupliObject *)data->dupli_list->first; if (BKE_object_is_visible(object, (eObjectVisibilityCheck)data->visibility_check) == false) { return; @@ -209,13 +209,10 @@ void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data) return; } - /* TODO(sergey): What evaluation type we want here? */ - /* TODO(dfelinto): Get rid of evaluation context here, it's only used to do - * direct dupli-objects update in group.c. Which is terribly bad, and all - * objects are expected to be evaluated already. */ - DEG_evaluation_context_init(&data->eval_ctx, DAG_EVAL_VIEWPORT); - data->eval_ctx.depsgraph = depsgraph; - data->eval_ctx.view_layer = DEG_get_evaluated_view_layer(depsgraph); + /* TODO: Calling this forces the scene datablock to be expanded, + * otherwise we get crashes on load with copy-on-write. There may + * be a better solution for this. */ + DEG_get_evaluated_view_layer(depsgraph); iter->data = data; data->dupli_parent = NULL; diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h index d6c410347f6..6d328b399e0 100644 --- a/source/blender/depsgraph/intern/depsgraph_types.h +++ b/source/blender/depsgraph/intern/depsgraph_types.h @@ -49,8 +49,8 @@ struct bAction; struct ChannelDriver; struct ModifierData; struct PointerRNA; -struct EvaluationContext; struct FCurve; +struct Depsgraph; namespace DEG { @@ -61,7 +61,7 @@ using std::max; /* Evaluation Operation for atomic operation */ // XXX: move this to another header that can be exposed? -typedef function<void(struct EvaluationContext *)> DepsEvalOperationCb; +typedef function<void(struct ::Depsgraph *)> DepsEvalOperationCb; /* Metatype of Nodes - The general "level" in the graph structure * the node serves. diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc index d40e3e85979..4dd3842070e 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval.cc @@ -69,7 +69,6 @@ static void schedule_children(TaskPool *pool, const int thread_id); struct DepsgraphEvalState { - EvaluationContext *eval_ctx; Depsgraph *graph; bool do_stats; }; @@ -86,11 +85,11 @@ static void deg_task_run_func(TaskPool *pool, /* Perform operation. */ if (state->do_stats) { const double start_time = PIL_check_seconds_timer(); - node->evaluate(state->eval_ctx); + node->evaluate((::Depsgraph*)state->graph); node->stats.current_time += PIL_check_seconds_timer() - start_time; } else { - node->evaluate(state->eval_ctx); + node->evaluate((::Depsgraph*)state->graph); } /* Schedule children. */ BLI_task_pool_delayed_push_begin(pool, thread_id); @@ -229,21 +228,20 @@ static void schedule_children(TaskPool *pool, */ void deg_evaluate_on_refresh(Depsgraph *graph) { - /* Set time for the current graph evaluation context. */ - TimeSourceDepsNode *time_src = graph->find_time_source(); /* Nothing to update, early out. */ if (BLI_gset_len(graph->entry_tags) == 0) { return; } const bool do_time_debug = ((G.debug & G_DEBUG_DEPSGRAPH_TIME) != 0); const double start_time = do_time_debug ? PIL_check_seconds_timer() : 0; - /* Set up evaluation context. */ - EvaluationContext eval_ctx; - DEG_evaluation_context_init_from_depsgraph(&eval_ctx, (::Depsgraph*)graph, graph->mode); - eval_ctx.ctime = time_src->cfra; + + /* TODO: Calling this forces the scene datablock to be expanded, + * otherwise we get crashes on load with copy-on-write. There may + * be a better solution for this. */ + DEG_get_evaluated_view_layer((const ::Depsgraph*)graph); + /* Set up evaluation state. */ DepsgraphEvalState state; - state.eval_ctx = &eval_ctx; state.graph = graph; state.do_stats = do_time_debug; /* Set up task scheduler and pull for threaded evaluation. */ diff --git a/source/blender/depsgraph/intern/eval/deg_eval.h b/source/blender/depsgraph/intern/eval/deg_eval.h index 0fb60e8f779..a8f5f7c145f 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval.h +++ b/source/blender/depsgraph/intern/eval/deg_eval.h @@ -32,8 +32,6 @@ #pragma once -struct EvaluationContext; - namespace DEG { struct Depsgraph; diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc index 1d2169f5ec4..91790522590 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc @@ -781,10 +781,10 @@ void deg_free_copy_on_write_datablock(ID *id_cow) id_cow->name[0] = '\0'; } -void deg_evaluate_copy_on_write(const EvaluationContext * /*eval_ctx*/, - const Depsgraph *depsgraph, +void deg_evaluate_copy_on_write(struct ::Depsgraph *graph, const IDDepsNode *id_node) { + const DEG::Depsgraph *depsgraph = reinterpret_cast<const DEG::Depsgraph *>(graph); DEBUG_PRINT("%s on %s\n", __func__, id_node->id_orig->name); if (id_node->id_orig == &depsgraph->scene->id) { /* NOTE: This is handled by eval_ctx setup routines, which diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h index a2b57cb7198..8fca90e9f5b 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h @@ -32,7 +32,6 @@ #include <stddef.h> -struct EvaluationContext; struct ID; /* Unkomment this to have verbose log about original and CoW pointers @@ -47,6 +46,8 @@ struct ID; # define DEG_COW_PRINT(format, ...) #endif +struct Depsgraph; + namespace DEG { struct Depsgraph; @@ -79,8 +80,7 @@ void deg_free_copy_on_write_datablock(struct ID *id_cow); /* Callback function for depsgraph operation node which ensures copy-on-write * datablock is ready for use by further evaluation routines. */ -void deg_evaluate_copy_on_write(const struct EvaluationContext *eval_ctx, - const struct Depsgraph *depsgraph, +void deg_evaluate_copy_on_write(struct ::Depsgraph *depsgraph, const struct IDDepsNode *id_node); /* Check that given ID is propely expanded and does not have any shallow diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.h b/source/blender/depsgraph/intern/nodes/deg_node_component.h index b8009cc0a7f..5b6461f950e 100644 --- a/source/blender/depsgraph/intern/nodes/deg_node_component.h +++ b/source/blender/depsgraph/intern/nodes/deg_node_component.h @@ -39,8 +39,6 @@ struct ID; struct bPoseChannel; struct GHash; -struct EvaluationContext; - namespace DEG { struct Depsgraph; diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index f96f496a0f9..3bf1acaf79e 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -234,6 +234,7 @@ data_to_c_simple(modes/shaders/object_empty_image_vert.glsl SRC) data_to_c_simple(modes/shaders/object_outline_resolve_frag.glsl SRC) data_to_c_simple(modes/shaders/object_outline_expand_frag.glsl SRC) data_to_c_simple(modes/shaders/object_outline_detect_frag.glsl SRC) +data_to_c_simple(modes/shaders/object_outline_prepass_frag.glsl SRC) data_to_c_simple(modes/shaders/object_grid_frag.glsl SRC) data_to_c_simple(modes/shaders/object_grid_vert.glsl SRC) data_to_c_simple(modes/shaders/object_lightprobe_grid_vert.glsl SRC) diff --git a/source/blender/draw/engines/eevee/eevee_motion_blur.c b/source/blender/draw/engines/eevee/eevee_motion_blur.c index 9b19163c8d7..4bac8ba2ebd 100644 --- a/source/blender/draw/engines/eevee/eevee_motion_blur.c +++ b/source/blender/draw/engines/eevee/eevee_motion_blur.c @@ -68,16 +68,13 @@ static void eevee_motion_blur_camera_get_matrix_at_time( cam_cpy.data = &camdata_cpy; const DRWContextState *draw_ctx = DRW_context_state_get(); - /* We will be modifying time, so we create copy of eval_ctx. */ - EvaluationContext eval_ctx = draw_ctx->eval_ctx; - eval_ctx.ctime = time; /* Past matrix */ /* FIXME : This is a temporal solution that does not take care of parent animations */ /* Recalc Anim manualy */ BKE_animsys_evaluate_animdata(scene, &cam_cpy.id, cam_cpy.adt, time, ADT_RECALC_ALL); BKE_animsys_evaluate_animdata(scene, &camdata_cpy.id, camdata_cpy.adt, time, ADT_RECALC_ALL); - BKE_object_where_is_calc_time(&eval_ctx, scene, &cam_cpy, time); + BKE_object_where_is_calc_time(draw_ctx->depsgraph, scene, &cam_cpy, time); /* Compute winmat */ CameraParams params; diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 66ca8971a46..27f2d891cc0 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -187,6 +187,7 @@ typedef enum { DRW_TEX_R_8, DRW_TEX_R_16, DRW_TEX_R_16I, + DRW_TEX_R_16U, DRW_TEX_R_32, DRW_TEX_DEPTH_16, DRW_TEX_DEPTH_24, @@ -506,7 +507,6 @@ typedef struct DRWContextState { struct RenderEngineType *engine_type; - EvaluationContext eval_ctx; struct Depsgraph *depsgraph; eObjectMode object_mode; diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c index c14fe70e0c3..fe87e7f17fd 100644 --- a/source/blender/draw/intern/draw_armature.c +++ b/source/blender/draw/intern/draw_armature.c @@ -1228,7 +1228,7 @@ static void draw_armature_edit(Object *ob) const bool show_text = DRW_state_show_text(); - for (eBone = arm->edbo->first, index = 0; eBone; eBone = eBone->next, index++) { + for (eBone = arm->edbo->first, index = ob->select_color; eBone; eBone = eBone->next, index += 0x10000) { if (eBone->layer & arm->layer) { if ((eBone->flag & BONE_HIDDEN_A) == 0) { const int select_id = is_select ? index : (unsigned int)-1; diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c index 0530d05c199..d7e8a6b71df 100644 --- a/source/blender/draw/intern/draw_cache_impl_particles.c +++ b/source/blender/draw/intern/draw_cache_impl_particles.c @@ -46,6 +46,8 @@ #include "GPU_batch.h" +#include "DEG_depsgraph_query.h" + #include "draw_cache_impl.h" /* own include */ static void particle_batch_cache_clear(ParticleSystem *psys); @@ -466,7 +468,7 @@ static void particle_batch_cache_ensure_pos(Object *object, ParticleSystem *psys ParticleSimulationData sim = {NULL}; const DRWContextState *draw_ctx = DRW_context_state_get(); - sim.eval_ctx = &draw_ctx->eval_ctx; + sim.depsgraph = draw_ctx->depsgraph; sim.scene = draw_ctx->scene; sim.ob = object; sim.psys = psys; @@ -494,7 +496,7 @@ static void particle_batch_cache_ensure_pos(Object *object, ParticleSystem *psys GWN_vertbuf_data_alloc(cache->pos, psys->totpart); for (curr_point = 0, i = 0, pa = psys->particles; i < psys->totpart; i++, pa++) { - state.time = draw_ctx->eval_ctx.ctime; + state.time = DEG_get_ctime(draw_ctx->depsgraph); if (!psys_get_particle_state(&sim, curr_point, &state, 0)) { continue; } diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index b8ed341e2c5..7d4d27b7147 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -351,16 +351,6 @@ static void drw_viewport_cache_resize(void) DRW_instance_data_list_resize(DST.idatalist); } -static void drw_state_eval_ctx_init(DRWManager *dst) -{ - DRWContextState *draw_ctx = &dst->draw_ctx; - DEG_evaluation_context_init_from_scene( - &draw_ctx->eval_ctx, - draw_ctx->scene, - draw_ctx->view_layer, - DST.options.is_scene_render ? DAG_EVAL_RENDER : DAG_EVAL_VIEWPORT); -} - /* Not a viewport variable, we could split this out. */ static void drw_context_state_init(void) { @@ -389,8 +379,6 @@ static void drw_context_state_init(void) else { DST.draw_ctx.object_pose = NULL; } - - drw_state_eval_ctx_init(&DST); } /* It also stores viewport variable to an immutable place: DST @@ -1123,15 +1111,14 @@ void DRW_notify_id_update(const DRWUpdateContext *update_ctx, ID *id) * for each relevant engine / mode engine. */ void DRW_draw_view(const bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); RenderEngineType *engine_type = CTX_data_engine_type(C); ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); /* Reset before using it. */ drw_state_prepare_clean_for_draw(&DST); - DRW_draw_render_loop_ex(eval_ctx.depsgraph, engine_type, ar, v3d, C); + DRW_draw_render_loop_ex(depsgraph, engine_type, ar, v3d, C); } /** @@ -1555,7 +1542,14 @@ void DRW_draw_select_loop( drw_engines_cache_init(); if (use_obedit) { +#if 0 drw_engines_cache_populate(obact); +#else + FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, obact->mode, ob_iter) { + drw_engines_cache_populate(ob_iter); + } + FOREACH_OBJECT_IN_MODE_END; +#endif } else { DEG_OBJECT_ITER_BEGIN( diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index dd7e84f67d4..4f322b11931 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -222,6 +222,7 @@ struct DRWShadingGroup { int normalworld; int orcotexfac; int eye; + int callid; uint16_t matflag; /* Matrices needed, same as DRWCall.flag */ #ifndef NDEBUG diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index ae7854b436c..544129ea124 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -498,6 +498,7 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) shgroup->normalworld = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_WORLDNORMAL); shgroup->orcotexfac = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_ORCO); shgroup->eye = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_EYE); + shgroup->callid = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_CALLID); shgroup->matflag = 0; if (shgroup->modelinverse > -1) diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 2a5a595c682..dcd976805fd 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -384,100 +384,53 @@ void DRW_state_clip_planes_reset(void) /** \name Clipping (DRW_clipping) * \{ */ -/* Extract the 8 corners (world space). +/* Extract the 8 corners from a Projection Matrix. * Although less accurate, this solution can be simplified as follows: * BKE_boundbox_init_from_minmax(&bbox, (const float[3]){-1.0f, -1.0f, -1.0f}, (const float[3]){1.0f, 1.0f, 1.0f}); - * for (int i = 0; i < 8; i++) {mul_project_m4_v3(viewprojinv, bbox.vec[i]);} + * for (int i = 0; i < 8; i++) {mul_project_m4_v3(projinv, bbox.vec[i]);} */ -static void draw_frustum_boundbox_calc( - const float (*projmat)[4], const float (*viewinv)[4], BoundBox *r_bbox) +static void draw_frustum_boundbox_calc(const float(*projmat)[4], BoundBox *r_bbox) { - float screenvecs[3][3], loc[3], near, far, w_half, h_half; + float near, far, left, right, bottom, top; bool is_persp = projmat[3][3] == 0.0f; - copy_m3_m4(screenvecs, viewinv); - copy_v3_v3(loc, viewinv[3]); - /* get the values of the minimum and maximum clipping planes distances - * and half the width and height of the nearplane rectangle. */ if (is_persp) { - near = projmat[3][2] / (projmat[2][2] - 1.0f); - far = projmat[3][2] / (projmat[2][2] + 1.0f); - w_half = near / projmat[0][0]; - h_half = near / projmat[1][1]; + near = projmat[3][2] / (projmat[2][2] - 1.0f); + far = projmat[3][2] / (projmat[2][2] + 1.0f); + left = near * (projmat[2][0] - 1.0f) / projmat[0][0]; + right = near * (projmat[2][0] + 1.0f) / projmat[0][0]; + bottom = near * (projmat[2][1] - 1.0f) / projmat[1][1]; + top = near * (projmat[2][1] + 1.0f) / projmat[1][1]; } else { - near = (projmat[3][2] + 1.0f) / projmat[2][2]; - far = (projmat[3][2] - 1.0f) / projmat[2][2]; - w_half = 1.0f / projmat[0][0]; - h_half = 1.0f / projmat[1][1]; + near = ( projmat[3][2] + 1.0f) / projmat[2][2]; + far = ( projmat[3][2] - 1.0f) / projmat[2][2]; + left = (-projmat[3][0] - 1.0f) / projmat[0][0]; + right = (-projmat[3][0] + 1.0f) / projmat[0][0]; + bottom = (-projmat[3][1] - 1.0f) / projmat[1][1]; + top = (-projmat[3][1] + 1.0f) / projmat[1][1]; } - /* With vectors aligned to the screen, reconstruct - * the near plane from the dimensions obtained earlier. */ - float mid[3], hor[3], ver[3]; - mul_v3_v3fl(hor, screenvecs[0], w_half); - mul_v3_v3fl(ver, screenvecs[1], h_half); - madd_v3_v3v3fl(mid, loc, screenvecs[2], -near); - - /* The case below is for non-symmetric frustum. */ - if (is_persp) { - madd_v3_v3fl(mid, hor, projmat[2][0]); - madd_v3_v3fl(mid, ver, projmat[2][1]); - } - else { - madd_v3_v3fl(mid, hor, -projmat[3][0]); - madd_v3_v3fl(mid, ver, -projmat[3][1]); - } - - r_bbox->vec[0][0] = mid[0] - ver[0] - hor[0]; - r_bbox->vec[0][1] = mid[1] - ver[1] - hor[1]; - r_bbox->vec[0][2] = mid[2] - ver[2] - hor[2]; - - r_bbox->vec[3][0] = mid[0] + ver[0] - hor[0]; - r_bbox->vec[3][1] = mid[1] + ver[1] - hor[1]; - r_bbox->vec[3][2] = mid[2] + ver[2] - hor[2]; - - r_bbox->vec[7][0] = mid[0] + ver[0] + hor[0]; - r_bbox->vec[7][1] = mid[1] + ver[1] + hor[1]; - r_bbox->vec[7][2] = mid[2] + ver[2] + hor[2]; - - r_bbox->vec[4][0] = mid[0] - ver[0] + hor[0]; - r_bbox->vec[4][1] = mid[1] - ver[1] + hor[1]; - r_bbox->vec[4][2] = mid[2] - ver[2] + hor[2]; + r_bbox->vec[0][2] = r_bbox->vec[3][2] = r_bbox->vec[7][2] = r_bbox->vec[4][2] = -near; + r_bbox->vec[0][0] = r_bbox->vec[3][0] = left; + r_bbox->vec[4][0] = r_bbox->vec[7][0] = right; + r_bbox->vec[0][1] = r_bbox->vec[4][1] = bottom; + r_bbox->vec[7][1] = r_bbox->vec[3][1] = top; /* Get the coordinates of the far plane. */ if (is_persp) { float sca_far = far / near; - mid[0] = mid[0] + (mid[0] - loc[0]) * sca_far; - mid[1] = mid[1] + (mid[1] - loc[1]) * sca_far; - mid[2] = mid[2] + (mid[2] - loc[2]) * sca_far; - - mul_v3_fl(hor, sca_far); - mul_v3_fl(ver, sca_far); + left *= sca_far; + bottom *= sca_far; + right *= sca_far; + top *= sca_far; } - else { - madd_v3_v3v3fl(mid, loc, screenvecs[2], -far); - /* Non-symmetric frustum. */ - madd_v3_v3fl(mid, hor, -projmat[3][0]); - madd_v3_v3fl(mid, ver, -projmat[3][1]); - } - - r_bbox->vec[1][0] = mid[0] - ver[0] - hor[0]; - r_bbox->vec[1][1] = mid[1] - ver[1] - hor[1]; - r_bbox->vec[1][2] = mid[2] - ver[2] - hor[2]; - - r_bbox->vec[2][0] = mid[0] + ver[0] - hor[0]; - r_bbox->vec[2][1] = mid[1] + ver[1] - hor[1]; - r_bbox->vec[2][2] = mid[2] + ver[2] - hor[2]; - - r_bbox->vec[6][0] = mid[0] + ver[0] + hor[0]; - r_bbox->vec[6][1] = mid[1] + ver[1] + hor[1]; - r_bbox->vec[6][2] = mid[2] + ver[2] + hor[2]; - - r_bbox->vec[5][0] = mid[0] - ver[0] + hor[0]; - r_bbox->vec[5][1] = mid[1] - ver[1] + hor[1]; - r_bbox->vec[5][2] = mid[2] - ver[2] + hor[2]; + r_bbox->vec[1][2] = r_bbox->vec[2][2] = r_bbox->vec[6][2] = r_bbox->vec[5][2] = -far; + r_bbox->vec[1][0] = r_bbox->vec[2][0] = left; + r_bbox->vec[6][0] = r_bbox->vec[5][0] = right; + r_bbox->vec[1][1] = r_bbox->vec[5][1] = bottom; + r_bbox->vec[2][1] = r_bbox->vec[6][1] = top; } static void draw_clipping_setup_from_view(void) @@ -495,11 +448,15 @@ static void draw_clipping_setup_from_view(void) #if 0 /* It has accuracy problems. */ BKE_boundbox_init_from_minmax(&bbox, (const float[3]){-1.0f, -1.0f, -1.0f}, (const float[3]){1.0f, 1.0f, 1.0f}); for (int i = 0; i < 8; i++) { - mul_project_m4_v3(DST.view_data.matstate.mat[DRW_MAT_PERSINV], bbox.vec[i]); + mul_project_m4_v3(projinv, bbox.vec[i]); } #else - draw_frustum_boundbox_calc(projmat, viewinv, &bbox); + draw_frustum_boundbox_calc(projmat, &bbox); #endif + /* Transform into world space. */ + for (int i = 0; i < 8; i++) { + mul_m4_v3(viewinv, bbox.vec[i]); + } /* Compute clip planes using the world space frustum corners. */ for (int p = 0; p < 6; p++) { @@ -527,9 +484,6 @@ static void draw_clipping_setup_from_view(void) float *nearpoint = bbox.vec[0]; float *farpoint = bbox.vec[6]; - mul_project_m4_v3(projinv, nearpoint); - mul_project_m4_v3(projinv, farpoint); - /* just use median point */ mid_v3_v3v3(bsphere->center, farpoint, nearpoint); bsphere->radius = len_v3v3(bsphere->center, farpoint); @@ -553,7 +507,6 @@ static void draw_clipping_setup_from_view(void) float h_sq = len_squared_v3v3(mid_min, mid_max); float fac = (4 * h_sq + b_sq - a_sq) / (8 * h_sq); - BLI_assert(fac >= 0.0f); /* The goal is to get the smallest sphere, * not the sphere that passes through each corner */ @@ -1010,7 +963,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) # define GPU_SELECT_LOAD_IF_PICKSEL_LIST_END(start, count) # define GPU_SELECT_LOAD_IF_PICKSEL_LIST(_shgroup, _start, _count) \ _start = 0; \ - _count = _shgroup->interface.instance_count; + _count = _shgroup->instance_count; #endif @@ -1052,6 +1005,7 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) } else { bool prev_neg_scale = false; + int callid = 0; for (DRWCall *call = shgroup->calls.first; call; call = call->next) { /* OPTI/IDEA(clem): Do this preparation in another thread. */ @@ -1060,6 +1014,12 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) if ((call->state->flag & DRW_CALL_CULLED) != 0) continue; + /* XXX small exception/optimisation for outline rendering. */ + if (shgroup->callid != -1) { + GPU_shader_uniform_vector_int(shgroup->shader, shgroup->callid, 1, 1, &callid); + callid += 1; + } + /* Negative scale objects */ bool neg_scale = call->state->flag & DRW_CALL_NEGSCALE; if (neg_scale != prev_neg_scale) { diff --git a/source/blender/draw/intern/draw_manager_texture.c b/source/blender/draw/intern/draw_manager_texture.c index 65856a6bf5c..f083e399ac2 100644 --- a/source/blender/draw/intern/draw_manager_texture.c +++ b/source/blender/draw/intern/draw_manager_texture.c @@ -36,6 +36,7 @@ void drw_texture_get_format( * Generally they are multiple of 16bit. */ case DRW_TEX_R_16: case DRW_TEX_R_16I: + case DRW_TEX_R_16U: case DRW_TEX_R_32: case DRW_TEX_RG_8: case DRW_TEX_RG_16: @@ -72,6 +73,7 @@ void drw_texture_get_format( case DRW_TEX_R_8: *r_data_type = GPU_R8; break; case DRW_TEX_R_16: *r_data_type = GPU_R16F; break; case DRW_TEX_R_16I: *r_data_type = GPU_R16I; break; + case DRW_TEX_R_16U: *r_data_type = GPU_R16UI; break; case DRW_TEX_R_32: *r_data_type = GPU_R32F; break; #if 0 case DRW_TEX_RGB_8: *r_data_type = GPU_RGB8; break; diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c index 73a4fb1e9e6..b33ebd8ba60 100644 --- a/source/blender/draw/modes/edit_curve_mode.c +++ b/source/blender/draw/modes/edit_curve_mode.c @@ -28,6 +28,8 @@ #include "DNA_curve_types.h" +#include "BKE_object.h" + /* If builtin shaders are needed */ #include "GPU_shader.h" #include "GPU_batch.h" @@ -233,7 +235,12 @@ static void EDIT_CURVE_cache_populate(void *vedata, Object *ob) UNUSED_VARS(psl, stl); if (ob->type == OB_CURVE) { - if (ob == draw_ctx->object_edit) { +#if 0 + if (ob == draw_ctx->object_edit) +#else + if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) +#endif + { Curve *cu = ob->data; /* Get geometry cache */ struct Gwn_Batch *geom; diff --git a/source/blender/draw/modes/edit_lattice_mode.c b/source/blender/draw/modes/edit_lattice_mode.c index 0268f4eb453..e8628711ffd 100644 --- a/source/blender/draw/modes/edit_lattice_mode.c +++ b/source/blender/draw/modes/edit_lattice_mode.c @@ -26,6 +26,8 @@ #include "DRW_engine.h" #include "DRW_render.h" +#include "BKE_object.h" + /* If builtin shaders are needed */ #include "GPU_shader.h" @@ -192,7 +194,7 @@ static void EDIT_LATTICE_cache_populate(void *vedata, Object *ob) UNUSED_VARS(psl); if (ob->type == OB_LATTICE) { - if (ob == draw_ctx->object_edit) { + if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) { /* Get geometry cache */ struct Gwn_Batch *geom; diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index 4bd69941809..c465fa38f04 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -37,6 +37,8 @@ #include "edit_mesh_mode_intern.h" /* own include */ +#include "BKE_object.h" + extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ extern struct GlobalsUboStorage ts; /* draw_common.c */ @@ -448,7 +450,7 @@ static void EDIT_MESH_cache_populate(void *vedata, Object *ob) struct Gwn_Batch *geom; if (ob->type == OB_MESH) { - if (ob == draw_ctx->object_edit) { + if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) { const Mesh *me = ob->data; IDProperty *ces_mode_ed = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_EDIT, ""); bool do_occlude_wire = BKE_collection_engine_property_value_get_bool(ces_mode_ed, "show_occlude_wire"); diff --git a/source/blender/draw/modes/edit_metaball_mode.c b/source/blender/draw/modes/edit_metaball_mode.c index bcabeef5bc3..f7b7113a4d6 100644 --- a/source/blender/draw/modes/edit_metaball_mode.c +++ b/source/blender/draw/modes/edit_metaball_mode.c @@ -28,6 +28,7 @@ #include "DNA_meta_types.h" +#include "BKE_object.h" #include "BKE_mball.h" /* If builtin shaders are needed */ @@ -171,7 +172,7 @@ static void EDIT_METABALL_cache_populate(void *vedata, Object *ob) const DRWContextState *draw_ctx = DRW_context_state_get(); DRWShadingGroup *group = stl->g_data->group; - if (ob == draw_ctx->object_edit) { + if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) { MetaBall *mb = ob->data; const bool is_select = DRW_state_is_select(); diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 939507a4f21..0d9e46d1268 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -40,6 +40,8 @@ #include "BIF_gl.h" +#include "BLI_string_utils.h" + #include "BKE_anim.h" #include "BKE_camera.h" #include "BKE_curve.h" @@ -69,6 +71,7 @@ extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ extern struct GPUTexture *globals_ramp; /* draw_common.c */ extern GlobalsUboStorage ts; +extern char datatoc_object_outline_prepass_frag_glsl[]; extern char datatoc_object_outline_resolve_frag_glsl[]; extern char datatoc_object_outline_detect_frag_glsl[]; extern char datatoc_object_outline_expand_frag_glsl[]; @@ -223,6 +226,13 @@ typedef struct OBJECT_PrivateData { DRWShadingGroup *points_select; DRWShadingGroup *points_select_group; DRWShadingGroup *points_transform; + + /* Outlines id offset */ + int id_ofs_active; + int id_ofs_active_group; + int id_ofs_select; + int id_ofs_select_group; + int id_ofs_transform; } OBJECT_PrivateData; /* Transient data */ static struct { @@ -232,6 +242,7 @@ static struct { struct Gwn_VertFormat *empty_image_wire_format; /* fullscreen shaders */ + GPUShader *outline_prepass_sh; GPUShader *outline_resolve_sh; GPUShader *outline_resolve_aa_sh; GPUShader *outline_detect_sh; @@ -259,6 +270,7 @@ static struct { bool draw_grid; /* Temp buffer textures */ struct GPUTexture *outlines_depth_tx; + struct GPUTexture *outlines_id_tx; struct GPUTexture *outlines_color_tx; struct GPUTexture *outlines_blur_tx; } e_data = {NULL}; /* Engine data */ @@ -288,14 +300,20 @@ static void OBJECT_engine_init(void *vedata) if (DRW_state_is_fbo()) { e_data.outlines_depth_tx = DRW_texture_pool_query_2D(size[0], size[1], DRW_TEX_DEPTH_24, &draw_engine_object_type); - e_data.outlines_color_tx = DRW_texture_pool_query_2D(size[0], size[1], DRW_TEX_RGBA_8, - &draw_engine_object_type); + /* XXX TODO DRW_TEX_R_16U can overflow, it would cause no harm + * (only bad colored or missing outlines) but we should + * use 32bits only if the scene have that many objects */ + e_data.outlines_id_tx = DRW_texture_pool_query_2D(size[0], size[1], DRW_TEX_R_16U, + &draw_engine_object_type); GPU_framebuffer_ensure_config(&fbl->outlines_fb, { GPU_ATTACHMENT_TEXTURE(e_data.outlines_depth_tx), - GPU_ATTACHMENT_TEXTURE(e_data.outlines_color_tx) + GPU_ATTACHMENT_TEXTURE(e_data.outlines_id_tx) }); + e_data.outlines_color_tx = DRW_texture_pool_query_2D(size[0], size[1], DRW_TEX_RGBA_8, + &draw_engine_object_type); + GPU_framebuffer_ensure_config(&fbl->expand_fb, { GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(e_data.outlines_color_tx) @@ -310,66 +328,58 @@ static void OBJECT_engine_init(void *vedata) }); } + /* Shaders */ if (!e_data.outline_resolve_sh) { + /* Outline */ + e_data.outline_prepass_sh = DRW_shader_create_3D(datatoc_object_outline_prepass_frag_glsl, NULL); + e_data.outline_resolve_sh = DRW_shader_create_fullscreen(datatoc_object_outline_resolve_frag_glsl, NULL); - } - if (!e_data.outline_resolve_aa_sh) { e_data.outline_resolve_aa_sh = DRW_shader_create_with_lib( datatoc_common_fullscreen_vert_glsl, NULL, datatoc_object_outline_resolve_frag_glsl, datatoc_common_fxaa_lib_glsl, "#define FXAA_ALPHA\n" "#define USE_FXAA\n"); - } - if (!e_data.outline_detect_sh) { - e_data.outline_detect_sh = DRW_shader_create_fullscreen(datatoc_object_outline_detect_frag_glsl, NULL); - } + e_data.outline_detect_sh = DRW_shader_create_with_lib( + datatoc_common_fullscreen_vert_glsl, NULL, + datatoc_object_outline_detect_frag_glsl, + datatoc_common_globals_lib_glsl, + NULL); - if (!e_data.outline_fade_sh) { e_data.outline_fade_sh = DRW_shader_create_fullscreen(datatoc_object_outline_expand_frag_glsl, NULL); - } - if (!e_data.object_empty_image_sh) { + /* Empty images */ e_data.object_empty_image_sh = DRW_shader_create_with_lib( datatoc_object_empty_image_vert_glsl, NULL, datatoc_object_empty_image_frag_glsl, datatoc_common_globals_lib_glsl, NULL); - } - if (!e_data.object_empty_image_wire_sh) { e_data.object_empty_image_wire_sh = DRW_shader_create_with_lib( datatoc_object_empty_image_vert_glsl, NULL, datatoc_object_empty_image_frag_glsl, datatoc_common_globals_lib_glsl, "#define USE_WIRE\n"); - } - if (!e_data.grid_sh) { + /* Grid */ e_data.grid_sh = DRW_shader_create_with_lib( datatoc_object_grid_vert_glsl, NULL, datatoc_object_grid_frag_glsl, datatoc_common_globals_lib_glsl, NULL); - } - if (!e_data.part_prim_sh) { + /* Particles */ e_data.part_prim_sh = DRW_shader_create( datatoc_object_particle_prim_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl, NULL); - } - if (!e_data.part_axis_sh) { e_data.part_axis_sh = DRW_shader_create( datatoc_object_particle_prim_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl, "#define USE_AXIS\n"); - } - if (!e_data.part_dot_sh) { e_data.part_dot_sh = DRW_shader_create( datatoc_object_particle_dot_vert_glsl, NULL, datatoc_object_particle_dot_frag_glsl, NULL); - } - if (!e_data.lightprobe_grid_sh) { + /* Lightprobes */ e_data.lightprobe_grid_sh = DRW_shader_create( datatoc_object_lightprobe_grid_vert_glsl, NULL, datatoc_gpu_shader_uniform_color_frag_glsl, NULL); } @@ -558,6 +568,7 @@ static void OBJECT_engine_free(void) MEM_SAFE_FREE(e_data.particle_format); MEM_SAFE_FREE(e_data.empty_image_format); MEM_SAFE_FREE(e_data.empty_image_wire_format); + DRW_SHADER_FREE_SAFE(e_data.outline_prepass_sh); DRW_SHADER_FREE_SAFE(e_data.outline_resolve_sh); DRW_SHADER_FREE_SAFE(e_data.outline_resolve_aa_sh); DRW_SHADER_FREE_SAFE(e_data.outline_detect_sh); @@ -571,10 +582,10 @@ static void OBJECT_engine_free(void) DRW_SHADER_FREE_SAFE(e_data.lightprobe_grid_sh); } -static DRWShadingGroup *shgroup_outline(DRWPass *pass, const float col[4], GPUShader *sh) +static DRWShadingGroup *shgroup_outline(DRWPass *pass, const int *ofs, GPUShader *sh) { DRWShadingGroup *grp = DRW_shgroup_create(sh, pass); - DRW_shgroup_uniform_vec4(grp, "color", col, 1); + DRW_shgroup_uniform_int(grp, "baseId", ofs, 1); return grp; } @@ -602,12 +613,19 @@ static DRWShadingGroup *shgroup_theme_id_to_outline_or( { switch (theme_id) { case TH_ACTIVE: + stl->g_data->id_ofs_active++; return stl->g_data->outlines_active; case TH_SELECT: + stl->g_data->id_ofs_select++; return stl->g_data->outlines_select; - case TH_GROUP_ACTIVE: + case TH_GROUP: + stl->g_data->id_ofs_select_group++; return stl->g_data->outlines_select_group; + case TH_GROUP_ACTIVE: + stl->g_data->id_ofs_active_group++; + return stl->g_data->outlines_active_group; case TH_TRANSFORM: + stl->g_data->id_ofs_transform++; return stl->g_data->outlines_transform; default: return fallback; @@ -622,8 +640,10 @@ static DRWShadingGroup *shgroup_theme_id_to_wire_or( return stl->g_data->wire_active; case TH_SELECT: return stl->g_data->wire_select; - case TH_GROUP_ACTIVE: + case TH_GROUP: return stl->g_data->wire_select_group; + case TH_GROUP_ACTIVE: + return stl->g_data->wire_active_group; case TH_TRANSFORM: return stl->g_data->wire_transform; default: @@ -639,8 +659,10 @@ static DRWShadingGroup *shgroup_theme_id_to_point_or( return stl->g_data->points_active; case TH_SELECT: return stl->g_data->points_select; - case TH_GROUP_ACTIVE: + case TH_GROUP: return stl->g_data->points_select_group; + case TH_GROUP_ACTIVE: + return stl->g_data->points_active_group; case TH_TRANSFORM: return stl->g_data->points_transform; default: @@ -786,18 +808,24 @@ static void OBJECT_cache_init(void *vedata) DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE; psl->outlines = DRW_pass_create("Outlines Depth Pass", state); - GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + GPUShader *sh = e_data.outline_prepass_sh; /* Select */ - stl->g_data->outlines_select = shgroup_outline(psl->outlines, ts.colorSelect, sh); - stl->g_data->outlines_select_group = shgroup_outline(psl->outlines, ts.colorGroupActive, sh); + stl->g_data->outlines_select = shgroup_outline(psl->outlines, &stl->g_data->id_ofs_select, sh); + stl->g_data->outlines_select_group = shgroup_outline(psl->outlines, &stl->g_data->id_ofs_select_group, sh); /* Transform */ - stl->g_data->outlines_transform = shgroup_outline(psl->outlines, ts.colorTransform, sh); + stl->g_data->outlines_transform = shgroup_outline(psl->outlines, &stl->g_data->id_ofs_transform, sh); /* Active */ - stl->g_data->outlines_active = shgroup_outline(psl->outlines, ts.colorActive, sh); - stl->g_data->outlines_active_group = shgroup_outline(psl->outlines, ts.colorGroupActive, sh); + stl->g_data->outlines_active = shgroup_outline(psl->outlines, &stl->g_data->id_ofs_active, sh); + stl->g_data->outlines_active_group = shgroup_outline(psl->outlines, &stl->g_data->id_ofs_active_group, sh); + + stl->g_data->id_ofs_select = 0; + stl->g_data->id_ofs_select_group = 0; + stl->g_data->id_ofs_active = 0; + stl->g_data->id_ofs_active_group = 0; + stl->g_data->id_ofs_transform = 0; } { @@ -822,10 +850,12 @@ static void OBJECT_cache_init(void *vedata) psl->outlines_search = DRW_pass_create("Outlines Detect Pass", state); DRWShadingGroup *grp = DRW_shgroup_create(e_data.outline_detect_sh, psl->outlines_search); - DRW_shgroup_uniform_texture_ref(grp, "outlineColor", &e_data.outlines_color_tx); + DRW_shgroup_uniform_texture_ref(grp, "outlineId", &e_data.outlines_id_tx); DRW_shgroup_uniform_texture_ref(grp, "outlineDepth", &e_data.outlines_depth_tx); DRW_shgroup_uniform_texture_ref(grp, "sceneDepth", &dtxl->depth); + DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo); DRW_shgroup_uniform_float(grp, "alphaOcclu", &alphaOcclu, 1); + DRW_shgroup_uniform_int(grp, "idOffsets", &stl->g_data->id_ofs_active, 5); DRW_shgroup_call_add(grp, quad, NULL); psl->outlines_expand = DRW_pass_create("Outlines Expand Pass", state); @@ -2038,6 +2068,7 @@ static void OBJECT_draw_scene(void *vedata) OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl; OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl; OBJECT_FramebufferList *fbl = ((OBJECT_Data *)vedata)->fbl; + OBJECT_PrivateData *g_data = stl->g_data; DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); @@ -2045,7 +2076,18 @@ static void OBJECT_draw_scene(void *vedata) if (DRW_state_is_fbo()) { DRW_stats_group_start("Outlines"); - + + int id_ct_select = g_data->id_ofs_select; + int id_ct_select_group = g_data->id_ofs_select_group; + int id_ct_active = g_data->id_ofs_active; + int id_ct_active_group = g_data->id_ofs_active_group; + + g_data->id_ofs_active = 1; + g_data->id_ofs_active_group = g_data->id_ofs_active + id_ct_active + 1; + g_data->id_ofs_select = g_data->id_ofs_active_group + id_ct_active_group + 1; + g_data->id_ofs_select_group = g_data->id_ofs_select + id_ct_select + 1; + g_data->id_ofs_transform = g_data->id_ofs_select_group + id_ct_select_group + 1; + /* Render filled polygon on a separate framebuffer */ GPU_framebuffer_bind(fbl->outlines_fb); GPU_framebuffer_clear_color_depth(fbl->outlines_fb, clearcol, 1.0f); diff --git a/source/blender/draw/modes/pose_mode.c b/source/blender/draw/modes/pose_mode.c index 749c3e71368..1d3d31ab54d 100644 --- a/source/blender/draw/modes/pose_mode.c +++ b/source/blender/draw/modes/pose_mode.c @@ -139,7 +139,9 @@ bool DRW_pose_mode_armature(Object *ob, Object *active_ob) const DRWContextState *draw_ctx = DRW_context_state_get(); /* Pode armature is handled by pose mode engine. */ - if ((ob == active_ob) && ((draw_ctx->object_mode & OB_MODE_POSE) != 0)) { + if (((ob == active_ob) || (ob->base_flag & BASE_SELECTED)) && + ((draw_ctx->object_mode & OB_MODE_POSE) != 0)) + { return true; } diff --git a/source/blender/draw/modes/sculpt_mode.c b/source/blender/draw/modes/sculpt_mode.c index 65f4653591f..4fb4464df06 100644 --- a/source/blender/draw/modes/sculpt_mode.c +++ b/source/blender/draw/modes/sculpt_mode.c @@ -202,7 +202,7 @@ static void SCULPT_cache_populate(void *vedata, Object *ob) * but this avoids waiting on first stroke) */ Scene *scene = draw_ctx->scene; - BKE_sculpt_update_mesh_elements(&draw_ctx->eval_ctx, scene, scene->toolsettings->sculpt, ob, false, false); + BKE_sculpt_update_mesh_elements(draw_ctx->depsgraph, scene, scene->toolsettings->sculpt, ob, false, false); } PBVH *pbvh = ob->sculpt->pbvh; diff --git a/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl index dc0ea938436..6b0f66d7c94 100644 --- a/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl +++ b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl @@ -3,77 +3,67 @@ in vec4 uvcoordsvar; out vec4 FragColor; -uniform sampler2D outlineColor; +uniform usampler2D outlineId; uniform sampler2D outlineDepth; uniform sampler2D sceneDepth; +uniform int idOffsets[5]; + uniform float alphaOcclu; uniform vec2 viewportSize; -void search_outline(ivec2 uv, vec4 ref_col, inout bool ref_occlu, inout bool outline) +vec4 convert_id_to_color(int id) { - if (!outline) { - vec4 color = texelFetch(outlineColor, uv, 0).rgba; - if (color != ref_col) { - outline = true; - } - else { - float depth = texelFetch(outlineDepth, uv, 0).r; - float scene_depth = texelFetch(sceneDepth, uv, 0).r; - bool occlu = (depth > scene_depth); - - if (occlu != ref_occlu && !ref_occlu) { - outline = true; - } - } + if (id == 0) { + return vec4(0.0); + } + if (id < idOffsets[1]) { + return colorActive; + } + else if (id < idOffsets[2]) { + return colorGroupActive; + } + else if (id < idOffsets[3]) { + return colorSelect; + } + else if (id < idOffsets[4]) { + return colorGroup; + } + else { + return colorTransform; } } +const ivec2 ofs[4] = ivec2[4]( + ivec2( 1, 0), ivec2( 0, 1), + ivec2(-1, 0), ivec2( 0, -1) +); + void main() { - ivec2 uv = ivec2(gl_FragCoord.xy); - - vec4 color[4]; - /* Idea : Use a 16bit ID to identify the color - * and store the colors in a UBO. And fetch all ids - * for discontinuity check with one textureGather \o/ */ - vec4 ref_col = texelFetch(outlineColor, uv, 0).rgba; - color[0] = texelFetchOffset(outlineColor, uv, 0, ivec2( 1, 0)).rgba; - color[1] = texelFetchOffset(outlineColor, uv, 0, ivec2( 0, 1)).rgba; - color[2] = texelFetchOffset(outlineColor, uv, 0, ivec2(-1, 0)).rgba; - color[3] = texelFetchOffset(outlineColor, uv, 0, ivec2( 0, -1)).rgba; - - /* TODO GATHER */ - vec4 depths; - float depth = texelFetch(outlineDepth, uv, 0).r; - depths.x = texelFetchOffset(outlineDepth, uv, 0, ivec2( 1, 0)).r; - depths.y = texelFetchOffset(outlineDepth, uv, 0, ivec2( 0, 1)).r; - depths.z = texelFetchOffset(outlineDepth, uv, 0, ivec2(-1, 0)).r; - depths.w = texelFetchOffset(outlineDepth, uv, 0, ivec2( 0, -1)).r; - - vec4 scene_depths; - float scene_depth = texelFetch(sceneDepth, uv, 0).r; - scene_depths.x = texelFetchOffset(sceneDepth, uv, 0, ivec2( 1, 0)).r; - scene_depths.y = texelFetchOffset(sceneDepth, uv, 0, ivec2( 0, 1)).r; - scene_depths.z = texelFetchOffset(sceneDepth, uv, 0, ivec2(-1, 0)).r; - scene_depths.w = texelFetchOffset(sceneDepth, uv, 0, ivec2( 0, -1)).r; + ivec2 texel = ivec2(gl_FragCoord.xy); + vec2 uv = gl_FragCoord.xy / vec2(textureSize(outlineId, 0).xy); - bool ref_occlu = (depth > scene_depth); - bool outline = false; - -#if 1 - bvec4 occlu = (!ref_occlu) ? notEqual(greaterThan(depths, scene_depths), bvec4(ref_occlu)) : bvec4(false); - outline = (!outline) ? (color[0] != ref_col) || occlu.x : true; - outline = (!outline) ? (color[1] != ref_col) || occlu.y : true; - outline = (!outline) ? (color[2] != ref_col) || occlu.z : true; - outline = (!outline) ? (color[3] != ref_col) || occlu.w : true; + uvec4 id; + uint ref_id = texelFetch(outlineId, texel, 0).r; +#if 0 /* commented out until being tested */ + id = textureGatherOffsets(outlineId, uv, ofs); #else - search_outline(uv + ivec2( 1, 0), ref_col, ref_occlu, outline); - search_outline(uv + ivec2( 0, 1), ref_col, ref_occlu, outline); - search_outline(uv + ivec2(-1, 0), ref_col, ref_occlu, outline); - search_outline(uv + ivec2( 0, -1), ref_col, ref_occlu, outline); + id.x = texelFetchOffset(outlineId, texel, 0, ofs[0]).r; + id.y = texelFetchOffset(outlineId, texel, 0, ofs[1]).r; + id.z = texelFetchOffset(outlineId, texel, 0, ofs[2]).r; + id.w = texelFetchOffset(outlineId, texel, 0, ofs[3]).r; #endif - FragColor = ref_col; - FragColor.a *= (outline) ? (ref_occlu) ? alphaOcclu : 1.0 : 0.0; + float ref_depth = texelFetch(outlineDepth, texel, 0).r; + float scene_depth = texelFetch(sceneDepth, texel, 0).r; + + /* Avoid bad cases of zfighting for occlusion only. */ + const float epsilon = 3.0 / 8388608.0; + bool occluded = (ref_depth > scene_depth + epsilon); + bool outline = any(notEqual(id, uvec4(ref_id))); + + FragColor = convert_id_to_color(int(ref_id)); + FragColor.a *= (occluded) ? alphaOcclu : 1.0; + FragColor.a = (outline) ? FragColor.a : 0.0; } diff --git a/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl b/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl new file mode 100644 index 00000000000..776adb787ad --- /dev/null +++ b/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl @@ -0,0 +1,10 @@ +uniform int callId; +uniform int baseId; + +/* using uint because 16bit uint can contain more ids than int. */ +out uint outId; + +void main() +{ + outId = uint(baseId + callId); +} diff --git a/source/blender/editors/armature/CMakeLists.txt b/source/blender/editors/armature/CMakeLists.txt index 4301fe6582f..8a40ea3b383 100644 --- a/source/blender/editors/armature/CMakeLists.txt +++ b/source/blender/editors/armature/CMakeLists.txt @@ -28,6 +28,7 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager + ../../../../intern/clog ../../../../intern/guardedalloc ../../../../intern/eigen ../../../../intern/glew-mx diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index cb072bee345..36dded5ed5e 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -1074,7 +1074,6 @@ void ARMATURE_OT_bone_primitive_add(wmOperatorType *ot) static int armature_subdivide_exec(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); - bArmature *arm = obedit->data; EditBone *newbone, *tbone; int cuts, i; @@ -1083,7 +1082,7 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op) /* loop over all editable bones */ // XXX the old code did this in reverse order though! - CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, selected_editable_bones, bArmature *, arm) { for (i = cuts + 1; i > 1; i--) { /* compute cut ratio first */ diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c index 75b80627dff..6a94443660b 100644 --- a/source/blender/editors/armature/armature_edit.c +++ b/source/blender/editors/armature/armature_edit.c @@ -48,6 +48,7 @@ #include "BKE_armature.h" #include "BKE_constraint.h" #include "BKE_context.h" +#include "BKE_layer.h" #include "BKE_global.h" #include "BKE_report.h" #include "BKE_object.h" @@ -630,25 +631,39 @@ static void fill_add_joint(EditBone *ebo, short eb_tail, ListBase *points) /* bone adding between selected joints */ static int armature_fill_bones_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - bArmature *arm = (obedit) ? obedit->data : NULL; + Object *obedit_active = CTX_data_edit_object(C); Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); ListBase points = {NULL, NULL}; EditBone *newbone = NULL; int count; + bool mixed_object_error = false; /* sanity checks */ - if (ELEM(NULL, obedit, arm)) + if (ELEM(NULL, obedit_active, obedit_active->data)) { return OPERATOR_CANCELLED; + } /* loop over all bones, and only consider if visible */ - CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones) + bArmature *arm = NULL; + CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, visible_bones, bArmature *, arm_iter) { - if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) + bool check = false; + if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) { fill_add_joint(ebone, 0, &points); - if (ebone->flag & BONE_TIPSEL) + check = true; + } + if (ebone->flag & BONE_TIPSEL) { fill_add_joint(ebone, 1, &points); + check = true; + } + + if (check) { + if (arm && (arm != arm_iter)) { + mixed_object_error = true; + } + arm = arm_iter; + } } CTX_DATA_END; @@ -658,12 +673,30 @@ static int armature_fill_bones_exec(bContext *C, wmOperator *op) * 3+) error (a smarter method involving finding chains needs to be worked out */ count = BLI_listbase_count(&points); - + if (count == 0) { BKE_report(op->reports, RPT_ERROR, "No joints selected"); return OPERATOR_CANCELLED; } - else if (count == 1) { + else if (mixed_object_error) { + BKE_report(op->reports, RPT_ERROR, "Bones for different objects selected"); + BLI_freelistN(&points); + return OPERATOR_CANCELLED; + } + + Object *obedit = NULL; + { + ViewLayer *view_layer = CTX_data_view_layer(C); + FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_EDIT, ob_iter) { + if (ob_iter->data == arm) { + obedit = ob_iter; + } + } + FOREACH_OBJECT_IN_MODE_END; + } + BLI_assert(obedit != NULL); + + if (count == 1) { EditBonePoint *ebp; float curs[3]; @@ -1301,38 +1334,49 @@ static bool armature_delete_ebone_cb(const char *bone_name, void *arm_p) /* only editmode! */ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op)) { - bArmature *arm; EditBone *curBone, *ebone_next; - Object *obedit = CTX_data_edit_object(C); - bool changed = false; - arm = obedit->data; + bool changed_multi = false; /* cancel if nothing selected */ if (CTX_DATA_COUNT(C, selected_bones) == 0) return OPERATOR_CANCELLED; - - armature_select_mirrored(arm); - - BKE_pose_channels_remove(obedit, armature_delete_ebone_cb, arm); - - for (curBone = arm->edbo->first; curBone; curBone = ebone_next) { - ebone_next = curBone->next; - if (arm->layer & curBone->layer) { - if (curBone->flag & BONE_SELECTED) { - if (curBone == arm->act_edbone) arm->act_edbone = NULL; - ED_armature_ebone_remove(arm, curBone); - changed = true; + + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + bArmature *arm = obedit->data; + bool changed = false; + + armature_select_mirrored(arm); + + BKE_pose_channels_remove(obedit, armature_delete_ebone_cb, arm); + + for (curBone = arm->edbo->first; curBone; curBone = ebone_next) { + ebone_next = curBone->next; + if (arm->layer & curBone->layer) { + if (curBone->flag & BONE_SELECTED) { + if (curBone == arm->act_edbone) arm->act_edbone = NULL; + ED_armature_ebone_remove(arm, curBone); + changed = true; + } } } + + if (changed) { + changed_multi = true; + + ED_armature_edit_sync_selection(arm->edbo); + BKE_pose_tag_recalc(CTX_data_main(C), obedit->pose); + + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); + } } - - if (!changed) - return OPERATOR_CANCELLED; - - ED_armature_edit_sync_selection(arm->edbo); - BKE_pose_tag_recalc(CTX_data_main(C), obedit->pose); - WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); + if (!changed_multi) { + return OPERATOR_CANCELLED; + } return OPERATOR_FINISHED; } diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index 0ba720a17d0..575d1597cc4 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -248,10 +248,15 @@ void armature_select_mirrored_ex(struct bArmature *arm, const int flag); void armature_select_mirrored(struct bArmature *arm); void armature_tag_unselect(struct bArmature *arm); -void *get_nearest_bone(struct bContext *C, const int xy[2], bool findunsel); +void *get_nearest_bone( + struct bContext *C, const int xy[2], bool findunsel, + struct Base **r_base); + void *get_bone_from_selectbuffer( - struct Base *base, struct Object *obedit, const unsigned int *buffer, short hits, - bool findunsel, bool do_nearest); + struct Base **bases, uint bases_len, + bool is_editmode, const unsigned int *buffer, short hits, + bool findunsel, bool do_nearest, + struct Base **r_base); int bone_looper(struct Object *ob, struct Bone *bone, void *data, int (*bone_func)(struct Object *, struct Bone *, void *)); diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c index 587cafa6d48..6ad33125a25 100644 --- a/source/blender/editors/armature/armature_select.c +++ b/source/blender/editors/armature/armature_select.c @@ -29,6 +29,8 @@ * \ingroup edarmature */ +#include "MEM_guardedalloc.h" + #include "DNA_armature_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -40,6 +42,7 @@ #include "BKE_context.h" #include "BKE_action.h" #include "BKE_report.h" +#include "BKE_layer.h" #include "BIF_gl.h" @@ -63,26 +66,84 @@ /* **************** PoseMode & EditMode Selection Buffer Queries *************************** */ -/* only for opengl selection indices */ -Bone *ED_armature_bone_find_index(Object *ob, int index) +Base *ED_armature_base_and_ebone_from_select_buffer( + Base **bases, uint bases_len, int hit, EditBone **r_ebone) { - bPoseChannel *pchan; - if (ob->pose == NULL) return NULL; - index >>= 16; // bone selection codes use left 2 bytes - - pchan = BLI_findlink(&ob->pose->chanbase, index); - return pchan ? pchan->bone : NULL; + const uint hit_object = hit & 0xFFFF; + Base *base = NULL; + EditBone *ebone = NULL; + /* TODO(campbell): optimize, eg: sort & binary search. */ + for (uint base_index = 0; base_index < bases_len; base_index++) { + if (bases[base_index]->object->select_color == hit_object) { + base = bases[base_index]; + break; + } + } + if (base != NULL) { + const uint hit_bone = (hit & ~BONESEL_ANY) >> 16; + bArmature *arm = base->object->data; + ebone = BLI_findlink(arm->edbo, hit_bone); + } + *r_ebone = ebone; + return base; +} + +Object *ED_armature_object_and_ebone_from_select_buffer( + Object **objects, uint objects_len, int hit, EditBone **r_ebone) +{ + const uint hit_object = hit & 0xFFFF; + Object *ob = NULL; + EditBone *ebone = NULL; + /* TODO(campbell): optimize, eg: sort & binary search. */ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + if (objects[ob_index]->select_color == hit_object) { + ob = objects[ob_index]; + break; + } + } + if (ob != NULL) { + const uint hit_bone = (hit & ~BONESEL_ANY) >> 16; + bArmature *arm = ob->data; + ebone = BLI_findlink(arm->edbo, hit_bone); + } + *r_ebone = ebone; + return ob; +} + +Base *ED_armature_base_and_bone_from_select_buffer( + Base **bases, uint bases_len, int hit, Bone **r_bone) +{ + const uint hit_object = hit & 0xFFFF; + Base *base = NULL; + Bone *bone = NULL; + /* TODO(campbell): optimize, eg: sort & binary search. */ + for (uint base_index = 0; base_index < bases_len; base_index++) { + if (bases[base_index]->object->select_color == hit_object) { + base = bases[base_index]; + break; + } + } + if (base != NULL) { + if (base->object->pose != NULL) { + const uint hit_bone = (hit & ~BONESEL_ANY) >> 16; + bPoseChannel *pchan = BLI_findlink(&base->object->pose->chanbase, hit_bone);; + bone = pchan ? pchan->bone : NULL; + } + } + *r_bone = bone; + return base; } /* See if there are any selected bones in this buffer */ /* only bones from base are checked on */ void *get_bone_from_selectbuffer( - Base *base, Object *obedit, const unsigned int *buffer, short hits, - bool findunsel, bool do_nearest) + Base **bases, uint bases_len, bool is_editmode, const unsigned int *buffer, short hits, + bool findunsel, bool do_nearest, Base **r_base) { Bone *bone; EditBone *ebone; void *firstunSel = NULL, *firstSel = NULL, *data; + Base *firstunSel_base = NULL, *firstSel_base = NULL; unsigned int hitresult; short i; bool takeNext = false; @@ -93,15 +154,14 @@ void *get_bone_from_selectbuffer( if (!(hitresult & BONESEL_NOSEL)) { if (hitresult & BONESEL_ANY) { /* to avoid including objects in selection */ + Base *base = NULL; bool sel; - + hitresult &= ~(BONESEL_ANY); /* Determine what the current bone is */ - if (obedit == NULL || base->object != obedit) { - /* no singular posemode, so check for correct object */ - if (base->object->select_color == (hitresult & 0xFFFF)) { - bone = ED_armature_bone_find_index(base->object, hitresult); - + if (is_editmode == false) { + base = ED_armature_base_and_bone_from_select_buffer(bases, bases_len, hitresult, &bone); + if (bone != NULL) { if (findunsel) sel = (bone->flag & BONE_SELECTED); else @@ -115,14 +175,12 @@ void *get_bone_from_selectbuffer( } } else { - bArmature *arm = obedit->data; - - ebone = BLI_findlink(arm->edbo, hitresult); + base = ED_armature_base_and_ebone_from_select_buffer(bases, bases_len, hitresult, &ebone); if (findunsel) sel = (ebone->flag & BONE_SELECTED); else sel = !(ebone->flag & BONE_SELECTED); - + data = ebone; } @@ -131,11 +189,15 @@ void *get_bone_from_selectbuffer( if (do_nearest) { if (minsel > buffer[4 * i + 1]) { firstSel = data; + firstSel_base = base; minsel = buffer[4 * i + 1]; } } else { - if (!firstSel) firstSel = data; + if (!firstSel) { + firstSel = data; + firstSel_base = base; + } takeNext = 1; } } @@ -143,12 +205,19 @@ void *get_bone_from_selectbuffer( if (do_nearest) { if (minunsel > buffer[4 * i + 1]) { firstunSel = data; + firstunSel_base = base; minunsel = buffer[4 * i + 1]; } } else { - if (!firstunSel) firstunSel = data; - if (takeNext) return data; + if (!firstunSel) { + firstunSel = data; + firstunSel_base = base; + } + if (takeNext) { + *r_base = base; + return data; + } } } } @@ -156,34 +225,50 @@ void *get_bone_from_selectbuffer( } } - if (firstunSel) + if (firstunSel) { + *r_base = firstunSel_base; return firstunSel; - else + } + else { + *r_base = firstSel_base; return firstSel; + } } /* used by posemode as well editmode */ /* only checks scene->basact! */ /* x and y are mouse coords (area space) */ -void *get_nearest_bone(bContext *C, const int xy[2], bool findunsel) +void *get_nearest_bone( + bContext *C, const int xy[2], bool findunsel, + Base **r_base) { - EvaluationContext eval_ctx; ViewContext vc; rcti rect; unsigned int buffer[MAXPICKBUF]; short hits; - CTX_data_eval_ctx(C, &eval_ctx); ED_view3d_viewcontext_init(C, &vc); // rect.xmin = ... mouseco! rect.xmin = rect.xmax = xy[0]; rect.ymin = rect.ymax = xy[1]; - hits = view3d_opengl_select(&eval_ctx, &vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST); + hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST); + + *r_base = NULL; if (hits > 0) { - return get_bone_from_selectbuffer(vc.view_layer->basact, vc.obedit, buffer, hits, findunsel, true); + uint bases_len = 0; + Base **bases = BKE_view_layer_array_from_bases_in_mode( + vc.view_layer, &bases_len, { + .object_mode = vc.obedit ? OB_MODE_EDIT : OB_MODE_POSE, + .no_dup_data = true}); + + void *bone = get_bone_from_selectbuffer( + bases, bases_len, vc.obedit != NULL, buffer, hits, findunsel, true, r_base); + + MEM_freeN(bases); + return bone; } return NULL; } @@ -197,16 +282,17 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv bArmature *arm; EditBone *bone, *curBone, *next; const bool extend = RNA_boolean_get(op->ptr, "extend"); - Object *obedit = CTX_data_edit_object(C); - arm = obedit->data; view3d_operator_needs_opengl(C); - bone = get_nearest_bone(C, event->mval, !extend); + Base *base = NULL; + bone = get_nearest_bone(C, event->mval, !extend, &base); if (!bone) return OPERATOR_CANCELLED; + arm = base->object->data; + /* Select parents */ for (curBone = bone; curBone; curBone = next) { if ((curBone->flag & BONE_UNSELECTABLE) == 0) { @@ -249,7 +335,7 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv ED_armature_edit_sync_selection(arm->edbo); - WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, base->object); return OPERATOR_FINISHED; } @@ -294,8 +380,9 @@ static int selectbuffer_ret_hits_5(unsigned int *buffer, const int hits12, const /* does bones and points */ /* note that BONE ROOT only gets drawn for root bones (or without IK) */ static EditBone *get_nearest_editbonepoint( - const EvaluationContext *eval_ctx, ViewContext *vc, - bool findunsel, bool use_cycle, int *r_selmask) + ViewContext *vc, + bool findunsel, bool use_cycle, + Base **r_base, int *r_selmask) { bArmature *arm = (bArmature *)vc->obedit->data; EditBone *ebone_next_act = arm->act_edbone; @@ -347,7 +434,7 @@ static EditBone *get_nearest_editbonepoint( view3d_opengl_select_cache_begin(); BLI_rcti_init_pt_radius(&rect, vc->mval, 12); - hits12 = view3d_opengl_select(eval_ctx, vc, buffer, MAXPICKBUF, &rect, select_mode); + hits12 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode); if (hits12 == 1) { hits = selectbuffer_ret_hits_12(buffer, hits12); goto cache_end; @@ -357,7 +444,7 @@ static EditBone *get_nearest_editbonepoint( offs = 4 * hits12; BLI_rcti_init_pt_radius(&rect, vc->mval, 5); - hits5 = view3d_opengl_select(eval_ctx, vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode); + hits5 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode); if (hits5 == 1) { hits = selectbuffer_ret_hits_5(buffer, hits12, hits5); @@ -371,9 +458,11 @@ static EditBone *get_nearest_editbonepoint( cache_end: view3d_opengl_select_cache_end(); + uint bases_len; + Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(vc->view_layer, &bases_len); + /* See if there are any selected bones in this group */ if (hits > 0) { - if (hits == 1) { if (!(buffer[3] & BONESEL_NOSEL)) besthitresult = buffer[3]; @@ -382,10 +471,11 @@ cache_end: for (i = 0; i < hits; i++) { hitresult = buffer[3 + (i * 4)]; if (!(hitresult & BONESEL_NOSEL)) { + Base *base = NULL; + base = ED_armature_base_and_ebone_from_select_buffer(bases, bases_len, hitresult, &ebone); + arm = base->object->data; + int dep; - - ebone = BLI_findlink(arm->edbo, hitresult & ~BONESEL_ANY); - /* clicks on bone points get advantage */ if (hitresult & (BONESEL_ROOT | BONESEL_TIP)) { /* but also the unselected one */ @@ -425,11 +515,13 @@ cache_end: } } } - + if (!(besthitresult & BONESEL_NOSEL)) { - - ebone = BLI_findlink(arm->edbo, besthitresult & ~BONESEL_ANY); - + Base *base = NULL; + base = ED_armature_base_and_ebone_from_select_buffer(bases, bases_len, hitresult, &ebone); + arm = base->object->data; + *r_base = base; + *r_selmask = 0; if (besthitresult & BONESEL_ROOT) *r_selmask |= BONE_ROOTSEL; @@ -441,6 +533,7 @@ cache_end: } } *r_selmask = 0; + *r_base = NULL; return NULL; } @@ -469,6 +562,23 @@ void ED_armature_edit_deselect_all_visible(Object *obedit) ED_armature_edit_sync_selection(arm->edbo); } + +void ED_armature_edit_deselect_all_multi(struct Object **objects, uint objects_len) +{ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + ED_armature_edit_deselect_all(obedit); + } +} + +void ED_armature_edit_deselect_all_visible_multi(struct Object **objects, uint objects_len) +{ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + ED_armature_edit_deselect_all_visible(obedit); + } +} + /* accounts for connected parents */ static int ebone_select_flag(EditBone *ebone) { @@ -483,13 +593,11 @@ static int ebone_select_flag(EditBone *ebone) /* context: editmode armature in view3d */ bool ED_armature_edit_select_pick(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) { - Object *obedit = CTX_data_edit_object(C); - EvaluationContext eval_ctx; ViewContext vc; EditBone *nearBone = NULL; int selmask; + Base *basact = NULL; - CTX_data_eval_ctx(C, &eval_ctx); ED_view3d_viewcontext_init(C, &vc); vc.mval[0] = mval[0]; vc.mval[1] = mval[1]; @@ -498,12 +606,16 @@ bool ED_armature_edit_select_pick(bContext *C, const int mval[2], bool extend, b return true; } - nearBone = get_nearest_editbonepoint(&eval_ctx, &vc, true, true, &selmask); + nearBone = get_nearest_editbonepoint(&vc, true, true, &basact, &selmask); if (nearBone) { - bArmature *arm = obedit->data; + ED_view3d_viewcontext_init_object(&vc, basact->object); + bArmature *arm = vc.obedit->data; if (!extend && !deselect && !toggle) { - ED_armature_edit_deselect_all(obedit); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc.view_layer, &objects_len); + ED_armature_edit_deselect_all_multi(objects, objects_len); + MEM_freeN(objects); } /* by definition the non-root connected bones have no root point drawn, @@ -581,9 +693,14 @@ bool ED_armature_edit_select_pick(bContext *C, const int mval[2], bool extend, b if (ebone_select_flag(nearBone)) { arm->act_edbone = nearBone; } + + if (vc.view_layer->basact != basact) { + vc.view_layer->basact = basact; + WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, vc.scene); + } } - - WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, vc.obedit); + + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, basact->object); return true; } @@ -1296,17 +1413,23 @@ static int armature_shortest_path_pick_invoke(bContext *C, wmOperator *op, const EditBone *ebone_isect_parent = NULL; EditBone *ebone_isect_child[2]; bool changed; + Base *base_dst = NULL; view3d_operator_needs_opengl(C); ebone_src = arm->act_edbone; - ebone_dst = get_nearest_bone(C, event->mval, false); + ebone_dst = get_nearest_bone(C, event->mval, false, &base_dst); /* fallback to object selection */ if (ELEM(NULL, ebone_src, ebone_dst) || (ebone_src == ebone_dst)) { return OPERATOR_PASS_THROUGH; } + if (base_dst && base_dst->object != obedit) { + /* Disconnected, ignore. */ + return OPERATOR_CANCELLED; + } + ebone_isect_child[0] = ebone_src; ebone_isect_child[1] = ebone_dst; diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c index e25056a7a4a..c98eb9218cc 100644 --- a/source/blender/editors/armature/armature_skinning.c +++ b/source/blender/editors/armature/armature_skinning.c @@ -251,7 +251,7 @@ static void envelope_bone_weighting( } static void add_verts_to_dgroups( - ReportList *reports, const EvaluationContext *eval_ctx, Scene *scene, Object *ob, Object *par, + ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par, int heat, const bool mirror) { /* This functions implements the automatic computation of vertex group @@ -377,7 +377,7 @@ static void add_verts_to_dgroups( if (wpmode) { /* if in weight paint mode, use final verts from derivedmesh */ - DerivedMesh *dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH); if (dm->foreachMappedVert) { mesh_get_mapped_verts_coords(dm, verts, mesh->totvert); @@ -432,7 +432,7 @@ static void add_verts_to_dgroups( } void ED_object_vgroup_calc_from_armature( - ReportList *reports, const EvaluationContext *eval_ctx, Scene *scene, Object *ob, Object *par, + ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par, const int mode, const bool mirror) { /* Lets try to create some vertex groups @@ -459,6 +459,6 @@ void ED_object_vgroup_calc_from_armature( * that are populated with the vertices for which the * bone is closest. */ - add_verts_to_dgroups(reports, eval_ctx, scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror); + add_verts_to_dgroups(reports, depsgraph, scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror); } } diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index bf6126658af..6b2893780d7 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -911,6 +911,7 @@ static void RIG_reconnectControlBones(RigGraph *rg) /* if we haven't found one yet, look in control bones */ if (ctrl->tail_mode == TL_NONE) { + /* pass */ } } } diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index 26f11f8fd60..4c208ef5411 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -998,7 +998,7 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S * the ideal would be to call this function only at the beginning of the snap operation, * or at the beginning of the operator itself */ struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( - CTX_data_main(C), CTX_data_scene(C), CTX_data_view_layer(C), 0, + CTX_data_main(C), CTX_data_scene(C), 0, CTX_wm_region(C), CTX_wm_view3d(C)); float mvalf[2] = {UNPACK2(dd->mval)}; @@ -1486,7 +1486,7 @@ static int cmpIntersections(const void *i1, const void *i2) /* returns the maximum number of intersections per stroke */ static int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, SK_Stroke *gesture) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ARegion *ar = CTX_wm_region(C); ScrArea *sa = CTX_wm_area(C); View3D *v3d = sa->spacedata.first; @@ -1925,18 +1925,16 @@ static void sk_applyGesture(bContext *C, SK_Sketch *sketch) static bool sk_selectStroke(bContext *C, SK_Sketch *sketch, const int mval[2], const bool extend) { - EvaluationContext eval_ctx; ViewContext vc; rcti rect; unsigned int buffer[MAXPICKBUF]; short hits; - CTX_data_eval_ctx(C, &eval_ctx); ED_view3d_viewcontext_init(C, &vc); BLI_rcti_init_pt_radius(&rect, mval, 5); - hits = view3d_opengl_select(&eval_ctx, &vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST); + hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST); if (hits > 0) { int besthitresult = -1; diff --git a/source/blender/editors/armature/editarmature_undo.c b/source/blender/editors/armature/editarmature_undo.c index 217de06d99b..f6f97af32b9 100644 --- a/source/blender/editors/armature/editarmature_undo.c +++ b/source/blender/editors/armature/editarmature_undo.c @@ -27,26 +27,34 @@ * \ingroup edarmature */ +#include "MEM_guardedalloc.h" + + +#include "CLG_log.h" + #include "DNA_armature_types.h" #include "DNA_object_types.h" -#include "MEM_guardedalloc.h" - #include "BLI_math.h" #include "BLI_array_utils.h" #include "BKE_context.h" +#include "BKE_layer.h" #include "BKE_undo_system.h" #include "DEG_depsgraph.h" #include "ED_armature.h" #include "ED_object.h" +#include "ED_undo.h" #include "ED_util.h" #include "WM_types.h" #include "WM_api.h" +/** We only need this locally. */ +static CLG_LogRef LOG = {"ed.undo.armature"}; + /* -------------------------------------------------------------------- */ /** \name Undo Conversion * \{ */ @@ -121,13 +129,20 @@ static Object *editarm_object_from_context(bContext *C) /* -------------------------------------------------------------------- */ /** \name Implements ED Undo System + * + * \note This is similar for all edit-mode types. * \{ */ -typedef struct ArmatureUndoStep { - UndoStep step; - /* note: will split out into list for multi-object-editmode. */ +typedef struct ArmatureUndoStep_Elem { + struct ArmatureUndoStep_Elem *next, *prev; UndoRefID_Object obedit_ref; UndoArmature data; +} ArmatureUndoStep_Elem; + +typedef struct ArmatureUndoStep { + UndoStep step; + ArmatureUndoStep_Elem *elems; + uint elems_len; } ArmatureUndoStep; static bool armature_undosys_poll(bContext *C) @@ -138,10 +153,24 @@ static bool armature_undosys_poll(bContext *C) static bool armature_undosys_step_encode(struct bContext *C, UndoStep *us_p) { ArmatureUndoStep *us = (ArmatureUndoStep *)us_p; - us->obedit_ref.ptr = editarm_object_from_context(C); - bArmature *arm = us->obedit_ref.ptr->data; - undoarm_from_editarm(&us->data, arm); - us->step.data_size = us->data.undo_size; + + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__); + us->elems_len = objects_len; + + for (uint i = 0; i < objects_len; i++) { + Object *ob = objects[i]; + ArmatureUndoStep_Elem *elem = &us->elems[i]; + + elem->obedit_ref.ptr = ob; + bArmature *arm = elem->obedit_ref.ptr->data; + undoarm_from_editarm(&elem->data, arm); + us->step.data_size += elem->data.undo_size; + } + MEM_freeN(objects); return true; } @@ -152,24 +181,46 @@ static void armature_undosys_step_decode(struct bContext *C, UndoStep *us_p, int BLI_assert(armature_undosys_poll(C)); ArmatureUndoStep *us = (ArmatureUndoStep *)us_p; - Object *obedit = us->obedit_ref.ptr; - bArmature *arm = obedit->data; - undoarm_to_editarm(&us->data, arm); - DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + + for (uint i = 0; i < us->elems_len; i++) { + ArmatureUndoStep_Elem *elem = &us->elems[i]; + Object *obedit = elem->obedit_ref.ptr; + bArmature *arm = obedit->data; + if (arm->edbo == NULL) { + /* Should never fail, may not crash but can give odd behavior. */ + CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", us_p->name, obedit->id.name); + continue; + } + undoarm_to_editarm(&elem->data, arm); + DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + } + + /* The first element is always active */ + ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } static void armature_undosys_step_free(UndoStep *us_p) { ArmatureUndoStep *us = (ArmatureUndoStep *)us_p; - undoarm_free_data(&us->data); + + for (uint i = 0; i < us->elems_len; i++) { + ArmatureUndoStep_Elem *elem = &us->elems[i]; + undoarm_free_data(&elem->data); + } + MEM_freeN(us->elems); } static void armature_undosys_foreach_ID_ref( UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data) { ArmatureUndoStep *us = (ArmatureUndoStep *)us_p; - foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref)); + + for (uint i = 0; i < us->elems_len; i++) { + ArmatureUndoStep_Elem *elem = &us->elems[i]; + foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref)); + } } /* Export for ED_undo_sys. */ diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index 520ecc797aa..80eeda1dd0c 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -178,8 +178,7 @@ static bool pose_has_protected_selected(Object *ob, short warn) void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob) { struct Main *bmain = CTX_data_main(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ListBase targets = {NULL, NULL}; /* set flag to force recalc, then grab the relevant bones to target */ @@ -187,7 +186,7 @@ void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob) animviz_get_object_motionpaths(ob, &targets); /* recalculate paths, then free */ - animviz_calc_motionpaths(&eval_ctx, bmain, scene, &targets); + animviz_calc_motionpaths(depsgraph, bmain, scene, &targets); BLI_freelistN(&targets); } @@ -1015,7 +1014,6 @@ static int armature_bone_layers_invoke(bContext *C, wmOperator *op, const wmEven static int armature_bone_layers_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - bArmature *arm = (ob) ? ob->data : NULL; PointerRNA ptr; int layers[32]; /* hardcoded for now - we can only have 32 armature layers, so this should be fine... */ @@ -1023,7 +1021,7 @@ static int armature_bone_layers_exec(bContext *C, wmOperator *op) RNA_boolean_get_array(op->ptr, "layers", layers); /* set layers of pchans based on the values set in the operator props */ - CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) + CTX_DATA_BEGIN_WITH_ID (C, EditBone *, ebone, selected_editable_bones, bArmature *, arm) { /* get pointer for pchan, and write flags this way */ RNA_pointer_create((ID *)arm, &RNA_EditBone, ebone, &ptr); diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c index 54c40621a14..609281a7bf2 100644 --- a/source/blender/editors/armature/pose_lib.c +++ b/source/blender/editors/armature/pose_lib.c @@ -1080,9 +1080,6 @@ static void poselib_keytag_pose(bContext *C, Scene *scene, tPoseLib_PreviewData static void poselib_preview_apply(bContext *C, wmOperator *op) { tPoseLib_PreviewData *pld = (tPoseLib_PreviewData *)op->customdata; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); /* only recalc pose (and its dependencies) if pose has changed */ if (pld->redraw == PL_PREVIEW_REDRAWALL) { @@ -1107,7 +1104,7 @@ static void poselib_preview_apply(bContext *C, wmOperator *op) if ((pld->arm->flag & ARM_DELAYDEFORM) == 0) DEG_id_tag_update(&pld->ob->id, OB_RECALC_DATA); /* sets recalc flags */ else - BKE_pose_where_is(&eval_ctx, pld->scene, pld->ob); + BKE_pose_where_is(CTX_data_depsgraph(C), pld->scene, pld->ob); } /* do header print - if interactively previewing */ @@ -1598,9 +1595,6 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op) bArmature *arm = pld->arm; bAction *act = pld->act; TimeMarker *marker = pld->marker; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); /* redraw the header so that it doesn't show any of our stuff anymore */ ED_area_headerprint(pld->sa, NULL); @@ -1618,7 +1612,7 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op) if ((arm->flag & ARM_DELAYDEFORM) == 0) DEG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */ else - BKE_pose_where_is(&eval_ctx, scene, ob); + BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob); } else if (pld->state == PL_PREVIEW_CONFIRM) { /* tag poses as appropriate */ @@ -1636,7 +1630,7 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op) //remake_action_ipos(ob->action); } else - BKE_pose_where_is(&eval_ctx, scene, ob); + BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob); } /* Request final redraw of the view. */ diff --git a/source/blender/editors/armature/pose_select.c b/source/blender/editors/armature/pose_select.c index 1c23f71233d..b6f1e101291 100644 --- a/source/blender/editors/armature/pose_select.c +++ b/source/blender/editors/armature/pose_select.c @@ -45,6 +45,7 @@ #include "BKE_context.h" #include "BKE_object.h" #include "BKE_report.h" +#include "BKE_layer.h" #include "DEG_depsgraph.h" @@ -145,7 +146,9 @@ bool ED_armature_pose_select_pick_with_buffer( Object *ob_act = OBACT(view_layer); Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); - nearBone = get_bone_from_selectbuffer(base, obedit, buffer, hits, 1, do_nearest); + /* Callers happen to already get the active base */ + Base *base_dummy = NULL; + nearBone = get_bone_from_selectbuffer(&base, 1, obedit != NULL, buffer, hits, 1, do_nearest, &base_dummy); /* if the bone cannot be affected, don't do anything */ if ((nearBone) && !(nearBone->flag & BONE_UNSELECTABLE)) { @@ -166,7 +169,12 @@ bool ED_armature_pose_select_pick_with_buffer( } if (!extend && !deselect && !toggle) { - ED_pose_deselect_all(ob, SEL_DESELECT, true); + { + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + ED_pose_deselect_all_multi(objects, objects_len, SEL_DESELECT, true); + MEM_SAFE_FREE(objects); + } nearBone->flag |= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); arm->act_bone = nearBone; } @@ -252,6 +260,43 @@ void ED_pose_deselect_all(Object *ob, int select_mode, const bool ignore_visibil } } +static bool ed_pose_is_any_selected(Object *ob, bool ignore_visibility) +{ + bArmature *arm = ob->data; + for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + if (ignore_visibility || PBONE_VISIBLE(arm, pchan->bone)) { + if (pchan->bone->flag & BONE_SELECTED) { + return true; + } + } + } + return false; +} + +static bool ed_pose_is_any_selected_multi(Object **objects, uint objects_len, bool ignore_visibility) +{ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob_iter = objects[ob_index]; + if (ed_pose_is_any_selected(ob_iter, ignore_visibility)) { + return true; + } + } + return false; +} + +void ED_pose_deselect_all_multi(Object **objects, uint objects_len, int select_mode, const bool ignore_visibility) +{ + if (select_mode == SEL_TOGGLE) { + select_mode = ed_pose_is_any_selected_multi( + objects, objects_len, ignore_visibility) ? SEL_DESELECT : SEL_SELECT; + } + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob_iter = objects[ob_index]; + ED_pose_deselect_all(ob_iter, select_mode, ignore_visibility); + } +} + /* ***************** Selections ********************** */ static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend) @@ -278,17 +323,18 @@ static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend) /* previously known as "selectconnected_posearmature" */ static int pose_select_connected_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); - bArmature *arm = (bArmature *)ob->data; Bone *bone, *curBone, *next = NULL; const bool extend = RNA_boolean_get(op->ptr, "extend"); view3d_operator_needs_opengl(C); - bone = get_nearest_bone(C, event->mval, !extend); + Base *base = NULL; + bone = get_nearest_bone(C, event->mval, !extend, &base); if (!bone) return OPERATOR_CANCELLED; + + bArmature *arm = base->object->data; /* Select parents */ for (curBone = bone; curBone; curBone = next) { @@ -310,14 +356,14 @@ static int pose_select_connected_invoke(bContext *C, wmOperator *op, const wmEve /* Select children */ for (curBone = bone->childbase.first; curBone; curBone = next) - selectconnected_posebonechildren(ob, curBone, extend); + selectconnected_posebonechildren(base->object, curBone, extend); /* updates */ - WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob); + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, base->object); if (arm->flag & ARM_HAS_VIZ_DEPS) { /* mask modifier ('armature' mode), etc. */ - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&base->object->id, OB_RECALC_DATA); } return OPERATOR_FINISHED; @@ -354,27 +400,31 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op) int action = RNA_enum_get(op->ptr, "action"); Scene *scene = CTX_data_scene(C); - Object *ob = ED_object_context(C); - bArmature *arm = ob->data; int multipaint = scene->toolsettings->multipaint; if (action == SEL_TOGGLE) { action = CTX_DATA_COUNT(C, selected_pose_bones) ? SEL_DESELECT : SEL_SELECT; } + + Object *ob_prev = NULL; /* Set the flags */ - CTX_DATA_BEGIN(C, bPoseChannel *, pchan, visible_pose_bones) + CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) { + bArmature *arm = ob->data; pose_do_bone_select(pchan, action); + + if (ob_prev != ob) { + /* weightpaint or mask modifiers need depsgraph updates */ + if (multipaint || (arm->flag & ARM_HAS_VIZ_DEPS)) { + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + } + ob_prev = ob; + } } CTX_DATA_END; WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, NULL); - - /* weightpaint or mask modifiers need depsgraph updates */ - if (multipaint || (arm->flag & ARM_HAS_VIZ_DEPS)) { - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); - } return OPERATOR_FINISHED; } @@ -450,13 +500,13 @@ void POSE_OT_select_parent(wmOperatorType *ot) static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op)) { - Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); - bArmature *arm = (bArmature *)ob->data; bConstraint *con; int found = 0; - - CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones) + Object *ob_prev = NULL; + + CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob) { + bArmature *arm = ob->data; if (pchan->bone->flag & BONE_SELECTED) { for (con = pchan->constraints.first; con; con = con->next) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); @@ -472,6 +522,16 @@ static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op if ((pchanc) && !(pchanc->bone->flag & BONE_UNSELECTABLE)) { pchanc->bone->flag |= BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL; found = 1; + + if (ob != ob_prev) { + /* updates */ + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob); + if (arm->flag & ARM_HAS_VIZ_DEPS) { + /* mask modifier ('armature' mode), etc. */ + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + } + ob_prev = ob; + } } } } @@ -487,14 +547,6 @@ static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op if (!found) return OPERATOR_CANCELLED; - /* updates */ - WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob); - - if (arm->flag & ARM_HAS_VIZ_DEPS) { - /* mask modifier ('armature' mode), etc. */ - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); - } - return OPERATOR_FINISHED; } diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c index 7fc40d00042..a8ba3ad646c 100644 --- a/source/blender/editors/armature/pose_transform.c +++ b/source/blender/editors/armature/pose_transform.c @@ -73,10 +73,8 @@ /* helper for apply_armature_pose2bones - fixes parenting of objects that are bone-parented to armature */ static void applyarmature_fix_boneparents(const bContext *C, Scene *scene, Object *armob) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Object workob, *ob; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); /* go through all objects in database */ for (ob = G.main->object.first; ob; ob = ob->id.next) { @@ -87,7 +85,7 @@ static void applyarmature_fix_boneparents(const bContext *C, Scene *scene, Objec */ BKE_object_apply_mat4(ob, ob->obmat, false, false); - BKE_object_workob_calc_parent(&eval_ctx, scene, ob, &workob); + BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob); invert_m4_m4(ob->parentinv, workob.obmat); } } @@ -96,16 +94,14 @@ static void applyarmature_fix_boneparents(const bContext *C, Scene *scene, Objec /* set the current pose as the restpose */ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); // must be active object, not edit-object - EvaluationContext eval_ctx; bArmature *arm = BKE_armature_from_object(ob); bPose *pose; bPoseChannel *pchan; EditBone *curbone; - CTX_data_eval_ctx(C, &eval_ctx); - /* don't check if editmode (should be done by caller) */ if (ob->type != OB_ARMATURE) return OPERATOR_CANCELLED; @@ -196,7 +192,7 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) ED_armature_edit_free(arm); /* flush positions of posebones */ - BKE_pose_where_is(&eval_ctx, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); /* fix parenting of objects which are bone-parented */ applyarmature_fix_boneparents(C, scene, ob); diff --git a/source/blender/editors/armature/pose_utils.c b/source/blender/editors/armature/pose_utils.c index acb9363cf10..0dc89aa4716 100644 --- a/source/blender/editors/armature/pose_utils.c +++ b/source/blender/editors/armature/pose_utils.c @@ -183,10 +183,8 @@ void poseAnim_mapping_free(ListBase *pfLinks) /* helper for apply() / reset() - refresh the data */ void poseAnim_mapping_refresh(bContext *C, Scene *scene, Object *ob) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); bArmature *arm = (bArmature *)ob->data; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); /* old optimize trick... this enforces to bypass the depgraph * - note: code copied from transform_generics.c -> recalcData() @@ -195,7 +193,7 @@ void poseAnim_mapping_refresh(bContext *C, Scene *scene, Object *ob) if ((arm->flag & ARM_DELAYDEFORM) == 0) DEG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */ else - BKE_pose_where_is(&eval_ctx, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); /* note, notifier might evolve */ WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob); diff --git a/source/blender/editors/curve/CMakeLists.txt b/source/blender/editors/curve/CMakeLists.txt index 85daa7e44e5..301d333ebdb 100644 --- a/source/blender/editors/curve/CMakeLists.txt +++ b/source/blender/editors/curve/CMakeLists.txt @@ -28,6 +28,7 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager + ../../../../intern/clog ../../../../intern/guardedalloc ../../../../intern/glew-mx ../../../../extern/curve_fit_nd diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 3ea8592ac3e..14571343ac9 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -5013,7 +5013,7 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event) const float mval[2] = {UNPACK2(event->mval)}; struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( - CTX_data_main(C), vc.scene, vc.view_layer, 0, vc.ar, vc.v3d); + CTX_data_main(C), vc.scene, 0, vc.ar, vc.v3d); ED_transform_snap_object_project_view3d_mixed( snap_context, @@ -6237,17 +6237,15 @@ static int match_texture_space_poll(bContext *C) static int match_texture_space_exec(bContext *C, wmOperator *UNUSED(op)) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *object = CTX_data_active_object(C); - EvaluationContext eval_ctx; Curve *curve = (Curve *) object->data; float min[3], max[3], size[3], loc[3]; int a; - CTX_data_eval_ctx(C, &eval_ctx); - if (object->curve_cache == NULL) { - BKE_displist_make_curveTypes(&eval_ctx, scene, object, false); + BKE_displist_make_curveTypes(depsgraph, scene, object, false); } INIT_MINMAX(min, max); diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c index 36eb4c6c5bc..056e8a2668c 100644 --- a/source/blender/editors/curve/editcurve_paint.c +++ b/source/blender/editors/curve/editcurve_paint.c @@ -93,7 +93,7 @@ struct StrokeElem { }; struct CurveDrawData { - const Depsgraph *depsgraph; + Depsgraph *depsgraph; short init_event_type; short curve_type; @@ -1095,13 +1095,10 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event) if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && (v3d->drawtype > OB_WIRE)) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - /* needed or else the draw matrix can be incorrect */ view3d_operator_needs_opengl(C); - ED_view3d_autodist_init(&eval_ctx, cdd->vc.depsgraph, cdd->vc.ar, cdd->vc.v3d, 0); + ED_view3d_autodist_init(cdd->vc.depsgraph, cdd->vc.ar, cdd->vc.v3d, 0); if (cdd->vc.rv3d->depths) { cdd->vc.rv3d->depths->damaged = true; diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c index 4eb2abaefad..ad17331853b 100644 --- a/source/blender/editors/curve/editcurve_undo.c +++ b/source/blender/editors/curve/editcurve_undo.c @@ -22,12 +22,14 @@ * \ingroup edcurve */ +#include "MEM_guardedalloc.h" + +#include "CLG_log.h" + #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_anim_types.h" -#include "MEM_guardedalloc.h" - #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_array_utils.h" @@ -35,6 +37,7 @@ #include "BKE_context.h" #include "BKE_curve.h" #include "BKE_fcurve.h" +#include "BKE_layer.h" #include "BKE_library.h" #include "BKE_animsys.h" #include "BKE_undo_system.h" @@ -42,6 +45,7 @@ #include "DEG_depsgraph.h" #include "ED_object.h" +#include "ED_undo.h" #include "ED_util.h" #include "ED_curve.h" @@ -50,6 +54,9 @@ #include "curve_intern.h" +/** We only need this locally. */ +static CLG_LogRef LOG = {"ed.undo.curve"}; + /* -------------------------------------------------------------------- */ /** \name Undo Conversion * \{ */ @@ -187,13 +194,19 @@ static Object *editcurve_object_from_context(bContext *C) /* -------------------------------------------------------------------- */ /** \name Implements ED Undo System + * + * \note This is similar for all edit-mode types. * \{ */ -typedef struct CurveUndoStep { - UndoStep step; - /* note: will split out into list for multi-object-editmode. */ +typedef struct CurveUndoStep_Elem { UndoRefID_Object obedit_ref; UndoCurve data; +} CurveUndoStep_Elem; + +typedef struct CurveUndoStep { + UndoStep step; + CurveUndoStep_Elem *elems; + uint elems_len; } CurveUndoStep; static bool curve_undosys_poll(bContext *C) @@ -205,9 +218,23 @@ static bool curve_undosys_poll(bContext *C) static bool curve_undosys_step_encode(struct bContext *C, UndoStep *us_p) { CurveUndoStep *us = (CurveUndoStep *)us_p; - us->obedit_ref.ptr = editcurve_object_from_context(C); - undocurve_from_editcurve(&us->data, us->obedit_ref.ptr->data, us->obedit_ref.ptr->shapenr); - us->step.data_size = us->data.undo_size; + + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__); + us->elems_len = objects_len; + + for (uint i = 0; i < objects_len; i++) { + Object *ob = objects[i]; + CurveUndoStep_Elem *elem = &us->elems[i]; + + elem->obedit_ref.ptr = ob; + undocurve_from_editcurve(&elem->data, ob->data, ob->shapenr); + us->step.data_size += elem->data.undo_size; + } + MEM_freeN(objects); return true; } @@ -218,23 +245,47 @@ static void curve_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UN BLI_assert(curve_undosys_poll(C)); CurveUndoStep *us = (CurveUndoStep *)us_p; - Object *obedit = us->obedit_ref.ptr; - undocurve_to_editcurve(&us->data, obedit->data, &obedit->shapenr); - DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + + for (uint i = 0; i < us->elems_len; i++) { + CurveUndoStep_Elem *elem = &us->elems[i]; + Object *obedit = elem->obedit_ref.ptr; + Curve *cu = obedit->data; + if (cu->editnurb == NULL) { + /* Should never fail, may not crash but can give odd behavior. */ + CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", + us_p->name, obedit->id.name); + continue; + } + undocurve_to_editcurve(&elem->data, obedit->data, &obedit->shapenr); + DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + } + + /* The first element is always active */ + ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } static void curve_undosys_step_free(UndoStep *us_p) { CurveUndoStep *us = (CurveUndoStep *)us_p; - undocurve_free_data(&us->data); + + for (uint i = 0; i < us->elems_len; i++) { + CurveUndoStep_Elem *elem = &us->elems[i]; + undocurve_free_data(&elem->data); + } + MEM_freeN(us->elems); } static void curve_undosys_foreach_ID_ref( UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data) { CurveUndoStep *us = (CurveUndoStep *)us_p; - foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref)); + + for (uint i = 0; i < us->elems_len; i++) { + CurveUndoStep_Elem *elem = &us->elems[i]; + foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref)); + } } /* Export for ED_undo_sys. */ diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index b72ac8c63c8..a9a8901acc6 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -422,9 +422,9 @@ void FONT_OT_text_paste_from_file(wmOperatorType *ot) static void txt_add_object(bContext *C, TextLine *firstline, int totline, const float offset[3]) { Main *bmain = CTX_data_main(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - EvaluationContext eval_ctx; Curve *cu; Object *obedit; Base *base; @@ -434,15 +434,13 @@ static void txt_add_object(bContext *C, TextLine *firstline, int totline, const int a; float rot[3] = {0.f, 0.f, 0.f}; - CTX_data_eval_ctx(C, &eval_ctx); - obedit = BKE_object_add(bmain, scene, view_layer, OB_FONT, NULL); base = view_layer->basact; /* seems to assume view align ? TODO - look into this, could be an operator option */ ED_object_base_init_transform(C, base, NULL, rot); - BKE_object_where_is_calc(&eval_ctx, scene, obedit); + BKE_object_where_is_calc(depsgraph, scene, obedit); add_v3_v3(obedit->loc, offset); diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 942aa861cec..50a6e9125a0 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -1672,7 +1672,7 @@ void ED_gpencil_draw_view2d(const bContext *C, bool onlyv2d) void ED_gpencil_draw_view3d(wmWindowManager *wm, Scene *scene, ViewLayer *view_layer, - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, View3D *v3d, ARegion *ar, bool only3d) diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 1eee774fd3e..4f9abff292a 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -2109,12 +2109,9 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) /* init autodist for geometry projection */ if (mode == GP_REPROJECT_SURFACE) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - struct Depsgraph *graph = CTX_data_depsgraph(C); view3d_region_operator_needs_opengl(CTX_wm_window(C), gsc.ar); - ED_view3d_autodist_init(&eval_ctx, graph, gsc.ar, CTX_wm_view3d(C), 0); + ED_view3d_autodist_init(graph, gsc.ar, CTX_wm_view3d(C), 0); } // TODO: For deforming geometry workflow, create new frames? diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 77e5dc8fe5d..b74d6ed8d69 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -115,7 +115,6 @@ typedef enum eGPencil_PaintFlags { * "p" = op->customdata */ typedef struct tGPsdata { - EvaluationContext eval_ctx; Scene *scene; /* current scene from context */ struct Depsgraph *graph; @@ -646,7 +645,7 @@ static short gp_stroke_addpoint( view3d_region_operator_needs_opengl(p->win, p->ar); ED_view3d_autodist_init( - &p->eval_ctx, p->graph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); + p->graph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); } /* convert screen-coordinates to appropriate coordinates (and store them) */ @@ -1247,7 +1246,7 @@ static void gp_stroke_doeraser(tGPsdata *p) if (p->flags & GP_PAINTFLAG_V3D_ERASER_DEPTH) { View3D *v3d = p->sa->spacedata.first; view3d_region_operator_needs_opengl(p->win, p->ar); - ED_view3d_autodist_init(&p->eval_ctx, p->graph, p->ar, v3d, 0); + ED_view3d_autodist_init(p->graph, p->ar, v3d, 0); } } @@ -1400,7 +1399,6 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p) } /* pass on current scene and window */ - CTX_data_eval_ctx(C, &p->eval_ctx); p->scene = CTX_data_scene(C); p->graph = CTX_data_depsgraph(C); p->win = CTX_wm_window(C); @@ -1608,7 +1606,7 @@ static void gp_session_cleanup(tGPsdata *p) } /* init new stroke */ -static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, const Depsgraph *depsgraph) +static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Depsgraph *depsgraph) { Scene *scene = p->scene; ToolSettings *ts = scene->toolsettings; @@ -1815,7 +1813,7 @@ static void gp_paint_strokeend(tGPsdata *p) /* need to restore the original projection settings before packing up */ view3d_region_operator_needs_opengl(p->win, p->ar); - ED_view3d_autodist_init(&p->eval_ctx, p->graph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); + ED_view3d_autodist_init(p->graph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0); } /* check if doing eraser or not */ @@ -2055,7 +2053,7 @@ static void gpencil_draw_status_indicators(tGPsdata *p) /* ------------------------------- */ /* create a new stroke point at the point indicated by the painting context */ -static void gpencil_draw_apply(wmOperator *op, tGPsdata *p, const Depsgraph *depsgraph) +static void gpencil_draw_apply(wmOperator *op, tGPsdata *p, Depsgraph *depsgraph) { /* handle drawing/erasing -> test for erasing first */ if (p->paintmode == GP_PAINTMODE_ERASER) { @@ -2110,7 +2108,7 @@ static void gpencil_draw_apply(wmOperator *op, tGPsdata *p, const Depsgraph *dep } /* handle draw event */ -static void gpencil_draw_apply_event(wmOperator *op, const wmEvent *event, const Depsgraph *depsgraph) +static void gpencil_draw_apply_event(wmOperator *op, const wmEvent *event, Depsgraph *depsgraph) { tGPsdata *p = op->customdata; PointerRNA itemptr; diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 94689fb59fa..d7e5b5a92aa 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -542,14 +542,11 @@ void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc) View3D *v3d = (View3D *)CTX_wm_space_data(C); RegionView3D *rv3d = ar->regiondata; - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - /* init 3d depth buffers */ view3d_operator_needs_opengl(C); view3d_region_operator_needs_opengl(win, ar); - ED_view3d_autodist_init(&eval_ctx, graph, ar, v3d, 0); + ED_view3d_autodist_init(graph, ar, v3d, 0); /* for camera view set the subrect */ if (rv3d->persp == RV3D_CAMOB) { diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index 186ca5313e5..69f71f3df44 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -39,7 +39,7 @@ struct Base; struct bContext; struct Bone; struct bPoseChannel; -struct EvaluationContext; +struct Depsgraph; struct IDProperty; struct ListBase; struct MeshDeformModifierData; @@ -142,19 +142,29 @@ void ED_armature_edit_free(struct bArmature *arm); void ED_armature_edit_deselect_all(struct Object *obedit); void ED_armature_edit_deselect_all_visible(struct Object *obedit); +void ED_armature_edit_deselect_all_multi(struct Object **objects, uint objects_len); +void ED_armature_edit_deselect_all_visible_multi(struct Object **objects, uint objects_len); + bool ED_armature_pose_select_pick_with_buffer( struct ViewLayer *view_layer, struct Base *base, const unsigned int *buffer, short hits, bool extend, bool deselect, bool toggle, bool do_nearest); bool ED_armature_edit_select_pick( struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); int join_armature_exec(struct bContext *C, struct wmOperator *op); -struct Bone *ED_armature_bone_find_index(struct Object *ob, int index); float ED_armature_ebone_roll_to_vector(const EditBone *bone, const float new_up_axis[3], const bool axis_only); EditBone *ED_armature_ebone_find_name(const struct ListBase *edbo, const char *name); EditBone *ED_armature_ebone_get_mirrored(const struct ListBase *edbo, EditBone *ebo); void ED_armature_edit_sync_selection(struct ListBase *edbo); void ED_armature_edit_validate_active(struct bArmature *arm); +struct Base *ED_armature_base_and_ebone_from_select_buffer( + struct Base **bases, uint bases_len, int hit, struct EditBone **r_ebone); +struct Object *ED_armature_object_and_ebone_from_select_buffer( + struct Object **objects, uint objects_len, int hit, struct EditBone **r_ebone); + +struct Base *ED_armature_base_and_bone_from_select_buffer( + struct Base **bases, uint bases_len, int hit, struct Bone **r_bone); + EditBone *ED_armature_ebone_add_primitive(struct Object *obedit_arm, float length, bool view_aligned); EditBone *ED_armature_ebone_add(struct bArmature *arm, const char *name); @@ -182,7 +192,7 @@ void ED_armature_transform(struct bArmature *arm, float mat[4][4], const bool do #define ARM_GROUPS_AUTO 3 void ED_object_vgroup_calc_from_armature( - struct ReportList *reports, const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct ReportList *reports, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *par, const int mode, const bool mirror); /* if bone is already in list, pass it as param to ignore it */ @@ -211,6 +221,7 @@ bool ED_object_posemode_exit(struct bContext *C, struct Object *ob); bool ED_object_posemode_enter_ex(struct Main *bmain, struct Object *ob); bool ED_object_posemode_enter(struct bContext *C, struct Object *ob); void ED_pose_deselect_all(struct Object *ob, int select_mode, const bool ignore_visibility); +void ED_pose_deselect_all_multi(struct Object **objects, uint objects_len, int select_mode, const bool ignore_visibility); void ED_pose_bone_select(struct Object *ob, struct bPoseChannel *pchan, bool select); void ED_pose_recalculate_paths(struct bContext *C, struct Scene *scene, struct Object *ob); struct Object *ED_pose_object_from_context(struct bContext *C); diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h index 3ea754b242c..57ca1f04c0a 100644 --- a/source/blender/editors/include/ED_gpencil.h +++ b/source/blender/editors/include/ED_gpencil.h @@ -153,7 +153,7 @@ void ED_gpencil_draw_view2d(const struct bContext *C, bool onlyv2d); void ED_gpencil_draw_view3d(struct wmWindowManager *wm, struct Scene *scene, struct ViewLayer *view_layer, - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, struct View3D *v3d, struct ARegion *ar, bool only3d); diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 3217433204e..787cf7f0524 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -126,7 +126,7 @@ void EDBM_flag_enable_all(struct BMEditMesh *em, const char hflag); void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag); bool BMBVH_EdgeVisible(struct BMBVHTree *tree, struct BMEdge *e, - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, struct ARegion *ar, struct View3D *v3d, struct Object *obedit); /* editmesh_undo.c */ @@ -138,36 +138,36 @@ void EDBM_select_mirrored( int *r_totmirr, int *r_totfail); void EDBM_automerge(struct Scene *scene, struct Object *ob, bool update, const char hflag); -bool EDBM_backbuf_border_init(const struct EvaluationContext *eval_ctx, struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax); +bool EDBM_backbuf_border_init(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax); bool EDBM_backbuf_check(unsigned int index); void EDBM_backbuf_free(void); bool EDBM_backbuf_border_mask_init( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, const int mcords[][2], short tot, + struct ViewContext *vc, const int mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax); -bool EDBM_backbuf_circle_init(const struct EvaluationContext *eval_ctx, struct ViewContext *vc, short xs, short ys, short rads); +bool EDBM_backbuf_circle_init(struct ViewContext *vc, short xs, short ys, short rads); struct BMVert *EDBM_vert_find_nearest_ex( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, float *r_dist, + struct ViewContext *vc, float *r_dist, const bool use_select_bias, bool use_cycle); struct BMVert *EDBM_vert_find_nearest( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, float *r_dist); + struct ViewContext *vc, float *r_dist); struct BMEdge *EDBM_edge_find_nearest_ex( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, float *r_dist, + struct ViewContext *vc, float *r_dist, float *r_dist_center, const bool use_select_bias, const bool use_cycle, struct BMEdge **r_eed_zbuf); struct BMEdge *EDBM_edge_find_nearest( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, float *r_dist); + struct ViewContext *vc, float *r_dist); struct BMFace *EDBM_face_find_nearest_ex( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, float *r_dist, + struct ViewContext *vc, float *r_dist, float *r_dist_center, const bool use_select_bias, const bool use_cycle, struct BMFace **r_efa_zbuf); struct BMFace *EDBM_face_find_nearest( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, float *r_dist); + struct ViewContext *vc, float *r_dist); bool EDBM_select_pick(struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); @@ -204,7 +204,7 @@ void EMBM_project_snap_verts(struct bContext *C, struct ARegion *ar, struct BMEd /* editface.c */ void paintface_flush_flags(struct Object *ob, short flag); bool paintface_mouse_select(struct bContext *C, struct Object *ob, const int mval[2], bool extend, bool deselect, bool toggle); -int do_paintface_box_select(const struct EvaluationContext *eval_ctx, struct ViewContext *vc, struct rcti *rect, bool select, bool extend); +int do_paintface_box_select(struct ViewContext *vc, struct rcti *rect, bool select, bool extend); void paintface_deselect_all_visible(struct Object *ob, int action, bool flush_flags); void paintface_select_linked(struct bContext *C, struct Object *ob, const int mval[2], const bool select); bool paintface_minmax(struct Object *ob, float r_min[3], float r_max[3]); @@ -340,6 +340,9 @@ struct MDeformVert *ED_mesh_active_dvert_get_em(struct Object *ob, struct BMVert struct MDeformVert *ED_mesh_active_dvert_get_ob(struct Object *ob, int *r_index); struct MDeformVert *ED_mesh_active_dvert_get_only(struct Object *ob); +void EDBM_mesh_stats_multi(struct Object **objects, const uint objects_len, int totelem[3], int totelem_sel[3]); +void EDBM_mesh_elem_index_ensure_multi(struct Object **objects, const uint objects_len, const char htype); + #define ED_MESH_PICK_DEFAULT_VERT_SIZE 50 #define ED_MESH_PICK_DEFAULT_FACE_SIZE 3 diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 83119062203..1d35401ebd2 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -57,7 +57,7 @@ struct wmWindowManager; struct PointerRNA; struct PropertyRNA; struct EnumPropertyItem; -struct EvaluationContext; +struct Depsgraph; #include "DNA_object_enums.h" @@ -124,10 +124,13 @@ enum { EM_WAITCURSOR = (1 << 1), EM_DO_UNDO = (1 << 2), EM_IGNORE_LAYER = (1 << 3), + EM_NO_CONTEXT = (1 << 4), }; void ED_object_editmode_exit_ex( struct bContext *C, struct Scene *scene, struct Object *obedit, int flag); void ED_object_editmode_exit(struct bContext *C, int flag); + +void ED_object_editmode_enter_ex(struct Scene *scene, struct Object *ob, int flag); void ED_object_editmode_enter(struct bContext *C, int flag); bool ED_object_editmode_load(struct Object *obedit); @@ -135,11 +138,11 @@ bool ED_object_editmode_calc_active_center(struct Object *obedit, const bool sel void ED_object_vpaintmode_enter_ex( - const struct EvaluationContext *eval_ctx, struct wmWindowManager *wm, + struct Depsgraph *depsgraph, struct wmWindowManager *wm, struct Scene *scene, struct Object *ob); void ED_object_vpaintmode_enter(struct bContext *C); void ED_object_wpaintmode_enter_ex( - const struct EvaluationContext *eval_ctx, struct wmWindowManager *wm, + struct Depsgraph *depsgraph, struct wmWindowManager *wm, struct Scene *scene, struct Object *ob); void ED_object_wpaintmode_enter(struct bContext *C); @@ -149,12 +152,12 @@ void ED_object_wpaintmode_exit_ex(struct Object *ob); void ED_object_wpaintmode_exit(struct bContext *C); void ED_object_sculptmode_enter_ex( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ReportList *reports); void ED_object_sculptmode_enter(struct bContext *C, struct ReportList *reports); void ED_object_sculptmode_exit_ex( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void ED_object_sculptmode_exit(struct bContext *C); @@ -213,10 +216,10 @@ bool ED_object_mode_generic_enter( struct bContext *C, eObjectMode object_mode); void ED_object_mode_generic_exit( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); bool ED_object_mode_generic_has_data( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Object *ob); bool ED_object_mode_generic_exists( @@ -238,7 +241,7 @@ int ED_object_modifier_move_down(struct ReportList *reports, struct Object *ob, int ED_object_modifier_move_up(struct ReportList *reports, struct Object *ob, struct ModifierData *md); int ED_object_modifier_convert(struct ReportList *reports, struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, struct Object *ob, struct ModifierData *md); -int ED_object_modifier_apply(struct ReportList *reports, const struct EvaluationContext *eval_ctx, struct Scene *scene, +int ED_object_modifier_apply(struct ReportList *reports, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ModifierData *md, int mode); int ED_object_modifier_copy(struct ReportList *reports, struct Object *ob, struct ModifierData *md); diff --git a/source/blender/editors/include/ED_particle.h b/source/blender/editors/include/ED_particle.h index b3e274a235a..f84015c53ee 100644 --- a/source/blender/editors/include/ED_particle.h +++ b/source/blender/editors/include/ED_particle.h @@ -47,15 +47,15 @@ int PE_start_edit(struct PTCacheEdit *edit); /* access */ struct PTCacheEdit *PE_get_current(struct Scene *scene, struct Object *ob); -struct PTCacheEdit *PE_create_current(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); -void PE_current_changed(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob); +struct PTCacheEdit *PE_create_current(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); +void PE_current_changed(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); int PE_minmax(struct Scene *scene, struct ViewLayer *view_layer, float min[3], float max[3]); struct ParticleEditSettings *PE_settings(struct Scene *scene); /* update calls */ void PE_hide_keys_time(struct Scene *scene, struct PTCacheEdit *edit, float cfra); void PE_update_object( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int useflag); /* selection tools */ diff --git a/source/blender/editors/include/ED_transform_snap_object_context.h b/source/blender/editors/include/ED_transform_snap_object_context.h index 26cef2599bd..07411fab12a 100644 --- a/source/blender/editors/include/ED_transform_snap_object_context.h +++ b/source/blender/editors/include/ED_transform_snap_object_context.h @@ -75,9 +75,9 @@ struct SnapObjectParams { typedef struct SnapObjectContext SnapObjectContext; SnapObjectContext *ED_transform_snap_object_context_create( - struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, int flag); + struct Main *bmain, struct Scene *scene, int flag); SnapObjectContext *ED_transform_snap_object_context_create_view3d( - struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, int flag, + struct Main *bmain, struct Scene *scene, int flag, /* extra args for view3d */ const struct ARegion *ar, const struct View3D *v3d); void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx); diff --git a/source/blender/editors/include/ED_undo.h b/source/blender/editors/include/ED_undo.h index b3814ab5899..43ffb091666 100644 --- a/source/blender/editors/include/ED_undo.h +++ b/source/blender/editors/include/ED_undo.h @@ -26,6 +26,7 @@ #define __ED_UNDO_H__ struct bContext; +struct CLG_LogRef; struct wmOperator; struct wmOperatorType; struct UndoStack; @@ -53,6 +54,10 @@ bool ED_undo_is_valid(const struct bContext *C, const char *undoname); struct UndoStack *ED_undo_stack_get(void); +/* helpers */ +void ED_undo_object_set_active_or_warn( + struct ViewLayer *view_layer, struct Object *ob, const char *info, struct CLG_LogRef *log); + /* undo_system_types.c */ void ED_undosys_type_init(void); void ED_undosys_type_free(void); diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h index 2a5ad494643..fd532e70478 100644 --- a/source/blender/editors/include/ED_uvedit.h +++ b/source/blender/editors/include/ED_uvedit.h @@ -119,17 +119,20 @@ void ED_uvedit_live_unwrap_end(short cancel); void ED_uvedit_live_unwrap(struct Scene *scene, struct Object *obedit); void ED_uvedit_pack_islands( -struct Scene *scene, struct Object *ob, struct BMesh *bm, bool selected, bool correct_aspect, bool do_rotate); + struct Scene *scene, struct Object *ob, struct BMesh *bm, bool selected, bool correct_aspect, bool do_rotate); +void ED_uvedit_pack_islands_multi( + struct Scene *scene, struct Object **objects, const uint objects_len, + bool selected, bool correct_aspect, bool do_rotate); void ED_uvedit_unwrap_cube_project( struct BMesh *bm, float cube_size, bool use_select, const float center[3]); /* single call up unwrap using scene settings, used for edge tag unwrapping */ -void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel); +void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel, const bool pack); /* uvedit_draw.c */ void ED_image_draw_cursor( -struct ARegion *ar, const float cursor[2]); + struct ARegion *ar, const float cursor[2]); void ED_uvedit_draw_main( struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct ViewLayer *view_layer, diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 7f18c10f970..c394060dfba 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -43,7 +43,6 @@ struct BoundBox; struct Camera; struct Depsgraph; struct EditBone; -struct EvaluationContext; struct ImBuf; struct MVert; struct Main; @@ -157,20 +156,20 @@ typedef enum { /* foreach iterators */ void meshobject_foreachScreenVert( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, + struct ViewContext *vc, void (*func)(void *userData, struct MVert *eve, const float screen_co[2], int index), void *userData, const eV3DProjTest clip_flag); void mesh_foreachScreenVert( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, + struct ViewContext *vc, void (*func)(void *userData, struct BMVert *eve, const float screen_co[2], int index), void *userData, const eV3DProjTest clip_flag); void mesh_foreachScreenEdge( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, + struct ViewContext *vc, void (*func)(void *userData, struct BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index), void *userData, const eV3DProjTest clip_flag); void mesh_foreachScreenFace( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, + struct ViewContext *vc, void (*func)(void *userData, struct BMFace *efa, const float screen_co[2], int index), void *userData, const eV3DProjTest clip_flag); void nurbs_foreachScreenVert( @@ -229,11 +228,11 @@ float ED_view3d_pixel_size(const struct RegionView3D *rv3d, const float co[3]); float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip); bool ED_view3d_clip_segment(const struct RegionView3D *rv3d, float ray_start[3], float ray_end[3]); bool ED_view3d_win_to_ray( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, const struct ARegion *ar, const struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3], const bool do_clip); bool ED_view3d_win_to_ray_ex( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, const struct ARegion *ar, const struct View3D *v3d, const float mval[2], float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip); void ED_view3d_global_to_vector(const struct RegionView3D *rv3d, const float coord[3], float vec[3]); @@ -248,7 +247,7 @@ void ED_view3d_win_to_3d_int( void ED_view3d_win_to_delta(const struct ARegion *ar, const float mval[2], float out[3], const float zfac); void ED_view3d_win_to_origin(const struct ARegion *ar, const float mval[2], float out[3]); void ED_view3d_win_to_vector(const struct ARegion *ar, const float mval[2], float out[3]); -bool ED_view3d_win_to_segment(const struct Depsgraph *depsgraph, +bool ED_view3d_win_to_segment(struct Depsgraph *depsgraph, const struct ARegion *ar, struct View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], const bool do_clip); void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]); @@ -264,28 +263,28 @@ void ED_view3d_dist_range_get( const struct View3D *v3d, float r_dist_range[2]); bool ED_view3d_clip_range_get( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, float *r_clipsta, float *r_clipend, const bool use_ortho_factor); bool ED_view3d_viewplane_get( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *r_viewplane, float *r_clipsta, float *r_clipend, float *r_pixsize); void ED_view3d_polygon_offset(const struct RegionView3D *rv3d, const float dist); void ED_view3d_calc_camera_border( - const struct Scene *scene, const struct Depsgraph *depsgraph, + const struct Scene *scene, struct Depsgraph *depsgraph, const struct ARegion *ar, const struct View3D *v3d, const struct RegionView3D *rv3d, struct rctf *r_viewborder, const bool no_shift); void ED_view3d_calc_camera_border_size( - const struct Scene *scene, const struct Depsgraph *depsgraph, + const struct Scene *scene, struct Depsgraph *depsgraph, const struct ARegion *ar, const struct View3D *v3d, const struct RegionView3D *rv3d, float r_size[2]); bool ED_view3d_calc_render_border( - const struct Scene *scene, const struct Depsgraph *depsgraph, + const struct Scene *scene, struct Depsgraph *depsgraph, struct View3D *v3d, struct ARegion *ar, struct rcti *rect); @@ -308,23 +307,23 @@ float ED_view3d_radius_to_dist( void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned pos); /* backbuffer select and draw support */ -void ED_view3d_backbuf_validate(const struct EvaluationContext *eval_ctx, struct ViewContext *vc); +void ED_view3d_backbuf_validate(struct ViewContext *vc); struct ImBuf *ED_view3d_backbuf_read( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, int xmin, int ymin, int xmax, int ymax); + struct ViewContext *vc, int xmin, int ymin, int xmax, int ymax); unsigned int ED_view3d_backbuf_sample_rect( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, const int mval[2], int size, + struct ViewContext *vc, const int mval[2], int size, unsigned int min, unsigned int max, float *r_dist); int ED_view3d_backbuf_sample_size_clamp(struct ARegion *ar, const float dist); unsigned int ED_view3d_backbuf_sample( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, int x, int y); + struct ViewContext *vc, int x, int y); bool ED_view3d_autodist( - const struct EvaluationContext *eval_ctx, struct Depsgraph *graph, struct ARegion *ar, struct View3D *v3d, + struct Depsgraph *graph, struct ARegion *ar, struct View3D *v3d, const int mval[2], float mouse_worldloc[3], const bool alphaoverride, const float fallback_depth_pt[3]); /* only draw so ED_view3d_autodist_simple can be called many times after */ -void ED_view3d_autodist_init(const struct EvaluationContext *eval_ctx, struct Depsgraph *graph, struct ARegion *ar, struct View3D *v3d, int mode); +void ED_view3d_autodist_init(struct Depsgraph *graph, struct ARegion *ar, struct View3D *v3d, int mode); bool ED_view3d_autodist_simple(struct ARegion *ar, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth); bool ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, float *depth); bool ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth); @@ -346,12 +345,13 @@ void view3d_opengl_select_cache_begin(void); void view3d_opengl_select_cache_end(void); int view3d_opengl_select( - const struct EvaluationContext *eval_ctx, struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const struct rcti *input, + struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const struct rcti *input, eV3DSelectMode select_mode); /* view3d_select.c */ float ED_view3d_select_dist_px(void); void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc); +void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact); void view3d_operator_needs_opengl(const struct bContext *C); void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar); void view3d_opengl_read_pixels(struct ARegion *ar, int x, int y, int w, int h, int format, int type, void *data); @@ -378,22 +378,22 @@ int ED_view3d_view_layer_set(int lay, const int *values, int *active); struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d); void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat); -void ED_draw_object_facemap(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, const float col[4], const int facemap); +void ED_draw_object_facemap(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, const float col[4], const int facemap); bool ED_view3d_context_activate(struct bContext *C); void ED_view3d_draw_offscreen_init( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct ViewLayer *view_layer, struct RenderEngineType *engine_type, struct View3D *v3d); void ED_view3d_draw_offscreen( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct ViewLayer *view_layer, struct RenderEngineType *engine_type, struct View3D *v3d, struct ARegion *ar, int winx, int winy, float viewmat[4][4], float winmat[4][4], bool do_bgpic, bool do_sky, bool is_persp, const char *viewname, struct GPUFXSettings *fx_settings, struct GPUOffScreen *ofs, struct GPUViewport *viewport); void ED_view3d_draw_setup_view( - struct wmWindow *win, const struct EvaluationContext *eval_ctx, struct Scene *scene, struct ARegion *ar, struct View3D *v3d, + struct wmWindow *win, struct Depsgraph *depsgraph, struct Scene *scene, struct ARegion *ar, struct View3D *v3d, float viewmat[4][4], float winmat[4][4], const struct rcti *rect); enum { @@ -409,14 +409,14 @@ enum { }; struct ImBuf *ED_view3d_draw_offscreen_imbuf( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct ViewLayer *view_layer, struct RenderEngineType *engine_type, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag, unsigned int draw_flags, int alpha_mode, int samples, const char *viewname, struct GPUOffScreen *ofs, char err_out[256]); struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct ViewLayer *view_layer, struct RenderEngineType *engine_type, struct Object *camera, int width, int height, unsigned int flag, unsigned int draw_flags, int drawtype, int alpha_mode, @@ -426,7 +426,7 @@ struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple( struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]); void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip); void ED_view3d_update_viewmat( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct View3D *v3d, struct ARegion *ar, + struct Depsgraph *depsgraph, struct Scene *scene, struct View3D *v3d, struct ARegion *ar, float viewmat[4][4], float winmat[4][4], const struct rcti *rect); bool ED_view3d_quat_from_axis_view(const char view, float quat[4]); char ED_view3d_quat_to_axis_view(const float quat[4], const float epsilon); @@ -490,7 +490,7 @@ void ED_view3d_id_remap(struct View3D *v3d, const struct ID *old_id, struct ID * /* view3d_draw_legacy.c */ /* Try avoid using these more move out of legacy. */ void ED_view3d_draw_bgpic_test( - struct Scene *scene, const struct Depsgraph *depsgraph, + struct Scene *scene, struct Depsgraph *depsgraph, struct ARegion *ar, struct View3D *v3d, const bool do_foreground, const bool do_camera_frame); diff --git a/source/blender/editors/interface/interface_eyedropper_depth.c b/source/blender/editors/interface/interface_eyedropper_depth.c index 6e85d091fdb..fd9c5f1869d 100644 --- a/source/blender/editors/interface/interface_eyedropper_depth.c +++ b/source/blender/editors/interface/interface_eyedropper_depth.c @@ -179,9 +179,6 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx, my - ar->winrct.ymin}; float co[3]; - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); @@ -190,7 +187,7 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx, view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(&eval_ctx, graph, ar, v3d, mval, co, true, NULL)) { + if (ED_view3d_autodist(graph, ar, v3d, mval, co, true, NULL)) { const float mval_center_fl[2] = { (float)ar->winx / 2, (float)ar->winy / 2}; diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 687b225b838..de9469a48cb 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -2953,9 +2953,11 @@ void init_userdef_do_versions(void) /** * Include next version bump. - * - * (keep this block even if it becomes empty). */ + { + /* (keep this block even if it becomes empty). */ + } + if (((bTheme *)U.themes.first)->tui.manipulator_hi[3] == 0) { for (bTheme *btheme = U.themes.first; btheme; btheme = btheme->next) { ui_theme_space_init_manipulator_colors(btheme); diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 4d0d59ae42c..576b24ed4b4 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -59,8 +59,6 @@ #include "io_collada.h" -#include "DEG_depsgraph.h" - static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { if (!RNA_struct_property_is_set(op->ptr, "filepath")) { @@ -83,7 +81,6 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent * /* function used for WM_OT_save_mainfile too */ static int wm_collada_export_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; char filepath[FILE_MAX]; int apply_modifiers; int export_mesh_type; @@ -113,8 +110,6 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) int export_count; - CTX_data_eval_ctx(C, &eval_ctx); - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; @@ -173,7 +168,6 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) ED_object_editmode_load(CTX_data_edit_object(C)); Scene *scene = CTX_data_scene(C); - CTX_data_eval_ctx(C, &eval_ctx); ExportSettings export_settings; @@ -205,7 +199,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE; if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE; - export_count = collada_export(&eval_ctx, + export_count = collada_export(CTX_data_depsgraph(C), scene, &export_settings ); diff --git a/source/blender/editors/lattice/CMakeLists.txt b/source/blender/editors/lattice/CMakeLists.txt index eaf837cf978..2207e0fa736 100644 --- a/source/blender/editors/lattice/CMakeLists.txt +++ b/source/blender/editors/lattice/CMakeLists.txt @@ -27,6 +27,7 @@ set(INC ../../makesrna ../../render/extern/include ../../windowmanager + ../../../../intern/clog ../../../../intern/guardedalloc ) diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c index 58fa08e5aa9..cbd89016b44 100644 --- a/source/blender/editors/lattice/editlattice_undo.c +++ b/source/blender/editors/lattice/editlattice_undo.c @@ -33,6 +33,8 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #include "BLI_utildefines.h" #include "BLI_array_utils.h" @@ -42,12 +44,14 @@ #include "DNA_scene_types.h" #include "BKE_context.h" +#include "BKE_layer.h" #include "BKE_undo_system.h" #include "DEG_depsgraph.h" #include "ED_object.h" #include "ED_lattice.h" +#include "ED_undo.h" #include "ED_util.h" #include "WM_types.h" @@ -55,6 +59,9 @@ #include "lattice_intern.h" +/** We only need this locally. */ +static CLG_LogRef LOG = {"ed.undo.lattice"}; + /* -------------------------------------------------------------------- */ /** \name Undo Conversion * \{ */ @@ -124,13 +131,19 @@ static Object *editlatt_object_from_context(bContext *C) /* -------------------------------------------------------------------- */ /** \name Implements ED Undo System + * + * \note This is similar for all edit-mode types. * \{ */ -typedef struct LatticeUndoStep { - UndoStep step; - /* note: will split out into list for multi-object-editmode. */ +typedef struct LatticeUndoStep_Elem { UndoRefID_Object obedit_ref; UndoLattice data; +} LatticeUndoStep_Elem; + +typedef struct LatticeUndoStep { + UndoStep step; + LatticeUndoStep_Elem *elems; + uint elems_len; } LatticeUndoStep; static bool lattice_undosys_poll(bContext *C) @@ -141,10 +154,24 @@ static bool lattice_undosys_poll(bContext *C) static bool lattice_undosys_step_encode(struct bContext *C, UndoStep *us_p) { LatticeUndoStep *us = (LatticeUndoStep *)us_p; - us->obedit_ref.ptr = editlatt_object_from_context(C); - Lattice *lt = us->obedit_ref.ptr->data; - undolatt_from_editlatt(&us->data, lt->editlatt); - us->step.data_size = us->data.undo_size; + + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__); + us->elems_len = objects_len; + + for (uint i = 0; i < objects_len; i++) { + Object *ob = objects[i]; + LatticeUndoStep_Elem *elem = &us->elems[i]; + + elem->obedit_ref.ptr = ob; + Lattice *lt = ob->data; + undolatt_from_editlatt(&elem->data, lt->editlatt); + us->step.data_size += elem->data.undo_size; + } + MEM_freeN(objects); return true; } @@ -155,25 +182,47 @@ static void lattice_undosys_step_decode(struct bContext *C, UndoStep *us_p, int BLI_assert(lattice_undosys_poll(C)); LatticeUndoStep *us = (LatticeUndoStep *)us_p; - Object *obedit = us->obedit_ref.ptr; - Lattice *lt = obedit->data; - EditLatt *editlatt = lt->editlatt; - undolatt_to_editlatt(&us->data, editlatt); - DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + + for (uint i = 0; i < us->elems_len; i++) { + LatticeUndoStep_Elem *elem = &us->elems[i]; + Object *obedit = elem->obedit_ref.ptr; + Lattice *lt = obedit->data; + if (lt->editlatt == NULL) { + /* Should never fail, may not crash but can give odd behavior. */ + CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", + us_p->name, obedit->id.name); + continue; + } + undolatt_to_editlatt(&elem->data, lt->editlatt); + DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + } + + /* The first element is always active */ + ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } static void lattice_undosys_step_free(UndoStep *us_p) { LatticeUndoStep *us = (LatticeUndoStep *)us_p; - undolatt_free_data(&us->data); + + for (uint i = 0; i < us->elems_len; i++) { + LatticeUndoStep_Elem *elem = &us->elems[i]; + undolatt_free_data(&elem->data); + } + MEM_freeN(us->elems); } static void lattice_undosys_foreach_ID_ref( UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data) { LatticeUndoStep *us = (LatticeUndoStep *)us_p; - foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref)); + + for (uint i = 0; i < us->elems_len; i++) { + LatticeUndoStep_Elem *elem = &us->elems[i]; + foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref)); + } } /* Export for ED_undo_sys. */ diff --git a/source/blender/editors/manipulator_library/manipulator_library_presets.c b/source/blender/editors/manipulator_library/manipulator_library_presets.c index 7b8d2104992..cccf484f29d 100644 --- a/source/blender/editors/manipulator_library/manipulator_library_presets.c +++ b/source/blender/editors/manipulator_library/manipulator_library_presets.c @@ -139,12 +139,9 @@ void ED_manipulator_draw_preset_facemap( GPU_select_load_id(select_id); } - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - gpuPushMatrix(); gpuMultMatrix(ob->obmat); - ED_draw_object_facemap(&eval_ctx, scene, ob, color, facemap); + ED_draw_object_facemap(CTX_data_depsgraph(C), scene, ob, color, facemap); gpuPopMatrix(); if (is_select) { diff --git a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c index 2991c972f6e..29aff0a1250 100644 --- a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c +++ b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c @@ -191,7 +191,7 @@ static void dial_ghostarc_draw( } static void dial_ghostarc_get_angles( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, const wmManipulator *mpr, const wmEvent *event, const ARegion *ar, const View3D *v3d, diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 3877838ec54..eae6b7192d7 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -32,6 +32,7 @@ set(INC ../../makesrna ../../render/extern/include ../../windowmanager + ../../../../intern/clog ../../../../intern/guardedalloc ../../../../intern/glew-mx ) diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 1b9ee70ccf5..53f21a1e32f 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -393,7 +393,7 @@ bool paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], b return true; } -int do_paintface_box_select(const struct EvaluationContext *eval_ctx, ViewContext *vc, rcti *rect, bool select, bool extend) +int do_paintface_box_select(ViewContext *vc, rcti *rect, bool select, bool extend) { Object *ob = vc->obact; Mesh *me; @@ -424,7 +424,7 @@ int do_paintface_box_select(const struct EvaluationContext *eval_ctx, ViewContex } } - ED_view3d_backbuf_validate(eval_ctx, vc); + ED_view3d_backbuf_validate(vc); ibuf = IMB_allocImBuf(size[0], size[1], 32, IB_rect); rt = ibuf->rect; diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 0a12291c128..80fed05a0b5 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -161,7 +161,6 @@ typedef struct KnifePosData { typedef struct KnifeTool_OpData { ARegion *ar; /* region that knifetool was activated in */ void *draw_handle; /* for drawing preview loop */ - EvaluationContext eval_ctx; ViewContext vc; /* note: _don't_ use 'mval', instead use the one we define below */ float mval[2]; /* mouse value with snapping applied */ //bContext *C; @@ -1562,8 +1561,8 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) } /* unproject screen line */ - ED_view3d_win_to_segment(kcd->eval_ctx.depsgraph, kcd->ar, kcd->vc.v3d, s1, v1, v3, true); - ED_view3d_win_to_segment(kcd->eval_ctx.depsgraph, kcd->ar, kcd->vc.v3d, s2, v2, v4, true); + ED_view3d_win_to_segment(kcd->vc.depsgraph, kcd->ar, kcd->vc.v3d, s1, v1, v3, true); + ED_view3d_win_to_segment(kcd->vc.depsgraph, kcd->ar, kcd->vc.v3d, s2, v2, v4, true); mul_m4_v3(kcd->ob->imat, v1); mul_m4_v3(kcd->ob->imat, v2); @@ -1838,7 +1837,7 @@ static BMFace *knife_find_closest_face(KnifeTool_OpData *kcd, float co[3], float if (!f) { if (kcd->is_interactive) { /* try to use backbuffer selection method if ray casting failed */ - f = EDBM_face_find_nearest(&kcd->eval_ctx, &kcd->vc, &dist); + f = EDBM_face_find_nearest(&kcd->vc, &dist); /* cheat for now; just put in the origin instead * of a true coordinate on the face. @@ -1961,7 +1960,7 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo /* check if we're close enough and calculate 'lambda' */ if (kcd->is_angle_snapping) { - /* if snapping, check we're in bounds */ + /* if snapping, check we're in bounds */ float sco_snap[2]; isect_line_line_v2_point(kfe->v1->sco, kfe->v2->sco, kcd->prev.mval, kcd->curr.mval, sco_snap); lambda = line_point_factor_v2(sco_snap, kfe->v1->sco, kfe->v2->sco); @@ -2519,7 +2518,7 @@ static void knife_recalc_projmat(KnifeTool_OpData *kcd) mul_v3_mat3_m4v3(kcd->proj_zaxis, kcd->ob->imat, kcd->vc.rv3d->viewinv[2]); normalize_v3(kcd->proj_zaxis); - kcd->is_ortho = ED_view3d_clip_range_get(kcd->eval_ctx.depsgraph, + kcd->is_ortho = ED_view3d_clip_range_get(kcd->vc.depsgraph, kcd->vc.v3d, kcd->vc.rv3d, &kcd->clipsta, &kcd->clipend, true); } @@ -2591,7 +2590,7 @@ static void knifetool_init_bmbvh(KnifeTool_OpData *kcd) { BM_mesh_elem_index_ensure(kcd->em->bm, BM_VERT); - kcd->cagecos = (const float (*)[3])BKE_editmesh_vertexCos_get(&kcd->eval_ctx, kcd->em, kcd->scene, NULL); + kcd->cagecos = (const float (*)[3])BKE_editmesh_vertexCos_get(kcd->vc.depsgraph, kcd->em, kcd->scene, NULL); kcd->bmbvh = BKE_bmbvh_new_from_editmesh( kcd->em, @@ -2625,7 +2624,6 @@ static void knifetool_init(bContext *C, KnifeTool_OpData *kcd, kcd->ob = obedit; kcd->ar = CTX_wm_region(C); - CTX_data_eval_ctx(C, &kcd->eval_ctx); em_setup_viewcontext(C, &kcd->vc); kcd->em = BKE_editmesh_from_object(kcd->ob); @@ -2793,7 +2791,6 @@ static int knifetool_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_FINISHED; } - CTX_data_eval_ctx(C, &kcd->eval_ctx); em_setup_viewcontext(C, &kcd->vc); kcd->ar = kcd->vc.ar; diff --git a/source/blender/editors/mesh/editmesh_knife_project.c b/source/blender/editors/mesh/editmesh_knife_project.c index c98d22503e1..ba030c42a04 100644 --- a/source/blender/editors/mesh/editmesh_knife_project.c +++ b/source/blender/editors/mesh/editmesh_knife_project.c @@ -60,15 +60,13 @@ static LinkNode *knifeproject_poly_from_object(const bContext *C, Scene *scene, Object *ob, LinkNode *polys) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); ARegion *ar = CTX_wm_region(C); - EvaluationContext eval_ctx; DerivedMesh *dm; bool dm_needsFree; - CTX_data_eval_ctx(C, &eval_ctx); - if (ob->type == OB_MESH || ob->derivedFinal) { - dm = ob->derivedFinal ? ob->derivedFinal : mesh_get_derived_final(&eval_ctx, scene, ob, CD_MASK_BAREMESH); + dm = ob->derivedFinal ? ob->derivedFinal : mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH); dm_needsFree = false; } else if (ELEM(ob->type, OB_FONT, OB_CURVE, OB_SURF)) { diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c index 793e5609d31..9817909ba4a 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.c +++ b/source/blender/editors/mesh/editmesh_loopcut.c @@ -555,23 +555,20 @@ static void loopcut_update_edge(RingSelOpData *lcd, BMEdge *e, const int preview } } -static void loopcut_mouse_move(const struct EvaluationContext *eval_ctx, RingSelOpData *lcd, const int previewlines) +static void loopcut_mouse_move(RingSelOpData *lcd, const int previewlines) { float dist = ED_view3d_select_dist_px(); - BMEdge *e = EDBM_edge_find_nearest(eval_ctx, &lcd->vc, &dist); + BMEdge *e = EDBM_edge_find_nearest(&lcd->vc, &dist); loopcut_update_edge(lcd, e, previewlines); } /* called by both init() and exec() */ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event) { - EvaluationContext eval_ctx; const bool is_interactive = (event != NULL); Object *obedit = CTX_data_edit_object(C); RingSelOpData *lcd; - CTX_data_eval_ctx(C, &eval_ctx); - if (modifiers_isDeformedByLattice(obedit) || modifiers_isDeformedByArmature(obedit)) BKE_report(op->reports, RPT_WARNING, "Loop cut does not work well on deformed edit mesh display"); @@ -599,7 +596,7 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event) if (is_interactive) { copy_v2_v2_int(lcd->vc.mval, event->mval); - loopcut_mouse_move(&eval_ctx, lcd, is_interactive ? 1 : 0); + loopcut_mouse_move(lcd, is_interactive ? 1 : 0); } else { const int e_index = RNA_int_get(op->ptr, "edge_index"); @@ -672,14 +669,12 @@ static int loopcut_finish(RingSelOpData *lcd, bContext *C, wmOperator *op) static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) { - EvaluationContext eval_ctx; RingSelOpData *lcd = op->customdata; float cuts = lcd->cuts; float smoothness = lcd->smoothness; bool show_cuts = false; const bool has_numinput = hasNumInput(&lcd->num); - CTX_data_eval_ctx(C, &eval_ctx); em_setup_viewcontext(C, &lcd->vc); lcd->ar = lcd->vc.ar; @@ -773,7 +768,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event) { lcd->vc.mval[0] = event->mval[0]; lcd->vc.mval[1] = event->mval[1]; - loopcut_mouse_move(&eval_ctx, lcd, (int)lcd->cuts); + loopcut_mouse_move(lcd, (int)lcd->cuts); ED_region_tag_redraw(lcd->ar); handled = true; diff --git a/source/blender/editors/mesh/editmesh_path.c b/source/blender/editors/mesh/editmesh_path.c index 2ae48bee095..4081e3b0302 100644 --- a/source/blender/editors/mesh/editmesh_path.c +++ b/source/blender/editors/mesh/editmesh_path.c @@ -578,19 +578,19 @@ static bool edbm_shortest_path_pick_ex( static int edbm_shortest_path_pick_exec(bContext *C, wmOperator *op); -static BMElem *edbm_elem_find_nearest(const struct EvaluationContext *eval_ctx, ViewContext *vc, const char htype) +static BMElem *edbm_elem_find_nearest(ViewContext *vc, const char htype) { BMEditMesh *em = vc->em; float dist = ED_view3d_select_dist_px(); if ((em->selectmode & SCE_SELECT_VERTEX) && (htype == BM_VERT)) { - return (BMElem *)EDBM_vert_find_nearest(eval_ctx, vc, &dist); + return (BMElem *)EDBM_vert_find_nearest(vc, &dist); } else if ((em->selectmode & SCE_SELECT_EDGE) && (htype == BM_EDGE)) { - return (BMElem *)EDBM_edge_find_nearest(eval_ctx, vc, &dist); + return (BMElem *)EDBM_edge_find_nearest(vc, &dist); } else if ((em->selectmode & SCE_SELECT_FACE) && (htype == BM_FACE)) { - return (BMElem *)EDBM_face_find_nearest(eval_ctx, vc, &dist); + return (BMElem *)EDBM_face_find_nearest(vc, &dist); } return NULL; @@ -613,12 +613,10 @@ static int edbm_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmE return edbm_shortest_path_pick_exec(C, op); } - EvaluationContext eval_ctx; ViewContext vc; BMEditMesh *em; bool track_active = true; - CTX_data_eval_ctx(C, &eval_ctx); em_setup_viewcontext(C, &vc); copy_v2_v2_int(vc.mval, event->mval); em = vc.em; @@ -627,14 +625,14 @@ static int edbm_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmE BMElem *ele_src, *ele_dst; if (!(ele_src = edbm_elem_active_elem_or_face_get(em->bm)) || - !(ele_dst = edbm_elem_find_nearest(&eval_ctx, &vc, ele_src->head.htype))) + !(ele_dst = edbm_elem_find_nearest(&vc, ele_src->head.htype))) { /* special case, toggle edge tags even when we don't have a path */ if (((em->selectmode & SCE_SELECT_EDGE) && (vc.scene->toolsettings->edge_mode != EDGE_MODE_SELECT)) && /* check if we only have a destination edge */ ((ele_src == NULL) && - (ele_dst = edbm_elem_find_nearest(&eval_ctx, &vc, BM_EDGE)))) + (ele_dst = edbm_elem_find_nearest(&vc, BM_EDGE)))) { ele_src = ele_dst; track_active = false; diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 87937fd4146..b45db94318b 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -45,6 +45,7 @@ #include "BKE_report.h" #include "BKE_paint.h" #include "BKE_editmesh.h" +#include "BKE_layer.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -212,7 +213,7 @@ static BLI_bitmap *edbm_backbuf_alloc(const int size) /* reads rect, and builds selection array for quick lookup */ /* returns if all is OK */ bool EDBM_backbuf_border_init( - const struct EvaluationContext *eval_ctx, ViewContext *vc, short xmin, + ViewContext *vc, short xmin, short ymin, short xmax, short ymax) { struct ImBuf *buf; @@ -223,7 +224,7 @@ bool EDBM_backbuf_border_init( return false; } - buf = ED_view3d_backbuf_read(eval_ctx, vc, xmin, ymin, xmax, ymax); + buf = ED_view3d_backbuf_read(vc, xmin, ymin, xmax, ymax); if ((buf == NULL) || (bm_vertoffs == 0)) { return false; } @@ -286,7 +287,7 @@ static void edbm_mask_lasso_px_cb(int x, int x_end, int y, void *user_data) * - grab again and compare * returns 'OK' */ -bool EDBM_backbuf_border_mask_init(const struct EvaluationContext *eval_ctx, ViewContext *vc, const int mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax) +bool EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax) { unsigned int *dr, *dr_mask, *dr_mask_arr; struct ImBuf *buf; @@ -303,7 +304,7 @@ bool EDBM_backbuf_border_mask_init(const struct EvaluationContext *eval_ctx, Vie return false; } - buf = ED_view3d_backbuf_read(eval_ctx, vc, xmin, ymin, xmax, ymax); + buf = ED_view3d_backbuf_read(vc, xmin, ymin, xmax, ymax); if ((buf == NULL) || (bm_vertoffs == 0)) { return false; } @@ -337,7 +338,7 @@ bool EDBM_backbuf_border_mask_init(const struct EvaluationContext *eval_ctx, Vie /* circle shaped sample area */ bool EDBM_backbuf_circle_init( - const struct EvaluationContext *eval_ctx, ViewContext *vc, + ViewContext *vc, short xs, short ys, short rads) { struct ImBuf *buf; @@ -357,7 +358,7 @@ bool EDBM_backbuf_circle_init( xmin = xs - rads; xmax = xs + rads; ymin = ys - rads; ymax = ys + rads; - buf = ED_view3d_backbuf_read(eval_ctx, vc, xmin, ymin, xmax, ymax); + buf = ED_view3d_backbuf_read(vc, xmin, ymin, xmax, ymax); if ((buf == NULL) || (bm_vertoffs == 0)) { return false; } @@ -456,7 +457,7 @@ static void findnearestvert__doClosest(void *userData, BMVert *eve, const float * \param use_cycle Cycle over elements within #FIND_NEAR_CYCLE_THRESHOLD_MIN in order of index. */ BMVert *EDBM_vert_find_nearest_ex( - const struct EvaluationContext *eval_ctx, ViewContext *vc, float *r_dist, + ViewContext *vc, float *r_dist, const bool use_select_bias, bool use_cycle) { BMesh *bm = vc->em->bm; @@ -468,10 +469,10 @@ BMVert *EDBM_vert_find_nearest_ex( BMVert *eve; /* No afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad. */ - ED_view3d_backbuf_validate(eval_ctx, vc); + ED_view3d_backbuf_validate(vc); index = ED_view3d_backbuf_sample_rect( - eval_ctx, vc, vc->mval, dist_px, bm_wireoffs, 0xFFFFFF, &dist_test); + vc, vc->mval, dist_px, bm_wireoffs, 0xFFFFFF, &dist_test); eve = index ? BM_vert_at_index_find_or_table(bm, index - 1) : NULL; if (eve) { @@ -506,7 +507,7 @@ BMVert *EDBM_vert_find_nearest_ex( data.cycle_index_prev = prev_select_index; ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); - mesh_foreachScreenVert(eval_ctx, vc, findnearestvert__doClosest, &data, clip_flag); + mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, clip_flag); hit = (data.use_cycle && data.hit_cycle.vert) ? &data.hit_cycle : &data.hit; *r_dist = hit->dist; @@ -518,9 +519,9 @@ BMVert *EDBM_vert_find_nearest_ex( } } -BMVert *EDBM_vert_find_nearest(const struct EvaluationContext *eval_ctx, ViewContext *vc, float *r_dist) +BMVert *EDBM_vert_find_nearest(ViewContext *vc, float *r_dist) { - return EDBM_vert_find_nearest_ex(eval_ctx, vc, r_dist, false, false); + return EDBM_vert_find_nearest_ex(vc, r_dist, false, false); } /* find the distance to the edge we already have */ @@ -642,7 +643,7 @@ static void find_nearest_edge__doClosest( } BMEdge *EDBM_edge_find_nearest_ex( - const struct EvaluationContext *eval_ctx, ViewContext *vc, float *r_dist, + ViewContext *vc, float *r_dist, float *r_dist_center, const bool use_select_bias, const bool use_cycle, BMEdge **r_eed_zbuf) @@ -661,12 +662,12 @@ BMEdge *EDBM_edge_find_nearest_ex( vc->scene->toolsettings->selectmode |= SCE_SELECT_EDGE; /* No afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad. */ - ED_view3d_backbuf_validate(eval_ctx, vc); + ED_view3d_backbuf_validate(vc); /* restore `selectmode` */ vc->scene->toolsettings->selectmode = ts_selectmode; - index = ED_view3d_backbuf_sample_rect(eval_ctx, vc, vc->mval, dist_px, bm_solidoffs, bm_wireoffs, &dist_test); + index = ED_view3d_backbuf_sample_rect(vc, vc->mval, dist_px, bm_solidoffs, bm_wireoffs, &dist_test); eed = index ? BM_edge_at_index_find_or_table(bm, index - 1) : NULL; if (r_eed_zbuf) { @@ -684,7 +685,7 @@ BMEdge *EDBM_edge_find_nearest_ex( ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); - mesh_foreachScreenEdge(eval_ctx, vc, find_nearest_edge_center__doZBuf, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + mesh_foreachScreenEdge(vc, find_nearest_edge_center__doZBuf, &data, V3D_PROJ_TEST_CLIP_DEFAULT); *r_dist_center = data.dist; } @@ -724,7 +725,7 @@ BMEdge *EDBM_edge_find_nearest_ex( data.cycle_index_prev = prev_select_index; ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); - mesh_foreachScreenEdge(eval_ctx, vc, find_nearest_edge__doClosest, &data, clip_flag); + mesh_foreachScreenEdge(vc, find_nearest_edge__doClosest, &data, clip_flag); hit = (data.use_cycle && data.hit_cycle.edge) ? &data.hit_cycle : &data.hit; *r_dist = hit->dist; @@ -740,9 +741,9 @@ BMEdge *EDBM_edge_find_nearest_ex( } BMEdge *EDBM_edge_find_nearest( - const struct EvaluationContext *eval_ctx, ViewContext *vc, float *r_dist) + ViewContext *vc, float *r_dist) { - return EDBM_edge_find_nearest_ex(eval_ctx, vc, r_dist, NULL, false, false, NULL); + return EDBM_edge_find_nearest_ex(vc, r_dist, NULL, false, false, NULL); } /* find the distance to the face we already have */ @@ -816,7 +817,7 @@ static void findnearestface__doClosest(void *userData, BMFace *efa, const float BMFace *EDBM_face_find_nearest_ex( - const struct EvaluationContext *eval_ctx, ViewContext *vc, float *r_dist, + ViewContext *vc, float *r_dist, float *r_dist_center, const bool use_select_bias, const bool use_cycle, BMFace **r_efa_zbuf) @@ -828,9 +829,9 @@ BMFace *EDBM_face_find_nearest_ex( unsigned int index; BMFace *efa; - ED_view3d_backbuf_validate(eval_ctx, vc); + ED_view3d_backbuf_validate(vc); - index = ED_view3d_backbuf_sample(eval_ctx, vc, vc->mval[0], vc->mval[1]); + index = ED_view3d_backbuf_sample(vc, vc->mval[0], vc->mval[1]); efa = index ? BM_face_at_index_find_or_table(bm, index - 1) : NULL; if (r_efa_zbuf) { @@ -848,7 +849,7 @@ BMFace *EDBM_face_find_nearest_ex( ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); - mesh_foreachScreenFace(eval_ctx, vc, find_nearest_face_center__doZBuf, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + mesh_foreachScreenFace(vc, find_nearest_face_center__doZBuf, &data, V3D_PROJ_TEST_CLIP_DEFAULT); *r_dist_center = data.dist; } @@ -886,7 +887,7 @@ BMFace *EDBM_face_find_nearest_ex( data.cycle_index_prev = prev_select_index; ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); - mesh_foreachScreenFace(eval_ctx, vc, findnearestface__doClosest, &data, clip_flag); + mesh_foreachScreenFace(vc, findnearestface__doClosest, &data, clip_flag); hit = (data.use_cycle && data.hit_cycle.face) ? &data.hit_cycle : &data.hit; *r_dist = hit->dist; @@ -901,9 +902,9 @@ BMFace *EDBM_face_find_nearest_ex( } } -BMFace *EDBM_face_find_nearest(const struct EvaluationContext *eval_ctx, ViewContext *vc, float *r_dist) +BMFace *EDBM_face_find_nearest(ViewContext *vc, float *r_dist) { - return EDBM_face_find_nearest_ex(eval_ctx, vc, r_dist, NULL, false, false, NULL); + return EDBM_face_find_nearest_ex(vc, r_dist, NULL, false, false, NULL); } #undef FIND_NEAR_SELECT_BIAS @@ -916,8 +917,8 @@ BMFace *EDBM_face_find_nearest(const struct EvaluationContext *eval_ctx, ViewCon * return 1 if found one */ static int unified_findnearest( - const struct EvaluationContext *eval_ctx, ViewContext *vc, - BMVert **r_eve, BMEdge **r_eed, BMFace **r_efa) + ViewContext *vc, + Base **r_base, BMVert **r_eve, BMEdge **r_eed, BMFace **r_efa) { BMEditMesh *em = vc->em; static short mval_prev[2] = {-1, -1}; @@ -934,32 +935,70 @@ static int unified_findnearest( BMEdge *eed = NULL; BMFace *efa = NULL; + /* TODO(campbell): perform selection as one pass + * instead of many smaller passes (which doesn't work for zbuf occlusion). */ + uint bases_len = 0; + Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(vc->view_layer, &bases_len); /* no afterqueue (yet), so we check it now, otherwise the em_xxxofs indices are bad */ - ED_view3d_backbuf_validate(eval_ctx, vc); if ((dist > 0.0f) && em->selectmode & SCE_SELECT_FACE) { float dist_center = 0.0f; float *dist_center_p = (em->selectmode & (SCE_SELECT_EDGE | SCE_SELECT_VERTEX)) ? &dist_center : NULL; - efa = EDBM_face_find_nearest_ex(eval_ctx, vc, &dist, dist_center_p, true, use_cycle, &efa_zbuf); - if (efa && dist_center_p) { - dist = min_ff(dist_margin, dist_center); - } + + for (uint base_index = 0; base_index < bases_len; base_index++) { + Base *base_iter = bases[base_index]; + Object *obedit = base_iter->object; + ED_view3d_viewcontext_init_object(vc, obedit); + ED_view3d_backbuf_validate(vc); + + BMFace *efa_test = EDBM_face_find_nearest_ex(vc, &dist, dist_center_p, true, use_cycle, &efa_zbuf); + if (efa && dist_center_p) { + dist = min_ff(dist_margin, dist_center); + } + if (efa_test) { + *r_base = base_iter; + efa = efa_test; + } + } /* bases */ } if ((dist > 0.0f) && (em->selectmode & SCE_SELECT_EDGE)) { float dist_center = 0.0f; float *dist_center_p = (em->selectmode & SCE_SELECT_VERTEX) ? &dist_center : NULL; - eed = EDBM_edge_find_nearest_ex(eval_ctx, vc, &dist, dist_center_p, true, use_cycle, &eed_zbuf); - if (eed && dist_center_p) { - dist = min_ff(dist_margin, dist_center); - } + + for (uint base_index = 0; base_index < bases_len; base_index++) { + Base *base_iter = bases[base_index]; + Object *obedit = base_iter->object; + ED_view3d_viewcontext_init_object(vc, obedit); + ED_view3d_backbuf_validate(vc); + BMEdge *eed_test = EDBM_edge_find_nearest_ex(vc, &dist, dist_center_p, true, use_cycle, &eed_zbuf); + if (eed && dist_center_p) { + dist = min_ff(dist_margin, dist_center); + } + if (eed_test) { + *r_base = base_iter; + eed = eed_test; + } + } /* bases */ } if ((dist > 0.0f) && em->selectmode & SCE_SELECT_VERTEX) { - eve = EDBM_vert_find_nearest_ex(eval_ctx, vc, &dist, true, use_cycle); + for (uint base_index = 0; base_index < bases_len; base_index++) { + Base *base_iter = bases[base_index]; + Object *obedit = base_iter->object; + ED_view3d_viewcontext_init_object(vc, obedit); + ED_view3d_backbuf_validate(vc); + BMVert *eve_test = EDBM_vert_find_nearest_ex(vc, &dist, true, use_cycle); + if (eve_test) { + *r_base = base_iter; + eve = eve_test; + } + } /* bases */ } + MEM_SAFE_FREE(bases); + /* return only one of 3 pointers, for frontbuffer redraws */ if (eve) { efa = NULL; eed = NULL; @@ -1601,7 +1640,6 @@ static void mouse_mesh_loop_edge(BMEditMesh *em, BMEdge *eed, bool select, bool static bool mouse_mesh_loop(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle, bool ring) { - EvaluationContext eval_ctx; ViewContext vc; BMEditMesh *em; BMEdge *eed; @@ -1611,7 +1649,6 @@ static bool mouse_mesh_loop(bContext *C, const int mval[2], bool extend, bool de float dist = ED_view3d_select_dist_px() * 0.6666f; float mvalf[2]; - CTX_data_eval_ctx(C, &eval_ctx); em_setup_viewcontext(C, &vc); mvalf[0] = (float)(vc.mval[0] = mval[0]); mvalf[1] = (float)(vc.mval[1] = mval[1]); @@ -1623,12 +1660,12 @@ static bool mouse_mesh_loop(bContext *C, const int mval[2], bool extend, bool de vc.scene->toolsettings->selectmode |= SCE_SELECT_EDGE; /* no afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad */ - ED_view3d_backbuf_validate(&eval_ctx, &vc); + ED_view3d_backbuf_validate(&vc); /* restore `selectmode` */ vc.scene->toolsettings->selectmode = ts_selectmode; - eed = EDBM_edge_find_nearest_ex(&eval_ctx, &vc, &dist, NULL, true, true, NULL); + eed = EDBM_edge_find_nearest_ex(&vc, &dist, NULL, true, true, NULL); if (eed == NULL) { return false; } @@ -1804,27 +1841,43 @@ void MESH_OT_edgering_select(wmOperatorType *ot) static int edbm_select_all_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); - const int action = RNA_enum_get(op->ptr, "action"); + ViewLayer *view_layer = CTX_data_view_layer(C); + int action = RNA_enum_get(op->ptr, "action"); + + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + if (action == SEL_TOGGLE) { + action = SEL_SELECT; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + if (em->bm->totvertsel || em->bm->totedgesel || em->bm->totfacesel) { + action = SEL_DESELECT; + break; + } + } + } - switch (action) { - case SEL_TOGGLE: - EDBM_select_toggle_all(em); - break; - case SEL_SELECT: - EDBM_flag_enable_all(em, BM_ELEM_SELECT); - break; - case SEL_DESELECT: - EDBM_flag_disable_all(em, BM_ELEM_SELECT); - break; - case SEL_INVERT: - EDBM_select_swap(em); - EDBM_selectmode_flush(em); - break; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + switch (action) { + case SEL_SELECT: + EDBM_flag_enable_all(em, BM_ELEM_SELECT); + break; + case SEL_DESELECT: + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + break; + case SEL_INVERT: + EDBM_select_swap(em); + EDBM_selectmode_flush(em); + break; + } + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); } - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + MEM_SAFE_FREE(objects); return OPERATOR_FINISHED; } @@ -1894,23 +1947,35 @@ void MESH_OT_select_interior_faces(wmOperatorType *ot) bool EDBM_select_pick(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) { - EvaluationContext eval_ctx; ViewContext vc; + + Base *basact = NULL; BMVert *eve = NULL; BMEdge *eed = NULL; BMFace *efa = NULL; /* setup view context for argument to callbacks */ - CTX_data_eval_ctx(C, &eval_ctx); em_setup_viewcontext(C, &vc); vc.mval[0] = mval[0]; vc.mval[1] = mval[1]; - if (unified_findnearest(&eval_ctx, &vc, &eve, &eed, &efa)) { + if (unified_findnearest(&vc, &basact, &eve, &eed, &efa)) { + ED_view3d_viewcontext_init_object(&vc, basact->object); /* Deselect everything */ - if (extend == false && deselect == false && toggle == false) - EDBM_flag_disable_all(vc.em, BM_ELEM_SELECT); + if (extend == false && deselect == false && toggle == false) { + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc.view_layer, &objects_len); + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob_iter = objects[ob_index]; + EDBM_flag_disable_all(BKE_editmesh_from_object(ob_iter), BM_ELEM_SELECT); + if (basact->object != ob_iter) { + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data); + } + } + MEM_SAFE_FREE(objects); + } if (efa) { if (extend) { @@ -2020,7 +2085,14 @@ bool EDBM_select_pick(bContext *C, const int mval[2], bool extend, bool deselect } + /* Changing active object is handy since it allows us to + * switch UV layers, vgroups for eg. */ + if (vc.view_layer->basact != basact) { + vc.view_layer->basact = basact; + WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, vc.scene); + } WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); + return true; } @@ -2242,6 +2314,7 @@ bool EDBM_selectmode_toggle( bContext *C, const short selectmode_new, const int action, const bool use_extend, const bool use_expand) { + ViewLayer *view_layer = CTX_data_view_layer(C); ToolSettings *ts = CTX_data_tool_settings(C); Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = NULL; @@ -2255,6 +2328,7 @@ bool EDBM_selectmode_toggle( return ret; } + bool only_update = false; switch (action) { case -1: /* already set */ @@ -2262,21 +2336,24 @@ bool EDBM_selectmode_toggle( case 0: /* disable */ /* check we have something to do */ if ((em->selectmode & selectmode_new) == 0) { - return false; + only_update = true; + break; } em->selectmode &= ~selectmode_new; break; case 1: /* enable */ /* check we have something to do */ if ((em->selectmode & selectmode_new) != 0) { - return false; + only_update = true; + break; } em->selectmode |= selectmode_new; break; case 2: /* toggle */ /* can't disable this flag if its the only one set */ if (em->selectmode == selectmode_new) { - return false; + only_update = true; + break; } em->selectmode ^= selectmode_new; break; @@ -2285,10 +2362,30 @@ bool EDBM_selectmode_toggle( break; } + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob_iter = objects[ob_index]; + BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter); + if (em_iter != em) { + em_iter->selectmode = em->selectmode; + } + } + + if (only_update) { + MEM_SAFE_FREE(objects); + return false; + } + if (use_extend == 0 || em->selectmode == 0) { if (use_expand) { const short selmode_max = highest_order_bit_s(ts->selectmode); - EDBM_selectmode_convert(em, selmode_max, selectmode_new); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob_iter = objects[ob_index]; + BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter); + EDBM_selectmode_convert(em_iter, selmode_max, selectmode_new); + } } } @@ -2297,24 +2394,18 @@ bool EDBM_selectmode_toggle( if (use_extend == 0 || em->selectmode == 0) { em->selectmode = SCE_SELECT_VERTEX; } - ts->selectmode = em->selectmode; - EDBM_selectmode_set(em); ret = true; break; case SCE_SELECT_EDGE: if (use_extend == 0 || em->selectmode == 0) { em->selectmode = SCE_SELECT_EDGE; } - ts->selectmode = em->selectmode; - EDBM_selectmode_set(em); ret = true; break; case SCE_SELECT_FACE: if (use_extend == 0 || em->selectmode == 0) { em->selectmode = SCE_SELECT_FACE; } - ts->selectmode = em->selectmode; - EDBM_selectmode_set(em); ret = true; break; default: @@ -2323,10 +2414,18 @@ bool EDBM_selectmode_toggle( } if (ret == true) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + ts->selectmode = em->selectmode; + em = NULL; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob_iter = objects[ob_index]; + BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter); + EDBM_selectmode_set(em_iter); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data); + } WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL); } + MEM_SAFE_FREE(objects); return ret; } @@ -2528,7 +2627,7 @@ static bool select_linked_delimit_test( * Gets the default from the operator fallback to own last-used value * (selected based on mode) */ -static int select_linked_delimit_default_from_op(wmOperator *op, int select_mode) +static int select_linked_delimit_default_from_op(wmOperator *op, const int select_mode) { static char delimit_last_store[2] = {0, BMO_DELIM_SEAM}; int delimit_last_index = (select_mode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) == 0; @@ -2594,172 +2693,186 @@ static void select_linked_delimit_end(BMEditMesh *em) static int edbm_select_linked_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); - BMesh *bm = em->bm; - BMIter iter; - BMWalker walker; + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); #ifdef USE_LINKED_SELECT_DEFAULT_HACK - int delimit = select_linked_delimit_default_from_op(op, em->selectmode); + const int delimit_init = select_linked_delimit_default_from_op(op, scene->toolsettings->selectmode); #else - int delimit = RNA_enum_get(op->ptr, "delimit"); + const int delimit_init = RNA_enum_get(op->ptr, "delimit"); #endif - select_linked_delimit_validate(bm, &delimit); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); - if (delimit) { - select_linked_delimit_begin(em->bm, delimit); - } + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; - if (em->selectmode & SCE_SELECT_VERTEX) { - BMVert *v; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + BMIter iter; + BMWalker walker; - BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { - BM_elem_flag_set(v, BM_ELEM_TAG, BM_elem_flag_test(v, BM_ELEM_SELECT)); - } + int delimit = delimit_init; + + select_linked_delimit_validate(bm, &delimit); - /* exclude all delimited verts */ if (delimit) { - BMEdge *e; - BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - if (!BMO_edge_flag_test(bm, e, BMO_ELE_TAG)) { - BM_elem_flag_disable(e->v1, BM_ELEM_TAG); - BM_elem_flag_disable(e->v2, BM_ELEM_TAG); - } - } + select_linked_delimit_begin(em->bm, delimit); } - BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL, - BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP, - BMW_FLAG_TEST_HIDDEN, - BMW_NIL_LAY); + if (em->selectmode & SCE_SELECT_VERTEX) { + BMVert *v; - if (delimit) { BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(v, BM_ELEM_TAG)) { - BMElem *ele_walk; - BMW_ITER (ele_walk, &walker, v) { - if (ele_walk->head.htype == BM_LOOP) { - BMVert *v_step = ((BMLoop *)ele_walk)->v; - BM_vert_select_set(em->bm, v_step, true); - BM_elem_flag_disable(v_step, BM_ELEM_TAG); - } - else { - BMEdge *e_step = (BMEdge *)ele_walk; - BLI_assert(ele_walk->head.htype == BM_EDGE); - BM_edge_select_set(em->bm, e_step, true); - BM_elem_flag_disable(e_step->v1, BM_ELEM_TAG); - BM_elem_flag_disable(e_step->v2, BM_ELEM_TAG); + BM_elem_flag_set(v, BM_ELEM_TAG, BM_elem_flag_test(v, BM_ELEM_SELECT)); + } + + /* exclude all delimited verts */ + if (delimit) { + BMEdge *e; + BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { + if (!BMO_edge_flag_test(bm, e, BMO_ELE_TAG)) { + BM_elem_flag_disable(e->v1, BM_ELEM_TAG); + BM_elem_flag_disable(e->v2, BM_ELEM_TAG); + } + } + } + + BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL, + BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_TEST_HIDDEN, + BMW_NIL_LAY); + + if (delimit) { + BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { + if (BM_elem_flag_test(v, BM_ELEM_TAG)) { + BMElem *ele_walk; + BMW_ITER (ele_walk, &walker, v) { + if (ele_walk->head.htype == BM_LOOP) { + BMVert *v_step = ((BMLoop *)ele_walk)->v; + BM_vert_select_set(em->bm, v_step, true); + BM_elem_flag_disable(v_step, BM_ELEM_TAG); + } + else { + BMEdge *e_step = (BMEdge *)ele_walk; + BLI_assert(ele_walk->head.htype == BM_EDGE); + BM_edge_select_set(em->bm, e_step, true); + BM_elem_flag_disable(e_step->v1, BM_ELEM_TAG); + BM_elem_flag_disable(e_step->v2, BM_ELEM_TAG); + } } } } } - } - else { - BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(v, BM_ELEM_TAG)) { - BMEdge *e_walk; - BMW_ITER (e_walk, &walker, v) { - BM_edge_select_set(em->bm, e_walk, true); - BM_elem_flag_disable(e_walk, BM_ELEM_TAG); + else { + BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { + if (BM_elem_flag_test(v, BM_ELEM_TAG)) { + BMEdge *e_walk; + BMW_ITER (e_walk, &walker, v) { + BM_edge_select_set(em->bm, e_walk, true); + BM_elem_flag_disable(e_walk, BM_ELEM_TAG); + } } } } - } - BMW_end(&walker); + BMW_end(&walker); - EDBM_selectmode_flush(em); - } - else if (em->selectmode & SCE_SELECT_EDGE) { - BMEdge *e; + EDBM_selectmode_flush(em); + } + else if (em->selectmode & SCE_SELECT_EDGE) { + BMEdge *e; - if (delimit) { - BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - BM_elem_flag_set( - e, BM_ELEM_TAG, - (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_edge_flag_test(bm, e, BMO_ELE_TAG))); + if (delimit) { + BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { + BM_elem_flag_set( + e, BM_ELEM_TAG, + (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_edge_flag_test(bm, e, BMO_ELE_TAG))); + } } - } - else { - BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT)); + else { + BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { + BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT)); + } } - } - BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL, - BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP, - BMW_FLAG_TEST_HIDDEN, - BMW_NIL_LAY); - - if (delimit) { - BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_TAG)) { - BMElem *ele_walk; - BMW_ITER (ele_walk, &walker, e) { - if (ele_walk->head.htype == BM_LOOP) { - BMLoop *l_step = (BMLoop *)ele_walk; - BM_edge_select_set(em->bm, l_step->e, true); - BM_edge_select_set(em->bm, l_step->prev->e, true); - BM_elem_flag_disable(l_step->e, BM_ELEM_TAG); - } - else { - BMEdge *e_step = (BMEdge *)ele_walk; - BLI_assert(ele_walk->head.htype == BM_EDGE); - BM_edge_select_set(em->bm, e_step, true); - BM_elem_flag_disable(e_step, BM_ELEM_TAG); + BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL, + BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_TEST_HIDDEN, + BMW_NIL_LAY); + + if (delimit) { + BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { + if (BM_elem_flag_test(e, BM_ELEM_TAG)) { + BMElem *ele_walk; + BMW_ITER (ele_walk, &walker, e) { + if (ele_walk->head.htype == BM_LOOP) { + BMLoop *l_step = (BMLoop *)ele_walk; + BM_edge_select_set(em->bm, l_step->e, true); + BM_edge_select_set(em->bm, l_step->prev->e, true); + BM_elem_flag_disable(l_step->e, BM_ELEM_TAG); + } + else { + BMEdge *e_step = (BMEdge *)ele_walk; + BLI_assert(ele_walk->head.htype == BM_EDGE); + BM_edge_select_set(em->bm, e_step, true); + BM_elem_flag_disable(e_step, BM_ELEM_TAG); + } } } } } - } - else { - BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_TAG)) { - BMEdge *e_walk; - BMW_ITER (e_walk, &walker, e) { - BM_edge_select_set(em->bm, e_walk, true); - BM_elem_flag_disable(e_walk, BM_ELEM_TAG); + else { + BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { + if (BM_elem_flag_test(e, BM_ELEM_TAG)) { + BMEdge *e_walk; + BMW_ITER (e_walk, &walker, e) { + BM_edge_select_set(em->bm, e_walk, true); + BM_elem_flag_disable(e_walk, BM_ELEM_TAG); + } } } } - } - - BMW_end(&walker); - EDBM_selectmode_flush(em); - } - else { - BMFace *f; + BMW_end(&walker); - BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { - BM_elem_flag_set(f, BM_ELEM_TAG, BM_elem_flag_test(f, BM_ELEM_SELECT)); + EDBM_selectmode_flush(em); } + else { + BMFace *f; - BMW_init(&walker, bm, BMW_ISLAND, - BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP, - BMW_FLAG_TEST_HIDDEN, - BMW_NIL_LAY); + BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { + BM_elem_flag_set(f, BM_ELEM_TAG, BM_elem_flag_test(f, BM_ELEM_SELECT)); + } - BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(f, BM_ELEM_TAG)) { - BMFace *f_walk; - BMW_ITER (f_walk, &walker, f) { - BM_face_select_set(bm, f_walk, true); - BM_elem_flag_disable(f_walk, BM_ELEM_TAG); + BMW_init(&walker, bm, BMW_ISLAND, + BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP, + BMW_FLAG_TEST_HIDDEN, + BMW_NIL_LAY); + + BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { + if (BM_elem_flag_test(f, BM_ELEM_TAG)) { + BMFace *f_walk; + BMW_ITER (f_walk, &walker, f) { + BM_face_select_set(bm, f_walk, true); + BM_elem_flag_disable(f_walk, BM_ELEM_TAG); + } } } + + BMW_end(&walker); } - BMW_end(&walker); - } + if (delimit) { + select_linked_delimit_end(em); + } + + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); - if (delimit) { - select_linked_delimit_end(em); } - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + MEM_SAFE_FREE(objects); return OPERATOR_FINISHED; } @@ -2902,11 +3015,8 @@ static void edbm_select_linked_pick_ex(BMEditMesh *em, BMElem *ele, bool sel, in static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - Object *obedit = CTX_data_edit_object(C); - EvaluationContext eval_ctx; ViewContext vc; - BMEditMesh *em; - BMesh *bm; + Base *basact = NULL; BMVert *eve; BMEdge *eed; BMFace *efa; @@ -2921,27 +3031,40 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmE view3d_operator_needs_opengl(C); /* setup view context for argument to callbacks */ - CTX_data_eval_ctx(C, &eval_ctx); em_setup_viewcontext(C, &vc); - em = vc.em; - bm = em->bm; - if (bm->totedge == 0) { - return OPERATOR_CANCELLED; + { + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc.view_layer, &objects_len); + bool has_edges = false; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob_iter = objects[ob_index]; + ED_view3d_viewcontext_init_object(&vc, ob_iter); + if (vc.em->bm->totedge) { + has_edges = true; + } + } + MEM_SAFE_FREE(objects); + if (has_edges == false) { + return OPERATOR_CANCELLED; + } } vc.mval[0] = event->mval[0]; vc.mval[1] = event->mval[1]; /* return warning! */ - if (unified_findnearest(&eval_ctx, &vc, &eve, &eed, &efa) == 0) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + if (unified_findnearest(&vc, &basact, &eve, &eed, &efa) == 0) { + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, basact->object->data); return OPERATOR_CANCELLED; } + ED_view3d_viewcontext_init_object(&vc, basact->object); + BMEditMesh *em = vc.em; + BMesh *bm = em->bm; #ifdef USE_LINKED_SELECT_DEFAULT_HACK - int delimit = select_linked_delimit_default_from_op(op, em->selectmode); + int delimit = select_linked_delimit_default_from_op(op, vc.scene->toolsettings->selectmode); #else int delimit = RNA_enum_get(op->ptr, "delimit"); #endif @@ -2954,9 +3077,11 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmE BM_mesh_elem_index_ensure(bm, ele->head.htype); index = EDBM_elem_to_index_any(em, ele); + /* TODO(MULTI_EDIT), index doesn't know which object, + * index selections isn't very common. */ RNA_int_set(op->ptr, "index", index); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, basact->object->data); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index bf70cc3fa7e..3d12f8ce868 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -93,29 +93,39 @@ static int edbm_subdivide_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); - const int cuts = RNA_int_get(op->ptr, "number_cuts"); - float smooth = RNA_float_get(op->ptr, "smoothness"); - const float fractal = RNA_float_get(op->ptr, "fractal") / 2.5f; - const float along_normal = RNA_float_get(op->ptr, "fractal_along_normal"); + ViewLayer *view_layer = CTX_data_view_layer(C); - if (RNA_boolean_get(op->ptr, "quadtri") && - RNA_enum_get(op->ptr, "quadcorner") == SUBD_CORNER_STRAIGHT_CUT) - { - RNA_enum_set(op->ptr, "quadcorner", SUBD_CORNER_INNERVERT); - } + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); - BM_mesh_esubdivide( - em->bm, BM_ELEM_SELECT, - smooth, SUBD_FALLOFF_LIN, false, - fractal, along_normal, - cuts, - SUBDIV_SELECT_ORIG, RNA_enum_get(op->ptr, "quadcorner"), - RNA_boolean_get(op->ptr, "quadtri"), true, false, - RNA_int_get(op->ptr, "seed")); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; - EDBM_update_generic(em, true, true); + BMEditMesh *em = BKE_editmesh_from_object(obedit); + const int cuts = RNA_int_get(op->ptr, "number_cuts"); + float smooth = RNA_float_get(op->ptr, "smoothness"); + const float fractal = RNA_float_get(op->ptr, "fractal") / 2.5f; + const float along_normal = RNA_float_get(op->ptr, "fractal_along_normal"); + + if (RNA_boolean_get(op->ptr, "quadtri") && + RNA_enum_get(op->ptr, "quadcorner") == SUBD_CORNER_STRAIGHT_CUT) + { + RNA_enum_set(op->ptr, "quadcorner", SUBD_CORNER_INNERVERT); + } + + BM_mesh_esubdivide( + em->bm, BM_ELEM_SELECT, + smooth, SUBD_FALLOFF_LIN, false, + fractal, along_normal, + cuts, + SUBDIV_SELECT_ORIG, RNA_enum_get(op->ptr, "quadcorner"), + RNA_boolean_get(op->ptr, "quadtri"), true, false, + RNA_int_get(op->ptr, "seed")); + + EDBM_update_generic(em, true, true); + } + + MEM_SAFE_FREE(objects); return OPERATOR_FINISHED; } @@ -326,7 +336,7 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em) ED_view3d_init_mats_rv3d(obedit, ar->regiondata); struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( - CTX_data_main(C), CTX_data_scene(C), CTX_data_view_layer(C), 0, + CTX_data_main(C), CTX_data_scene(C), 0, ar, CTX_wm_view3d(C)); BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { @@ -367,50 +377,58 @@ enum { MESH_DELETE_ONLY_FACE = 4, }; -static void edbm_report_delete_info(ReportList *reports, BMesh *bm, const int totelem[3]) +static void edbm_report_delete_info(ReportList *reports, const int totelem_old[3], const int totelem_new[3]) { BKE_reportf(reports, RPT_INFO, "Removed: %d vertices, %d edges, %d faces", - totelem[0] - bm->totvert, totelem[1] - bm->totedge, totelem[2] - bm->totface); + totelem_old[0] - totelem_new[0], totelem_old[1] - totelem_new[1], totelem_old[2] - totelem_new[2]); } static int edbm_delete_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); - const int type = RNA_enum_get(op->ptr, "type"); + ViewLayer *view_layer = CTX_data_view_layer(C); - switch (type) { - case MESH_DELETE_VERT: - if (!EDBM_op_callf(em, op, "delete geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS)) /* Erase Vertices */ - return OPERATOR_CANCELLED; - break; - case MESH_DELETE_EDGE: - if (!EDBM_op_callf(em, op, "delete geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES)) /* Erase Edges */ - return OPERATOR_CANCELLED; - break; - case MESH_DELETE_FACE: - if (!EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES)) /* Erase Faces */ - return OPERATOR_CANCELLED; - break; - case MESH_DELETE_EDGE_FACE: - /* Edges and Faces */ - if (!EDBM_op_callf(em, op, "delete geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES)) - return OPERATOR_CANCELLED; - break; - case MESH_DELETE_ONLY_FACE: - /* Only faces. */ - if (!EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_ONLYFACES)) - return OPERATOR_CANCELLED; - break; - default: - BLI_assert(0); - break; - } + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); - EDBM_flag_disable_all(em, BM_ELEM_SELECT); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + const int type = RNA_enum_get(op->ptr, "type"); - EDBM_update_generic(em, true, true); + switch (type) { + case MESH_DELETE_VERT: + if (!EDBM_op_callf(em, op, "delete geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS)) /* Erase Vertices */ + return OPERATOR_CANCELLED; + break; + case MESH_DELETE_EDGE: + if (!EDBM_op_callf(em, op, "delete geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES)) /* Erase Edges */ + return OPERATOR_CANCELLED; + break; + case MESH_DELETE_FACE: + if (!EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES)) /* Erase Faces */ + return OPERATOR_CANCELLED; + break; + case MESH_DELETE_EDGE_FACE: + /* Edges and Faces */ + if (!EDBM_op_callf(em, op, "delete geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES)) + return OPERATOR_CANCELLED; + break; + case MESH_DELETE_ONLY_FACE: + /* Only faces. */ + if (!EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_ONLYFACES)) + return OPERATOR_CANCELLED; + break; + default: + BLI_assert(0); + break; + } + + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + + EDBM_update_generic(em, true, true); + + } return OPERATOR_FINISHED; } @@ -467,61 +485,75 @@ static bool bm_face_is_loose(BMFace *f) static int edbm_delete_loose_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); - BMesh *bm = em->bm; - BMIter iter; + ViewLayer *view_layer = CTX_data_view_layer(C); + int totelem_old_sel[3]; + int totelem_old[3]; - const bool use_verts = (RNA_boolean_get(op->ptr, "use_verts") && bm->totvertsel); - const bool use_edges = (RNA_boolean_get(op->ptr, "use_edges") && bm->totedgesel); - const bool use_faces = (RNA_boolean_get(op->ptr, "use_faces") && bm->totfacesel); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); - const int totelem[3] = {bm->totvert, bm->totedge, bm->totface}; + EDBM_mesh_stats_multi(objects, objects_len, totelem_old, totelem_old_sel); + const bool use_verts = (RNA_boolean_get(op->ptr, "use_verts") && totelem_old_sel[0]); + const bool use_edges = (RNA_boolean_get(op->ptr, "use_edges") && totelem_old_sel[1]); + const bool use_faces = (RNA_boolean_get(op->ptr, "use_faces") && totelem_old_sel[2]); - BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; - if (use_faces) { - BMFace *f; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + BMIter iter; - BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { - BM_elem_flag_set(f, BM_ELEM_TAG, bm_face_is_loose(f)); + BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false); + + if (use_faces) { + BMFace *f; + + BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { + if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { + BM_elem_flag_set(f, BM_ELEM_TAG, bm_face_is_loose(f)); + } } - } - BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_FACES); - } + BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_FACES); + } - if (use_edges) { - BMEdge *e; + if (use_edges) { + BMEdge *e; - BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { - if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { - BM_elem_flag_set(e, BM_ELEM_TAG, BM_edge_is_wire(e)); + BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { + if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { + BM_elem_flag_set(e, BM_ELEM_TAG, BM_edge_is_wire(e)); + } } - } - BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_EDGES); - } + BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_EDGES); + } - if (use_verts) { - BMVert *v; + if (use_verts) { + BMVert *v; - BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { - BM_elem_flag_set(v, BM_ELEM_TAG, (v->e == NULL)); + BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { + if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { + BM_elem_flag_set(v, BM_ELEM_TAG, (v->e == NULL)); + } } + + BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_VERTS); } - BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_VERTS); + EDBM_flag_disable_all(em, BM_ELEM_SELECT); + + EDBM_update_generic(em, true, true); } - EDBM_flag_disable_all(em, BM_ELEM_SELECT); + int totelem_new[3]; + EDBM_mesh_stats_multi(objects, objects_len, totelem_new, NULL); - EDBM_update_generic(em, true, true); + edbm_report_delete_info(op->reports, totelem_old, totelem_new); - edbm_report_delete_info(op->reports, bm, totelem); + MEM_SAFE_FREE(objects); return OPERATOR_FINISHED; } @@ -4096,32 +4128,43 @@ void MESH_OT_poke(wmOperatorType *ot) static int edbm_quads_convert_to_tris_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); - BMOperator bmop; const int quad_method = RNA_enum_get(op->ptr, "quad_method"); const int ngon_method = RNA_enum_get(op->ptr, "ngon_method"); - BMOIter oiter; - BMFace *f; + ViewLayer *view_layer = CTX_data_view_layer(C); - EDBM_op_init(em, &bmop, op, "triangulate faces=%hf quad_method=%i ngon_method=%i", BM_ELEM_SELECT, quad_method, ngon_method); - BMO_op_exec(em->bm, &bmop); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); - /* select the output */ - BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; - /* remove the doubles */ - BMO_ITER (f, &oiter, bmop.slots_out, "face_map_double.out", BM_FACE) { - BM_face_kill(em->bm, f); - } + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMOperator bmop; + BMOIter oiter; + BMFace *f; - EDBM_selectmode_flush(em); + EDBM_op_init(em, &bmop, op, "triangulate faces=%hf quad_method=%i ngon_method=%i", BM_ELEM_SELECT, quad_method, ngon_method); + BMO_op_exec(em->bm, &bmop); - if (!EDBM_op_finish(em, &bmop, op, true)) { - return OPERATOR_CANCELLED; - } + /* select the output */ + BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true); - EDBM_update_generic(em, true, true); + /* remove the doubles */ + BMO_ITER (f, &oiter, bmop.slots_out, "face_map_double.out", BM_FACE) { + BM_face_kill(em->bm, f); + } + + EDBM_selectmode_flush(em); + + // XXX, TODO + #if 0 + if (!EDBM_op_finish(em, &bmop, op, true)) { + return OPERATOR_CANCELLED; + } + #endif + + EDBM_update_generic(em, true, true); + } return OPERATOR_FINISHED; } @@ -4155,52 +4198,68 @@ void MESH_OT_quads_convert_to_tris(wmOperatorType *ot) static int edbm_tris_convert_to_quads_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); - bool do_seam, do_sharp, do_uvs, do_vcols, do_materials; - float angle_face_threshold, angle_shape_threshold; - PropertyRNA *prop; + ViewLayer *view_layer = CTX_data_view_layer(C); - /* When joining exactly 2 faces, no limit. - * this is useful for one off joins while editing. */ - prop = RNA_struct_find_property(op->ptr, "face_threshold"); - if ((em->bm->totfacesel == 2) && - (RNA_property_is_set(op->ptr, prop) == false)) - { - angle_face_threshold = DEG2RADF(180.0f); - } - else { - angle_face_threshold = RNA_property_float_get(op->ptr, prop); - } + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + bool is_face_pair; - prop = RNA_struct_find_property(op->ptr, "shape_threshold"); - if ((em->bm->totfacesel == 2) && - (RNA_property_is_set(op->ptr, prop) == false)) { - angle_shape_threshold = DEG2RADF(180.0f); - } - else { - angle_shape_threshold = RNA_property_float_get(op->ptr, prop); + int totelem_sel[3]; + EDBM_mesh_stats_multi(objects, objects_len, NULL, totelem_sel); + is_face_pair = (totelem_sel[2] == 2); } - do_seam = RNA_boolean_get(op->ptr, "seam"); - do_sharp = RNA_boolean_get(op->ptr, "sharp"); - do_uvs = RNA_boolean_get(op->ptr, "uvs"); - do_vcols = RNA_boolean_get(op->ptr, "vcols"); - do_materials = RNA_boolean_get(op->ptr, "materials"); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; - if (!EDBM_op_call_and_selectf( - em, op, - "faces.out", true, - "join_triangles faces=%hf angle_face_threshold=%f angle_shape_threshold=%f " - "cmp_seam=%b cmp_sharp=%b cmp_uvs=%b cmp_vcols=%b cmp_materials=%b", - BM_ELEM_SELECT, angle_face_threshold, angle_shape_threshold, - do_seam, do_sharp, do_uvs, do_vcols, do_materials)) - { - return OPERATOR_CANCELLED; - } + BMEditMesh *em = BKE_editmesh_from_object(obedit); + bool do_seam, do_sharp, do_uvs, do_vcols, do_materials; + float angle_face_threshold, angle_shape_threshold; + PropertyRNA *prop; + + /* When joining exactly 2 faces, no limit. + * this is useful for one off joins while editing. */ + prop = RNA_struct_find_property(op->ptr, "face_threshold"); + if (is_face_pair && + (RNA_property_is_set(op->ptr, prop) == false)) + { + angle_face_threshold = DEG2RADF(180.0f); + } + else { + angle_face_threshold = RNA_property_float_get(op->ptr, prop); + } - EDBM_update_generic(em, true, true); + prop = RNA_struct_find_property(op->ptr, "shape_threshold"); + if (is_face_pair && + (RNA_property_is_set(op->ptr, prop) == false)) + { + angle_shape_threshold = DEG2RADF(180.0f); + } + else { + angle_shape_threshold = RNA_property_float_get(op->ptr, prop); + } + + do_seam = RNA_boolean_get(op->ptr, "seam"); + do_sharp = RNA_boolean_get(op->ptr, "sharp"); + do_uvs = RNA_boolean_get(op->ptr, "uvs"); + do_vcols = RNA_boolean_get(op->ptr, "vcols"); + do_materials = RNA_boolean_get(op->ptr, "materials"); + + if (!EDBM_op_call_and_selectf( + em, op, + "faces.out", true, + "join_triangles faces=%hf angle_face_threshold=%f angle_shape_threshold=%f " + "cmp_seam=%b cmp_sharp=%b cmp_uvs=%b cmp_vcols=%b cmp_materials=%b", + BM_ELEM_SELECT, angle_face_threshold, angle_shape_threshold, + do_seam, do_sharp, do_uvs, do_vcols, do_materials)) + { + continue; + } + + EDBM_update_generic(em, true, true); + } return OPERATOR_FINISHED; } @@ -4727,26 +4786,48 @@ void MESH_OT_dissolve_limited(wmOperatorType *ot) static int edbm_dissolve_degenerate_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); + ViewLayer *view_layer = CTX_data_view_layer(C); + int totelem_old[3] = {0, 0, 0}; + int totelem_new[3] = {0, 0, 0}; + + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + totelem_old[0] += bm->totvert; + totelem_old[1] += bm->totedge; + totelem_old[2] += bm->totface; + } /* objects */ + const float thresh = RNA_float_get(op->ptr, "threshold"); - BMesh *bm = em->bm; - const int totelem[3] = {bm->totvert, bm->totedge, bm->totface}; + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; - if (!EDBM_op_callf( - em, op, - "dissolve_degenerate edges=%he dist=%f", - BM_ELEM_SELECT, thresh)) - { - return OPERATOR_CANCELLED; - } + if (!EDBM_op_callf( + em, op, + "dissolve_degenerate edges=%he dist=%f", + BM_ELEM_SELECT, thresh)) + { + return OPERATOR_CANCELLED; + } - /* tricky to maintain correct selection here, so just flush up from verts */ - EDBM_select_flush(em); + /* tricky to maintain correct selection here, so just flush up from verts */ + EDBM_select_flush(em); - EDBM_update_generic(em, true, true); + EDBM_update_generic(em, true, true); + + totelem_new[0] += bm->totvert; + totelem_new[1] += bm->totedge; + totelem_new[2] += bm->totface; + } - edbm_report_delete_info(op->reports, bm, totelem); + edbm_report_delete_info(op->reports, totelem_old, totelem_new); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c index ab7e13117a0..4d4b7a098b0 100644 --- a/source/blender/editors/mesh/editmesh_undo.c +++ b/source/blender/editors/mesh/editmesh_undo.c @@ -24,9 +24,12 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #include "DNA_mesh_types.h" #include "DNA_object_types.h" #include "DNA_key_types.h" +#include "DNA_layer_types.h" #include "BLI_listbase.h" #include "BLI_array_utils.h" @@ -35,6 +38,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_context.h" #include "BKE_key.h" +#include "BKE_layer.h" #include "BKE_mesh.h" #include "BKE_editmesh.h" #include "BKE_undo_system.h" @@ -44,6 +48,7 @@ #include "ED_object.h" #include "ED_mesh.h" #include "ED_util.h" +#include "ED_undo.h" #include "WM_types.h" #include "WM_api.h" @@ -69,6 +74,9 @@ # include "BLI_task.h" #endif +/** We only need this locally. */ +static CLG_LogRef LOG = {"ed.undo.mesh"}; + /* -------------------------------------------------------------------- */ /** \name Undo Conversion * \{ */ @@ -668,16 +676,21 @@ static Object *editmesh_object_from_context(bContext *C) /* -------------------------------------------------------------------- */ /** \name Implements ED Undo System + * + * \note This is similar for all edit-mode types. * \{ */ +typedef struct MeshUndoStep_Elem { + struct MeshUndoStep_Elem *next, *prev; + UndoRefID_Object obedit_ref; + UndoMesh data; +} MeshUndoStep_Elem; + typedef struct MeshUndoStep { UndoStep step; - /* Use for all ID lookups (can be NULL). */ struct UndoIDPtrMap *id_map; - - /* note: will split out into list for multi-object-editmode. */ - UndoRefID_Object obedit_ref; - UndoMesh data; + MeshUndoStep_Elem *elems; + uint elems_len; } MeshUndoStep; static bool mesh_undosys_poll(bContext *C) @@ -688,10 +701,24 @@ static bool mesh_undosys_poll(bContext *C) static bool mesh_undosys_step_encode(struct bContext *C, UndoStep *us_p) { MeshUndoStep *us = (MeshUndoStep *)us_p; - us->obedit_ref.ptr = editmesh_object_from_context(C); - Mesh *me = us->obedit_ref.ptr->data; - undomesh_from_editmesh(&us->data, me->edit_btmesh, me->key); - us->step.data_size = us->data.undo_size; + + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__); + us->elems_len = objects_len; + + for (uint i = 0; i < objects_len; i++) { + Object *ob = objects[i]; + MeshUndoStep_Elem *elem = &us->elems[i]; + + elem->obedit_ref.ptr = ob; + Mesh *me = elem->obedit_ref.ptr->data; + undomesh_from_editmesh(&elem->data, me->edit_btmesh, me->key); + us->step.data_size += elem->data.undo_size; + } + MEM_freeN(objects); return true; } @@ -702,18 +729,37 @@ static void mesh_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNU BLI_assert(mesh_undosys_poll(C)); MeshUndoStep *us = (MeshUndoStep *)us_p; - Object *obedit = us->obedit_ref.ptr; - Mesh *me = obedit->data; - BMEditMesh *em = me->edit_btmesh; - undomesh_to_editmesh(&us->data, em, obedit->data); - DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + + for (uint i = 0; i < us->elems_len; i++) { + MeshUndoStep_Elem *elem = &us->elems[i]; + Object *obedit = elem->obedit_ref.ptr; + Mesh *me = obedit->data; + if (me->edit_btmesh == NULL) { + /* Should never fail, may not crash but can give odd behavior. */ + CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", + us_p->name, obedit->id.name); + continue; + } + BMEditMesh *em = me->edit_btmesh; + undomesh_to_editmesh(&elem->data, em, obedit->data); + DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + } + + /* The first element is always active */ + ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } static void mesh_undosys_step_free(UndoStep *us_p) { MeshUndoStep *us = (MeshUndoStep *)us_p; - undomesh_free_data(&us->data); + + for (uint i = 0; i < us->elems_len; i++) { + MeshUndoStep_Elem *elem = &us->elems[i]; + undomesh_free_data(&elem->data); + } + MEM_freeN(us->elems); if (us->id_map != NULL) { BKE_undosys_ID_map_destroy(us->id_map); @@ -724,7 +770,12 @@ static void mesh_undosys_foreach_ID_ref( UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data) { MeshUndoStep *us = (MeshUndoStep *)us_p; - foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref)); + + for (uint i = 0; i < us->elems_len; i++) { + MeshUndoStep_Elem *elem = &us->elems[i]; + foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref)); + } + if (us->id_map != NULL) { BKE_undosys_ID_map_foreach_ID_ref(us->id_map, foreach_ID_ref_fn, user_data); } diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 3382847c8a4..af4ef00bc25 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -1481,7 +1481,7 @@ static void scale_point(float c1[3], const float p[3], const float s) } bool BMBVH_EdgeVisible(struct BMBVHTree *tree, BMEdge *e, - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, ARegion *ar, View3D *v3d, Object *obedit) { BMFace *f; diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c index bd2ad21d51c..c94015de0f6 100644 --- a/source/blender/editors/mesh/mesh_navmesh.c +++ b/source/blender/editors/mesh/mesh_navmesh.c @@ -73,22 +73,20 @@ static void createVertsTrisData(bContext *C, LinkNode *obs, Object *ob; LinkNode *oblink, *dmlink; DerivedMesh *dm; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); - EvaluationContext eval_ctx; LinkNodePair dms_pair = {NULL, NULL}; int nverts, ntris, *tris; float *verts; - CTX_data_eval_ctx(C, &eval_ctx); - nverts = 0; ntris = 0; /* calculate number of verts and tris */ for (oblink = obs; oblink; oblink = oblink->next) { ob = (Object *) oblink->link; - dm = mesh_create_derived_no_virtual(&eval_ctx, scene, ob, NULL, CD_MASK_MESH); + dm = mesh_create_derived_no_virtual(depsgraph, scene, ob, NULL, CD_MASK_MESH); DM_ensure_tessface(dm); BLI_linklist_append(&dms_pair, dm); diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 531a26a66a8..83458127820 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -60,6 +60,7 @@ #include "BKE_report.h" #include "BKE_editmesh.h" #include "BKE_multires.h" +#include "BKE_layer.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" @@ -79,7 +80,7 @@ * return 0 if no join is made (error) and 1 if the join is done */ static void join_mesh_single( - const EvaluationContext *eval_ctx, Main *bmain, Scene *scene, + Depsgraph *depsgraph, Main *bmain, Scene *scene, Object *ob_dst, Object *ob_src, float imat[4][4], MVert **mvert_pp, MEdge **medge_pp, MLoop **mloop_pp, MPoly **mpoly_pp, CustomData *vdata, CustomData *edata, CustomData *ldata, CustomData *pdata, @@ -207,7 +208,7 @@ static void join_mesh_single( if (ob_src != ob_dst) { MultiresModifierData *mmd; - multiresModifier_prepare_join(eval_ctx, scene, ob_src, ob_dst); + multiresModifier_prepare_join(depsgraph, scene, ob_src, ob_dst); if ((mmd = get_multires_modifier(scene, ob_src, true))) { ED_object_iter_other(bmain, ob_src, true, @@ -292,8 +293,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); /* count & check */ CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) @@ -489,7 +489,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) * active mesh will remain first ones in new result of the merge, in same order for CD layers, etc. See also T50084. */ join_mesh_single( - &eval_ctx, bmain, scene, + depsgraph, bmain, scene, ob, ob, imat, &mvert, &medge, &mloop, &mpoly, &vdata, &edata, &ldata, &pdata, @@ -506,7 +506,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) /* only join if this is a mesh */ if (base->object->type == OB_MESH) { join_mesh_single( - &eval_ctx, bmain, scene, + depsgraph, bmain, scene, ob, base->object, imat, &mvert, &medge, &mloop, &mpoly, &vdata, &edata, &ldata, &pdata, @@ -606,7 +606,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Mesh *me = (Mesh *)ob->data; Mesh *selme = NULL; DerivedMesh *dm = NULL; @@ -614,8 +614,6 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) KeyBlock *kb; bool ok = false, nonequal_verts = false; - CTX_data_eval_ctx(C, &eval_ctx); - CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { if (base->object == ob) continue; @@ -657,7 +655,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) selme = (Mesh *)base->object->data; if (selme->totvert == me->totvert) { - dm = mesh_get_derived_deform(&eval_ctx, scene, base->object, CD_MASK_BAREMESH); + dm = mesh_get_derived_deform(depsgraph, scene, base->object, CD_MASK_BAREMESH); if (!dm) continue; @@ -1008,7 +1006,6 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, DerivedMesh *dm) */ bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size) { - EvaluationContext eval_ctx; ViewContext vc; Mesh *me = ob->data; @@ -1017,7 +1014,6 @@ bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int if (!me || me->totpoly == 0) return false; - CTX_data_eval_ctx(C, &eval_ctx); ED_view3d_viewcontext_init(C, &vc); if (size) { @@ -1025,11 +1021,11 @@ bool ED_mesh_pick_face(bContext *C, Object *ob, const int mval[2], unsigned int * on an edge in the backbuf, we can still select a face */ float dummy_dist; - *index = ED_view3d_backbuf_sample_rect(&eval_ctx, &vc, mval, size, 1, me->totpoly + 1, &dummy_dist); + *index = ED_view3d_backbuf_sample_rect(&vc, mval, size, 1, me->totpoly + 1, &dummy_dist); } else { /* sample only on the exact position */ - *index = ED_view3d_backbuf_sample(&eval_ctx, &vc, mval[0], mval[1]); + *index = ED_view3d_backbuf_sample(&vc, mval[0], mval[1]); } if ((*index) == 0 || (*index) > (unsigned int)me->totpoly) @@ -1068,12 +1064,10 @@ static void ed_mesh_pick_face_vert__mpoly_find( */ bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size) { - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); unsigned int poly_index; Mesh *me = ob->data; - CTX_data_eval_ctx(C, &eval_ctx); - BLI_assert(me && GS(me->id.name) == ID_ME); if (ED_mesh_pick_face(C, ob, mval, &poly_index, size)) { @@ -1081,7 +1075,7 @@ bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned struct ARegion *ar = CTX_wm_region(C); /* derived mesh to find deformed locations */ - DerivedMesh *dm = mesh_get_derived_final(&eval_ctx, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); int v_idx_best = ORIGINDEX_NONE; @@ -1178,12 +1172,9 @@ static void ed_mesh_pick_vert__mapFunc(void *userData, int index, const float co } bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size, bool use_zbuf) { - EvaluationContext eval_ctx; ViewContext vc; Mesh *me = ob->data; - CTX_data_eval_ctx(C, &eval_ctx); - BLI_assert(me && GS(me->id.name) == ID_ME); if (!me || me->totvert == 0) @@ -1197,11 +1188,11 @@ bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int * on an face in the backbuf, we can still select a vert */ float dummy_dist; - *index = ED_view3d_backbuf_sample_rect(&eval_ctx, &vc, mval, size, 1, me->totvert + 1, &dummy_dist); + *index = ED_view3d_backbuf_sample_rect(&vc, mval, size, 1, me->totvert + 1, &dummy_dist); } else { /* sample only on the exact position */ - *index = ED_view3d_backbuf_sample(&eval_ctx, &vc, mval[0], mval[1]); + *index = ED_view3d_backbuf_sample(&vc, mval[0], mval[1]); } if ((*index) == 0 || (*index) > (unsigned int)me->totvert) @@ -1211,7 +1202,7 @@ bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int } else { /* derived mesh to find deformed locations */ - DerivedMesh *dm = mesh_get_derived_final(&eval_ctx, vc.scene, ob, CD_MASK_BAREMESH); + DerivedMesh *dm = mesh_get_derived_final(vc.depsgraph, vc.scene, ob, CD_MASK_BAREMESH); ARegion *ar = vc.ar; RegionView3D *rv3d = ar->regiondata; @@ -1297,3 +1288,47 @@ MDeformVert *ED_mesh_active_dvert_get_only(Object *ob) return NULL; } } + +void EDBM_mesh_stats_multi( + struct Object **objects, const uint objects_len, + int totelem[3], int totelem_sel[3]) +{ + if (totelem) { + totelem[0] = 0; + totelem[1] = 0; + totelem[2] = 0; + } + if (totelem_sel) { + totelem_sel[0] = 0; + totelem_sel[1] = 0; + totelem_sel[2] = 0; + } + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + if (totelem) { + totelem[0] += bm->totvert; + totelem[1] += bm->totedge; + totelem[2] += bm->totface; + } + if (totelem_sel) { + totelem_sel[0] += bm->totvertsel; + totelem_sel[1] += bm->totedgesel; + totelem_sel[2] += bm->totfacesel; + } + } +} + + +void EDBM_mesh_elem_index_ensure_multi(Object **objects, const uint objects_len, const char htype) +{ + int elem_offset[4] = {0, 0, 0, 0}; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + BM_mesh_elem_index_ensure_ex(bm, htype, elem_offset); + } +} diff --git a/source/blender/editors/metaball/CMakeLists.txt b/source/blender/editors/metaball/CMakeLists.txt index 73f80774716..b0ae3122727 100644 --- a/source/blender/editors/metaball/CMakeLists.txt +++ b/source/blender/editors/metaball/CMakeLists.txt @@ -27,6 +27,7 @@ set(INC ../../makesrna ../../render/extern/include ../../windowmanager + ../../../../intern/clog ../../../../intern/guardedalloc ) diff --git a/source/blender/editors/metaball/editmball_undo.c b/source/blender/editors/metaball/editmball_undo.c index cc461c0c365..7045025e227 100644 --- a/source/blender/editors/metaball/editmball_undo.c +++ b/source/blender/editors/metaball/editmball_undo.c @@ -27,6 +27,8 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #include "BLI_utildefines.h" #include "BLI_listbase.h" #include "BLI_array_utils.h" @@ -36,17 +38,22 @@ #include "DNA_object_types.h" #include "BKE_context.h" +#include "BKE_layer.h" #include "BKE_undo_system.h" #include "DEG_depsgraph.h" #include "ED_object.h" #include "ED_mball.h" +#include "ED_undo.h" #include "ED_util.h" #include "WM_types.h" #include "WM_api.h" +/** We only need this locally. */ +static CLG_LogRef LOG = {"ed.undo.mball"}; + /* -------------------------------------------------------------------- */ /** \name Undo Conversion * \{ */ @@ -130,13 +137,19 @@ static Object *editmball_object_from_context(bContext *C) /* -------------------------------------------------------------------- */ /** \name Implements ED Undo System + * + * \note This is similar for all edit-mode types. * \{ */ -typedef struct MBallUndoStep { - UndoStep step; - /* note: will split out into list for multi-object-editmode. */ +typedef struct MBallUndoStep_Elem { UndoRefID_Object obedit_ref; UndoMBall data; +} MBallUndoStep_Elem; + +typedef struct MBallUndoStep { + UndoStep step; + MBallUndoStep_Elem *elems; + uint elems_len; } MBallUndoStep; static bool mball_undosys_poll(bContext *C) @@ -147,36 +160,74 @@ static bool mball_undosys_poll(bContext *C) static bool mball_undosys_step_encode(struct bContext *C, UndoStep *us_p) { MBallUndoStep *us = (MBallUndoStep *)us_p; - us->obedit_ref.ptr = editmball_object_from_context(C); - MetaBall *mb = us->obedit_ref.ptr->data; - editmball_from_undomball(&us->data, mb); - us->step.data_size = us->data.undo_size; + + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__); + us->elems_len = objects_len; + + for (uint i = 0; i < objects_len; i++) { + Object *ob = objects[i]; + MBallUndoStep_Elem *elem = &us->elems[i]; + + elem->obedit_ref.ptr = ob; + MetaBall *mb = ob->data; + editmball_from_undomball(&elem->data, mb); + us->step.data_size += elem->data.undo_size; + } + MEM_freeN(objects); return true; } static void mball_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNUSED(dir)) { + /* TODO(campbell): undo_system: use low-level API to set mode. */ ED_object_mode_set(C, OB_MODE_EDIT); + BLI_assert(mball_undosys_poll(C)); MBallUndoStep *us = (MBallUndoStep *)us_p; - Object *obedit = us->obedit_ref.ptr; - MetaBall *mb = obedit->data; - undomball_to_editmball(&us->data, mb); - DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + + for (uint i = 0; i < us->elems_len; i++) { + MBallUndoStep_Elem *elem = &us->elems[i]; + Object *obedit = elem->obedit_ref.ptr; + MetaBall *mb = obedit->data; + if (mb->editelems == NULL) { + /* Should never fail, may not crash but can give odd behavior. */ + CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", us_p->name, obedit->id.name); + continue; + } + undomball_to_editmball(&elem->data, mb); + DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + } + + /* The first element is always active */ + ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } static void mball_undosys_step_free(UndoStep *us_p) { MBallUndoStep *us = (MBallUndoStep *)us_p; - undomball_free_data(&us->data); + + for (uint i = 0; i < us->elems_len; i++) { + MBallUndoStep_Elem *elem = &us->elems[i]; + undomball_free_data(&elem->data); + } + MEM_freeN(us->elems); } static void mball_undosys_foreach_ID_ref( UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data) { MBallUndoStep *us = (MBallUndoStep *)us_p; - foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref)); + + for (uint i = 0; i < us->elems_len; i++) { + MBallUndoStep_Elem *elem = &us->elems[i]; + foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref)); + } } /* Export for ED_undo_sys. */ diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index 6dd16b52387..0aea5cb5480 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -587,7 +587,6 @@ bool ED_mball_select_pick(bContext *C, const int mval[2], bool extend, bool dese { static MetaElem *startelem = NULL; Object *obedit = CTX_data_edit_object(C); - EvaluationContext eval_ctx; ViewContext vc; MetaBall *mb = (MetaBall *)obedit->data; MetaElem *ml, *ml_act = NULL; @@ -595,12 +594,11 @@ bool ED_mball_select_pick(bContext *C, const int mval[2], bool extend, bool dese unsigned int buffer[MAXPICKBUF]; rcti rect; - CTX_data_eval_ctx(C, &eval_ctx); ED_view3d_viewcontext_init(C, &vc); BLI_rcti_init_pt_radius(&rect, mval, 12); - hits = view3d_opengl_select(&eval_ctx, &vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST); + hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST); /* does startelem exist? */ ml = mb->editelems->first; diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index d2c859565a3..4abd80a18e8 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -223,19 +223,17 @@ void ED_object_base_init_transform(bContext *C, Base *base, const float loc[3], { Object *ob = base->object; Scene *scene = CTX_data_scene(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); if (!scene) return; - CTX_data_eval_ctx(C, &eval_ctx); - if (loc) copy_v3_v3(ob->loc, loc); if (rot) copy_v3_v3(ob->rot, rot); - BKE_object_where_is_calc(&eval_ctx, scene, ob); + BKE_object_where_is_calc(depsgraph, scene, ob); } /* Uses context to figure out transform for primitive. @@ -1431,6 +1429,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base, { Main *bmain = CTX_data_main(C); ViewLayer *view_layer = CTX_data_view_layer(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ListBase *lb_duplis; DupliObject *dob; GHash *dupli_gh, *parent_gh = NULL; @@ -1439,7 +1438,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base, return; } - lb_duplis = object_duplilist(bmain->eval_ctx, scene, base->object); + lb_duplis = object_duplilist(depsgraph, scene, base->object); dupli_gh = BLI_ghash_ptr_new(__func__); if (use_hierarchy) { @@ -1638,24 +1637,24 @@ static const EnumPropertyItem convert_target_items[] = { {0, NULL, 0, NULL, NULL} }; -static void convert_ensure_curve_cache(EvaluationContext *eval_ctx, Main *bmain, Scene *scene, Object *ob) +static void convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Object *ob) { if (ob->curve_cache == NULL) { /* Force creation. This is normally not needed but on operator * redo we might end up with an object which isn't evaluated yet. */ if (ELEM(ob->type, OB_SURF, OB_CURVE, OB_FONT)) { - BKE_displist_make_curveTypes(eval_ctx, scene, ob, false); + BKE_displist_make_curveTypes(depsgraph, scene, ob, false); } else if (ob->type == OB_MBALL) { - BKE_displist_make_mball(bmain->eval_ctx, scene, ob); + BKE_displist_make_mball(depsgraph, scene, ob); } } } -static void curvetomesh(EvaluationContext *eval_ctx, Main *bmain, Scene *scene, Object *ob) +static void curvetomesh(Depsgraph *depsgraph, Scene *scene, Object *ob) { - convert_ensure_curve_cache(eval_ctx, bmain, scene, ob); + convert_ensure_curve_cache(depsgraph, scene, ob); BKE_mesh_from_nurbs(ob); /* also does users */ if (ob->type == OB_MESH) { @@ -1700,9 +1699,9 @@ static Base *duplibase_for_convert(Main *bmain, Scene *scene, ViewLayer *view_la static int convert_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - EvaluationContext eval_ctx; Base *basen = NULL, *basact = NULL; Object *ob1, *newob, *obact = CTX_data_active_object(C); DerivedMesh *dm; @@ -1714,8 +1713,6 @@ static int convert_exec(bContext *C, wmOperator *op) bool keep_original = RNA_boolean_get(op->ptr, "keep_original"); int a, mballConverted = 0; - CTX_data_eval_ctx(C, &eval_ctx); - /* don't forget multiple users! */ { @@ -1766,7 +1763,6 @@ static int convert_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&base->object->id, OB_RECALC_DATA); } - Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true); uint64_t customdata_mask_prev = scene->customdata_mask; scene->customdata_mask |= CD_MASK_MESH; BKE_scene_graph_update_tagged(depsgraph, bmain); @@ -1810,7 +1806,7 @@ static int convert_exec(bContext *C, wmOperator *op) newob = ob; } - BKE_mesh_to_curve(&eval_ctx, scene, newob); + BKE_mesh_to_curve(depsgraph, scene, newob); if (newob->type == OB_CURVE) { BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */ @@ -1840,7 +1836,7 @@ static int convert_exec(bContext *C, wmOperator *op) /* note: get the mesh from the original, not from the copy in some * cases this doesnt give correct results (when MDEF is used for eg) */ - dm = mesh_get_derived_final(&eval_ctx, scene, newob, CD_MASK_MESH); + dm = mesh_get_derived_final(depsgraph, scene, newob, CD_MASK_MESH); DM_to_mesh(dm, newob->data, newob, CD_MASK_MESH, true); @@ -1912,7 +1908,7 @@ static int convert_exec(bContext *C, wmOperator *op) BKE_curve_curve_dimension_update(cu); if (target == OB_MESH) { - curvetomesh(&eval_ctx, bmain, scene, newob); + curvetomesh(depsgraph, scene, newob); /* meshes doesn't use displist */ BKE_object_free_curve_cache(newob); @@ -1936,7 +1932,7 @@ static int convert_exec(bContext *C, wmOperator *op) newob = ob; } - curvetomesh(&eval_ctx, bmain, scene, newob); + curvetomesh(depsgraph, scene, newob); /* meshes doesn't use displist */ BKE_object_free_curve_cache(newob); @@ -1974,7 +1970,7 @@ static int convert_exec(bContext *C, wmOperator *op) for (a = 0; a < newob->totcol; a++) id_us_plus((ID *)me->mat[a]); } - convert_ensure_curve_cache(&eval_ctx, bmain, scene, baseob); + convert_ensure_curve_cache(depsgraph, scene, baseob); BKE_mesh_from_metaball(&baseob->curve_cache->disp, newob->data); if (obact->type == OB_MBALL) { diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 40a49df1657..60533e382e8 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -623,11 +623,11 @@ static size_t initialize_internal_images(BakeImages *bake_images, ReportList *re } /* create new mesh with edit mode changes and modifiers applied */ -static Mesh *bake_mesh_new_from_object(EvaluationContext *eval_ctx, Main *bmain, Scene *scene, Object *ob) +static Mesh *bake_mesh_new_from_object(Depsgraph *depsgraph, Main *bmain, Scene *scene, Object *ob) { ED_object_editmode_load(ob); - Mesh *me = BKE_mesh_new_from_object(eval_ctx, bmain, scene, ob, 1, 0, 0); + Mesh *me = BKE_mesh_new_from_object(depsgraph, bmain, scene, ob, 1, 0, 0); if (me->flag & ME_AUTOSMOOTH) { BKE_mesh_split_faces(me, true); } @@ -645,9 +645,7 @@ static int bake( const char *custom_cage, const char *filepath, const int width, const int height, const char *identifier, ScrArea *sa, const char *uv_layer) { - EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); Depsgraph *depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER); - DEG_evaluation_context_init_from_view_layer_for_render(eval_ctx, depsgraph, scene, view_layer); int op_result = OPERATOR_CANCELLED; bool ok = false; @@ -795,7 +793,7 @@ static int bake( BKE_scene_graph_update_tagged(depsgraph, bmain); /* get the mesh as it arrives in the renderer */ - me_low = bake_mesh_new_from_object(eval_ctx, bmain, scene, ob_low); + me_low = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low); /* populate the pixel array with the face data */ if ((is_selected_to_active && (ob_cage == NULL) && is_cage) == false) @@ -810,7 +808,7 @@ static int bake( /* prepare cage mesh */ if (ob_cage) { - me_cage = bake_mesh_new_from_object(eval_ctx, bmain, scene, ob_cage); + me_cage = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_cage); if ((me_low->totpoly != me_cage->totpoly) || (me_low->totloop != me_cage->totloop)) { BKE_report(reports, RPT_ERROR, "Invalid cage object, the cage mesh must have the same number " @@ -842,7 +840,7 @@ static int bake( ob_low->modifiers = modifiers_tmp; /* get the cage mesh as it arrives in the renderer */ - me_cage = bake_mesh_new_from_object(eval_ctx, bmain, scene, ob_low); + me_cage = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low); RE_bake_pixels_populate(me_cage, pixel_array_low, num_pixels, &bake_images, uv_layer); } @@ -868,7 +866,7 @@ static int bake( tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED; tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP; - highpoly[i].me = bake_mesh_new_from_object(eval_ctx, bmain, scene, highpoly[i].ob); + highpoly[i].me = bake_mesh_new_from_object(depsgraph, bmain, scene, highpoly[i].ob); highpoly[i].ob->restrictflag &= ~OB_RESTRICT_RENDER; /* lowpoly to highpoly transformation matrix */ @@ -971,7 +969,7 @@ cage_cleanup: md->mode &= ~eModifierMode_Render; } - me_nores = bake_mesh_new_from_object(eval_ctx, bmain, scene, ob_low); + me_nores = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low); RE_bake_pixels_populate(me_nores, pixel_array_low, num_pixels, &bake_images, uv_layer); RE_bake_normal_world_to_tangent(pixel_array_low, num_pixels, depth, result, me_nores, normal_swizzle, ob_low->obmat); diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 1a20a8db5b3..ca742222d81 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -684,8 +684,6 @@ static bConstraint *edit_constraint_property_get(wmOperator *op, Object *ob, int static int stretchto_reset_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_STRETCHTO); bStretchToConstraint *data = (con) ? (bStretchToConstraint *)con->data : NULL; @@ -732,8 +730,6 @@ void CONSTRAINT_OT_stretchto_reset(wmOperatorType *ot) static int limitdistance_reset_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_DISTLIMIT); bDistLimitConstraint *data = (con) ? (bDistLimitConstraint *)con->data : NULL; @@ -781,9 +777,7 @@ void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot) static void child_get_inverse_matrix(const bContext *C, Scene *scene, Object *ob, bConstraint *con, float invmat[4][4], const int owner) { - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); /* nullify inverse matrix first */ unit_m4(invmat); @@ -810,7 +804,7 @@ static void child_get_inverse_matrix(const bContext *C, Scene *scene, Object *ob * to use as baseline ("pmat") to derive delta from. This extra calc saves users * from having pressing "Clear Inverse" first */ - BKE_pose_where_is(&eval_ctx, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); copy_m4_m4(pmat, pchan->pose_mat); /* 2. knock out constraints starting from this one */ @@ -827,7 +821,7 @@ static void child_get_inverse_matrix(const bContext *C, Scene *scene, Object *ob } /* 3. solve pose without disabled constraints */ - BKE_pose_where_is(&eval_ctx, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); /* 4. determine effect of constraint by removing the newly calculated * pchan->pose_mat from the original pchan->pose_mat, thus determining @@ -850,7 +844,7 @@ static void child_get_inverse_matrix(const bContext *C, Scene *scene, Object *ob } /* 6. recalculate pose with new inv-mat applied */ - BKE_pose_where_is(&eval_ctx, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); } } if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { @@ -861,7 +855,7 @@ static void child_get_inverse_matrix(const bContext *C, Scene *scene, Object *ob BLI_assert(BLI_findindex(&ob->constraints, con) != -1); /* use BKE_object_workob_calc_parent to find inverse - just like for normal parenting */ - BKE_object_workob_calc_parent(&eval_ctx, scene, ob, &workob); + BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob); invert_m4_m4(invmat, workob.obmat); } } @@ -870,8 +864,6 @@ static void child_get_inverse_matrix(const bContext *C, Scene *scene, Object *ob /* ChildOf Constraint - set inverse callback */ static int childof_set_inverse_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF); @@ -923,8 +915,6 @@ void CONSTRAINT_OT_childof_set_inverse(wmOperatorType *ot) static int childof_clear_inverse_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_active_context(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF); bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : NULL; @@ -972,8 +962,6 @@ void CONSTRAINT_OT_childof_clear_inverse(wmOperatorType *ot) static int followpath_path_animate_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_FOLLOWPATH); bFollowPathConstraint *data = (con) ? (bFollowPathConstraint *)con->data : NULL; @@ -1098,8 +1086,6 @@ void CONSTRAINT_OT_followpath_path_animate(wmOperatorType *ot) static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); @@ -1149,8 +1135,6 @@ void CONSTRAINT_OT_objectsolver_set_inverse(wmOperatorType *ot) static int objectsolver_clear_inverse_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : NULL; @@ -1320,8 +1304,6 @@ void CONSTRAINT_OT_delete(wmOperatorType *ot) static int constraint_move_down_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, 0); @@ -1371,8 +1353,6 @@ void CONSTRAINT_OT_move_down(wmOperatorType *ot) static int constraint_move_up_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, 0); @@ -1593,8 +1573,6 @@ void OBJECT_OT_constraints_copy(wmOperatorType *ot) /* get the Object and/or PoseChannel to use as target */ static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, bool add) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Object *obact = ED_object_active_context(C); bPoseChannel *pchanact = BKE_pose_channel_active(obact); bool only_curve = false, only_mesh = false, only_ob = false; @@ -1673,7 +1651,7 @@ static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob /* for armatures in pose mode, look inside the armature for the active bone * so that we set up cross-armature constraints with less effort */ - if ((ob->type == OB_ARMATURE) && (eval_ctx.mode & OB_MODE_POSE) && + if ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE) && (!only_curve && !only_mesh)) { /* just use the active bone, and assume that it is visible + usable */ diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index 2daa8652335..603f5b1c77f 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -94,7 +94,6 @@ static const EnumPropertyItem DT_layer_items[] = { static const EnumPropertyItem *dt_layers_select_src_itemf( bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free) { - EvaluationContext eval_ctx; EnumPropertyItem *item = NULL, tmp_item = {0}; int totitem = 0; const int data_type = RNA_enum_get(ptr, "data_type"); @@ -103,7 +102,7 @@ static const EnumPropertyItem *dt_layers_select_src_itemf( return rna_enum_dt_layers_select_src_items; } - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ACTIVE_SRC); RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ALL_SRC); @@ -142,7 +141,7 @@ static const EnumPropertyItem *dt_layers_select_src_itemf( int num_data, i; /* XXX Is this OK? */ - dm_src = mesh_get_derived_final(&eval_ctx, scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPUV); + dm_src = mesh_get_derived_final(depsgraph, scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPUV); ldata = dm_src->getLoopDataLayout(dm_src); num_data = CustomData_number_of_layers(ldata, CD_MLOOPUV); @@ -165,7 +164,7 @@ static const EnumPropertyItem *dt_layers_select_src_itemf( int num_data, i; /* XXX Is this OK? */ - dm_src = mesh_get_derived_final(&eval_ctx, scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPCOL); + dm_src = mesh_get_derived_final(depsgraph, scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPCOL); ldata = dm_src->getLoopDataLayout(dm_src); num_data = CustomData_number_of_layers(ldata, CD_MLOOPCOL); @@ -347,9 +346,7 @@ static int data_transfer_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob_src = ED_object_active_context(C); - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ListBase ctx_objects; CollectionPointerLink *ctx_ob_dst; @@ -418,7 +415,7 @@ static int data_transfer_exec(bContext *C, wmOperator *op) } if (BKE_object_data_transfer_mesh( - &eval_ctx, scene, ob_src, ob_dst, data_type, use_create, + depsgraph, scene, ob_src, ob_dst, data_type, use_create, map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode, space_transform, use_auto_transform, max_distance, ray_radius, islands_precision, @@ -628,11 +625,9 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob_act = ED_object_active_context(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); DataTransferModifierData *dtmd; - CTX_data_eval_ctx(C, &eval_ctx); - dtmd = (DataTransferModifierData *)edit_modifier_property_get(op, ob_act, eModifierType_DataTransfer); /* If we have a modifier, we transfer data layout from this modifier's source object to active one. @@ -647,7 +642,7 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - BKE_object_data_transfer_layout(&eval_ctx, scene, ob_src, ob_dst, dtmd->data_types, use_delete, + BKE_object_data_transfer_layout(depsgraph, scene, ob_src, ob_dst, dtmd->data_types, use_delete, dtmd->layers_select_src, dtmd->layers_select_dst); DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA); @@ -677,7 +672,7 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op) for (ctx_ob_dst = ctx_objects.first; ctx_ob_dst; ctx_ob_dst = ctx_ob_dst->next) { Object *ob_dst = ctx_ob_dst->ptr.data; if (data_transfer_exec_is_object_valid(op, ob_src, ob_dst, false)) { - BKE_object_data_transfer_layout(&eval_ctx, scene, ob_src, ob_dst, data_type, use_delete, + BKE_object_data_transfer_layout(depsgraph, scene, ob_src, ob_dst, data_type, use_delete, layers_select_src, layers_select_dst); } diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index f4066360805..e884989b6b5 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -89,6 +89,7 @@ #include "BKE_report.h" #include "BKE_object.h" #include "BKE_workspace.h" +#include "BKE_layer.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" @@ -277,9 +278,6 @@ bool ED_object_editmode_load(Object *obedit) void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int flag) { BLI_assert(C || !(flag & EM_DO_UNDO)); - /* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */ - /* Note! if 'EM_FREEDATA' isn't in the flag, use ED_object_editmode_load directly */ - ViewLayer *view_layer = CTX_data_view_layer(C); const bool freedata = (flag & EM_FREEDATA) != 0; if (flag & EM_WAITCURSOR) waitcursor(1); @@ -287,8 +285,8 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f if (ED_object_editmode_load_ex(G.main, obedit, freedata) == false) { /* in rare cases (background mode) its possible active object * is flagged for editmode, without 'obedit' being set [#35489] */ - if (UNLIKELY(view_layer->basact && (view_layer->basact->object->mode & OB_MODE_EDIT))) { - view_layer->basact->object->mode &= ~OB_MODE_EDIT; + if (UNLIKELY(obedit && obedit->mode & OB_MODE_EDIT)) { + obedit->mode &= ~OB_MODE_EDIT; } if (flag & EM_WAITCURSOR) waitcursor(0); return; @@ -315,15 +313,18 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f if (flag & EM_DO_UNDO) ED_undo_push(C, "Editmode"); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene); + if (C != NULL) { + WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene); + } + else { + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene); + } + obedit->mode &= ~OB_MODE_EDIT; } if (flag & EM_WAITCURSOR) waitcursor(0); - - /* This way we ensure scene's obedit is copied into all CoW scenes. */ - DEG_id_tag_update(&scene->id, 0); } void ED_object_editmode_exit(bContext *C, int flag) @@ -333,25 +334,12 @@ void ED_object_editmode_exit(bContext *C, int flag) ED_object_editmode_exit_ex(C, scene, obedit, flag); } -void ED_object_editmode_enter(bContext *C, int flag) +void ED_object_editmode_enter_ex(Scene *scene, Object *ob, int flag) { - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob; bool ok = false; - if (ID_IS_LINKED(scene)) return; - - if ((flag & EM_IGNORE_LAYER) == 0) { - ob = CTX_data_active_object(C); /* active layer checked here for view3d */ - - if (ob == NULL) return; - } - else { - ob = view_layer->basact->object; - } - if (ELEM(NULL, ob, ob->data)) return; + if (ID_IS_LINKED(ob)) return; /* this checks actual object->data, for cases when other scenes have it in editmode context */ if (BKE_object_is_in_editmode(ob)) @@ -366,11 +354,6 @@ void ED_object_editmode_enter(bContext *C, int flag) ob->restore_mode = ob->mode; - /* note, when switching scenes the object can have editmode data but - * not be scene->obedit: bug 22954, this avoids calling self eternally */ - if ((ob->restore_mode & OB_MODE_EDIT) == 0) - ED_object_mode_toggle(C, ob->mode); - ob->mode = OB_MODE_EDIT; if (ob->type == OB_MESH) { @@ -387,7 +370,7 @@ void ED_object_editmode_enter(bContext *C, int flag) BKE_editmesh_tessface_calc(em); } - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MESH, scene); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_MESH, NULL); } else if (ob->type == OB_ARMATURE) { bArmature *arm = ob->data; @@ -409,45 +392,64 @@ void ED_object_editmode_enter(bContext *C, int flag) /* to ensure all goes in restposition and without striding */ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */ - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_ARMATURE, scene); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_ARMATURE, scene); } else if (ob->type == OB_FONT) { ok = 1; ED_curve_editfont_make(ob); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_TEXT, scene); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_TEXT, scene); } else if (ob->type == OB_MBALL) { ok = 1; ED_mball_editmball_make(ob); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MBALL, scene); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_MBALL, scene); } else if (ob->type == OB_LATTICE) { ok = 1; BKE_editlattice_make(ob); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_LATTICE, scene); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_LATTICE, scene); } else if (ob->type == OB_SURF || ob->type == OB_CURVE) { ok = 1; ED_curve_editnurb_make(ob); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_CURVE, scene); + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_CURVE, scene); } if (ok) { DEG_id_tag_update(&ob->id, OB_RECALC_DATA); - /* This way we ensure scene's obedit is copied into all CoW scenes. */ - DEG_id_tag_update(&scene->id, 0); } else { - ob->mode &= ~OB_MODE_EDIT; - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene); + if ((flag & EM_NO_CONTEXT) == 0) { + ob->mode &= ~OB_MODE_EDIT; + } + WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene); } - if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode"); if (flag & EM_WAITCURSOR) waitcursor(0); + BLI_assert((flag & EM_DO_UNDO) == 0); +} + +void ED_object_editmode_enter(bContext *C, int flag) +{ + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob; + + if ((flag & EM_IGNORE_LAYER) == 0) { + ob = CTX_data_active_object(C); /* active layer checked here for view3d */ + } + else { + ob = view_layer->basact->object; + } + if (ob == NULL) return; + if (ID_IS_LINKED(ob)) return; + + ED_object_editmode_enter_ex(scene, ob, flag & ~EM_DO_UNDO); + if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode"); } static int editmode_toggle_exec(bContext *C, wmOperator *op) @@ -455,18 +457,43 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op) const int mode_flag = OB_MODE_EDIT; const bool is_mode_set = (CTX_data_edit_object(C) != NULL); Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *obact = OBACT(view_layer); if (!is_mode_set) { - Object *ob = CTX_data_active_object(C); - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } - if (!is_mode_set) + if (!is_mode_set) { ED_object_editmode_enter(C, EM_WAITCURSOR); - else + if (obact->mode & mode_flag) { + FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob) + { + if ((ob != obact) && (ob->type == obact->type)) { + if (ob->flag & SELECT) { + ED_object_editmode_enter_ex(scene, ob, EM_WAITCURSOR | EM_NO_CONTEXT); + } + } + } + FOREACH_SELECTED_OBJECT_END; + } + } + else { ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR); /* had EM_DO_UNDO but op flag calls undo too [#24685] */ + if ((obact->mode & mode_flag) == 0) { + FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob) + { + if ((ob != obact) && (ob->type == obact->type)) { + if (ob->flag & SELECT) { + ED_object_editmode_exit_ex(NULL, scene, ob, EM_FREEDATA | EM_WAITCURSOR); + } + } + } + FOREACH_SELECTED_OBJECT_END; + } + } ED_space_image_uv_sculpt_update(CTX_wm_manager(C), scene); @@ -510,27 +537,60 @@ void OBJECT_OT_editmode_toggle(wmOperatorType *ot) static int posemode_exec(bContext *C, wmOperator *op) { Base *base = CTX_data_active_base(C); - Object *ob = base->object; + Object *obact = base->object; const int mode_flag = OB_MODE_POSE; - bool is_mode_set = (ob->mode & mode_flag) != 0; + bool is_mode_set = (obact->mode & mode_flag) != 0; if (!is_mode_set) { - if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } - if (ob->type == OB_ARMATURE) { - if (ob == CTX_data_edit_object(C)) { + if (obact->type == OB_ARMATURE) { + if (obact == CTX_data_edit_object(C)) { ED_object_editmode_exit(C, EM_FREEDATA | EM_DO_UNDO); is_mode_set = false; } if (is_mode_set) { - ED_object_posemode_exit(C, ob); + bool ok = ED_object_posemode_exit(C, obact); + if (ok) { + struct Main *bmain = CTX_data_main(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob) + { + if ((ob != obact) && + (ob->type == OB_ARMATURE) && + (ob->mode & mode_flag)) + { + if (ob->flag & SELECT) { + ED_object_posemode_exit_ex(bmain, ob); + } + } + } + FOREACH_SELECTED_OBJECT_END; + } } else { - ED_object_posemode_enter(C, ob); + bool ok = ED_object_posemode_enter(C, obact); + if (ok) { + struct Main *bmain = CTX_data_main(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob) + { + if ((ob != obact) && + (ob->type == OB_ARMATURE) && + (ob->mode == OB_MODE_OBJECT) && + (!ID_IS_LINKED(ob))) + { + if (ob->flag & SELECT) { + ED_object_posemode_enter_ex(bmain, ob); + } + } + } + FOREACH_SELECTED_OBJECT_END; + } } return OPERATOR_FINISHED; } @@ -1075,8 +1135,7 @@ void OBJECT_OT_forcefield_toggle(wmOperatorType *ot) void ED_objects_recalculate_paths(bContext *C, Scene *scene) { struct Main *bmain = CTX_data_main(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ListBase targets = {NULL, NULL}; /* loop over objects in scene */ @@ -1089,7 +1148,7 @@ void ED_objects_recalculate_paths(bContext *C, Scene *scene) CTX_DATA_END; /* recalculate paths, then free */ - animviz_calc_motionpaths(&eval_ctx, bmain, scene, &targets); + animviz_calc_motionpaths(depsgraph, bmain, scene, &targets); BLI_freelistN(&targets); } diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c index 3ff794772fa..b5a71bb7a35 100644 --- a/source/blender/editors/object/object_hook.c +++ b/source/blender/editors/object/object_hook.c @@ -471,14 +471,11 @@ static int add_hook_object(const bContext *C, Main *bmain, Scene *scene, ViewLay { ModifierData *md = NULL; HookModifierData *hmd = NULL; - EvaluationContext eval_ctx; float cent[3]; float pose_mat[4][4]; int tot, ok, *indexar; char name[MAX_NAME]; - CTX_data_eval_ctx(C, &eval_ctx); - ok = object_hook_index_array(scene, obedit, &tot, &indexar, name, cent); if (!ok) { @@ -547,7 +544,7 @@ static int add_hook_object(const bContext *C, Main *bmain, Scene *scene, ViewLay /* matrix calculus */ /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */ /* (parentinv ) */ - BKE_object_where_is_calc(&eval_ctx, scene, ob); + BKE_object_where_is_calc(CTX_data_depsgraph(C), scene, ob); invert_m4_m4(ob->imat, ob->obmat); /* apparently this call goes from right to left... */ diff --git a/source/blender/editors/object/object_modes.c b/source/blender/editors/object/object_modes.c index f074a56fb86..3fb0e75a01e 100644 --- a/source/blender/editors/object/object_modes.c +++ b/source/blender/editors/object/object_modes.c @@ -177,6 +177,9 @@ bool ED_object_mode_generic_enter( struct bContext *C, eObjectMode object_mode) { Object *ob = CTX_data_active_object(C); + if (ob == NULL) { + return (object_mode == OB_MODE_OBJECT); + } if (ob->mode == object_mode) { return true; } @@ -194,7 +197,7 @@ bool ED_object_mode_generic_enter( * Caller can check #OB_MODE_ALL_MODE_DATA to test if this needs to be run. */ static bool ed_object_mode_generic_exit_ex( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, bool only_test) { @@ -227,7 +230,7 @@ static bool ed_object_mode_generic_exit_ex( if (only_test) { return true; } - ED_object_sculptmode_exit_ex(eval_ctx, scene, ob); + ED_object_sculptmode_exit_ex(depsgraph, scene, ob); } } else { @@ -241,17 +244,17 @@ static bool ed_object_mode_generic_exit_ex( } void ED_object_mode_generic_exit( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob) { - ed_object_mode_generic_exit_ex(eval_ctx, scene, ob, false); + ed_object_mode_generic_exit_ex(depsgraph, scene, ob, false); } bool ED_object_mode_generic_has_data( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Object *ob) { - return ed_object_mode_generic_exit_ex(eval_ctx, NULL, ob, true); + return ed_object_mode_generic_exit_ex(depsgraph, NULL, ob, true); } /** \} */ diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index c79bd3bcb1d..5e12a15b49f 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -76,6 +76,7 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" +#include "DEG_depsgraph_query.h" #include "RNA_access.h" #include "RNA_define.h" @@ -522,7 +523,7 @@ int ED_object_modifier_convert(ReportList *UNUSED(reports), Main *bmain, Scene * return 1; } -static int modifier_apply_shape(ReportList *reports, const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ModifierData *md) +static int modifier_apply_shape(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -555,7 +556,7 @@ static int modifier_apply_shape(ReportList *reports, const EvaluationContext *ev return 0; } - dm = mesh_create_derived_for_modifier(eval_ctx, scene, ob, md, 0); + dm = mesh_create_derived_for_modifier(depsgraph, scene, ob, md, 0); if (!dm) { BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply"); return 0; @@ -582,7 +583,7 @@ static int modifier_apply_shape(ReportList *reports, const EvaluationContext *ev return 1; } -static int modifier_apply_obdata(ReportList *reports, const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ModifierData *md) +static int modifier_apply_obdata(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); @@ -608,13 +609,13 @@ static int modifier_apply_obdata(ReportList *reports, const EvaluationContext *e multires_force_update(ob); if (mmd && mmd->totlvl && mti->type == eModifierTypeType_OnlyDeform) { - if (!multiresModifier_reshapeFromDeformMod(eval_ctx, scene, mmd, ob, md)) { + if (!multiresModifier_reshapeFromDeformMod(depsgraph, scene, mmd, ob, md)) { BKE_report(reports, RPT_ERROR, "Multires modifier returned error, skipping apply"); return 0; } } else { - dm = mesh_create_derived_for_modifier(eval_ctx, scene, ob, md, 1); + dm = mesh_create_derived_for_modifier(depsgraph, scene, ob, md, 1); if (!dm) { BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply"); return 0; @@ -640,7 +641,7 @@ static int modifier_apply_obdata(ReportList *reports, const EvaluationContext *e BKE_report(reports, RPT_INFO, "Applied modifier only changed CV points, not tessellated/bevel vertices"); vertexCos = BKE_curve_nurbs_vertexCos_get(&cu->nurb, &numVerts); - mti->deformVerts(md, eval_ctx, ob, NULL, vertexCos, numVerts, 0); + mti->deformVerts(md, depsgraph, ob, NULL, vertexCos, numVerts, 0); BK_curve_nurbs_vertexCos_apply(&cu->nurb, vertexCos); MEM_freeN(vertexCos); @@ -662,7 +663,7 @@ static int modifier_apply_obdata(ReportList *reports, const EvaluationContext *e if (psys->part->type != PART_HAIR) continue; - psys_apply_hair_lattice(eval_ctx, scene, ob, psys); + psys_apply_hair_lattice(depsgraph, scene, ob, psys); } } @@ -670,7 +671,7 @@ static int modifier_apply_obdata(ReportList *reports, const EvaluationContext *e } int ED_object_modifier_apply( - ReportList *reports, const EvaluationContext *eval_ctx, + ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md, int mode) { int prev_mode; @@ -699,13 +700,13 @@ int ED_object_modifier_apply( md->mode |= eModifierMode_Realtime; if (mode == MODIFIER_APPLY_SHAPE) { - if (!modifier_apply_shape(reports, eval_ctx, scene, ob, md)) { + if (!modifier_apply_shape(reports, depsgraph, scene, ob, md)) { md->mode = prev_mode; return 0; } } else { - if (!modifier_apply_obdata(reports, eval_ctx, scene, ob, md)) { + if (!modifier_apply_obdata(reports, depsgraph, scene, ob, md)) { md->mode = prev_mode; return 0; } @@ -1004,15 +1005,13 @@ void OBJECT_OT_modifier_move_down(wmOperatorType *ot) static int modifier_apply_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); ModifierData *md = edit_modifier_property_get(op, ob, 0); int apply_as = RNA_enum_get(op->ptr, "apply_as"); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - - if (!md || !ED_object_modifier_apply(op->reports, &eval_ctx, scene, ob, md, apply_as)) { + if (!md || !ED_object_modifier_apply(op->reports, depsgraph, scene, ob, md, apply_as)) { return OPERATOR_CANCELLED; } @@ -1237,6 +1236,7 @@ void OBJECT_OT_multires_subdivide(wmOperatorType *ot) static int multires_reshape_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Object *ob = ED_object_active_context(C), *secondob = NULL; Scene *scene = CTX_data_scene(C); MultiresModifierData *mmd = (MultiresModifierData *)edit_modifier_property_get(op, ob, eModifierType_Multires); @@ -1263,10 +1263,7 @@ static int multires_reshape_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - - if (!multiresModifier_reshape(&eval_ctx, scene, mmd, ob, secondob)) { + if (!multiresModifier_reshape(depsgraph, scene, mmd, ob, secondob)) { BKE_report(op->reports, RPT_ERROR, "Objects do not have the same number of vertices"); return OPERATOR_CANCELLED; } @@ -1699,7 +1696,7 @@ static void skin_armature_bone_create(Object *skin_ob, } } -static Object *modifier_skin_armature_create(const EvaluationContext *eval_ctx, Main *bmain, Scene *scene, Object *skin_ob) +static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain, Scene *scene, Object *skin_ob) { BLI_bitmap *edges_visited; DerivedMesh *deform_dm; @@ -1712,7 +1709,7 @@ static Object *modifier_skin_armature_create(const EvaluationContext *eval_ctx, int *emap_mem; int v; - deform_dm = mesh_get_derived_deform(eval_ctx, scene, skin_ob, CD_MASK_BAREMESH); + deform_dm = mesh_get_derived_deform(depsgraph, scene, skin_ob, CD_MASK_BAREMESH); mvert = deform_dm->getVertArray(deform_dm); /* add vertex weights to original mesh */ @@ -1722,7 +1719,8 @@ static Object *modifier_skin_armature_create(const EvaluationContext *eval_ctx, NULL, me->totvert); - arm_ob = BKE_object_add(bmain, scene, eval_ctx->view_layer, OB_ARMATURE, NULL); + ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); + arm_ob = BKE_object_add(bmain, scene, view_layer, OB_ARMATURE, NULL); BKE_object_transform_copy(arm_ob, skin_ob); arm = arm_ob->data; arm->layer = 1; @@ -1780,6 +1778,7 @@ static Object *modifier_skin_armature_create(const EvaluationContext *eval_ctx, static int skin_armature_create_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C), *arm_ob; Mesh *me = ob->data; @@ -1791,11 +1790,8 @@ static int skin_armature_create_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - /* create new armature */ - arm_ob = modifier_skin_armature_create(&eval_ctx, bmain, scene, ob); + arm_ob = modifier_skin_armature_create(depsgraph, bmain, scene, ob); /* add a modifier to connect the new armature to the mesh */ arm_md = (ArmatureModifierData *)modifier_new(eModifierType_Armature); @@ -1915,11 +1911,9 @@ static int meshdeform_bind_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); MeshDeformModifierData *mmd = (MeshDeformModifierData *)edit_modifier_property_get(op, ob, eModifierType_MeshDeform); - CTX_data_eval_ctx(C, &eval_ctx); - if (!mmd) return OPERATOR_CANCELLED; @@ -1957,17 +1951,17 @@ static int meshdeform_bind_exec(bContext *C, wmOperator *op) mmd->modifier.mode |= eModifierMode_Realtime; if (ob->type == OB_MESH) { - dm = mesh_create_derived_view(&eval_ctx, scene, ob, 0); + dm = mesh_create_derived_view(depsgraph, scene, ob, 0); dm->release(dm); } else if (ob->type == OB_LATTICE) { - BKE_lattice_modifiers_calc(&eval_ctx, scene, ob); + BKE_lattice_modifiers_calc(depsgraph, scene, ob); } else if (ob->type == OB_MBALL) { - BKE_displist_make_mball(&eval_ctx, scene, ob); + BKE_displist_make_mball(depsgraph, scene, ob); } else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { - BKE_displist_make_curveTypes(&eval_ctx, scene, ob, 0); + BKE_displist_make_curveTypes(depsgraph, scene, ob, 0); } mmd->bindfunc = NULL; diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index ba58c0d3d2a..417c32a71e9 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -129,9 +129,9 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *obedit = CTX_data_edit_object(C); - EvaluationContext eval_ctx; BMVert *eve; BMIter iter; Curve *cu; @@ -141,8 +141,6 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) Object *par; int a, v1 = 0, v2 = 0, v3 = 0, v4 = 0, nr = 1; - CTX_data_eval_ctx(C, &eval_ctx); - /* we need 1 to 3 selected vertices */ if (obedit->type == OB_MESH) { @@ -161,7 +159,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) /* derivedMesh might be needed for solving parenting, * so re-create it here */ - makeDerivedMesh(&eval_ctx, scene, obedit, em, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX, false); + makeDerivedMesh(depsgraph, scene, obedit, em, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX, false); BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { @@ -257,7 +255,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) ob->par3 = v3 - 1; /* inverse parent matrix */ - BKE_object_workob_calc_parent(&eval_ctx, scene, ob, &workob); + BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob); invert_m4_m4(ob->parentinv, workob.obmat); } else { @@ -265,7 +263,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) ob->par1 = v1 - 1; /* inverse parent matrix */ - BKE_object_workob_calc_parent(&eval_ctx, scene, ob, &workob); + BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob); invert_m4_m4(ob->parentinv, workob.obmat); } } @@ -619,12 +617,10 @@ bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene, int partype, const bool xmirror, const bool keep_transform, const int vert_par[3]) { Main *bmain = CTX_data_main(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); bPoseChannel *pchan = NULL; const bool pararm = ELEM(partype, PAR_ARMATURE, PAR_ARMATURE_NAME, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO); - CTX_data_eval_ctx(C, &eval_ctx); - DEG_id_tag_update(&par->id, OB_RECALC_OB); /* preconditions */ @@ -636,7 +632,7 @@ bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene, if ((cu->flag & CU_PATH) == 0) { cu->flag |= CU_PATH | CU_FOLLOW; - BKE_displist_make_curveTypes(&eval_ctx, scene, par, 0); /* force creation of path data */ + BKE_displist_make_curveTypes(depsgraph, scene, par, 0); /* force creation of path data */ } else { cu->flag |= CU_FOLLOW; @@ -778,32 +774,32 @@ bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene, data = con->data; data->tar = par; - BKE_constraint_target_matrix_get(&eval_ctx, scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra); + BKE_constraint_target_matrix_get(depsgraph, scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra); sub_v3_v3v3(vec, ob->obmat[3], cmat[3]); copy_v3_v3(ob->loc, vec); } else if (pararm && (ob->type == OB_MESH) && (par->type == OB_ARMATURE)) { if (partype == PAR_ARMATURE_NAME) { - ED_object_vgroup_calc_from_armature(reports, &eval_ctx, scene, ob, par, ARM_GROUPS_NAME, false); + ED_object_vgroup_calc_from_armature(reports, depsgraph, scene, ob, par, ARM_GROUPS_NAME, false); } else if (partype == PAR_ARMATURE_ENVELOPE) { - ED_object_vgroup_calc_from_armature(reports, &eval_ctx, scene, ob, par, ARM_GROUPS_ENVELOPE, xmirror); + ED_object_vgroup_calc_from_armature(reports, depsgraph, scene, ob, par, ARM_GROUPS_ENVELOPE, xmirror); } else if (partype == PAR_ARMATURE_AUTO) { WM_cursor_wait(1); - ED_object_vgroup_calc_from_armature(reports, &eval_ctx, scene, ob, par, ARM_GROUPS_AUTO, xmirror); + ED_object_vgroup_calc_from_armature(reports, depsgraph, scene, ob, par, ARM_GROUPS_AUTO, xmirror); WM_cursor_wait(0); } /* get corrected inverse */ ob->partype = PAROBJECT; - BKE_object_workob_calc_parent(&eval_ctx, scene, ob, &workob); + BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob); invert_m4_m4(ob->parentinv, workob.obmat); } else { /* calculate inverse parent matrix */ - BKE_object_workob_calc_parent(&eval_ctx, scene, ob, &workob); + BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob); invert_m4_m4(ob->parentinv, workob.obmat); } @@ -1061,17 +1057,15 @@ void OBJECT_OT_parent_no_inverse_set(wmOperatorType *ot) static int object_slow_parent_clear_exec(bContext *C, wmOperator *UNUSED(op)) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { if (ob->parent) { if (ob->partype & PARSLOW) { ob->partype -= PARSLOW; - BKE_object_where_is_calc(&eval_ctx, scene, ob); + BKE_object_where_is_calc(depsgraph, scene, ob); ob->partype |= PARSLOW; DEG_id_tag_update(&ob->id, OB_RECALC_OB); } @@ -2417,41 +2411,48 @@ static int make_override_static_exec(bContext *C, wmOperator *op) Base *base = BLI_findlink(&obact->dup_group->view_layer->object_bases, RNA_enum_get(op->ptr, "object")); Object *obgroup = obact; obact = base->object; + Group *group = obgroup->dup_group; /* First, we make a static override of the linked group itself. */ - obgroup->dup_group->id.tag |= LIB_TAG_DOIT; + group->id.tag |= LIB_TAG_DOIT; - /* Then, we tag our 'main' object and its detected dependencies to be also overridden. */ - obact->id.tag |= LIB_TAG_DOIT; - - FOREACH_GROUP_OBJECT_BEGIN(obgroup->dup_group, ob) + /* Then, we make static override of the whole set of objects in the group. */ + FOREACH_GROUP_OBJECT_BEGIN(group, ob) { - make_override_static_tag_object(obact, ob); + ob->id.tag |= LIB_TAG_DOIT; } FOREACH_GROUP_OBJECT_END; success = BKE_override_static_create_from_tag(bmain); - /* Intantiate our 'main' newly overridden object in scene, if not yet done. */ + /* Intantiate our newly overridden objects in scene, if not yet done. */ Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *new_obact = (Object *)obact->id.newid; - if (new_obact != NULL && (base = BKE_view_layer_base_find(view_layer, new_obact)) == NULL) { - BKE_collection_object_add_from(scene, obgroup, new_obact); - base = BKE_view_layer_base_find(view_layer, new_obact); - BKE_view_layer_base_select(view_layer, base); + Group *new_group = (Group *)group->id.newid; + FOREACH_GROUP_OBJECT_BEGIN(new_group, new_ob) + { + if (new_ob != NULL && (base = BKE_view_layer_base_find(view_layer, new_ob)) == NULL) { + BKE_collection_object_add_from(scene, obgroup, new_ob); + DEG_id_tag_update_ex(bmain, &new_ob->id, OB_RECALC_OB | DEG_TAG_BASE_FLAGS_UPDATE); + /* parent to 'group' empty */ + if (new_ob->parent == NULL) { + new_ob->parent = obgroup; + } + if (new_ob == (Object *)obact->id.newid) { + base = BKE_view_layer_base_find(view_layer, new_ob); + BKE_view_layer_base_select(view_layer, base); + } + } } + FOREACH_GROUP_OBJECT_END; - /* Parent the group instantiating object to the new overridden one, or vice-versa, if possible. */ - if (obgroup->parent == NULL) { - obgroup->parent = new_obact; - } - else if (new_obact->parent == NULL) { - new_obact->parent = obgroup; - } + /* obgroup is no more dupligroup-ing, it merely parents whole group of overriding instantiated objects. */ + obgroup->dup_group = NULL; /* Also, we'd likely want to lock by default things like transformations of implicitly overriden objects? */ + DEG_id_tag_update(&scene->id, 0); + /* Cleanup. */ BKE_main_id_clear_newpoins(bmain); BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, false); @@ -2474,7 +2475,7 @@ static int make_override_static_exec(bContext *C, wmOperator *op) BKE_main_id_clear_newpoins(bmain); BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, false); } - /* TODO: probably more cases where we want ot do automated smart things in the future! */ + /* TODO: probably more cases where we want to do automated smart things in the future! */ else { success = (BKE_override_static_create_from_id(bmain, &obact->id) != NULL); } diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index d0ebb0cd6fe..df8a1b8b87a 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -408,15 +408,13 @@ static void ignore_parent_tx(const bContext *C, Main *bmain, Scene *scene, Objec { Object workob; Object *ob_child; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); /* a change was made, adjust the children to compensate */ for (ob_child = bmain->object.first; ob_child; ob_child = ob_child->id.next) { if (ob_child->parent == ob) { BKE_object_apply_mat4(ob_child, ob_child->obmat, true, false); - BKE_object_workob_calc_parent(&eval_ctx, scene, ob_child, &workob); + BKE_object_workob_calc_parent(depsgraph, scene, ob_child, &workob); invert_m4_m4(ob_child->parentinv, workob.obmat); } } @@ -429,12 +427,10 @@ static int apply_objects_internal( { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale; bool changed = true; - CTX_data_eval_ctx(C, &eval_ctx); - /* first check if we can execute */ CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { @@ -536,7 +532,7 @@ static int apply_objects_internal( Mesh *me = ob->data; if (apply_scale) - multiresModifier_scale_disp(&eval_ctx, scene, ob); + multiresModifier_scale_disp(depsgraph, scene, ob); /* adjust data */ BKE_mesh_transform(me, mat, true); @@ -626,9 +622,9 @@ static int apply_objects_internal( unit_axis_angle(ob->rotAxis, &ob->rotAngle); } - BKE_object_where_is_calc(&eval_ctx, scene, ob); + BKE_object_where_is_calc(depsgraph, scene, ob); if (ob->type == OB_ARMATURE) { - BKE_pose_where_is(&eval_ctx, scene, ob); /* needed for bone parents */ + BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */ } ignore_parent_tx(C, bmain, scene, ob); @@ -651,16 +647,14 @@ static int apply_objects_internal( static int visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); bool changed = false; - - CTX_data_eval_ctx(C, &eval_ctx); CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { - BKE_object_where_is_calc(&eval_ctx, scene, ob); + BKE_object_where_is_calc(depsgraph, scene, ob); BKE_object_apply_mat4(ob, ob->obmat, true, true); - BKE_object_where_is_calc(&eval_ctx, scene, ob); + BKE_object_where_is_calc(depsgraph, scene, ob); /* update for any children that may get moved */ DEG_id_tag_update(&ob->id, OB_RECALC_OB); @@ -744,7 +738,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Object *obact = CTX_data_active_object(C); Object *obedit = CTX_data_edit_object(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Object *tob; float cursor[3], cent[3], cent_neg[3], centn[3]; int centermode = RNA_enum_get(op->ptr, "type"); @@ -754,8 +748,6 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) CollectionPointerLink *ctx_ob; CollectionPointerLink *ctx_ob_act = NULL; - CTX_data_eval_ctx(C, &eval_ctx); - /* keep track of what is changed */ int tot_change = 0, tot_lib_error = 0, tot_multiuser_arm_error = 0; @@ -871,7 +863,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) float min[3], max[3]; /* only bounds support */ INIT_MINMAX(min, max); - BKE_object_minmax_dupli(scene, ob, min, max, true); + BKE_object_minmax_dupli(depsgraph, scene, ob, min, max, true); mid_v3_v3v3(cent, min, max); invert_m4_m4(ob->imat, ob->obmat); mul_m4_v3(ob->imat, cent); @@ -988,8 +980,8 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) arm->id.tag |= LIB_TAG_DOIT; /* do_inverse_offset = true; */ /* docenter_armature() handles this */ - BKE_object_where_is_calc(&eval_ctx, scene, ob); - BKE_pose_where_is(&eval_ctx, scene, ob); /* needed for bone parents */ + BKE_object_where_is_calc(depsgraph, scene, ob); + BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */ ignore_parent_tx(C, bmain, scene, ob); @@ -1047,9 +1039,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) add_v3_v3(ob->loc, centn); - BKE_object_where_is_calc(&eval_ctx, scene, ob); + BKE_object_where_is_calc(depsgraph, scene, ob); if (ob->type == OB_ARMATURE) { - BKE_pose_where_is(&eval_ctx, scene, ob); /* needed for bone parents */ + BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */ } ignore_parent_tx(C, bmain, scene, ob); @@ -1076,9 +1068,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) mul_v3_mat3_m4v3(centn, ob_other->obmat, cent); /* omit translation part */ add_v3_v3(ob_other->loc, centn); - BKE_object_where_is_calc(&eval_ctx, scene, ob_other); + BKE_object_where_is_calc(depsgraph, scene, ob_other); if (ob_other->type == OB_ARMATURE) { - BKE_pose_where_is(&eval_ctx, scene, ob_other); /* needed for bone parents */ + BKE_pose_where_is(depsgraph, scene, ob_other); /* needed for bone parents */ } ignore_parent_tx(C, bmain, scene, ob_other); } @@ -1292,11 +1284,7 @@ static int object_transform_axis_target_invoke(bContext *C, wmOperator *op, cons return OPERATOR_PASS_THROUGH; } - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); - - ED_view3d_autodist_init(&eval_ctx, vc.depsgraph, vc.ar, vc.v3d, 0); + ED_view3d_autodist_init(vc.depsgraph, vc.ar, vc.v3d, 0); if (vc.rv3d->depths != NULL) { vc.rv3d->depths->damaged = true; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 7026e8671ad..ff40aa07cd2 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1273,9 +1273,9 @@ static void dm_deform_clear(DerivedMesh *dm, Object *ob) } /* recalculate the deformation */ -static DerivedMesh *dm_deform_recalc(EvaluationContext *eval_ctx, Scene *scene, Object *ob) +static DerivedMesh *dm_deform_recalc(Depsgraph *depsgraph, Scene *scene, Object *ob) { - return mesh_get_derived_deform(eval_ctx, scene, ob, CD_MASK_BAREMESH); + return mesh_get_derived_deform(depsgraph, scene, ob, CD_MASK_BAREMESH); } /* by changing nonzero weights, try to move a vertex in me->mverts with index 'index' to @@ -1288,7 +1288,7 @@ static DerivedMesh *dm_deform_recalc(EvaluationContext *eval_ctx, Scene *scene, * coord is a point on the plane */ static void moveCloserToDistanceFromPlane( - EvaluationContext *eval_ctx, Scene *scene, Object *ob, Mesh *me, int index, float norm[3], + Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *me, int index, float norm[3], float coord[3], float d, float distToBe, float strength, float cp) { DerivedMesh *dm; @@ -1315,7 +1315,7 @@ static void moveCloserToDistanceFromPlane( float originalDistToBe = distToBe; do { wasChange = false; - dm = dm_deform_recalc(eval_ctx, scene, ob); + dm = dm_deform_recalc(depsgraph, scene, ob); dm->getVert(dm, index, &m); copy_v3_v3(oldPos, m.co); distToStart = dot_v3v3(norm, oldPos) + d; @@ -1353,7 +1353,7 @@ static void moveCloserToDistanceFromPlane( if (dw->weight > 1) { dw->weight = 1; } - dm = dm_deform_recalc(eval_ctx, scene, ob); + dm = dm_deform_recalc(depsgraph, scene, ob); dm->getVert(dm, index, &m); getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m.co, changes, dists, i); dw->weight = oldw; @@ -1465,11 +1465,9 @@ static void moveCloserToDistanceFromPlane( * but it could be used to raise or lower an existing 'bump.' */ static void vgroup_fix(const bContext *C, Scene *scene, Object *ob, float distToBe, float strength, float cp) { - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); int i; - CTX_data_eval_ctx(C, &eval_ctx); - Mesh *me = ob->data; MVert *mvert = me->mvert; int *verts = NULL; @@ -1483,7 +1481,7 @@ static void vgroup_fix(const bContext *C, Scene *scene, Object *ob, float distTo MVert *p = MEM_callocN(sizeof(MVert) * (count), "deformedPoints"); int k; - DerivedMesh *dm = mesh_get_derived_deform(&eval_ctx, scene, ob, CD_MASK_BAREMESH); + DerivedMesh *dm = mesh_get_derived_deform(depsgraph, scene, ob, CD_MASK_BAREMESH); k = count; while (k--) { dm->getVert(dm, verts[k], &m); @@ -1501,7 +1499,7 @@ static void vgroup_fix(const bContext *C, Scene *scene, Object *ob, float distTo if (mag) { /* zeros fix */ d = -dot_v3v3(norm, coord); /* dist = (dot_v3v3(norm, m.co) + d); */ /* UNUSED */ - moveCloserToDistanceFromPlane(&eval_ctx, scene, ob, me, i, norm, coord, d, distToBe, strength, cp); + moveCloserToDistanceFromPlane(depsgraph, scene, ob, me, i, norm, coord, d, distToBe, strength, cp); } } diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c index 5d928d69da2..6dee6825b31 100644 --- a/source/blender/editors/physics/dynamicpaint_ops.c +++ b/source/blender/editors/physics/dynamicpaint_ops.c @@ -294,8 +294,6 @@ typedef struct DynamicPaintBakeJob { DynamicPaintSurface *surface; DynamicPaintCanvasSettings *canvas; - EvaluationContext *eval_ctx; - int success; double start; } DynamicPaintBakeJob; @@ -315,8 +313,6 @@ static void dpaint_bake_endjob(void *customdata) dynamicPaint_freeSurfaceData(job->surface); - MEM_freeN(job->eval_ctx); - G.is_rendering = false; BKE_spacedata_draw_locks(false); @@ -391,7 +387,7 @@ static void dynamicPaint_bakeImageSequence(DynamicPaintBakeJob *job) /* calculate a frame */ scene->r.cfra = (int)frame; ED_update_for_newframe(job->bmain, job->depsgraph); - if (!dynamicPaint_calculateFrame(surface, job->eval_ctx, scene, cObject, frame)) { + if (!dynamicPaint_calculateFrame(surface, job->depsgraph, scene, cObject, frame)) { job->success = 0; return; } @@ -459,9 +455,6 @@ static int dynamicpaint_bake_exec(struct bContext *C, struct wmOperator *op) DynamicPaintCanvasSettings *canvas; Object *ob = ED_object_context(C); Scene *scene = CTX_data_scene(C); - EvaluationContext *eval_ctx = MEM_mallocN(sizeof(*eval_ctx), "EvaluationContext"); - - CTX_data_eval_ctx(C, eval_ctx); DynamicPaintSurface *surface; @@ -493,7 +486,6 @@ static int dynamicpaint_bake_exec(struct bContext *C, struct wmOperator *op) job->ob = ob; job->canvas = canvas; job->surface = surface; - job->eval_ctx = eval_ctx; wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Dynamic Paint Bake", WM_JOB_PROGRESS, diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 51abb5b2eaa..7012046fc31 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -194,7 +194,7 @@ static float pe_brush_size_get(const Scene *UNUSED(scene), ParticleBrushData *br * note: this function runs on poll, therefor it can runs many times a second * keep it fast! */ static PTCacheEdit *pe_get_current( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, int create) + Depsgraph *depsgraph, Scene *scene, Object *ob, int create) { ParticleEditSettings *pset= PE_settings(scene); PTCacheEdit *edit = NULL; @@ -233,18 +233,18 @@ static PTCacheEdit *pe_get_current( if (psys->part && psys->part->type == PART_HAIR) { if (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED) { if (create && !psys->pointcache->edit) - PE_create_particle_edit(eval_ctx, scene, ob, pid->cache, NULL); + PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL); edit = pid->cache->edit; } else { if (create && !psys->edit && psys->flag & PSYS_HAIR_DONE) - PE_create_particle_edit(eval_ctx, scene, ob, NULL, psys); + PE_create_particle_edit(depsgraph, scene, ob, NULL, psys); edit = psys->edit; } } else { if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) - PE_create_particle_edit(eval_ctx, scene, ob, pid->cache, psys); + PE_create_particle_edit(depsgraph, scene, ob, pid->cache, psys); edit = pid->cache->edit; } @@ -255,7 +255,7 @@ static PTCacheEdit *pe_get_current( if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) { pset->flag |= PE_FADE_TIME; // NICE TO HAVE but doesn't work: pset->brushtype = PE_BRUSH_COMB; - PE_create_particle_edit(eval_ctx, scene, ob, pid->cache, NULL); + PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL); } edit = pid->cache->edit; break; @@ -264,7 +264,7 @@ static PTCacheEdit *pe_get_current( if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) { pset->flag |= PE_FADE_TIME; // NICE TO HAVE but doesn't work: pset->brushtype = PE_BRUSH_COMB; - PE_create_particle_edit(eval_ctx, scene, ob, pid->cache, NULL); + PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL); } edit = pid->cache->edit; break; @@ -284,15 +284,15 @@ PTCacheEdit *PE_get_current(Scene *scene, Object *ob) return pe_get_current(NULL, scene, ob, 0); } -PTCacheEdit *PE_create_current(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +PTCacheEdit *PE_create_current(Depsgraph *depsgraph, Scene *scene, Object *ob) { - return pe_get_current(eval_ctx, scene, ob, 1); + return pe_get_current(depsgraph, scene, ob, 1); } -void PE_current_changed(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +void PE_current_changed(Depsgraph *depsgraph, Scene *scene, Object *ob) { if (ob->mode == OB_MODE_PARTICLE_EDIT) { - PE_create_current(eval_ctx, scene, ob); + PE_create_current(depsgraph, scene, ob); } } @@ -343,7 +343,7 @@ typedef struct PEData { DerivedMesh *dm; PTCacheEdit *edit; BVHTreeFromMesh shape_bvh; - EvaluationContext eval_ctx; + Depsgraph *depsgraph; const int *mval; rcti *rect; @@ -376,7 +376,7 @@ static void PE_set_data(bContext *C, PEData *data) data->scene = CTX_data_scene(C); data->view_layer = CTX_data_view_layer(C); data->ob = CTX_data_active_object(C); - CTX_data_eval_ctx(C, &data->eval_ctx); + data->depsgraph = CTX_data_depsgraph(C); data->edit = PE_get_current(data->scene, data->ob); } @@ -391,7 +391,7 @@ static void PE_set_view3d_data(bContext *C, PEData *data) /* needed or else the draw matrix can be incorrect */ view3d_operator_needs_opengl(C); - ED_view3d_backbuf_validate(&data->eval_ctx, &data->vc); + ED_view3d_backbuf_validate(&data->vc); /* we may need to force an update here by setting the rv3d as dirty * for now it seems ok, but take care!: * rv3d->depths->dirty = 1; */ @@ -1136,7 +1136,7 @@ void recalc_emitter_field(Object *ob, ParticleSystem *psys) BLI_kdtree_balance(edit->emitter_field); } -static void PE_update_selection(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, int useflag) +static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag) { PTCacheEdit *edit = PE_get_current(scene, ob); HairKey *hkey; @@ -1157,7 +1157,7 @@ static void PE_update_selection(const EvaluationContext *eval_ctx, Scene *scene, } } - psys_cache_edit_paths(eval_ctx, scene, ob, edit, CFRA, G.is_rendering); + psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering); /* disable update flag */ @@ -1243,7 +1243,7 @@ static void update_velocities(PTCacheEdit *edit) } } -void PE_update_object(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, int useflag) +void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag) { /* use this to do partial particle updates, not usable when adding or * removing, then a full redo is necessary and calling this may crash */ @@ -1273,7 +1273,7 @@ void PE_update_object(const EvaluationContext *eval_ctx, Scene *scene, Object *o PE_hide_keys_time(scene, edit, CFRA); /* regenerate path caches */ - psys_cache_edit_paths(eval_ctx, scene, ob, edit, CFRA, G.is_rendering); + psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering); /* disable update flag */ LOOP_POINTS { @@ -1357,36 +1357,35 @@ static void toggle_key_select(PEData *data, int point_index, int key_index) static void select_action_apply(PTCacheEditPoint *point, PTCacheEditKey *key, int action) { switch (action) { - case SEL_SELECT: - if ((key->flag & PEK_SELECT) == 0) { - key->flag |= PEK_SELECT; - point->flag |= PEP_EDIT_RECALC; - } - break; - case SEL_DESELECT: - if (key->flag & PEK_SELECT) { - key->flag &= ~PEK_SELECT; - point->flag |= PEP_EDIT_RECALC; - } - break; - case SEL_INVERT: - if ((key->flag & PEK_SELECT) == 0) { - key->flag |= PEK_SELECT; - point->flag |= PEP_EDIT_RECALC; - } - else { - key->flag &= ~PEK_SELECT; - point->flag |= PEP_EDIT_RECALC; - } - break; + case SEL_SELECT: + if ((key->flag & PEK_SELECT) == 0) { + key->flag |= PEK_SELECT; + point->flag |= PEP_EDIT_RECALC; + } + break; + case SEL_DESELECT: + if (key->flag & PEK_SELECT) { + key->flag &= ~PEK_SELECT; + point->flag |= PEP_EDIT_RECALC; + } + break; + case SEL_INVERT: + if ((key->flag & PEK_SELECT) == 0) { + key->flag |= PEK_SELECT; + point->flag |= PEP_EDIT_RECALC; + } + else { + key->flag &= ~PEK_SELECT; + point->flag |= PEP_EDIT_RECALC; + } + break; } } static int pe_select_all_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Object *ob= CTX_data_active_object(C); PTCacheEdit *edit= PE_get_current(scene, ob); POINT_P; KEY_K; @@ -1411,7 +1410,7 @@ static int pe_select_all_exec(bContext *C, wmOperator *op) } } - PE_update_selection(&eval_ctx, scene, ob, 1); + PE_update_selection(depsgraph, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1468,7 +1467,7 @@ int PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselec else for_mouse_hit_keys(&data, toggle_key_select, 1); - PE_update_selection(&data.eval_ctx, scene, ob, 1); + PE_update_selection(data.depsgraph, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1509,7 +1508,7 @@ static int select_roots_exec(bContext *C, wmOperator *op) data.select_action = action; foreach_point(&data, select_root); - PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); + PE_update_selection(data.depsgraph, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1574,7 +1573,7 @@ static int select_tips_exec(bContext *C, wmOperator *op) data.select_action = action; foreach_point(&data, select_tip); - PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); + PE_update_selection(data.depsgraph, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1658,7 +1657,7 @@ static int select_random_exec(bContext *C, wmOperator *op) BLI_rng_free(rng); - PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); + PE_update_selection(data.depsgraph, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1702,7 +1701,7 @@ static int select_linked_exec(bContext *C, wmOperator *op) data.select= !RNA_boolean_get(op->ptr, "deselect"); for_mouse_hit_keys(&data, select_keys, 1); /* nearest only */ - PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); + PE_update_selection(data.depsgraph, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1766,7 +1765,7 @@ int PE_border_select(bContext *C, rcti *rect, bool select, bool extend) for_mouse_hit_keys(&data, select_key, 0); - PE_update_selection(&data.eval_ctx, scene, ob, 1); + PE_update_selection(data.depsgraph, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1791,7 +1790,7 @@ int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) for_mouse_hit_keys(&data, select_key, 0); - PE_update_selection(&data.eval_ctx, scene, ob, 1); + PE_update_selection(data.depsgraph, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1879,7 +1878,7 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, bool } } - PE_update_selection(&data.eval_ctx, scene, ob, 1); + PE_update_selection(data.depsgraph, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1891,8 +1890,7 @@ static int hide_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); Scene *scene= CTX_data_scene(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); PTCacheEdit *edit= PE_get_current(scene, ob); POINT_P; KEY_K; @@ -1917,7 +1915,7 @@ static int hide_exec(bContext *C, wmOperator *op) } } - PE_update_selection(&eval_ctx, scene, ob, 1); + PE_update_selection(depsgraph, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1947,8 +1945,7 @@ static int reveal_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); Scene *scene= CTX_data_scene(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); PTCacheEdit *edit= PE_get_current(scene, ob); const bool select = RNA_boolean_get(op->ptr, "select"); POINT_P; KEY_K; @@ -1964,7 +1961,7 @@ static int reveal_exec(bContext *C, wmOperator *op) } } - PE_update_selection(&eval_ctx, scene, ob, 1); + PE_update_selection(depsgraph, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -2026,7 +2023,7 @@ static int select_less_exec(bContext *C, wmOperator *UNUSED(op)) PE_set_data(C, &data); foreach_point(&data, select_less_keys); - PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); + PE_update_selection(data.depsgraph, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -2088,7 +2085,7 @@ static int select_more_exec(bContext *C, wmOperator *UNUSED(op)) PE_set_data(C, &data); foreach_point(&data, select_more_keys); - PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); + PE_update_selection(data.depsgraph, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -2121,12 +2118,10 @@ static void rekey_particle(PEData *data, int pa_index) ParticleKey state; HairKey *key, *new_keys, *okey; PTCacheEditKey *ekey; - EvaluationContext eval_ctx; float dval, sta, end; int k; - CTX_data_eval_ctx(data->context, &eval_ctx); - sim.eval_ctx = &eval_ctx; + sim.depsgraph = data->depsgraph; sim.scene = data->scene; sim.ob = data->ob; sim.psys = edit->psys; @@ -2180,9 +2175,6 @@ static int rekey_exec(bContext *C, wmOperator *op) { PEData data; - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - PE_set_data(C, &data); data.dval= 1.0f / (float)(data.totrekey-1); @@ -2191,7 +2183,7 @@ static int rekey_exec(bContext *C, wmOperator *op) foreach_selected_point(&data, rekey_particle); recalc_lengths(data.edit); - PE_update_object(&eval_ctx, data.scene, data.ob, 1); + PE_update_object(data.depsgraph, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); return OPERATOR_FINISHED; @@ -2225,16 +2217,13 @@ static void rekey_particle_to_time(const bContext *C, Scene *scene, Object *ob, ParticleKey state; HairKey *new_keys, *key; PTCacheEditKey *ekey; - EvaluationContext eval_ctx; int k; - CTX_data_eval_ctx(C, &eval_ctx); - if (!edit || !edit->psys) return; psys = edit->psys; - sim.eval_ctx = &eval_ctx; + sim.depsgraph = CTX_data_depsgraph(C); sim.scene = scene; sim.ob = ob; sim.psys = psys; @@ -2447,14 +2436,12 @@ static void subdivide_particle(PEData *data, int pa_index) ParticleKey state; HairKey *key, *nkey, *new_keys; PTCacheEditKey *ekey, *nekey, *new_ekeys; - EvaluationContext eval_ctx; int k; short totnewkey=0; float endtime; - CTX_data_eval_ctx(data->context, &eval_ctx); - sim.eval_ctx = &eval_ctx; + sim.depsgraph = data->depsgraph; sim.scene = data->scene; sim.ob = data->ob; sim.psys = edit->psys; @@ -2525,14 +2512,11 @@ static int subdivide_exec(bContext *C, wmOperator *UNUSED(op)) { PEData data; - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - PE_set_data(C, &data); foreach_point(&data, subdivide_particle); recalc_lengths(data.edit); - PE_update_object(&eval_ctx, data.scene, data.ob, 1); + PE_update_object(data.depsgraph, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); return OPERATOR_FINISHED; @@ -3356,21 +3340,19 @@ static int particle_intersect_dm(const bContext *C, Scene *scene, Object *ob, De float *face_minmax, float *pa_minmax, float radius, float *ipoint) { - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); MFace *mface= NULL; MVert *mvert= NULL; int i, totface, intersect=0; float cur_d, cur_uv[2], v1[3], v2[3], v3[3], v4[3], min[3], max[3], p_min[3], p_max[3]; float cur_ipoint[3]; - CTX_data_eval_ctx(C, &eval_ctx); - if (dm == NULL) { psys_disable_all(ob); - dm = mesh_get_derived_final(&eval_ctx, scene, ob, 0); + dm = mesh_get_derived_final(depsgraph, scene, ob, 0); if (dm == NULL) - dm = mesh_get_derived_deform(&eval_ctx, scene, ob, 0); + dm = mesh_get_derived_deform(depsgraph, scene, ob, 0); psys_enable_all(ob); @@ -3485,8 +3467,7 @@ static int particle_intersect_dm(const bContext *C, Scene *scene, Object *ob, De static int brush_add(const bContext *C, PEData *data, short number) { - EvaluationContext eval_ctx; - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene= data->scene; Object *ob= data->ob; DerivedMesh *dm; @@ -3514,9 +3495,7 @@ static int brush_add(const bContext *C, PEData *data, short number) rng = BLI_rng_new_srandom(psys->seed+data->mval[0]+data->mval[1]); - CTX_data_eval_ctx(C, &eval_ctx); - - sim.eval_ctx = &eval_ctx; + sim.depsgraph = depsgraph; sim.scene= scene; sim.ob= ob; sim.psys= psys; @@ -3805,8 +3784,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) if (!PE_start_edit(edit)) return; - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); RNA_float_get_array(itemptr, "mouse", mousef); mouse[0] = mousef[0]; @@ -3991,7 +3969,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) DEG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { - PE_update_object(&eval_ctx, scene, ob, 1); + PE_update_object(depsgraph, scene, ob, 1); } } @@ -4254,7 +4232,7 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) DEG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { - PE_update_object(&data.eval_ctx, scene, ob, 1); + PE_update_object(data.depsgraph, scene, ob, 1); } if (edit->psys) { @@ -4331,7 +4309,7 @@ int PE_minmax(Scene *scene, ViewLayer *view_layer, float min[3], float max[3]) /* initialize needed data for bake edit */ void PE_create_particle_edit( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys) + Depsgraph *depsgraph, Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys) { PTCacheEdit *edit; ParticleSystemModifierData *psmd = (psys) ? psys_get_modifier(ob, psys) : NULL; @@ -4433,7 +4411,7 @@ void PE_create_particle_edit( if (psys && !cache) recalc_emitter_field(ob, psys); - PE_update_object(eval_ctx, scene, ob, 1); + PE_update_object(depsgraph, scene, ob, 1); } } @@ -4455,6 +4433,7 @@ static int particle_edit_toggle_poll(bContext *C) static int particle_edit_toggle_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_PARTICLE_EDIT; @@ -4468,11 +4447,9 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op) if (!is_mode_set) { PTCacheEdit *edit; - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); ob->mode |= mode_flag; - edit= PE_create_current(&eval_ctx, scene, ob); + edit= PE_create_current(depsgraph, scene, ob); /* mesh may have changed since last entering editmode. * note, this may have run before if the edit data was just created, so could avoid this and speed up a little */ @@ -4642,8 +4619,7 @@ static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); PTCacheEdit *edit = PE_get_current(scene, ob); float average_length = calculate_average_length(edit); @@ -4654,7 +4630,7 @@ static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) scale_points_to_length(edit, average_length); - PE_update_object(&eval_ctx, scene, ob, 1); + PE_update_object(depsgraph, scene, ob, 1); if (edit->psys) { WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob); } diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index 1fae5b70aff..23a6ba68fc9 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -546,7 +546,7 @@ void PARTICLE_OT_dupliob_move_down(wmOperatorType *ot) /************************ connect/disconnect hair operators *********************/ static void disconnect_hair( - const EvaluationContext *eval_ctx, Scene *scene, + Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys) { ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); @@ -593,30 +593,28 @@ static void disconnect_hair( if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_PUFF)) pset->brushtype = PE_BRUSH_NONE; - PE_update_object(eval_ctx, scene, ob, 0); + PE_update_object(depsgraph, scene, ob, 0); } static int disconnect_hair_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene= CTX_data_scene(C); Object *ob= ED_object_context(C); ParticleSystem *psys= NULL; const bool all = RNA_boolean_get(op->ptr, "all"); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - if (!ob) return OPERATOR_CANCELLED; if (all) { for (psys=ob->particlesystem.first; psys; psys=psys->next) { - disconnect_hair(&eval_ctx, scene, ob, psys); + disconnect_hair(depsgraph, scene, ob, psys); } } else { psys = psys_get_current(ob); - disconnect_hair(&eval_ctx, scene, ob, psys); + disconnect_hair(depsgraph, scene, ob, psys); } DEG_id_tag_update(&ob->id, OB_RECALC_DATA); @@ -643,7 +641,7 @@ void PARTICLE_OT_disconnect_hair(wmOperatorType *ot) * from/to_mat : additional transform for from/to particles (e.g. for using object space copying) */ static bool remap_hair_emitter( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, ParticleSystem *psys, + Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, Object *target_ob, ParticleSystem *target_psys, PTCacheEdit *target_edit, float from_mat[4][4], float to_mat[4][4], bool from_global, bool to_global) { @@ -714,8 +712,8 @@ static bool remap_hair_emitter( for (i = 0, tpa = target_psys->particles, pa = psys->particles; i < target_psys->totpart; - i++, tpa++, pa++) { - + i++, tpa++, pa++) + { float from_co[3]; BVHTreeNearest nearest; @@ -829,13 +827,13 @@ static bool remap_hair_emitter( psys_free_path_cache(target_psys, target_edit); - PE_update_object(eval_ctx, scene, target_ob, 0); + PE_update_object(depsgraph, scene, target_ob, 0); return true; } static bool connect_hair( - const EvaluationContext *eval_ctx, Scene *scene, + Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys) { bool ok; @@ -844,7 +842,7 @@ static bool connect_hair( return false; ok = remap_hair_emitter( - eval_ctx, scene, ob, psys, ob, psys, psys->edit, + depsgraph, scene, ob, psys, ob, psys, psys->edit, ob->obmat, ob->obmat, psys->flag & PSYS_GLOBAL_HAIR, false); psys->flag &= ~PSYS_GLOBAL_HAIR; @@ -853,7 +851,7 @@ static bool connect_hair( static int connect_hair_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene= CTX_data_scene(C); Object *ob= ED_object_context(C); ParticleSystem *psys= NULL; @@ -863,16 +861,14 @@ static int connect_hair_exec(bContext *C, wmOperator *op) if (!ob) return OPERATOR_CANCELLED; - CTX_data_eval_ctx(C, &eval_ctx); - if (all) { for (psys=ob->particlesystem.first; psys; psys=psys->next) { - any_connected |= connect_hair(&eval_ctx, scene, ob, psys); + any_connected |= connect_hair(depsgraph, scene, ob, psys); } } else { psys = psys_get_current(ob); - any_connected |= connect_hair(&eval_ctx, scene, ob, psys); + any_connected |= connect_hair(depsgraph, scene, ob, psys); } if (!any_connected) { @@ -909,7 +905,7 @@ typedef enum eCopyParticlesSpace { } eCopyParticlesSpace; static void copy_particle_edit( - const EvaluationContext *eval_ctx, Scene *scene, + Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystem *psys_from) { PTCacheEdit *edit_from = psys_from->edit, *edit; @@ -957,7 +953,7 @@ static void copy_particle_edit( recalc_lengths(edit); recalc_emitter_field(ob, psys); - PE_update_object(eval_ctx, scene, ob, true); + PE_update_object(depsgraph, scene, ob, true); } static void remove_particle_systems_from_object(Object *ob_to) @@ -994,15 +990,13 @@ static bool copy_particle_systems_to_object(const bContext *C, bool duplicate_settings) { Main *bmain = CTX_data_main(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); ModifierData *md; ParticleSystem *psys_start = NULL, *psys, *psys_from; ParticleSystem **tmp_psys; DerivedMesh *final_dm; CustomDataMask cdmask; int i, totpsys; - - CTX_data_eval_ctx(C, &eval_ctx); if (ob_to->type != OB_MESH) return false; @@ -1026,8 +1020,8 @@ static bool copy_particle_systems_to_object(const bContext *C, cdmask = 0; for (psys_from = PSYS_FROM_FIRST, i = 0; psys_from; - psys_from = PSYS_FROM_NEXT(psys_from), ++i) { - + psys_from = PSYS_FROM_NEXT(psys_from), ++i) + { psys = BKE_object_copy_particlesystem(psys_from, 0); tmp_psys[i] = psys; @@ -1042,13 +1036,13 @@ static bool copy_particle_systems_to_object(const bContext *C, psys_start = totpsys > 0 ? tmp_psys[0] : NULL; /* get the DM (psys and their modifiers have not been appended yet) */ - final_dm = mesh_get_derived_final(&eval_ctx, scene, ob_to, cdmask); + final_dm = mesh_get_derived_final(depsgraph, scene, ob_to, cdmask); /* now append psys to the object and make modifiers */ for (i = 0, psys_from = PSYS_FROM_FIRST; i < totpsys; - ++i, psys_from = PSYS_FROM_NEXT(psys_from)) { - + ++i, psys_from = PSYS_FROM_NEXT(psys_from)) + { ParticleSystemModifierData *psmd; psys = tmp_psys[i]; @@ -1071,7 +1065,7 @@ static bool copy_particle_systems_to_object(const bContext *C, DM_ensure_tessface(psmd->dm_final); if (psys_from->edit) { - copy_particle_edit(&eval_ctx, scene, ob_to, psys, psys_from); + copy_particle_edit(depsgraph, scene, ob_to, psys, psys_from); } if (duplicate_settings) { @@ -1086,8 +1080,8 @@ static bool copy_particle_systems_to_object(const bContext *C, */ for (psys = psys_start, psys_from = PSYS_FROM_FIRST, i = 0; psys; - psys = psys->next, psys_from = PSYS_FROM_NEXT(psys_from), ++i) { - + psys = psys->next, psys_from = PSYS_FROM_NEXT(psys_from), ++i) + { float (*from_mat)[4], (*to_mat)[4]; switch (space) { @@ -1107,7 +1101,7 @@ static bool copy_particle_systems_to_object(const bContext *C, } if (ob_from != ob_to) { remap_hair_emitter( - &eval_ctx, scene, ob_from, psys_from, ob_to, psys, psys->edit, + depsgraph, scene, ob_from, psys_from, ob_to, psys, psys->edit, from_mat, to_mat, psys_from->flag & PSYS_GLOBAL_HAIR, psys->flag & PSYS_GLOBAL_HAIR); } diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index c0b2ae8ded4..541242fdc09 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -246,7 +246,7 @@ static void set_channel(float *channel, float time, float *value, int i, int siz } } -static void set_vertex_channel(EvaluationContext *eval_ctx, float *channel, float time, struct Scene *scene, struct FluidObject *fobj, int i) +static void set_vertex_channel(Depsgraph *depsgraph, float *channel, float time, struct Scene *scene, struct FluidObject *fobj, int i) { Object *ob = fobj->object; FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim); @@ -259,7 +259,7 @@ static void set_vertex_channel(EvaluationContext *eval_ctx, float *channel, floa if (channel == NULL) return; - initElbeemMesh(eval_ctx, scene, ob, &numVerts, &verts, &numTris, &tris, 1, modifierIndex); + initElbeemMesh(depsgraph, scene, ob, &numVerts, &verts, &numTris, &tris, 1, modifierIndex); /* don't allow mesh to change number of verts in anim sequence */ if (numVerts != fobj->numVerts) { @@ -333,14 +333,11 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Depsgraph *depsgraph = CTX_data_depsgraph(C); - EvaluationContext eval_ctx; Base *base; int i; int length = channels->length; float eval_time; - CTX_data_eval_ctx(C, &eval_ctx); - /* init time values (assuming that time moves at a constant speed; may be overridden later) */ init_time(domainSettings, channels); @@ -380,7 +377,7 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid float *verts=NULL; int *tris=NULL, modifierIndex = BLI_findindex(&ob->modifiers, (ModifierData *)fluidmd); - initElbeemMesh(&eval_ctx, scene, ob, &fobj->numVerts, &verts, &fobj->numTris, &tris, 0, modifierIndex); + initElbeemMesh(depsgraph, scene, ob, &fobj->numVerts, &verts, &fobj->numTris, &tris, 0, modifierIndex); fobj->VertexCache = MEM_callocN(length *((fobj->numVerts*CHANNEL_VEC)+1) * sizeof(float), "fluidobject VertexCache"); MEM_freeN(verts); @@ -468,7 +465,7 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid } if (fluid_is_animated_mesh(fluidmd->fss)) { - set_vertex_channel(&eval_ctx, fobj->VertexCache, timeAtFrame, scene, fobj, i); + set_vertex_channel(depsgraph, fobj->VertexCache, timeAtFrame, scene, fobj, i); } } } @@ -476,10 +473,8 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid static void export_fluid_objects(const bContext *C, ListBase *fobjects, Scene *scene, int length) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); FluidObject *fobj; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); for (fobj=fobjects->first; fobj; fobj=fobj->next) { Object *ob = fobj->object; @@ -501,7 +496,7 @@ static void export_fluid_objects(const bContext *C, ListBase *fobjects, Scene *s fsmesh.type = fluidmd->fss->type; fsmesh.name = ob->id.name; - initElbeemMesh(&eval_ctx, scene, ob, &numVerts, &verts, &numTris, &tris, 0, modifierIndex); + initElbeemMesh(depsgraph, scene, ob, &numVerts, &verts, &numTris, &tris, 0, modifierIndex); fsmesh.numVertices = numVerts; fsmesh.numTriangles = numTris; diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h index 246bf79360f..72da417da63 100644 --- a/source/blender/editors/physics/physics_intern.h +++ b/source/blender/editors/physics/physics_intern.h @@ -33,7 +33,7 @@ #ifndef __PHYSICS_INTERN_H__ #define __PHYSICS_INTERN_H__ -struct EvaluationContext; +struct Depsgraph; struct Object; struct PTCacheEdit; struct ParticleSystem; @@ -71,7 +71,7 @@ void PARTICLE_OT_edited_clear(struct wmOperatorType *ot); void PARTICLE_OT_unify_length(struct wmOperatorType *ot); void PE_create_particle_edit( - const struct EvaluationContext *eval_ctx, struct Scene *scene, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct PointCache *cache, struct ParticleSystem *psys); void recalc_lengths(struct PTCacheEdit *edit); void recalc_emitter_field(struct Object *ob, struct ParticleSystem *psys); diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 51a75e36044..965e213631d 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -1092,7 +1092,6 @@ typedef struct RenderPreview { wmJob *job; Scene *scene; - EvaluationContext *eval_ctx; Depsgraph *depsgraph; ScrArea *sa; ARegion *ar; @@ -1108,7 +1107,7 @@ typedef struct RenderPreview { bool has_freestyle; } RenderPreview; -static int render_view3d_disprect(Scene *scene, const Depsgraph *depsgraph, +static int render_view3d_disprect(Scene *scene, Depsgraph *depsgraph, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rcti *disprect) { /* copied code from view3d_draw.c */ @@ -1145,7 +1144,7 @@ static int render_view3d_disprect(Scene *scene, const Depsgraph *depsgraph, /* returns true if OK */ static bool render_view3d_get_rects( - const Depsgraph *depsgraph, + Depsgraph *depsgraph, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewplane, RenderEngine *engine, float *r_clipsta, float *r_clipend, float *r_pixsize, bool *r_ortho) { @@ -1341,7 +1340,7 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda WM_job_main_thread_lock_release(rp->job); /* do preprocessing like building raytree, shadows, volumes, SSS */ - RE_Database_Preprocess(rp->eval_ctx, re); + RE_Database_Preprocess(rp->depsgraph, re); /* conversion not completed, need to do it again */ if (!rstats->convertdone) { @@ -1407,7 +1406,6 @@ static void render_view3d_startjob(void *customdata, short *stop, short *do_upda static void render_view3d_free(void *customdata) { RenderPreview *rp = customdata; - DEG_evaluation_context_free(rp->eval_ctx); MEM_freeN(rp); } @@ -1523,8 +1521,6 @@ static void render_view3d_do(RenderEngine *engine, const bContext *C) /* customdata for preview thread */ rp->scene = scene; rp->depsgraph = depsgraph; - rp->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_PREVIEW); - CTX_data_eval_ctx(C, rp->eval_ctx); rp->engine = engine; rp->sa = CTX_wm_area(C); rp->ar = CTX_wm_region(C); diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index be2b184626d..a334d3abc68 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -268,6 +268,7 @@ static void screen_opengl_views_setup(OGLRender *oglrender) static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, RenderResult *rr) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = oglrender->scene; ViewLayer *view_layer = oglrender->view_layer; ARegion *ar = oglrender->ar; @@ -282,9 +283,6 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R float *rectf = NULL; const char *viewname = RE_GetActiveRenderView(oglrender->re); ImBuf *ibuf_result = NULL; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); if (oglrender->is_sequencer) { SpaceSeq *sseq = oglrender->sseq; @@ -362,7 +360,7 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R draw_flags |= (draw_bgpic) ? V3D_OFSDRAW_USE_BACKGROUND : 0; ibuf_view = ED_view3d_draw_offscreen_imbuf( - &eval_ctx, scene, view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, v3d, ar, sizex, sizey, IB_rectfloat, draw_flags, alpha_mode, oglrender->ofs_samples, viewname, oglrender->ofs, err_out); @@ -375,7 +373,7 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R else { draw_flags |= (V3D_OFSDRAW_USE_GPENCIL | V3D_OFSDRAW_USE_BACKGROUND); ibuf_view = ED_view3d_draw_offscreen_imbuf_simple( - &eval_ctx, scene, view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, scene->camera, oglrender->sizex, oglrender->sizey, IB_rectfloat, draw_flags, OB_SOLID, alpha_mode, oglrender->ofs_samples, viewname, @@ -539,8 +537,8 @@ static void screen_opengl_render_apply(const bContext *C, OGLRender *oglrender) int chanshown = sseq ? sseq->chanshown : 0; BKE_sequencer_new_render_data( - oglrender->bmain->eval_ctx, oglrender->bmain, scene, - oglrender->sizex, oglrender->sizey, 100.0f, + oglrender->bmain, scene, + oglrender->sizex, oglrender->sizey, 100.0f, false, &context); for (view_id = 0; view_id < oglrender->views_len; view_id++) { diff --git a/source/blender/editors/scene/scene_edit.c b/source/blender/editors/scene/scene_edit.c index d16d60ba7b9..58a58ef8172 100644 --- a/source/blender/editors/scene/scene_edit.c +++ b/source/blender/editors/scene/scene_edit.c @@ -132,8 +132,6 @@ void ED_scene_change_update( #if 0 /* mode syncing */ - EvaluationContext eval_ctx_old; - CTX_data_eval_ctx(C, &eval_ctx_old); eObjectMode object_mode_old = workspace->object_mode; ViewLayer *layer_old = BKE_view_layer_from_workspace_get(scene_old, workspace); Object *obact_old = OBACT(layer_old); diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c index 343e615f76b..d51abee2b04 100644 --- a/source/blender/editors/screen/screen_context.c +++ b/source/blender/editors/screen/screen_context.c @@ -30,6 +30,8 @@ #include <stdlib.h> #include <string.h> +#include "MEM_guardedalloc.h" + #include "DNA_object_types.h" #include "DNA_armature_types.h" #include "DNA_gpencil_types.h" @@ -42,7 +44,6 @@ #include "BLI_utildefines.h" - #include "BKE_context.h" #include "BKE_object.h" #include "BKE_action.h" @@ -209,38 +210,47 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult const bool editable_bones = CTX_data_equals(member, "editable_bones"); if (arm && arm->edbo) { - /* Attention: X-Axis Mirroring is also handled here... */ - for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { - /* first and foremost, bone must be visible and selected */ - if (EBONE_VISIBLE(arm, ebone)) { - /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled - * so that most users of this data don't need to explicitly check for it themselves. - * - * We need to make sure that these mirrored copies are not selected, otherwise some - * bones will be operated on twice. - */ - if (arm->flag & ARM_MIRROR_EDIT) - flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); - - /* if we're filtering for editable too, use the check for that instead, as it has selection check too */ - if (editable_bones) { - /* only selected + editable */ - if (EBONE_EDITABLE(ebone)) { + uint objects_len; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + for (uint i = 0; i < objects_len; i++) { + Object *ob = objects[i]; + arm = ob->data; + + /* Attention: X-Axis Mirroring is also handled here... */ + for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { + /* first and foremost, bone must be visible and selected */ + if (EBONE_VISIBLE(arm, ebone)) { + /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled + * so that most users of this data don't need to explicitly check for it themselves. + * + * We need to make sure that these mirrored copies are not selected, otherwise some + * bones will be operated on twice. + */ + if (arm->flag & ARM_MIRROR_EDIT) + flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); + + /* if we're filtering for editable too, use the check for that instead, as it has selection check too */ + if (editable_bones) { + /* only selected + editable */ + if (EBONE_EDITABLE(ebone)) { + CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); + + if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) + CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); + } + } + else { + /* only include bones if visible */ CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); - - if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) + + if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0) CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); } } - else { - /* only include bones if visible */ - CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); - - if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0) - CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); - } } } + MEM_freeN(objects); + CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); return 1; } @@ -251,38 +261,47 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult const bool selected_editable_bones = CTX_data_equals(member, "selected_editable_bones"); if (arm && arm->edbo) { - /* Attention: X-Axis Mirroring is also handled here... */ - for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { - /* first and foremost, bone must be visible and selected */ - if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) { - /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled - * so that most users of this data don't need to explicitly check for it themselves. - * - * We need to make sure that these mirrored copies are not selected, otherwise some - * bones will be operated on twice. - */ - if (arm->flag & ARM_MIRROR_EDIT) - flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); - - /* if we're filtering for editable too, use the check for that instead, as it has selection check too */ - if (selected_editable_bones) { - /* only selected + editable */ - if (EBONE_EDITABLE(ebone)) { + uint objects_len; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + for (uint i = 0; i < objects_len; i++) { + Object *ob = objects[i]; + arm = ob->data; + + /* Attention: X-Axis Mirroring is also handled here... */ + for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { + /* first and foremost, bone must be visible and selected */ + if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) { + /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled + * so that most users of this data don't need to explicitly check for it themselves. + * + * We need to make sure that these mirrored copies are not selected, otherwise some + * bones will be operated on twice. + */ + if (arm->flag & ARM_MIRROR_EDIT) + flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone); + + /* if we're filtering for editable too, use the check for that instead, as it has selection check too */ + if (selected_editable_bones) { + /* only selected + editable */ + if (EBONE_EDITABLE(ebone)) { + CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); + + if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) + CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); + } + } + else { + /* only include bones if selected */ CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); - + if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); } } - else { - /* only include bones if selected */ - CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone); - - if ((flipbone) && !(flipbone->flag & BONE_SELECTED)) - CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone); - } } } + MEM_freeN(objects); + CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); return 1; } @@ -293,12 +312,24 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult bPoseChannel *pchan; if (obpose && obpose->pose && arm) { - for (pchan = obpose->pose->chanbase.first; pchan; pchan = pchan->next) { - /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ - if (PBONE_VISIBLE(arm, pchan->bone)) { - CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); + if (obpose != obact) { + for (pchan = obpose->pose->chanbase.first; pchan; pchan = pchan->next) { + /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ + if (PBONE_VISIBLE(arm, pchan->bone)) { + CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); + } } } + else if (obact->mode & OB_MODE_POSE) { + FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, obact->mode, ob_iter) { + for (pchan = ob_iter->pose->chanbase.first; pchan; pchan = pchan->next) { + /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ + if (PBONE_VISIBLE(arm, pchan->bone)) { + CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan); + } + } + } FOREACH_OBJECT_IN_MODE_END; + } CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); return 1; } @@ -309,13 +340,28 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult bPoseChannel *pchan; if (obpose && obpose->pose && arm) { - for (pchan = obpose->pose->chanbase.first; pchan; pchan = pchan->next) { - /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ - if (PBONE_VISIBLE(arm, pchan->bone)) { - if (pchan->bone->flag & BONE_SELECTED) - CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); + if (obpose != obact) { + /* TODO(de-duplicate!) */ + for (pchan = obpose->pose->chanbase.first; pchan; pchan = pchan->next) { + /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ + if (PBONE_VISIBLE(arm, pchan->bone)) { + if (pchan->bone->flag & BONE_SELECTED) + CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan); + } } } + else if (obact->mode & OB_MODE_POSE) { + /* TODO(de-duplicate!) */ + FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob_iter) { + for (pchan = ob_iter->pose->chanbase.first; pchan; pchan = pchan->next) { + /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */ + if (PBONE_VISIBLE(arm, pchan->bone)) { + if (pchan->bone->flag & BONE_SELECTED) + CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan); + } + } + } FOREACH_OBJECT_IN_MODE_END; + } CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); return 1; } diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index e65fd2701b4..e961a7f5d64 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -86,182 +86,19 @@ static ScrVert *screen_addvert(bScreen *sc, short x, short y) return sv; } -static void sortscrvert(ScrVert **v1, ScrVert **v2) -{ - ScrVert *tmp; - - if (*v1 > *v2) { - tmp = *v1; - *v1 = *v2; - *v2 = tmp; - } -} - static ScrEdge *screen_addedge(bScreen *sc, ScrVert *v1, ScrVert *v2) { ScrEdge *se = MEM_callocN(sizeof(ScrEdge), "addscredge"); - - sortscrvert(&v1, &v2); + + BKE_screen_sort_scrvert(&v1, &v2); se->v1 = v1; se->v2 = v2; - + BLI_addtail(&sc->edgebase, se); return se; } -ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2) -{ - ScrEdge *se; - - sortscrvert(&v1, &v2); - for (se = sc->edgebase.first; se; se = se->next) - if (se->v1 == v1 && se->v2 == v2) - return se; - - return NULL; -} - -void removedouble_scrverts(bScreen *sc) -{ - ScrVert *v1, *verg; - ScrEdge *se; - ScrArea *sa; - - verg = sc->vertbase.first; - while (verg) { - if (verg->newv == NULL) { /* !!! */ - v1 = verg->next; - while (v1) { - if (v1->newv == NULL) { /* !?! */ - if (v1->vec.x == verg->vec.x && v1->vec.y == verg->vec.y) { - /* printf("doublevert\n"); */ - v1->newv = verg; - } - } - v1 = v1->next; - } - } - verg = verg->next; - } - - /* replace pointers in edges and faces */ - se = sc->edgebase.first; - while (se) { - if (se->v1->newv) se->v1 = se->v1->newv; - if (se->v2->newv) se->v2 = se->v2->newv; - /* edges changed: so.... */ - sortscrvert(&(se->v1), &(se->v2)); - se = se->next; - } - sa = sc->areabase.first; - while (sa) { - if (sa->v1->newv) sa->v1 = sa->v1->newv; - if (sa->v2->newv) sa->v2 = sa->v2->newv; - if (sa->v3->newv) sa->v3 = sa->v3->newv; - if (sa->v4->newv) sa->v4 = sa->v4->newv; - sa = sa->next; - } - - /* remove */ - verg = sc->vertbase.first; - while (verg) { - v1 = verg->next; - if (verg->newv) { - BLI_remlink(&sc->vertbase, verg); - MEM_freeN(verg); - } - verg = v1; - } - -} - -void removenotused_scrverts(bScreen *sc) -{ - ScrVert *sv, *svn; - ScrEdge *se; - - /* we assume edges are ok */ - - se = sc->edgebase.first; - while (se) { - se->v1->flag = 1; - se->v2->flag = 1; - se = se->next; - } - - sv = sc->vertbase.first; - while (sv) { - svn = sv->next; - if (sv->flag == 0) { - BLI_remlink(&sc->vertbase, sv); - MEM_freeN(sv); - } - else { - sv->flag = 0; - } - sv = svn; - } -} - -void removedouble_scredges(bScreen *sc) -{ - ScrEdge *verg, *se, *sn; - - /* compare */ - verg = sc->edgebase.first; - while (verg) { - se = verg->next; - while (se) { - sn = se->next; - if (verg->v1 == se->v1 && verg->v2 == se->v2) { - BLI_remlink(&sc->edgebase, se); - MEM_freeN(se); - } - se = sn; - } - verg = verg->next; - } -} - -void removenotused_scredges(bScreen *sc) -{ - ScrEdge *se, *sen; - ScrArea *sa; - int a = 0; - - /* sets flags when edge is used in area */ - sa = sc->areabase.first; - while (sa) { - se = screen_findedge(sc, sa->v1, sa->v2); - if (se == NULL) printf("error: area %d edge 1 doesn't exist\n", a); - else se->flag = 1; - se = screen_findedge(sc, sa->v2, sa->v3); - if (se == NULL) printf("error: area %d edge 2 doesn't exist\n", a); - else se->flag = 1; - se = screen_findedge(sc, sa->v3, sa->v4); - if (se == NULL) printf("error: area %d edge 3 doesn't exist\n", a); - else se->flag = 1; - se = screen_findedge(sc, sa->v4, sa->v1); - if (se == NULL) printf("error: area %d edge 4 doesn't exist\n", a); - else se->flag = 1; - sa = sa->next; - a++; - } - se = sc->edgebase.first; - while (se) { - sen = se->next; - if (se->flag == 0) { - BLI_remlink(&sc->edgebase, se); - MEM_freeN(se); - } - else { - se->flag = 0; - } - se = sen; - } -} - bool scredge_is_horizontal(ScrEdge *se) { return (se->v1->vec.y == se->v2->vec.y); @@ -452,9 +289,9 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge) /* remove double vertices en edges */ if (merge) - removedouble_scrverts(sc); - removedouble_scredges(sc); - removenotused_scredges(sc); + BKE_screen_remove_double_scrverts(sc); + BKE_screen_remove_double_scredges(sc); + BKE_screen_remove_unused_scredges(sc); return newa; } @@ -509,7 +346,7 @@ void screen_data_copy(bScreen *to, bScreen *from) for (se = to->edgebase.first; se; se = se->next) { se->v1 = se->v1->newv; se->v2 = se->v2->newv; - sortscrvert(&(se->v1), &(se->v2)); + BKE_screen_sort_scrvert(&(se->v1), &(se->v2)); } saf = from->areabase.first; @@ -618,8 +455,7 @@ int screen_area_join(bContext *C, bScreen *scr, ScrArea *sa1, ScrArea *sa2) } screen_delarea(C, scr, sa2); - removedouble_scrverts(scr); - + BKE_screen_remove_double_scrverts(scr); /* Update preview thumbnail */ BKE_icon_changed(scr->id.icon_id); @@ -772,7 +608,7 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y) if (sa->temp == TEMP_TOP) { /* lower edge */ const int yval = sa->v2->vec.y - headery_init; - se = screen_findedge(sc, sa->v4, sa->v1); + se = BKE_screen_find_edge(sc, sa->v4, sa->v1); if (se != NULL) { select_connected_scredge(sc, se); } @@ -787,7 +623,7 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y) else { /* upper edge */ const int yval = sa->v1->vec.y + headery_init; - se = screen_findedge(sc, sa->v2, sa->v3); + se = BKE_screen_find_edge(sc, sa->v2, sa->v3); if (se != NULL) { select_connected_scredge(sc, se); } @@ -823,7 +659,7 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y) if (sa->v2->vec.y - sa->v1->vec.y + 1 < headery) { /* lower edge */ - ScrEdge *se = screen_findedge(sc, sa->v4, sa->v1); + ScrEdge *se = BKE_screen_find_edge(sc, sa->v4, sa->v1); if (se && sa->v1 != sa->v2) { int yval; @@ -1030,11 +866,12 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen) screen->active_region = NULL; - for (ar = screen->regionbase.first; ar; ar = ar->next) + for (ar = screen->regionbase.first; ar; ar = ar->next) { ED_region_exit(C, ar); - - for (sa = screen->areabase.first; sa; sa = sa->next) + } + for (sa = screen->areabase.first; sa; sa = sa->next) { ED_area_exit(C, sa); + } /* mark it available for use for other windows */ screen->winid = 0; diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h index 6d0a9f1e7d0..606838ae890 100644 --- a/source/blender/editors/screen/screen_intern.h +++ b/source/blender/editors/screen/screen_intern.h @@ -52,16 +52,11 @@ void screen_data_copy(bScreen *to, bScreen *from); void screen_new_activate_prepare(const wmWindow *win, bScreen *screen_new); void screen_change_update(struct bContext *C, wmWindow *win, bScreen *sc); bScreen *screen_change_prepare(bScreen *screen_old, bScreen *screen_new, struct Main *bmain, struct bContext *C, wmWindow *win); -ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2); ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge); int screen_area_join(struct bContext *C, bScreen *scr, ScrArea *sa1, ScrArea *sa2); int area_getorientation(ScrArea *sa, ScrArea *sb); void select_connected_scredge(bScreen *sc, ScrEdge *edge); -void removenotused_scrverts(bScreen *sc); -void removedouble_scrverts(bScreen *sc); -void removedouble_scredges(bScreen *sc); -void removenotused_scredges(bScreen *sc); bool scredge_is_horizontal(ScrEdge *se); ScrEdge *screen_find_active_scredge(const bScreen *sc, const int winsize_x, const int winsize_y, diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 488f240ba48..c944d94fac5 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1328,8 +1328,8 @@ static void area_move_exit(bContext *C, wmOperator *op) op->customdata = NULL; /* this makes sure aligned edges will result in aligned grabbing */ - removedouble_scrverts(CTX_wm_screen(C)); - removedouble_scredges(CTX_wm_screen(C)); + BKE_screen_remove_double_scrverts(CTX_wm_screen(C)); + BKE_screen_remove_double_scredges(CTX_wm_screen(C)); } static int area_move_exec(bContext *C, wmOperator *op) @@ -1557,16 +1557,16 @@ static ScrEdge *area_findsharededge(bScreen *screen, ScrArea *sa, ScrArea *sb) ScrVert *sbv4 = sb->v4; if (sav1 == sbv4 && sav2 == sbv3) { /* sa to right of sb = W */ - return screen_findedge(screen, sav1, sav2); + return BKE_screen_find_edge(screen, sav1, sav2); } else if (sav2 == sbv1 && sav3 == sbv4) { /* sa to bottom of sb = N */ - return screen_findedge(screen, sav2, sav3); + return BKE_screen_find_edge(screen, sav2, sav3); } else if (sav3 == sbv2 && sav4 == sbv1) { /* sa to left of sb = E */ - return screen_findedge(screen, sav3, sav4); + return BKE_screen_find_edge(screen, sav3, sav4); } else if (sav1 == sbv2 && sav4 == sbv3) { /* sa on top of sb = S*/ - return screen_findedge(screen, sav1, sav4); + return BKE_screen_find_edge(screen, sav1, sav4); } return NULL; @@ -1632,8 +1632,8 @@ static void area_split_exit(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); /* this makes sure aligned edges will result in aligned grabbing */ - removedouble_scrverts(CTX_wm_screen(C)); - removedouble_scredges(CTX_wm_screen(C)); + BKE_screen_remove_double_scrverts(CTX_wm_screen(C)); + BKE_screen_remove_double_scredges(CTX_wm_screen(C)); } static void area_split_preview_update_cursor(bContext *C, wmOperator *op) @@ -1764,6 +1764,7 @@ static void area_split_cancel(bContext *C, wmOperator *op) sAreaSplitData *sd = (sAreaSplitData *)op->customdata; if (sd->previewmode) { + /* pass */ } else { if (screen_area_join(C, CTX_wm_screen(C), sd->sarea, sd->narea)) { @@ -2725,9 +2726,9 @@ static void area_join_exit(bContext *C, wmOperator *op) } /* this makes sure aligned edges will result in aligned grabbing */ - removedouble_scredges(CTX_wm_screen(C)); - removenotused_scredges(CTX_wm_screen(C)); - removenotused_scrverts(CTX_wm_screen(C)); + BKE_screen_remove_double_scredges(CTX_wm_screen(C)); + BKE_screen_remove_unused_scredges(CTX_wm_screen(C)); + BKE_screen_remove_unused_scrverts(CTX_wm_screen(C)); } static int area_join_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index 4d3c8fe4d5c..4dd770d79b9 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -362,7 +362,7 @@ static int hide_show_exec(bContext *C, wmOperator *op) { ARegion *ar = CTX_wm_region(C); Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Mesh *me = ob->data; PartialVisAction action; PartialVisArea area; @@ -374,8 +374,6 @@ static int hide_show_exec(bContext *C, wmOperator *op) rcti rect; int totnode, i; - CTX_data_eval_ctx(C, &eval_ctx); - /* read operator properties */ action = RNA_enum_get(op->ptr, "action"); area = RNA_enum_get(op->ptr, "area"); @@ -383,7 +381,7 @@ static int hide_show_exec(bContext *C, wmOperator *op) clip_planes_from_rect(C, clip_planes, &rect); - dm = mesh_get_derived_final(&eval_ctx, CTX_data_scene(C), ob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(depsgraph, CTX_data_scene(C), ob, CD_MASK_BAREMESH); pbvh = dm->getPBVH(ob, dm); ob->sculpt->pbvh = pbvh; diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index c81a59b045f..ef125da46a7 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -227,7 +227,7 @@ typedef struct ProjPaintState { View3D *v3d; RegionView3D *rv3d; ARegion *ar; - const Depsgraph *depsgraph; + Depsgraph *depsgraph; Scene *scene; int source; /* PROJ_SRC_**** */ @@ -3426,13 +3426,12 @@ static void project_paint_bleed_add_face_user( /* Return true if DM can be painted on, false otherwise */ static bool proj_paint_state_dm_init(const bContext *C, ProjPaintState *ps) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); /* Workaround for subsurf selection, try the display mesh first */ if (ps->source == PROJ_SRC_IMAGE_CAM) { /* using render mesh, assume only camera was rendered from */ - ps->dm = mesh_create_derived_render(&eval_ctx, ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE); + ps->dm = mesh_create_derived_render(depsgraph, ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE); ps->dm_release = true; } else if (ps->ob->derivedFinal && @@ -3444,7 +3443,7 @@ static bool proj_paint_state_dm_init(const bContext *C, ProjPaintState *ps) } else { ps->dm = mesh_get_derived_final( - &eval_ctx, ps->scene, ps->ob, + depsgraph, ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE | (ps->do_face_sel ? CD_ORIGINDEX : 0)); ps->dm_release = true; } @@ -5030,7 +5029,6 @@ void paint_proj_stroke( /* clone gets special treatment here to avoid going through image initialization */ if (ps_handle->is_clone_cursor_pick) { - EvaluationContext eval_ctx; Scene *scene = ps_handle->scene; struct Depsgraph *graph = CTX_data_depsgraph(C); View3D *v3d = CTX_wm_view3d(C); @@ -5040,9 +5038,7 @@ void paint_proj_stroke( view3d_operator_needs_opengl(C); - CTX_data_eval_ctx(C, &eval_ctx); - - if (!ED_view3d_autodist(&eval_ctx, graph, ar, v3d, mval_i, cursor, false, NULL)) { + if (!ED_view3d_autodist(graph, ar, v3d, mval_i, cursor, false, NULL)) { return; } @@ -5457,18 +5453,16 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) ImBuf *ibuf; char filename[FILE_MAX]; + struct RenderEngineType *engine_type = CTX_data_engine_type(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - struct RenderEngineType *engine_type = CTX_data_engine_type(C); - EvaluationContext eval_ctx; ToolSettings *settings = scene->toolsettings; int w = settings->imapaint.screen_grab_size[0]; int h = settings->imapaint.screen_grab_size[1]; int maxsize; char err_out[256] = "unknown"; - CTX_data_eval_ctx(C, &eval_ctx); - RNA_string_get(op->ptr, "filepath", filename); maxsize = GPU_max_texture_size(); @@ -5477,7 +5471,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) if (h > maxsize) h = maxsize; ibuf = ED_view3d_draw_offscreen_imbuf( - &eval_ctx, scene, view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, CTX_wm_view3d(C), CTX_wm_region(C), w, h, IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL, NULL, err_out); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index e22b996c6e5..4298fba3b2b 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -157,10 +157,10 @@ void PAINT_OT_weight_sample_group(struct wmOperatorType *ot); /* paint_vertex_proj.c */ struct VertProjHandle; struct VertProjHandle *ED_vpaint_proj_handle_create( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct DMCoNo **r_vcosnos); void ED_vpaint_proj_handle_update( - const struct EvaluationContext *eval_ctx, struct VertProjHandle *vp_handle, + struct Depsgraph *depsgraph, struct VertProjHandle *vp_handle, /* runtime vars */ struct ARegion *ar, const float mval_fl[2]); void ED_vpaint_proj_handle_free( diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index 162c067166c..f22e6f514e6 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -134,7 +134,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op) ARegion *ar = CTX_wm_region(C); struct Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); PaintMaskFloodMode mode; float value; PBVH *pbvh; @@ -143,12 +143,10 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op) bool multires; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; - CTX_data_eval_ctx(C, &eval_ctx); - mode = RNA_enum_get(op->ptr, "mode"); value = RNA_float_get(op->ptr, "value"); - BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, false, true); + BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, true); pbvh = ob->sculpt->pbvh; multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS); @@ -261,7 +259,7 @@ static void mask_box_select_task_cb( int ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *rect, bool select, bool UNUSED(extend)) { - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Sculpt *sd = vc->scene->toolsettings->sculpt; BoundBox bb; float clip_planes[4][4]; @@ -277,8 +275,6 @@ int ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *r int totnode, symmpass; int symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; - CTX_data_eval_ctx(C, &eval_ctx); - mode = PAINT_MASK_FLOOD_VALUE; value = select ? 1.0 : 0.0; @@ -286,7 +282,7 @@ int ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *r ED_view3d_clipping_calc(&bb, clip_planes, vc->ar, vc->obact, rect); negate_m4(clip_planes); - BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, false, true); + BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, true); pbvh = ob->sculpt->pbvh; multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS); @@ -428,7 +424,7 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) const int (*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot); if (mcords) { - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); float clip_planes[4][4], clip_planes_final[4][4]; BoundBox bb; Object *ob; @@ -444,8 +440,6 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) PaintMaskFloodMode mode = RNA_enum_get(op->ptr, "mode"); float value = RNA_float_get(op->ptr, "value"); - CTX_data_eval_ctx(C, &eval_ctx); - /* Calculations of individual vertices are done in 2D screen space to diminish the amount of * calculations done. Bounding box PBVH collision is not computed against enclosing rectangle * of lasso */ @@ -468,7 +462,7 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) ED_view3d_clipping_calc(&bb, clip_planes, vc.ar, vc.obact, &data.rect); negate_m4(clip_planes); - BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, false, true); + BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, true); pbvh = ob->sculpt->pbvh; multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS); diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 0f22973c45d..82589857ba5 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -274,9 +274,9 @@ static void imapaint_tri_weights(float matrix[4][4], GLint view[4], } /* compute uv coordinates of mouse in face */ -static void imapaint_pick_uv(EvaluationContext *eval_ctx, Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2]) +static void imapaint_pick_uv(Depsgraph *depsgraph, Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2]) { - DerivedMesh *dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH); const int tottri = dm->getNumLoopTri(dm); int i, findex; float p[2], w[3], absw, minabsw; @@ -353,14 +353,14 @@ static void imapaint_pick_uv(EvaluationContext *eval_ctx, Scene *scene, Object * /* returns 0 if not found, otherwise 1 */ static int imapaint_pick_face( - const struct EvaluationContext *eval_ctx, ViewContext *vc, const int mval[2], + ViewContext *vc, const int mval[2], unsigned int *r_index, unsigned int totpoly) { if (totpoly == 0) return 0; /* sample only on the exact position */ - *r_index = ED_view3d_backbuf_sample(eval_ctx, vc, mval[0], mval[1]); + *r_index = ED_view3d_backbuf_sample(vc, mval[0], mval[1]); if ((*r_index) == 0 || (*r_index) > (unsigned int)totpoly) { return 0; @@ -426,7 +426,7 @@ void flip_qt_qt(float out[4], const float in[4], const char symm) void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_proj, bool use_palette) { Scene *scene = CTX_data_scene(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Paint *paint = BKE_paint_get_active_from_context(C); Palette *palette = BKE_paint_palette(paint); PaletteColor *color = NULL; @@ -434,8 +434,6 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr unsigned int col; const unsigned char *cp; - CTX_data_eval_ctx(C, &eval_ctx); - CLAMP(x, 0, ar->winx); CLAMP(y, 0, ar->winy); @@ -460,7 +458,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr if (ob) { Mesh *me = (Mesh *)ob->data; - DerivedMesh *dm = mesh_get_derived_final(&eval_ctx, scene, ob, CD_MASK_BAREMESH); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH); ViewContext vc; const int mval[2] = {x, y}; @@ -472,7 +470,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr view3d_operator_needs_opengl(C); - if (imapaint_pick_face(&eval_ctx, &vc, mval, &faceindex, totpoly)) { + if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) { Image *image; if (use_material) @@ -485,7 +483,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr if (ibuf && ibuf->rect) { float uv[2]; float u, v; - imapaint_pick_uv(&eval_ctx, scene, ob, faceindex, mval, uv); + imapaint_pick_uv(depsgraph, scene, ob, faceindex, mval, uv); sample_success = true; u = fmodf(uv[0], 1.0f); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 12fe55fb956..0ae6db1f41d 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -940,14 +940,14 @@ static void do_weight_paint_vertex( /* Toggle operator for turning vertex paint mode on or off (copied from sculpt.c) */ -static void vertex_paint_init_session(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +static void vertex_paint_init_session(Depsgraph *depsgraph, Scene *scene, Object *ob) { /* Create persistent sculpt mode data */ BKE_sculpt_toolsettings_data_ensure(scene); if (ob->sculpt == NULL) { ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); - BKE_sculpt_update_mesh_elements(eval_ctx, scene, scene->toolsettings->sculpt, ob, 0, false); + BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, 0, false); } } @@ -1034,7 +1034,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob) * \{ */ static void ed_vwpaintmode_enter_generic( - const EvaluationContext *eval_ctx, wmWindowManager *wm, Scene *scene, + Depsgraph *depsgraph, wmWindowManager *wm, Scene *scene, Object *ob, const eObjectMode mode_flag) { ob->mode |= mode_flag; @@ -1080,41 +1080,39 @@ static void ed_vwpaintmode_enter_generic( BKE_sculptsession_free(ob); } - vertex_paint_init_session(eval_ctx, scene, ob); + vertex_paint_init_session(depsgraph, scene, ob); } void ED_object_vpaintmode_enter_ex( - const EvaluationContext *eval_ctx, wmWindowManager *wm, + Depsgraph *depsgraph, wmWindowManager *wm, Scene *scene, Object *ob) { ed_vwpaintmode_enter_generic( - eval_ctx, wm, scene, ob, OB_MODE_VERTEX_PAINT); + depsgraph, wm, scene, ob, OB_MODE_VERTEX_PAINT); } void ED_object_vpaintmode_enter(struct bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); wmWindowManager *wm = CTX_wm_manager(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - ED_object_vpaintmode_enter_ex(&eval_ctx, wm, scene, ob); + ED_object_vpaintmode_enter_ex(depsgraph, wm, scene, ob); } void ED_object_wpaintmode_enter_ex( - const EvaluationContext *eval_ctx, wmWindowManager *wm, + Depsgraph *depsgraph, wmWindowManager *wm, Scene *scene, Object *ob) { ed_vwpaintmode_enter_generic( - eval_ctx, wm, scene, ob, OB_MODE_WEIGHT_PAINT); + depsgraph, wm, scene, ob, OB_MODE_WEIGHT_PAINT); } void ED_object_wpaintmode_enter(struct bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); wmWindowManager *wm = CTX_wm_manager(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - ED_object_wpaintmode_enter_ex(&eval_ctx, wm, scene, ob); + ED_object_wpaintmode_enter_ex(depsgraph, wm, scene, ob); } /** \} */ @@ -1211,10 +1209,9 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) ED_object_wpaintmode_exit_ex(ob); } else { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); wmWindowManager *wm = CTX_wm_manager(C); - ED_object_wpaintmode_enter_ex(&eval_ctx, wm, scene, ob); + ED_object_wpaintmode_enter_ex(depsgraph, wm, scene, ob); } /* Weightpaint works by overriding colors in mesh, @@ -1405,6 +1402,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo bool *defbase_sel; SculptSession *ss = ob->sculpt; VPaint *vp = CTX_data_tool_settings(C)->wpaint; + Depsgraph *depsgraph = CTX_data_depsgraph(C); if (ED_wpaint_ensure_data(C, op->reports, WPAINT_ENSURE_MIRROR, &vgroup_index) == false) { return false; @@ -1507,11 +1505,8 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo wpd->precomputed_weight = MEM_mallocN(sizeof(float) * me->totvert, __func__); } - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - /* If not previously created, create vertex/weight paint mode session data */ - vertex_paint_init_session(&eval_ctx, scene, ob); + vertex_paint_init_session(depsgraph, scene, ob); vwpaint_update_cache_invariants(C, vp, ss, op, mouse); vertex_paint_init_session_data(ts, ob); @@ -2347,10 +2342,9 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op) ED_object_vpaintmode_exit_ex(ob); } else { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); wmWindowManager *wm = CTX_wm_manager(C); - ED_object_vpaintmode_enter_ex(&eval_ctx, wm, scene, ob); + ED_object_vpaintmode_enter_ex(depsgraph, wm, scene, ob); } BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL); @@ -2442,9 +2436,7 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f Object *ob = CTX_data_active_object(C); Mesh *me; SculptSession *ss = ob->sculpt; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); /* context checks could be a poll() */ me = BKE_mesh_from_object(ob); @@ -2492,12 +2484,12 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f /* Create projection handle */ if (vpd->is_texbrush) { ob->sculpt->building_vp_handle = true; - vpd->vp_handle = ED_vpaint_proj_handle_create(&eval_ctx, scene, ob, &vpd->vertexcosnos); + vpd->vp_handle = ED_vpaint_proj_handle_create(depsgraph, scene, ob, &vpd->vertexcosnos); ob->sculpt->building_vp_handle = false; } /* If not previously created, create vertex/weight paint mode session data */ - vertex_paint_init_session(&eval_ctx, scene, ob); + vertex_paint_init_session(depsgraph, scene, ob); vwpaint_update_cache_invariants(C, vp, ss, op, mouse); vertex_paint_init_session_data(ts, ob); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_proj.c b/source/blender/editors/sculpt_paint/paint_vertex_proj.c index 336f851d4c1..c5c9aa48760 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_proj.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_proj.c @@ -102,13 +102,13 @@ static void vpaint_proj_dm_map_cosnos_init__map_cb( } static void vpaint_proj_dm_map_cosnos_init( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, struct VertProjHandle *vp_handle) { Mesh *me = ob->data; DerivedMesh *dm; - dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); if (dm->foreachMappedVert) { memset(vp_handle->vcosnos, 0, sizeof(DMCoNo) * me->totvert); @@ -176,7 +176,7 @@ static void vpaint_proj_dm_map_cosnos_update__map_cb( } static void vpaint_proj_dm_map_cosnos_update( - const struct EvaluationContext *eval_ctx, struct VertProjHandle *vp_handle, + struct Depsgraph *depsgraph, struct VertProjHandle *vp_handle, ARegion *ar, const float mval_fl[2]) { struct VertProjUpdate vp_update = {vp_handle, ar, mval_fl}; @@ -189,7 +189,7 @@ static void vpaint_proj_dm_map_cosnos_update( /* quick sanity check - we shouldn't have to run this if there are no modifiers */ BLI_assert(BLI_listbase_is_empty(&ob->modifiers) == false); - dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); + dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX); /* highly unlikely this will become unavailable once painting starts (perhaps with animated modifiers) */ if (LIKELY(dm->foreachMappedVert)) { @@ -206,7 +206,7 @@ static void vpaint_proj_dm_map_cosnos_update( /* Public Functions */ struct VertProjHandle *ED_vpaint_proj_handle_create( - const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, + struct Depsgraph *depsgraph, Scene *scene, Object *ob, DMCoNo **r_vcosnos) { struct VertProjHandle *vp_handle = MEM_mallocN(sizeof(struct VertProjHandle), __func__); @@ -217,7 +217,7 @@ struct VertProjHandle *ED_vpaint_proj_handle_create( vp_handle->use_update = false; /* sets 'use_update' if needed */ - vpaint_proj_dm_map_cosnos_init(eval_ctx, scene, ob, vp_handle); + vpaint_proj_dm_map_cosnos_init(depsgraph, scene, ob, vp_handle); if (vp_handle->use_update) { vp_handle->dists_sq = MEM_mallocN(sizeof(float) * me->totvert, __func__); @@ -237,11 +237,11 @@ struct VertProjHandle *ED_vpaint_proj_handle_create( } void ED_vpaint_proj_handle_update( - const struct EvaluationContext *eval_ctx, struct VertProjHandle *vp_handle, + struct Depsgraph *depsgraph, struct VertProjHandle *vp_handle, ARegion *ar, const float mval_fl[2]) { if (vp_handle->use_update) { - vpaint_proj_dm_map_cosnos_update(eval_ctx, vp_handle, ar, mval_fl); + vpaint_proj_dm_map_cosnos_update(depsgraph, vp_handle, ar, mval_fl); } } diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index a5b9a840c33..3773806e192 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -125,17 +125,14 @@ static int weight_from_bones_poll(bContext *C) static int weight_from_bones_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Object *armob = modifiers_isDeformedByArmature(ob); Mesh *me = ob->data; int type = RNA_enum_get(op->ptr, "type"); - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); - - ED_object_vgroup_calc_from_armature(op->reports, &eval_ctx, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X)); + ED_object_vgroup_calc_from_armature(op->reports, depsgraph, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X)); DEG_id_tag_update(&me->id, 0); WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); @@ -726,11 +723,9 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) float sco_end[2] = {x_end, y_end}; const bool is_interactive = (gesture != NULL); - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); - DerivedMesh *dm = mesh_get_derived_final(&eval_ctx, scene, ob, scene->customdata_mask); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, scene->customdata_mask); DMGradient_userData data = {NULL}; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 4a9d2597415..3af789d4ebe 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -4601,12 +4601,11 @@ static void sculpt_stroke_modifiers_check(const bContext *C, Object *ob, const B SculptSession *ss = ob->sculpt; if (ss->kb || ss->modifiers_active) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Sculpt *sd = scene->toolsettings->sculpt; bool need_pmap = sculpt_any_smooth_mode(brush, ss->cache, 0); - BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, need_pmap, false); + BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, need_pmap, false); } } @@ -4809,18 +4808,16 @@ static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; - EvaluationContext eval_ctx; SculptSession *ss = CTX_data_active_object(C)->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); int mode = RNA_enum_get(op->ptr, "mode"); bool is_smooth; bool need_mask = false; - CTX_data_eval_ctx(C, &eval_ctx); - if (brush->sculpt_tool == SCULPT_TOOL_MASK) { need_mask = true; } @@ -4829,7 +4826,7 @@ static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op) sculpt_brush_init_tex(scene, sd, ss); is_smooth = sculpt_any_smooth_mode(brush, NULL, mode); - BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, is_smooth, need_mask); + BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, is_smooth, need_mask); return 1; } @@ -5256,18 +5253,18 @@ void sculpt_dyntopo_node_layers_add(SculptSession *ss) void sculpt_update_after_dynamic_topology_toggle( - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob) { Sculpt *sd = scene->toolsettings->sculpt; /* Create the PBVH */ - BKE_sculpt_update_mesh_elements(eval_ctx, scene, sd, ob, false, false); + BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, false); WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob); } void sculpt_dynamic_topology_enable_ex( - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; @@ -5305,7 +5302,7 @@ void sculpt_dynamic_topology_enable_ex( ss->bm_log = BM_log_create(ss->bm); /* Refresh */ - sculpt_update_after_dynamic_topology_toggle(eval_ctx, scene, ob); + sculpt_update_after_dynamic_topology_toggle(depsgraph, scene, ob); } /* Free the sculpt BMesh and BMLog @@ -5313,7 +5310,7 @@ void sculpt_dynamic_topology_enable_ex( * If 'unode' is given, the BMesh's data is copied out to the unode * before the BMesh is deleted so that it can be restored from */ void sculpt_dynamic_topology_disable_ex( - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob, SculptUndoNode *unode) { SculptSession *ss = ob->sculpt; @@ -5364,38 +5361,37 @@ void sculpt_dynamic_topology_disable_ex( } /* Refresh */ - sculpt_update_after_dynamic_topology_toggle(eval_ctx, scene, ob); + sculpt_update_after_dynamic_topology_toggle(depsgraph, scene, ob); } void sculpt_dynamic_topology_disable(bContext *C, SculptUndoNode *unode) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - sculpt_dynamic_topology_disable_ex(&eval_ctx, scene, ob, unode); + sculpt_dynamic_topology_disable_ex(depsgraph, scene, ob, unode); } static void sculpt_dynamic_topology_disable_with_undo( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob) + Depsgraph *depsgraph, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; if (ss->bm) { sculpt_undo_push_begin("Dynamic topology disable"); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END); - sculpt_dynamic_topology_disable_ex(eval_ctx, scene, ob, NULL); + sculpt_dynamic_topology_disable_ex(depsgraph, scene, ob, NULL); sculpt_undo_push_end(); } } static void sculpt_dynamic_topology_enable_with_undo( - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; if (ss->bm == NULL) { sculpt_undo_push_begin("Dynamic topology enable"); - sculpt_dynamic_topology_enable_ex(eval_ctx, scene, ob); + sculpt_dynamic_topology_enable_ex(depsgraph, scene, ob); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); sculpt_undo_push_end(); } @@ -5403,19 +5399,18 @@ static void sculpt_dynamic_topology_enable_with_undo( static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); WM_cursor_wait(1); if (ss->bm) { - sculpt_dynamic_topology_disable_with_undo(&eval_ctx, scene, ob); + sculpt_dynamic_topology_disable_with_undo(depsgraph, scene, ob); } else { - sculpt_dynamic_topology_enable_with_undo(&eval_ctx, scene, ob); + sculpt_dynamic_topology_enable_with_undo(depsgraph, scene, ob); } WM_cursor_wait(0); @@ -5626,14 +5621,14 @@ static void SCULPT_OT_symmetrize(wmOperatorType *ot) /**** Toggle operator for turning sculpt mode on or off ****/ -static void sculpt_init_session(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +static void sculpt_init_session(Depsgraph *depsgraph, Scene *scene, Object *ob) { /* Create persistent sculpt mode data */ BKE_sculpt_toolsettings_data_ensure(scene); ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); ob->sculpt->mode_type = OB_MODE_SCULPT; - BKE_sculpt_update_mesh_elements(eval_ctx, scene, scene->toolsettings->sculpt, ob, 0, false); + BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, 0, false); } static int ed_object_sculptmode_flush_recalc_flag(Scene *scene, Object *ob, MultiresModifierData *mmd) @@ -5647,7 +5642,7 @@ static int ed_object_sculptmode_flush_recalc_flag(Scene *scene, Object *ob, Mult } void ED_object_sculptmode_enter_ex( - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob, ReportList *reports) { @@ -5669,7 +5664,7 @@ void ED_object_sculptmode_enter_ex( BKE_sculptsession_free(ob); } - sculpt_init_session(eval_ctx, scene, ob); + sculpt_init_session(depsgraph, scene, ob); /* Mask layer is required */ if (mmd) { @@ -5727,7 +5722,7 @@ void ED_object_sculptmode_enter_ex( if (message_unsupported == NULL) { /* undo push is needed to prevent memory leak */ sculpt_undo_push_begin("Dynamic topology enable"); - sculpt_dynamic_topology_enable_ex(eval_ctx, scene, ob); + sculpt_dynamic_topology_enable_ex(depsgraph, scene, ob); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); } else { @@ -5750,13 +5745,12 @@ void ED_object_sculptmode_enter(struct bContext *C, ReportList *reports) { Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - ED_object_sculptmode_enter_ex(&eval_ctx, scene, ob, reports); + Depsgraph *depsgraph = CTX_data_depsgraph(C); + ED_object_sculptmode_enter_ex(depsgraph, scene, ob, reports); } void ED_object_sculptmode_exit_ex( - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, Object *ob) { const int mode_flag = OB_MODE_SCULPT; @@ -5783,7 +5777,7 @@ void ED_object_sculptmode_exit_ex( /* Dynamic topology must be disabled before exiting sculpt * mode to ensure the undo stack stays in a consistent * state */ - sculpt_dynamic_topology_disable_with_undo(eval_ctx, scene, ob); + sculpt_dynamic_topology_disable_with_undo(depsgraph, scene, ob); /* store so we know to re-enable when entering sculpt mode */ me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY; @@ -5806,15 +5800,15 @@ void ED_object_sculptmode_exit_ex( void ED_object_sculptmode_exit(bContext *C) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - ED_object_sculptmode_exit_ex(&eval_ctx, scene, ob); + ED_object_sculptmode_exit_ex(depsgraph, scene, ob); } static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_SCULPT; @@ -5826,14 +5820,11 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) } } - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - if (is_mode_set) { - ED_object_sculptmode_exit_ex(&eval_ctx, scene, ob); + ED_object_sculptmode_exit_ex(depsgraph, scene, ob); } else { - ED_object_sculptmode_enter_ex(&eval_ctx, scene, ob, op->reports); + ED_object_sculptmode_enter_ex(depsgraph, scene, ob, op->reports); } WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index ba39d51700d..bca33ad8014 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -61,15 +61,15 @@ bool sculpt_stroke_get_location(struct bContext *C, float out[3], const float mo void sculpt_pbvh_clear(Object *ob); void sculpt_dyntopo_node_layers_add(struct SculptSession *ss); void sculpt_update_after_dynamic_topology_toggle( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void sculpt_dynamic_topology_enable_ex( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); void sculpt_dynamic_topology_enable(bContext *C); void sculpt_dynamic_topology_disable_ex( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct SculptUndoNode *unode); void sculpt_dynamic_topology_disable(bContext *C, struct SculptUndoNode *unode); diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index e12ef2df4ab..3feb8e105e6 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -142,12 +142,10 @@ static bool sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoN Scene *scene = CTX_data_scene(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); SculptSession *ss = ob->sculpt; MVert *mvert; int *index; - - CTX_data_eval_ctx(C, &eval_ctx); if (unode->maxvert) { /* regular mesh restore */ @@ -161,7 +159,7 @@ static bool sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoN if (kb) { ob->shapenr = BLI_findindex(&key->block, kb) + 1; - BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, 0, false); + BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, 0, false); WM_event_add_notifier(C, NC_OBJECT | ND_DATA, ob); } else { @@ -477,7 +475,7 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) Scene *scene = CTX_data_scene(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); DerivedMesh *dm; SculptSession *ss = ob->sculpt; SculptUndoNode *unode; @@ -485,8 +483,6 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) bool need_mask = false; bool partial_update = true; - CTX_data_eval_ctx(C, &eval_ctx); - for (unode = lb->first; unode; unode = unode->next) { if (STREQ(unode->idname, ob->id.name)) { if (unode->type == SCULPT_UNDO_MASK) { @@ -498,10 +494,10 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) } } - BKE_sculpt_update_mesh_elements(&eval_ctx, scene, sd, ob, 0, need_mask); + BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, 0, need_mask); /* call _after_ sculpt_update_mesh_elements() which may update 'ob->derivedFinal' */ - dm = mesh_get_derived_final(&eval_ctx, scene, ob, 0); + dm = mesh_get_derived_final(depsgraph, scene, ob, 0); if (lb->first && sculpt_undo_bmesh_restore(C, lb->first, ob, ss)) return; diff --git a/source/blender/editors/space_clip/tracking_ops_orient.c b/source/blender/editors/space_clip/tracking_ops_orient.c index 583beef5001..2c6ef20f1c4 100644 --- a/source/blender/editors/space_clip/tracking_ops_orient.c +++ b/source/blender/editors/space_clip/tracking_ops_orient.c @@ -405,7 +405,7 @@ static int set_plane_exec(bContext *C, wmOperator *op) ListBase *tracksbase; Object *object; Object *camera = get_camera_with_movieclip(scene, clip); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); int tot = 0; float vec[3][3], mat[4][4], obmat[4][4], newmat[4][4], orig[3] = {0.0f, 0.0f, 0.0f}; int plane = RNA_enum_get(op->ptr, "plane"); @@ -430,8 +430,6 @@ static int set_plane_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - CTX_data_eval_ctx(C, &eval_ctx); - BKE_tracking_get_camera_object_matrix(scene, camera, mat); /* Get 3 bundles to use as reference. */ @@ -494,7 +492,7 @@ static int set_plane_exec(bContext *C, wmOperator *op) BKE_object_apply_mat4(object, mat, 0, 0); } - BKE_object_where_is_calc(&eval_ctx, scene, object); + BKE_object_where_is_calc(depsgraph, scene, object); set_axis(scene, object, clip, tracking_object, axis_track, 'X'); DEG_id_tag_update(&clip->id, 0); diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 0fe51ea1c70..61ea4961f3e 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -646,7 +646,7 @@ static void file_tools_region_listener( #if 0 /* context changes */ switch (wmn->category) { - + /* pass */ } #endif } diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c index 3080ac2de84..9551a1cf362 100644 --- a/source/blender/editors/space_nla/nla_buttons.c +++ b/source/blender/editors/space_nla/nla_buttons.c @@ -72,7 +72,7 @@ static void do_nla_region_buttons(bContext *C, void *UNUSED(arg), int UNUSED(eve //Scene *scene = CTX_data_scene(C); #if 0 switch (event) { - + /* pass */ } #endif /* default for now */ diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index 15b411280a5..04602e53697 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -1423,7 +1423,7 @@ static void outliner_draw_tree_element( /* Master collection can't expand/collapse. */ } else if (te->subtree.first || (tselem->type == 0 && te->idcode == ID_SCE) || (te->flag & TE_LAZY_CLOSED)) { - /* open/close icon, only when sublevels, except for scene */ + /* open/close icon, only when sublevels, except for scene */ int icon_x = startx; // icons a bit higher @@ -1900,8 +1900,6 @@ static void outliner_draw_restrictcols(ARegion *ar) void draw_outliner(const bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Main *mainvar = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index bedd2f09f3b..6bee26a0cf4 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -51,7 +51,6 @@ struct bPoseChannel; struct EditBone; struct wmEvent; struct wmKeyConfig; -struct EvaluationContext; typedef enum TreeElementInsertType { TE_INSERT_BEFORE, diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 8e5863fd514..6f88a3481b5 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -919,8 +919,8 @@ ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int recty = (render_size * (float)scene->r.ysch) / 100.0f + 0.5f; BKE_sequencer_new_render_data( - bmain->eval_ctx, bmain, scene, - rectx, recty, proxy_size, + bmain, scene, + rectx, recty, proxy_size, false, &context); context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname); @@ -1454,7 +1454,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not, * for now just disable drawing since the strip frame will likely be offset */ - //if (sc->mode == SC_MODE_MASKEDIT) { + // if (sc->mode == SC_MODE_MASKEDIT) if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) { Mask *mask = BKE_sequencer_mask_get(scene); diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 9a0578fe220..e200dffa308 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -71,7 +71,6 @@ #include "UI_view2d.h" #include "UI_interface.h" - /* own include */ #include "sequencer_intern.h" diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h index 7ce2f73cbef..de7c46cc02c 100644 --- a/source/blender/editors/space_sequencer/sequencer_intern.h +++ b/source/blender/editors/space_sequencer/sequencer_intern.h @@ -36,6 +36,7 @@ /* internal exports only */ +struct Depsgraph; struct Sequence; struct bContext; struct rctf; diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index 77cd64be7c1..9a82bce4b4b 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -1611,7 +1611,7 @@ static void draw_bone(const short dt, int armflag, int boneflag, short constflag } static void draw_custom_bone( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Object *ob, const short dt, int armflag, int boneflag, unsigned int id, float length) { @@ -1628,7 +1628,7 @@ static void draw_custom_bone( GPU_select_load_id((GLuint) id | BONESEL_BONE); } - draw_object_instance(eval_ctx, scene, view_layer, v3d, rv3d, ob, dt, armflag & ARM_POSEMODE, fcolor); + draw_object_instance(depsgraph, scene, view_layer, v3d, rv3d, ob, dt, armflag & ARM_POSEMODE, fcolor); } @@ -1933,7 +1933,7 @@ static void bone_matrix_translate_y(float mat[4][4], float y) /* assumes object is Armature with pose */ static void draw_pose_bones( - const struct EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base, + struct Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base, const short dt, const unsigned char ob_wire_col[4], const bool do_const_color, const bool is_outline) { @@ -2060,7 +2060,7 @@ static void draw_pose_bones( glDisable(GL_CULL_FACE); } - draw_custom_bone(eval_ctx, scene, view_layer, v3d, rv3d, pchan->custom, + draw_custom_bone(depsgraph, scene, view_layer, v3d, rv3d, pchan->custom, OB_SOLID, arm->flag, flag, index, PCHAN_CUSTOM_DRAW_SIZE(pchan)); } } @@ -2156,7 +2156,7 @@ static void draw_pose_bones( if (bone == arm->act_bone) flag |= BONE_DRAW_ACTIVE; - draw_custom_bone(eval_ctx, scene, view_layer, v3d, rv3d, pchan->custom, + draw_custom_bone(depsgraph, scene, view_layer, v3d, rv3d, pchan->custom, OB_WIRE, arm->flag, flag, index, PCHAN_CUSTOM_DRAW_SIZE(pchan)); gpuPopMatrix(); @@ -2667,7 +2667,7 @@ static void ghost_poses_tag_unselected(Object *ob, short unset) * note: object should be in posemode */ static void draw_ghost_poses_range( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base) + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base) { Object *ob = base->object; AnimData *adt = BKE_animdata_from_id(&ob->id); @@ -2711,8 +2711,8 @@ static void draw_ghost_poses_range( UI_GetThemeColorShadeAlpha4ubv(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)), col); BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL); - BKE_pose_where_is(eval_ctx, scene, ob); - draw_pose_bones(eval_ctx, scene, view_layer, v3d, ar, base, OB_WIRE, col, true, false); + BKE_pose_where_is(depsgraph, scene, ob); + draw_pose_bones(depsgraph, scene, view_layer, v3d, ar, base, OB_WIRE, col, true, false); } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); @@ -2735,7 +2735,7 @@ static void draw_ghost_poses_range( * - object should be in posemode */ static void draw_ghost_poses_keys( - const struct EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, + struct Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base) { Object *ob = base->object; @@ -2794,8 +2794,8 @@ static void draw_ghost_poses_keys( CFRA = (int)ak->cfra; BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL); - BKE_pose_where_is(eval_ctx, scene, ob); - draw_pose_bones(eval_ctx, scene, view_layer, v3d, ar, base, OB_WIRE, col, true, false); + BKE_pose_where_is(depsgraph, scene, ob); + draw_pose_bones(depsgraph, scene, view_layer, v3d, ar, base, OB_WIRE, col, true, false); } glDisable(GL_BLEND); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); @@ -2819,7 +2819,7 @@ static void draw_ghost_poses_keys( * - object is supposed to be armature in posemode */ static void draw_ghost_poses( - const struct EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, + struct Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base) { Object *ob = base->object; @@ -2874,8 +2874,8 @@ static void draw_ghost_poses( if (CFRA != cfrao) { BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL); - BKE_pose_where_is(eval_ctx, scene, ob); - draw_pose_bones(eval_ctx, scene, view_layer, v3d, ar, base, OB_WIRE, col, true, false); + BKE_pose_where_is(depsgraph, scene, ob); + draw_pose_bones(depsgraph, scene, view_layer, v3d, ar, base, OB_WIRE, col, true, false); } } @@ -2889,8 +2889,8 @@ static void draw_ghost_poses( if (CFRA != cfrao) { BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL); - BKE_pose_where_is(eval_ctx, scene, ob); - draw_pose_bones(eval_ctx, scene, view_layer, v3d, ar, base, OB_WIRE, col, true, false); + BKE_pose_where_is(depsgraph, scene, ob); + draw_pose_bones(depsgraph, scene, view_layer, v3d, ar, base, OB_WIRE, col, true, false); } } } @@ -2916,7 +2916,7 @@ static void draw_ghost_poses( /* called from drawobject.c, return true if nothing was drawn * (ob_wire_col == NULL) when drawing ghost */ bool draw_armature( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base, const short dt, const short dflag, const unsigned char ob_wire_col[4], const bool is_outline) { @@ -2976,14 +2976,14 @@ bool draw_armature( } else if (ob->mode & OB_MODE_POSE) { if (arm->ghosttype == ARM_GHOST_RANGE) { - draw_ghost_poses_range(eval_ctx, scene, view_layer, v3d, ar, base); + draw_ghost_poses_range(depsgraph, scene, view_layer, v3d, ar, base); } else if (arm->ghosttype == ARM_GHOST_KEYS) { - draw_ghost_poses_keys(eval_ctx, scene, view_layer, v3d, ar, base); + draw_ghost_poses_keys(depsgraph, scene, view_layer, v3d, ar, base); } else if (arm->ghosttype == ARM_GHOST_CUR) { if (arm->ghostep) - draw_ghost_poses(eval_ctx, scene, view_layer, v3d, ar, base); + draw_ghost_poses(depsgraph, scene, view_layer, v3d, ar, base); } if ((dflag & DRAW_SCENESET) == 0) { if (ob == OBACT(view_layer)) @@ -2996,7 +2996,7 @@ bool draw_armature( } } } - draw_pose_bones(eval_ctx, scene, view_layer, v3d, ar, base, dt, ob_wire_col, (dflag & DRAW_CONSTCOLOR), is_outline); + draw_pose_bones(depsgraph, scene, view_layer, v3d, ar, base, dt, ob_wire_col, (dflag & DRAW_CONSTCOLOR), is_outline); arm->flag &= ~ARM_POSEMODE; } else { diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 93bcbc3ea0c..287613c847b 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -83,6 +83,7 @@ #include "BKE_editmesh.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -2394,7 +2395,7 @@ static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, i #ifdef SEQUENCER_DAG_WORKAROUND static void ensure_curve_cache( - const EvaluationContext *eval_ctx, Scene *scene, Object *object) + Depsgraph *depsgraph, Scene *scene, Object *object) { bool need_recalc = object->curve_cache == NULL; /* Render thread might have freed the curve cache if the @@ -2423,13 +2424,13 @@ static void ensure_curve_cache( case OB_CURVE: case OB_SURF: case OB_FONT: - BKE_displist_make_curveTypes(eval_ctx, scene, object, false); + BKE_displist_make_curveTypes(depsgraph, scene, object, false); break; case OB_MBALL: - BKE_displist_make_mball(eval_ctx, scene, object); + BKE_displist_make_mball(depsgraph, scene, object); break; case OB_LATTICE: - BKE_lattice_modifiers_calc(eval_ctx, scene, object); + BKE_lattice_modifiers_calc(depsgraph, scene, object); break; } } @@ -4296,7 +4297,7 @@ static bool object_is_halo(Scene *scene, Object *ob) } static void draw_mesh_fancy( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt, const unsigned char ob_wire_col[4], const short dflag) { #ifdef WITH_GAMEENGINE @@ -4307,7 +4308,7 @@ static void draw_mesh_fancy( Mesh *me = ob->data; eWireDrawMode draw_wire = OBDRAW_WIRE_OFF; bool /* no_verts,*/ no_edges, no_faces; - DerivedMesh *dm = mesh_get_derived_final(eval_ctx, scene, ob, scene->customdata_mask); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, scene->customdata_mask); const bool is_obact = (ob == OBACT(view_layer)); int draw_flags = (is_obact && BKE_paint_select_face_test(ob)) ? DRAW_FACE_SELECT : 0; @@ -4561,7 +4562,7 @@ static void draw_mesh_fancy( /* returns true if nothing was drawn, for detecting to draw an object center */ static bool draw_mesh_object( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt, const unsigned char ob_wire_col[4], const short dflag) { Object *ob = base->object; @@ -4602,7 +4603,7 @@ static bool draw_mesh_object( } else { cageDM = editbmesh_get_derived_cage_and_final( - eval_ctx, scene, ob, em, scene->customdata_mask, + depsgraph, scene, ob, em, scene->customdata_mask, &finalDM); } @@ -4643,7 +4644,7 @@ static bool draw_mesh_object( } } - draw_mesh_fancy(eval_ctx, scene, view_layer, ar, v3d, rv3d, base, dt, ob_wire_col, dflag); + draw_mesh_fancy(depsgraph, scene, view_layer, ar, v3d, rv3d, base, dt, ob_wire_col, dflag); GPU_end_object_materials(); @@ -4706,14 +4707,14 @@ static void make_color_variations(const unsigned char base_ubyte[4], float low[4 } static void draw_mesh_fancy_new( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt, const unsigned char ob_wire_col[4], const short dflag, const bool other_obedit) { if (dflag & (DRAW_PICKING | DRAW_CONSTCOLOR)) { /* too complicated! use existing methods */ /* TODO: move this into a separate depth pre-pass */ - draw_mesh_fancy(eval_ctx, scene, view_layer, ar, v3d, rv3d, base, dt, ob_wire_col, dflag); + draw_mesh_fancy(depsgraph, scene, view_layer, ar, v3d, rv3d, base, dt, ob_wire_col, dflag); return; } @@ -4725,7 +4726,7 @@ static void draw_mesh_fancy_new( Mesh *me = ob->data; eWireDrawMode draw_wire = OBDRAW_WIRE_OFF; /* could be bool draw_wire_overlay */ bool no_edges, no_faces; - DerivedMesh *dm = mesh_get_derived_final(eval_ctx, scene, ob, scene->customdata_mask); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, scene->customdata_mask); const bool is_obact = (ob == OBACT(view_layer)); int draw_flags = (is_obact && BKE_paint_select_face_test(ob)) ? DRAW_FACE_SELECT : 0; @@ -5026,9 +5027,10 @@ static void draw_mesh_fancy_new( } static bool UNUSED_FUNCTION(draw_mesh_object_new)( - const EvaluationContext *eval_ctx, Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, + Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt, const unsigned char ob_wire_col[4], const short dflag) { + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); Object *ob = base->object; Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; @@ -5038,7 +5040,7 @@ static bool UNUSED_FUNCTION(draw_mesh_object_new)( /* TODO: handle shadow pass separately */ return true; } - Object *obedit = OBEDIT_FROM_VIEW_LAYER(eval_ctx->view_layer); + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); if (obedit && ob != obedit && ob->data == obedit->data) { if (BKE_key_from_object(ob) || BKE_key_from_object(obedit)) {} @@ -5064,7 +5066,7 @@ static bool UNUSED_FUNCTION(draw_mesh_object_new)( } else { cageDM = editbmesh_get_derived_cage_and_final( - eval_ctx, scene, ob, em, scene->customdata_mask, + depsgraph, scene, ob, em, scene->customdata_mask, &finalDM); } @@ -5083,9 +5085,9 @@ static bool UNUSED_FUNCTION(draw_mesh_object_new)( DM_update_materials(cageDM, ob); } - const bool glsl = draw_glsl_material(scene, eval_ctx->view_layer, ob, v3d, dt); + const bool glsl = draw_glsl_material(scene, view_layer, ob, v3d, dt); - GPU_begin_object_materials(v3d, rv3d, scene, eval_ctx->view_layer, ob, glsl, NULL); + GPU_begin_object_materials(v3d, rv3d, scene, view_layer, ob, glsl, NULL); } draw_em_fancy_new(scene, ar, v3d, ob, me, em, cageDM, finalDM, dt); @@ -5101,18 +5103,18 @@ static bool UNUSED_FUNCTION(draw_mesh_object_new)( /* ob->bb was set by derived mesh system, do NULL check just to be sure */ if (me->totpoly <= 4 || (!ob->bb || ED_view3d_boundbox_clip(rv3d, ob->bb))) { if (solid) { - const bool glsl = draw_glsl_material(scene, eval_ctx->view_layer, ob, v3d, dt); + const bool glsl = draw_glsl_material(scene, view_layer, ob, v3d, dt); if (dt == OB_SOLID || glsl) { const bool check_alpha = check_alpha_pass(base); - GPU_begin_object_materials(v3d, rv3d, scene, eval_ctx->view_layer, ob, glsl, + GPU_begin_object_materials(v3d, rv3d, scene, view_layer, ob, glsl, (check_alpha) ? &do_alpha_after : NULL); } } const bool other_obedit = obedit && (obedit != ob); - draw_mesh_fancy_new(eval_ctx, scene, eval_ctx->view_layer, ar, v3d, rv3d, base, dt, ob_wire_col, dflag, other_obedit); + draw_mesh_fancy_new(depsgraph, scene, view_layer, ar, v3d, rv3d, base, dt, ob_wire_col, dflag, other_obedit); GPU_end_object_materials(); @@ -5581,7 +5583,7 @@ static bool drawDispList_nobackface(Scene *scene, ViewLayer *view_layer, View3D return false; } static bool drawDispList( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Base *base, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt, const short dflag, const unsigned char ob_wire_col[4]) { bool retval; @@ -5594,7 +5596,7 @@ static bool drawDispList( } #ifdef SEQUENCER_DAG_WORKAROUND - ensure_curve_cache(eval_ctx, scene, base->object); + ensure_curve_cache(depsgraph, scene, base->object); #endif if (drawCurveDerivedMesh(scene, view_layer, v3d, rv3d, base, dt) == false) { @@ -5904,7 +5906,7 @@ static void draw_particle_data(ParticleSystem *psys, RegionView3D *rv3d, * 7. clean up */ static void draw_new_particle_system( - const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, RegionView3D *rv3d, + Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, ParticleSystem *psys, const char ob_dt, const short dflag) { @@ -5937,7 +5939,7 @@ static void draw_new_particle_system( if (pars == NULL) return; /* don't draw normal paths in edit mode */ - if (psys_in_edit_mode(eval_ctx->depsgraph, psys) && (pset->flag & PE_DRAW_PART) == 0) + if (psys_in_edit_mode(depsgraph, psys) && (pset->flag & PE_DRAW_PART) == 0) return; if (part->draw_as == PART_DRAW_REND) @@ -5957,7 +5959,7 @@ static void draw_new_particle_system( curvemapping_changed_all(psys->part->twistcurve); /* 2. */ - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = ob; sim.psys = psys; @@ -6594,14 +6596,14 @@ static void draw_new_particle_system( } static void draw_update_ptcache_edit( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, PTCacheEdit *edit) + Depsgraph *depsgraph, Scene *scene, Object *ob, PTCacheEdit *edit) { if (edit->psys && edit->psys->flag & PSYS_HAIR_UPDATED) - PE_update_object(eval_ctx, scene, ob, 0); + PE_update_object(depsgraph, scene, ob, 0); /* create path and child path cache if it doesn't exist already */ if (edit->pathcache == NULL) { - psys_cache_edit_paths(eval_ctx, scene, ob, edit, CFRA, G.is_rendering); + psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering); } } @@ -7336,7 +7338,7 @@ static void draw_editnurb_splines(Object *ob, Nurb *nurb, const bool sel) } static void draw_editnurb( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Base *base, Nurb *nurb, const char dt, const short dflag, const unsigned char UNUSED(ob_wire_col[4])) { @@ -7351,7 +7353,7 @@ static void draw_editnurb( /* DispList */ UI_GetThemeColor3ubv(TH_WIRE_EDIT, wire_col); - drawDispList(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, wire_col); + drawDispList(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, wire_col); /* for shadows only show solid faces */ if (v3d->flag2 & V3D_RENDER_SHADOW) @@ -7477,7 +7479,7 @@ static void draw_editfont_textcurs(RegionView3D *rv3d, float textcurs[4][2]) } static void draw_editfont( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Base *base, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt, const short dflag, const unsigned char ob_wire_col[4]) { Object *ob = base->object; @@ -7490,11 +7492,11 @@ static void draw_editfont( if (cu->flag & CU_FAST) { imm_cpack(0xFFFFFF); set_inverted_drawing(1); - drawDispList(eval_ctx, scene, view_layer, v3d, rv3d, base, OB_WIRE, dflag, ob_wire_col); + drawDispList(depsgraph, scene, view_layer, v3d, rv3d, base, OB_WIRE, dflag, ob_wire_col); set_inverted_drawing(0); } else { - drawDispList(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); + drawDispList(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); } if (cu->linewidth != 0.0f) { @@ -7797,7 +7799,7 @@ static void imm_drawcone(const float vec[3], float radius, float height, float t /* return true if nothing was drawn */ static bool drawmball( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Base *base, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt, const short dflag, const unsigned char ob_wire_col[4]) { Object *ob = base->object; @@ -7811,13 +7813,13 @@ static bool drawmball( if ((G.f & G_PICKSEL) == 0) { unsigned char wire_col[4]; UI_GetThemeColor4ubv(TH_WIRE_EDIT, wire_col); - drawDispList(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, wire_col); + drawDispList(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, wire_col); } ml = mb->editelems->first; } else { if ((base->flag_legacy & OB_FROMDUPLI) == 0) { - drawDispList(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); + drawDispList(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); } ml = mb->elems.first; } @@ -8266,7 +8268,7 @@ static void drawtexspace(Object *ob, const unsigned char ob_wire_col[3]) /* draws wire outline */ static void draw_object_selected_outline( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base, const unsigned char ob_wire_col[4]) { RegionView3D *rv3d = ar->regiondata; @@ -8278,7 +8280,7 @@ static void draw_object_selected_outline( bool has_faces = false; #ifdef SEQUENCER_DAG_WORKAROUND - ensure_curve_cache(eval_ctx, scene, ob); + ensure_curve_cache(depsgraph, scene, ob); #endif DerivedMesh *dm = ob->derivedFinal; @@ -8315,7 +8317,7 @@ static void draw_object_selected_outline( else if (ob->type == OB_ARMATURE) { if (!(ob->mode & OB_MODE_POSE && base == view_layer->basact)) { glLineWidth(UI_GetThemeValuef(TH_OUTLINE_WIDTH) * 2.0f); - draw_armature(eval_ctx, scene, view_layer, v3d, ar, base, OB_WIRE, 0, ob_wire_col, true); + draw_armature(depsgraph, scene, view_layer, v3d, ar, base, OB_WIRE, 0, ob_wire_col, true); } } @@ -8569,7 +8571,7 @@ void draw_rigidbody_shape(Object *ob, const unsigned char ob_wire_col[4]) * \param dflag (draw flag) can be DRAW_PICKING and/or DRAW_CONSTCOLOR, DRAW_SCENESET */ void draw_object( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Base *base, const short dflag) { ModifierData *md = NULL; @@ -8755,7 +8757,7 @@ void draw_object( if ((v3d->flag & V3D_SELECT_OUTLINE) && !render_override && ob->type != OB_MESH) { if (dt > OB_WIRE && (ob->mode & OB_MODE_EDIT) == 0 && (dflag & DRAW_SCENESET) == 0) { if (!(ob->dtx & OB_DRAWWIRE) && (base->flag & BASE_SELECTED) && !(dflag & (DRAW_PICKING | DRAW_CONSTCOLOR))) { - draw_object_selected_outline(eval_ctx, scene, view_layer, v3d, ar, base, ob_wire_col); + draw_object_selected_outline(depsgraph, scene, view_layer, v3d, ar, base, ob_wire_col); } } } @@ -8769,7 +8771,7 @@ void draw_object( switch (ob->type) { case OB_MESH: - empty_object = draw_mesh_object(eval_ctx, scene, view_layer, ar, v3d, rv3d, base, dt, ob_wire_col, dflag); + empty_object = draw_mesh_object(depsgraph, scene, view_layer, ar, v3d, rv3d, base, dt, ob_wire_col, dflag); if ((dflag & DRAW_CONSTCOLOR) == 0) { /* mesh draws wire itself */ dtx &= ~OB_DRAWWIRE; @@ -8779,18 +8781,18 @@ void draw_object( case OB_FONT: cu = ob->data; if (cu->editfont) { - draw_editfont(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); + draw_editfont(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); } else if (dt == OB_BOUNDBOX) { if ((render_override && v3d->drawtype >= OB_WIRE) == 0) { #ifdef SEQUENCER_DAG_WORKAROUND - ensure_curve_cache(eval_ctx, scene, base->object); + ensure_curve_cache(depsgraph, scene, base->object); #endif draw_bounding_volume(ob, ob->boundtype, ob_wire_col); } } else if (ED_view3d_boundbox_clip(rv3d, ob->bb)) { - empty_object = drawDispList(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); + empty_object = drawDispList(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); } break; @@ -8800,18 +8802,18 @@ void draw_object( if (cu->editnurb) { ListBase *nurbs = BKE_curve_editNurbs_get(cu); - draw_editnurb(eval_ctx, scene, view_layer, v3d, rv3d, base, nurbs->first, dt, dflag, ob_wire_col); + draw_editnurb(depsgraph, scene, view_layer, v3d, rv3d, base, nurbs->first, dt, dflag, ob_wire_col); } else if (dt == OB_BOUNDBOX) { if ((render_override && (v3d->drawtype >= OB_WIRE)) == 0) { #ifdef SEQUENCER_DAG_WORKAROUND - ensure_curve_cache(eval_ctx, scene, base->object); + ensure_curve_cache(depsgraph, scene, base->object); #endif draw_bounding_volume(ob, ob->boundtype, ob_wire_col); } } else if (ED_view3d_boundbox_clip(rv3d, ob->bb)) { - empty_object = drawDispList(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); + empty_object = drawDispList(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); } break; case OB_MBALL: @@ -8819,17 +8821,17 @@ void draw_object( MetaBall *mb = ob->data; if (mb->editelems) - drawmball(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); + drawmball(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); else if (dt == OB_BOUNDBOX) { if ((render_override && (v3d->drawtype >= OB_WIRE)) == 0) { #ifdef SEQUENCER_DAG_WORKAROUND - ensure_curve_cache(eval_ctx, scene, base->object); + ensure_curve_cache(depsgraph, scene, base->object); #endif draw_bounding_volume(ob, ob->boundtype, ob_wire_col); } } else - empty_object = drawmball(eval_ctx, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); + empty_object = drawmball(depsgraph, scene, view_layer, v3d, rv3d, base, dt, dflag, ob_wire_col); break; } case OB_EMPTY: @@ -8868,7 +8870,7 @@ void draw_object( } else { #ifdef SEQUENCER_DAG_WORKAROUND - ensure_curve_cache(eval_ctx, scene, ob); + ensure_curve_cache(depsgraph, scene, ob); #endif drawlattice(v3d, ob, dflag, ob_wire_col); } @@ -8893,7 +8895,7 @@ void draw_object( else copy_v4_v4_uchar(arm_col, ob_wire_col); - empty_object = draw_armature(eval_ctx, scene, view_layer, v3d, ar, base, dt, dflag, arm_col, false); + empty_object = draw_armature(depsgraph, scene, view_layer, v3d, ar, base, dt, dflag, arm_col, false); } } break; @@ -8946,12 +8948,12 @@ afterdraw: for (psys = ob->particlesystem.first; psys; psys = psys->next) { /* run this so that possible child particles get cached */ if (ob->mode & OB_MODE_PARTICLE_EDIT && is_obact) { - PTCacheEdit *edit = PE_create_current(eval_ctx, scene, ob); + PTCacheEdit *edit = PE_create_current(depsgraph, scene, ob); if (edit && edit->psys == psys) - draw_update_ptcache_edit(eval_ctx, scene, ob, edit); + draw_update_ptcache_edit(depsgraph, scene, ob, edit); } - draw_new_particle_system(eval_ctx, scene, v3d, rv3d, base, psys, dt, dflag); + draw_new_particle_system(depsgraph, scene, v3d, rv3d, base, psys, dt, dflag); } invert_m4_m4(ob->imat, ob->obmat); view3d_cached_text_draw_end(v3d, ar, 0); @@ -8967,10 +8969,10 @@ afterdraw: { if (ob->mode & OB_MODE_PARTICLE_EDIT && is_obact) { - PTCacheEdit *edit = PE_create_current(eval_ctx, scene, ob); + PTCacheEdit *edit = PE_create_current(depsgraph, scene, ob); if (edit) { gpuLoadMatrix(rv3d->viewmat); - draw_update_ptcache_edit(eval_ctx, scene, ob, edit); + draw_update_ptcache_edit(depsgraph, scene, ob, edit); draw_ptcache_edit(scene, v3d, edit); gpuMultMatrix(ob->obmat); } @@ -9221,7 +9223,7 @@ afterdraw: /* help lines and so */ if ((is_obedit == false) && ob->parent) { - const eObjectVisibilityCheck mode = eval_ctx->mode != DAG_EVAL_VIEWPORT ? + const eObjectVisibilityCheck mode = DEG_get_mode(depsgraph) != DAG_EVAL_VIEWPORT ? OB_VISIBILITY_CHECK_FOR_RENDER : OB_VISIBILITY_CHECK_FOR_VIEWPORT; if (BKE_object_is_visible(ob->parent, mode)) { @@ -9288,7 +9290,7 @@ afterdraw: for (ct = targets.first; ct; ct = ct->next) { /* calculate target's matrix */ if (cti->get_target_matrix) - cti->get_target_matrix(eval_ctx, curcon, cob, ct, BKE_scene_frame_get(scene)); + cti->get_target_matrix(depsgraph, curcon, cob, ct, BKE_scene_frame_get(scene)); else unit_m4(ct->matrix); @@ -9338,11 +9340,11 @@ afterdraw: * caller must have called 'GPU_select_load_id(base->selcode)' first. */ void draw_object_select( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Base *base, const short dflag) { BLI_assert(dflag & DRAW_PICKING && dflag & DRAW_CONSTCOLOR); - draw_object(eval_ctx, scene, view_layer, ar, v3d, base, dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, base, dflag); /* we draw duplicators for selection too */ if ((base->object->transflag & OB_DUPLI)) { @@ -9351,7 +9353,7 @@ void draw_object_select( Base tbase; tbase.flag_legacy = OB_FROMDUPLI; - lb = object_duplilist(eval_ctx, scene, base->object); + lb = object_duplilist(depsgraph, scene, base->object); for (dob = lb->first; dob; dob = dob->next) { float omat[4][4]; @@ -9365,7 +9367,7 @@ void draw_object_select( char dt = tbase.object->dt; tbase.object->dt = MIN2(tbase.object->dt, base->object->dt); short dtx = tbase.object->dtx; tbase.object->dtx = base->object->dtx; - draw_object(eval_ctx, scene, view_layer, ar, v3d, &tbase, dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, &tbase, dflag); tbase.object->dt = dt; tbase.object->dtx = dtx; @@ -9691,10 +9693,10 @@ static DMDrawOption bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index) } } -static void bbs_mesh_solid_verts(const EvaluationContext *eval_ctx, Scene *scene, Object *ob) +static void bbs_mesh_solid_verts(Depsgraph *depsgraph, Scene *scene, Object *ob) { Mesh *me = ob->data; - DerivedMesh *dm = mesh_get_derived_final(eval_ctx, scene, ob, scene->customdata_mask); + DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, scene->customdata_mask); DM_update_materials(dm, ob); @@ -9711,7 +9713,7 @@ static void bbs_mesh_solid_verts(const EvaluationContext *eval_ctx, Scene *scene dm->release(dm); } #else -static void bbs_mesh_solid_verts(const EvaluationContext *UNUSED(eval_ctx), Scene *UNUSED(scene), Object *ob) +static void bbs_mesh_solid_verts(Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene), Object *ob) { Mesh *me = ob->data; @@ -9752,7 +9754,7 @@ static void bbs_mesh_solid_faces(Scene *scene, Object *ob) } void draw_object_backbufsel( - const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) + Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) { ToolSettings *ts = scene->toolsettings; @@ -9767,7 +9769,7 @@ void draw_object_backbufsel( Mesh *me = ob->data; BMEditMesh *em = me->edit_btmesh; - DerivedMesh *dm = editbmesh_get_derived_cage(eval_ctx, scene, ob, em, CD_MASK_BAREMESH); + DerivedMesh *dm = editbmesh_get_derived_cage(depsgraph, scene, ob, em, CD_MASK_BAREMESH); BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE); @@ -9811,7 +9813,7 @@ void draw_object_backbufsel( /* currently vertex select supports weight paint and vertex paint*/ ((ob->mode & OB_MODE_WEIGHT_PAINT) || (ob->mode & OB_MODE_VERTEX_PAINT))) { - bbs_mesh_solid_verts(eval_ctx, scene, ob); + bbs_mesh_solid_verts(depsgraph, scene, ob); } else { bbs_mesh_solid_faces(scene, ob); @@ -9832,7 +9834,7 @@ void draw_object_backbufsel( /* helper function for drawing object instances - meshes */ static void draw_object_mesh_instance( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Object *ob, const short dt, int outline, const unsigned char ob_wire_col[4]) { Mesh *me = ob->data; @@ -9843,7 +9845,7 @@ static void draw_object_mesh_instance( DM_update_materials(edm, ob); } else { - dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH); DM_update_materials(dm, ob); } @@ -9879,7 +9881,7 @@ static void draw_object_mesh_instance( if (dm) dm->release(dm); } -void draw_object_instance(const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Object *ob, const char dt, int outline, const float wire_col[4]) +void draw_object_instance(Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, Object *ob, const char dt, int outline, const float wire_col[4]) { if (ob == NULL) return; @@ -9889,7 +9891,7 @@ void draw_object_instance(const EvaluationContext *eval_ctx, Scene *scene, ViewL switch (ob->type) { case OB_MESH: - draw_object_mesh_instance(eval_ctx, scene, view_layer, v3d, rv3d, ob, dt, outline, bcol); + draw_object_mesh_instance(depsgraph, scene, view_layer, v3d, rv3d, ob, dt, outline, bcol); break; case OB_EMPTY: if (ob->empty_drawtype == OB_EMPTY_IMAGE) { @@ -9903,7 +9905,7 @@ void draw_object_instance(const EvaluationContext *eval_ctx, Scene *scene, ViewL } void ED_draw_object_facemap( - const EvaluationContext *eval_ctx, Scene *scene, Object *ob, const float col[4], const int facemap) + Depsgraph *depsgraph, Scene *scene, Object *ob, const float col[4], const int facemap) { DerivedMesh *dm = NULL; @@ -9916,7 +9918,7 @@ void ED_draw_object_facemap( return; } - dm = mesh_get_derived_final(eval_ctx, scene, ob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH); if (!dm || !CustomData_has_layer(&dm->polyData, CD_FACEMAP)) return; diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 9fb602c81d6..744553dedb7 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -918,6 +918,7 @@ static void view3d_main_region_listener( ob_data = OBEDIT_FROM_VIEW_LAYER(view_layer)->data; } if (ob_data) { + BLI_assert(OB_DATA_SUPPORT_ID(GS(ob_data->name))); /* TODO(sergey): Notifiers shouldn't really be doing DEG tags. */ DEG_id_tag_update(ob_data, DEG_TAG_SELECT_UPDATE); } diff --git a/source/blender/editors/space_view3d/view3d_camera_control.c b/source/blender/editors/space_view3d/view3d_camera_control.c index 5962f1ed2ff..d0475684262 100644 --- a/source/blender/editors/space_view3d/view3d_camera_control.c +++ b/source/blender/editors/space_view3d/view3d_camera_control.c @@ -138,7 +138,7 @@ Object *ED_view3d_cameracontrol_object_get(View3DCameraControl *vctrl) * the view for first-person style navigation. */ struct View3DCameraControl *ED_view3d_cameracontrol_acquire( - const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, RegionView3D *rv3d, + Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d, const bool use_parent_root) { View3DCameraControl *vctrl; @@ -178,7 +178,7 @@ struct View3DCameraControl *ED_view3d_cameracontrol_acquire( /* store the original camera loc and rot */ vctrl->obtfm = BKE_object_tfm_backup(ob_back); - BKE_object_where_is_calc(eval_ctx, scene, v3d->camera); + BKE_object_where_is_calc(depsgraph, scene, v3d->camera); negate_v3_v3(rv3d->ofs, v3d->camera->obmat[3]); rv3d->dist = 0.0; diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 4a0ee31a2b7..b2115aa2b75 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -119,10 +119,9 @@ static bool use_depth_doit(View3D *v3d, Object *obedit) * \note keep this synced with #ED_view3d_mats_rv3d_backup/#ED_view3d_mats_rv3d_restore */ void ED_view3d_update_viewmat( - const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, ARegion *ar, + Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4], const rcti *rect) { - const Depsgraph *depsgraph = eval_ctx->depsgraph; RegionView3D *rv3d = ar->regiondata; /* setup window matrices */ @@ -142,7 +141,7 @@ void ED_view3d_update_viewmat( rect_scale[1] = (float)BLI_rcti_size_y(rect) / (float)ar->winy; } /* note: calls BKE_object_where_is_calc for camera... */ - view3d_viewmatrix_set(eval_ctx, scene, v3d, rv3d, rect ? rect_scale : NULL); + view3d_viewmatrix_set(depsgraph, scene, v3d, rv3d, rect ? rect_scale : NULL); } /* update utility matrices */ mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); @@ -154,7 +153,7 @@ void ED_view3d_update_viewmat( /* store window coordinates scaling/offset */ if (rv3d->persp == RV3D_CAMOB && v3d->camera) { rctf cameraborder; - ED_view3d_calc_camera_border(scene, eval_ctx->depsgraph, ar, v3d, rv3d, &cameraborder, false); + ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &cameraborder, false); rv3d->viewcamtexcofac[0] = (float)ar->winx / BLI_rctf_size_x(&cameraborder); rv3d->viewcamtexcofac[1] = (float)ar->winy / BLI_rctf_size_y(&cameraborder); @@ -189,12 +188,12 @@ void ED_view3d_update_viewmat( } static void view3d_main_region_setup_view( - const EvaluationContext *eval_ctx, Scene *scene, + Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4], const rcti *rect) { RegionView3D *rv3d = ar->regiondata; - ED_view3d_update_viewmat(eval_ctx, scene, v3d, ar, viewmat, winmat, rect); + ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, viewmat, winmat, rect); /* set for opengl */ gpuLoadProjectionMatrix(rv3d->winmat); @@ -245,7 +244,7 @@ static bool view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, Reg * view3d)main_region_setup_view() code to account for that. */ static void view3d_stereo3d_setup( - const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, ARegion *ar, const rcti *rect) + Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, const rcti *rect) { bool is_left; const char *names[2] = { STEREO_LEFT_NAME, STEREO_RIGHT_NAME }; @@ -271,7 +270,7 @@ static void view3d_stereo3d_setup( data->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname); BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat); - view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, NULL, rect); + view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, NULL, rect); data->shiftx = shiftx; BLI_thread_unlock(LOCK_VIEW3D); @@ -285,7 +284,7 @@ static void view3d_stereo3d_setup( v3d->camera = camera; BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat); - view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, NULL, rect); + view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, NULL, rect); v3d->camera = view_ob; BLI_thread_unlock(LOCK_VIEW3D); @@ -296,24 +295,24 @@ static void view3d_stereo3d_setup( * Set the correct matrices */ void ED_view3d_draw_setup_view( - wmWindow *win, const EvaluationContext *eval_ctx, Scene *scene, ARegion *ar, View3D *v3d, + wmWindow *win, Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d, float viewmat[4][4], float winmat[4][4], const rcti *rect) { RegionView3D *rv3d = ar->regiondata; /* Setup the view matrix. */ if (view3d_stereo3d_active(win, scene, v3d, rv3d)) { - view3d_stereo3d_setup(eval_ctx, scene, v3d, ar, rect); + view3d_stereo3d_setup(depsgraph, scene, v3d, ar, rect); } else { - view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, winmat, rect); + view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, rect); } } /* ******************** view border ***************** */ static void view3d_camera_border( - const Scene *scene, const struct Depsgraph *depsgraph, + const Scene *scene, struct Depsgraph *depsgraph, const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d, rctf *r_viewborder, const bool no_shift, const bool no_zoom) { @@ -349,7 +348,7 @@ static void view3d_camera_border( } void ED_view3d_calc_camera_border_size( - const Scene *scene, const Depsgraph *depsgraph, + const Scene *scene, Depsgraph *depsgraph, const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d, float r_size[2]) { @@ -361,7 +360,7 @@ void ED_view3d_calc_camera_border_size( } void ED_view3d_calc_camera_border( - const Scene *scene, const Depsgraph *depsgraph, + const Scene *scene, Depsgraph *depsgraph, const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d, rctf *r_viewborder, const bool no_shift) { @@ -444,7 +443,7 @@ static void drawviewborder_triangle( immEnd(); } -static void drawviewborder(Scene *scene, const Depsgraph *depsgraph, ARegion *ar, View3D *v3d) +static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *ar, View3D *v3d) { float x1, x2, y1, y2; float x1i, x2i, y1i, y2i; @@ -709,11 +708,11 @@ static void drawrenderborder(ARegion *ar, View3D *v3d) } void ED_view3d_draw_depth( - const EvaluationContext *eval_ctx, struct Depsgraph *graph, + Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool alphaoverride) { struct bThemeState theme_state; - Scene *scene = DEG_get_evaluated_scene(graph); + Scene *scene = DEG_get_evaluated_scene(depsgraph); RegionView3D *rv3d = ar->regiondata; short zbuf = v3d->zbuf; @@ -730,7 +729,7 @@ void ED_view3d_draw_depth( UI_Theme_Store(&theme_state); UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); - ED_view3d_draw_setup_view(NULL, eval_ctx, scene, ar, v3d, NULL, NULL, NULL); + ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL); glClear(GL_DEPTH_BUFFER_BIT); @@ -751,7 +750,7 @@ void ED_view3d_draw_depth( else #endif /* WITH_OPENGL_LEGACY */ { - DRW_draw_depth_loop(graph, ar, v3d); + DRW_draw_depth_loop(depsgraph, ar, v3d); } if (rv3d->rflag & RV3D_CLIPPING) { @@ -1888,10 +1887,7 @@ void view3d_draw_region_info(const bContext *C, ARegion *ar, const int offset) static void view3d_draw_view(const bContext *C, ARegion *ar) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - - ED_view3d_draw_setup_view(CTX_wm_window(C), &eval_ctx, CTX_data_scene(C), ar, CTX_wm_view3d(C), NULL, NULL, NULL); + ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, CTX_wm_view3d(C), NULL, NULL, NULL); /* Only 100% compliant on new spec goes bellow */ DRW_draw_view(C); @@ -1937,7 +1933,7 @@ void view3d_main_region_draw(const bContext *C, ARegion *ar) * \{ */ static void view3d_stereo3d_setup_offscreen( - const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, ARegion *ar, + Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, float winmat[4][4], const char *viewname) { /* update the viewport matrices with the new camera */ @@ -1946,18 +1942,18 @@ static void view3d_stereo3d_setup_offscreen( const bool is_left = STREQ(viewname, STEREO_LEFT_NAME); BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat); - view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, winmat, NULL); + view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL); } else { /* SCE_VIEWS_FORMAT_MULTIVIEW */ float viewmat[4][4]; Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname); BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat); - view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, winmat, NULL); + view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL); } } -void ED_view3d_draw_offscreen_init(const EvaluationContext *eval_ctx, +void ED_view3d_draw_offscreen_init(Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, RenderEngineType *engine_type, @@ -1966,7 +1962,7 @@ void ED_view3d_draw_offscreen_init(const EvaluationContext *eval_ctx, if (engine_type->flag & RE_USE_LEGACY_PIPELINE) { /* shadow buffers, before we setup matrices */ if (draw_glsl_material(scene, view_layer, NULL, v3d, v3d->drawtype)) { - VP_deprecated_gpu_update_lamps_shadows_world(eval_ctx, scene, v3d); + VP_deprecated_gpu_update_lamps_shadows_world(depsgraph, scene, v3d); } } } @@ -1990,7 +1986,7 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar) * stuff like shadow buffers */ void ED_view3d_draw_offscreen( - const EvaluationContext *eval_ctx, Scene *scene, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, RenderEngineType *engine_type, View3D *v3d, ARegion *ar, int winx, int winy, float viewmat[4][4], float winmat[4][4], @@ -2031,15 +2027,13 @@ void ED_view3d_draw_offscreen( gpuLoadIdentity(); if ((viewname != NULL && viewname[0] != '\0') && (viewmat == NULL) && rv3d->persp == RV3D_CAMOB && v3d->camera) - view3d_stereo3d_setup_offscreen(eval_ctx, scene, v3d, ar, winmat, viewname); + view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, ar, winmat, viewname); else - view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, winmat, NULL); - - Depsgraph *depsgraph = eval_ctx->depsgraph; + view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL); /* main drawing call */ if (engine_type->flag & RE_USE_LEGACY_PIPELINE) { - VP_deprecated_view3d_draw_objects(NULL, eval_ctx, scene, v3d, ar, NULL, do_bgpic, true); + VP_deprecated_view3d_draw_objects(NULL, depsgraph, scene, v3d, ar, NULL, do_bgpic, true); if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) { /* draw grease-pencil stuff */ @@ -2080,7 +2074,7 @@ void ED_view3d_draw_offscreen( * (avoids re-creating when doing multiple GL renders). */ ImBuf *ED_view3d_draw_offscreen_imbuf( - const EvaluationContext *eval_ctx, Scene *scene, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, RenderEngineType *engine_type, View3D *v3d, ARegion *ar, int sizex, int sizey, unsigned int flag, unsigned int draw_flags, @@ -2088,7 +2082,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( /* output vars */ GPUOffScreen *ofs, char err_out[256]) { - const Depsgraph *depsgraph = eval_ctx->depsgraph; RegionView3D *rv3d = ar->regiondata; const bool draw_sky = (alpha_mode == R_ADDSKY); const bool draw_background = (draw_flags & V3D_OFSDRAW_USE_BACKGROUND); @@ -2116,7 +2109,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( } } - ED_view3d_draw_offscreen_init(eval_ctx, scene, view_layer, engine_type, v3d); + ED_view3d_draw_offscreen_init(depsgraph, scene, view_layer, engine_type, v3d); GPU_offscreen_bind(ofs, true); @@ -2158,7 +2151,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( if ((samples && use_full_sample) == 0) { /* Single-pass render, common case */ ED_view3d_draw_offscreen( - eval_ctx, scene, view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, v3d, ar, sizex, sizey, NULL, winmat, draw_background, draw_sky, !is_ortho, viewname, &fx_settings, ofs, NULL); @@ -2183,7 +2176,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( /* first sample buffer, also initializes 'rv3d->persmat' */ ED_view3d_draw_offscreen( - eval_ctx, scene, view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, v3d, ar, sizex, sizey, NULL, winmat, draw_background, draw_sky, !is_ortho, viewname, &fx_settings, ofs, viewport); @@ -2198,7 +2191,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( (jit_ofs[j][1] * 2.0f) / sizey); ED_view3d_draw_offscreen( - eval_ctx, scene, view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, v3d, ar, sizex, sizey, NULL, winmat_jitter, draw_background, draw_sky, !is_ortho, viewname, &fx_settings, ofs, viewport); @@ -2262,7 +2255,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf( * \note used by the sequencer */ ImBuf *ED_view3d_draw_offscreen_imbuf_simple( - const EvaluationContext *eval_ctx, Scene *scene, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, RenderEngineType *engine_type, Object *camera, int width, int height, unsigned int flag, unsigned int draw_flags, int drawtype, @@ -2325,7 +2318,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple( invert_m4_m4(rv3d.persinv, rv3d.viewinv); return ED_view3d_draw_offscreen_imbuf( - eval_ctx, scene, view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, &v3d, &ar, width, height, flag, draw_flags, alpha_mode, samples, viewname, ofs, err_out); } @@ -2375,10 +2368,10 @@ void VP_legacy_drawfloor(Scene *scene, View3D *v3d, const char **grid_unit, bool } void VP_legacy_view3d_main_region_setup_view( - const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, + Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4]) { - view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, viewmat, winmat, NULL); + view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL); } bool VP_legacy_view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d) @@ -2386,9 +2379,9 @@ bool VP_legacy_view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, return view3d_stereo3d_active(win, scene, v3d, rv3d); } -void VP_legacy_view3d_stereo3d_setup(const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, ARegion *ar) +void VP_legacy_view3d_stereo3d_setup(Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar) { - view3d_stereo3d_setup(eval_ctx, scene, v3d, ar, NULL); + view3d_stereo3d_setup(depsgraph, scene, v3d, ar, NULL); } bool VP_legacy_use_depth(View3D *v3d, Object *obedit) @@ -2396,7 +2389,7 @@ bool VP_legacy_use_depth(View3D *v3d, Object *obedit) return use_depth_doit(v3d, obedit); } -void VP_drawviewborder(Scene *scene, const struct Depsgraph *depsgraph, ARegion *ar, View3D *v3d) +void VP_drawviewborder(Scene *scene, struct Depsgraph *depsgraph, ARegion *ar, View3D *v3d) { drawviewborder(scene, depsgraph, ar, v3d); } diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c index 7272fc6b408..dcdcf95bf86 100644 --- a/source/blender/editors/space_view3d/view3d_draw_legacy.c +++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c @@ -71,6 +71,7 @@ #include "BKE_movieclip.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -211,7 +212,7 @@ static void draw_view_icon(RegionView3D *rv3d, rcti *rect) /* *********************** backdraw for selection *************** */ static void backdrawview3d( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d, Object *obact, Object *obedit) { @@ -311,7 +312,7 @@ static void backdrawview3d( G.f |= G_BACKBUFSEL; if (obact && ((obact->base_flag & BASE_VISIBLED) != 0)) { - draw_object_backbufsel(eval_ctx, scene, v3d, rv3d, obact); + draw_object_backbufsel(depsgraph, scene, v3d, rv3d, obact); } if (rv3d->gpuoffscreen) @@ -351,10 +352,10 @@ static void view3d_opengl_read_Z_pixels(ARegion *ar, int x, int y, int w, int h, glReadPixels(ar->winrct.xmin + x, ar->winrct.ymin + y, w, h, format, type, data); } -void ED_view3d_backbuf_validate(const struct EvaluationContext *eval_ctx, ViewContext *vc) +void ED_view3d_backbuf_validate(ViewContext *vc) { if (vc->v3d->flag & V3D_INVALID_BACKBUF) { - backdrawview3d(eval_ctx, vc->scene, vc->ar, vc->v3d, vc->obact, vc->obedit); + backdrawview3d(vc->depsgraph, vc->scene, vc->ar, vc->v3d, vc->obact, vc->obedit); } } @@ -369,13 +370,13 @@ int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist) /* samples a single pixel (copied from vpaint) */ unsigned int ED_view3d_backbuf_sample( - const EvaluationContext *eval_ctx, ViewContext *vc, int x, int y) + ViewContext *vc, int x, int y) { if (x >= vc->ar->winx || y >= vc->ar->winy) { return 0; } - ED_view3d_backbuf_validate(eval_ctx, vc); + ED_view3d_backbuf_validate(vc); unsigned int col; view3d_opengl_read_pixels(vc->ar, x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); @@ -390,7 +391,7 @@ unsigned int ED_view3d_backbuf_sample( /* reads full rect, converts indices */ ImBuf *ED_view3d_backbuf_read( - const EvaluationContext *eval_ctx, ViewContext *vc, int xmin, int ymin, int xmax, int ymax) + ViewContext *vc, int xmin, int ymin, int xmax, int ymax) { /* clip */ const rcti clip = { @@ -408,7 +409,7 @@ ImBuf *ED_view3d_backbuf_read( ImBuf *ibuf_clip = IMB_allocImBuf(size_clip[0], size_clip[1], 32, IB_rect); - ED_view3d_backbuf_validate(eval_ctx, vc); + ED_view3d_backbuf_validate(vc); view3d_opengl_read_pixels(vc->ar, clip.xmin, clip.ymin, size_clip[0], size_clip[1], GL_RGBA, GL_UNSIGNED_BYTE, ibuf_clip->rect); @@ -447,7 +448,7 @@ ImBuf *ED_view3d_backbuf_read( /* smart function to sample a rect spiralling outside, nice for backbuf selection */ unsigned int ED_view3d_backbuf_sample_rect( - const EvaluationContext *eval_ctx, ViewContext *vc, const int mval[2], int size, + ViewContext *vc, const int mval[2], int size, unsigned int min, unsigned int max, float *r_dist) { int dirvec[4][2]; @@ -456,7 +457,7 @@ unsigned int ED_view3d_backbuf_sample_rect( const int minx = mval[0] - (amount + 1); const int miny = mval[1] - (amount + 1); - ImBuf *buf = ED_view3d_backbuf_read(eval_ctx, vc, minx, miny, minx + size - 1, miny + size - 1); + ImBuf *buf = ED_view3d_backbuf_read(vc, minx, miny, minx + size - 1, miny + size - 1); if (!buf) return 0; unsigned index = 0; @@ -528,7 +529,7 @@ static void view3d_stereo_bgpic_setup(Scene *scene, View3D *v3d, Image *ima, Ima } } -static void view3d_draw_bgpic(Scene *scene, const Depsgraph *depsgraph, +static void view3d_draw_bgpic(Scene *scene, Depsgraph *depsgraph, ARegion *ar, View3D *v3d, const bool do_foreground, const bool do_camera_frame) { @@ -773,7 +774,7 @@ static void view3d_draw_bgpic(Scene *scene, const Depsgraph *depsgraph, } void ED_view3d_draw_bgpic_test( - Scene *scene, const Depsgraph *depsgraph, + Scene *scene, Depsgraph *depsgraph, ARegion *ar, View3D *v3d, const bool do_foreground, const bool do_camera_frame) { @@ -826,7 +827,7 @@ void ED_view3d_after_add(ListBase *lb, Base *base, const short dflag) /* disables write in zbuffer and draws it over */ static void view3d_draw_transp( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d) + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d) { View3DAfter *v3da; @@ -834,7 +835,7 @@ static void view3d_draw_transp( v3d->transp = true; while ((v3da = BLI_pophead(&v3d->afterdraw_transp))) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, v3da->base, v3da->dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, v3da->base, v3da->dflag); MEM_freeN(v3da); } v3d->transp = false; @@ -845,7 +846,7 @@ static void view3d_draw_transp( /* clears zbuffer and draws it over */ static void view3d_draw_xray( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, bool *clear) + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, bool *clear) { if (*clear && v3d->zbuf) { glClear(GL_DEPTH_BUFFER_BIT); @@ -855,7 +856,7 @@ static void view3d_draw_xray( v3d->xray = true; View3DAfter *v3da; while ((v3da = BLI_pophead(&v3d->afterdraw_xray))) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, v3da->base, v3da->dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, v3da->base, v3da->dflag); MEM_freeN(v3da); } v3d->xray = false; @@ -864,7 +865,7 @@ static void view3d_draw_xray( /* clears zbuffer and draws it over */ static void view3d_draw_xraytransp( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, const bool clear) + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, const bool clear) { if (clear && v3d->zbuf) glClear(GL_DEPTH_BUFFER_BIT); @@ -876,7 +877,7 @@ static void view3d_draw_xraytransp( View3DAfter *v3da; while ((v3da = BLI_pophead(&v3d->afterdraw_xraytransp))) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, v3da->base, v3da->dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, v3da->base, v3da->dflag); MEM_freeN(v3da); } @@ -889,7 +890,7 @@ static void view3d_draw_xraytransp( /* clears zbuffer and draws it over, * note that in the select version we don't care about transparent flag as with regular drawing */ static void view3d_draw_xray_select( - const struct EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, bool *clear) + struct Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, bool *clear) { /* Not ideal, but we need to read from the previous depths before clearing * otherwise we could have a function to load the depths after drawing. @@ -909,7 +910,7 @@ static void view3d_draw_xray_select( v3d->xray = true; while ((v3da = BLI_pophead(&v3d->afterdraw_xray))) { if (GPU_select_load_id(v3da->base->object->select_color)) { - draw_object_select(eval_ctx, scene, view_layer, ar, v3d, v3da->base, v3da->dflag); + draw_object_select(depsgraph, scene, view_layer, ar, v3d, v3da->base, v3da->dflag); } MEM_freeN(v3da); } @@ -945,7 +946,7 @@ static DupliObject *dupli_step(DupliObject *dob) } static void draw_dupli_objects_color( - const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Base *base, + Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Base *base, const short dflag, const int color) { RegionView3D *rv3d = ar->regiondata; @@ -972,10 +973,10 @@ static void draw_dupli_objects_color( tbase.flag_legacy = OB_FROMDUPLI | base->flag_legacy; tbase.flag = base->flag; - lb = object_duplilist(eval_ctx, scene, base->object); + lb = object_duplilist(depsgraph, scene, base->object); // BLI_listbase_sort(lb, dupli_ob_sort); /* might be nice to have if we have a dupli list with mixed objects. */ - apply_data = duplilist_apply(eval_ctx, base->object, scene, lb); + apply_data = duplilist_apply(depsgraph, base->object, scene, lb); DupliObject *dob_next = NULL; DupliObject *dob = dupli_step(lb->first); @@ -1028,7 +1029,7 @@ static void draw_dupli_objects_color( if (!testbb || ED_view3d_boundbox_clip_ex(rv3d, &bb, dob->mat)) { copy_m4_m4(dob->ob->obmat, dob->mat); GPU_begin_dupli_object(dob); - draw_object(eval_ctx, scene, view_layer, ar, v3d, &tbase, dflag_dupli); + draw_object(depsgraph, scene, view_layer, ar, v3d, &tbase, dflag_dupli); GPU_end_dupli_object(); } @@ -1046,7 +1047,7 @@ static void draw_dupli_objects_color( free_object_duplilist(lb); } -void draw_dupli_objects(const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Base *base) +void draw_dupli_objects(Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Base *base) { /* define the color here so draw_dupli_objects_color can be called * from the set loop */ @@ -1056,7 +1057,7 @@ void draw_dupli_objects(const EvaluationContext *eval_ctx, Scene *scene, ViewLay if (base->object->dup_group && base->object->dup_group->id.us < 1) color = TH_REDALERT; - draw_dupli_objects_color(eval_ctx, scene, view_layer, ar, v3d, base, 0, color); + draw_dupli_objects_color(depsgraph, scene, view_layer, ar, v3d, base, 0, color); } /* XXX warning, not using gpu offscreen here */ @@ -1170,12 +1171,13 @@ float view3d_depth_near(ViewDepths *d) } void ED_view3d_draw_depth_gpencil( - const EvaluationContext *eval_ctx, Scene *scene, ARegion *ar, View3D *v3d) + Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d) { + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); bool zbuf = v3d->zbuf; /* Setup view matrix. */ - ED_view3d_draw_setup_view(NULL, eval_ctx, scene, ar, v3d, NULL, NULL, NULL); + ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL); glClear(GL_DEPTH_BUFFER_BIT); @@ -1183,17 +1185,17 @@ void ED_view3d_draw_depth_gpencil( glEnable(GL_DEPTH_TEST); if (v3d->flag2 & V3D_SHOW_GPENCIL) { - ED_gpencil_draw_view3d(NULL, scene, eval_ctx->view_layer, eval_ctx->depsgraph, v3d, ar, true); + ED_gpencil_draw_view3d(NULL, scene, view_layer, depsgraph, v3d, ar, true); } v3d->zbuf = zbuf; if (!zbuf) glDisable(GL_DEPTH_TEST); } -void ED_view3d_draw_depth_loop(const EvaluationContext *eval_ctx, Scene *scene, ARegion *ar, View3D *v3d) +void ED_view3d_draw_depth_loop(Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d) { Base *base; - ViewLayer *view_layer = eval_ctx->view_layer; + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); /* no need for color when drawing depth buffer */ const short dflag_depth = DRAW_CONSTCOLOR; @@ -1202,9 +1204,9 @@ void ED_view3d_draw_depth_loop(const EvaluationContext *eval_ctx, Scene *scene, Scene *sce_iter; for (SETLOOPER(scene->set, sce_iter, base)) { if ((base->flag & BASE_VISIBLED) != 0) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, base, 0); + draw_object(depsgraph, scene, view_layer, ar, v3d, base, 0); if (base->object->transflag & OB_DUPLI) { - draw_dupli_objects_color(eval_ctx, scene, view_layer, ar, v3d, base, dflag_depth, TH_UNDEFINED); + draw_dupli_objects_color(depsgraph, scene, view_layer, ar, v3d, base, dflag_depth, TH_UNDEFINED); } } } @@ -1214,9 +1216,9 @@ void ED_view3d_draw_depth_loop(const EvaluationContext *eval_ctx, Scene *scene, if ((base->flag & BASE_VISIBLED) != 0) { /* dupli drawing */ if (base->object->transflag & OB_DUPLI) { - draw_dupli_objects_color(eval_ctx, scene, view_layer, ar, v3d, base, dflag_depth, TH_UNDEFINED); + draw_dupli_objects_color(depsgraph, scene, view_layer, ar, v3d, base, dflag_depth, TH_UNDEFINED); } - draw_object(eval_ctx, scene, view_layer, ar, v3d, base, dflag_depth); + draw_object(depsgraph, scene, view_layer, ar, v3d, base, dflag_depth); } } @@ -1237,7 +1239,7 @@ void ED_view3d_draw_depth_loop(const EvaluationContext *eval_ctx, Scene *scene, if (v3d->afterdraw_xray.first || v3d->afterdraw_xraytransp.first) { glDepthFunc(GL_ALWAYS); /* always write into the depth bufer, overwriting front z values */ for (v3da = v3d->afterdraw_xray.first; v3da; v3da = v3da->next) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, v3da->base, dflag_depth); + draw_object(depsgraph, scene, view_layer, ar, v3d, v3da->base, dflag_depth); } glDepthFunc(GL_LEQUAL); /* Now write the depth buffer normally */ } @@ -1246,21 +1248,21 @@ void ED_view3d_draw_depth_loop(const EvaluationContext *eval_ctx, Scene *scene, v3d->xray = false; v3d->transp = true; while ((v3da = BLI_pophead(&v3d->afterdraw_transp))) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, v3da->base, dflag_depth); + draw_object(depsgraph, scene, view_layer, ar, v3d, v3da->base, dflag_depth); MEM_freeN(v3da); } v3d->xray = true; v3d->transp = false; while ((v3da = BLI_pophead(&v3d->afterdraw_xray))) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, v3da->base, dflag_depth); + draw_object(depsgraph, scene, view_layer, ar, v3d, v3da->base, dflag_depth); MEM_freeN(v3da); } v3d->xray = true; v3d->transp = true; while ((v3da = BLI_pophead(&v3d->afterdraw_xraytransp))) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, v3da->base, dflag_depth); + draw_object(depsgraph, scene, view_layer, ar, v3d, v3da->base, dflag_depth); MEM_freeN(v3da); } @@ -1273,7 +1275,7 @@ void ED_view3d_draw_depth_loop(const EvaluationContext *eval_ctx, Scene *scene, } void ED_view3d_draw_select_loop( - const struct EvaluationContext *eval_ctx, ViewContext *vc, Scene *scene, ViewLayer *view_layer, + struct Depsgraph *depsgraph, ViewContext *vc, Scene *scene, ViewLayer *view_layer, View3D *v3d, ARegion *ar, bool use_obedit_skip, bool use_nearest) { struct bThemeState theme_state; @@ -1286,12 +1288,12 @@ void ED_view3d_draw_select_loop( UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); if (vc->obedit && vc->obedit->type == OB_MBALL) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, BASACT(view_layer), dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, BASACT(view_layer), dflag); } else if ((vc->obedit && vc->obedit->type == OB_ARMATURE)) { /* if not drawing sketch, draw bones */ if (!BDR_drawSketchNames(vc)) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, BASACT(view_layer), dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, BASACT(view_layer), dflag); } } else { @@ -1312,7 +1314,7 @@ void ED_view3d_draw_select_loop( } else { if (GPU_select_load_id(code)) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, base, dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, base, dflag); } } code++; @@ -1323,7 +1325,7 @@ void ED_view3d_draw_select_loop( if (use_nearest) { bool xrayclear = true; if (v3d->afterdraw_xray.first) { - view3d_draw_xray_select(eval_ctx, scene, view_layer, ar, v3d, &xrayclear); + view3d_draw_xray_select(depsgraph, scene, view_layer, ar, v3d, &xrayclear); } } } @@ -1363,8 +1365,9 @@ static void gpu_render_lamp_update(Scene *scene, View3D *v3d, } } -static void gpu_update_lamps_shadows_world(const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d) +static void gpu_update_lamps_shadows_world(Depsgraph *depsgraph, Scene *scene, View3D *v3d) { + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); ListBase shadows; Scene *sce_iter; Base *base; @@ -1381,7 +1384,7 @@ static void gpu_update_lamps_shadows_world(const EvaluationContext *eval_ctx, Sc if (ob->transflag & OB_DUPLI) { DupliObject *dob; - ListBase *lb = object_duplilist(G.main->eval_ctx, scene, ob); + ListBase *lb = object_duplilist(depsgraph, scene, ob); for (dob = lb->first; dob; dob = dob->next) if (dob->ob->type == OB_LAMP) @@ -1424,7 +1427,7 @@ static void gpu_update_lamps_shadows_world(const EvaluationContext *eval_ctx, Sc /* no need to call ED_view3d_draw_offscreen_init since shadow buffers were already updated */ ED_view3d_draw_offscreen( - eval_ctx, scene, eval_ctx->view_layer, engine_type, + depsgraph, scene, view_layer, engine_type, v3d, &ar, winsize, winsize, viewmat, winmat, false, false, true, NULL, NULL, NULL, NULL); @@ -1498,13 +1501,12 @@ CustomDataMask ED_view3d_screen_datamask(const Scene *scene, const bScreen *scre */ static void view3d_draw_objects( const bContext *C, - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, const char **grid_unit, const bool do_bgpic, const bool draw_offscreen) { ViewLayer *view_layer = C ? CTX_data_view_layer(C) : BKE_view_layer_from_scene_get(scene); - Depsgraph *depsgraph = CTX_data_depsgraph(C); RegionView3D *rv3d = ar->regiondata; Base *base; Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); @@ -1563,10 +1565,10 @@ static void view3d_draw_objects( for (SETLOOPER(scene->set, sce_iter, base)) { if ((base->flag & BASE_VISIBLED) != 0) { UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f); - draw_object(eval_ctx, scene, view_layer, ar, v3d, base, dflag); + draw_object(depsgraph, scene, view_layer, ar, v3d, base, dflag); if (base->object->transflag & OB_DUPLI) { - draw_dupli_objects_color(eval_ctx, scene, view_layer, ar, v3d, base, dflag, TH_UNDEFINED); + draw_dupli_objects_color(depsgraph, scene, view_layer, ar, v3d, base, dflag, TH_UNDEFINED); } } } @@ -1579,10 +1581,10 @@ static void view3d_draw_objects( if ((base->flag & BASE_VISIBLED) != 0) { /* dupli drawing */ if (base->object->transflag & OB_DUPLI) { - draw_dupli_objects(eval_ctx, scene, view_layer, ar, v3d, base); + draw_dupli_objects(depsgraph, scene, view_layer, ar, v3d, base); } - draw_object(eval_ctx, scene, view_layer, ar, v3d, base, 0); + draw_object(depsgraph, scene, view_layer, ar, v3d, base, 0); } } } @@ -1597,11 +1599,11 @@ static void view3d_draw_objects( /* dupli drawing */ if (base->object->transflag & OB_DUPLI) { - draw_dupli_objects(eval_ctx, scene, view_layer, ar, v3d, base); + draw_dupli_objects(depsgraph, scene, view_layer, ar, v3d, base); } if ((base->flag & BASE_SELECTED) == 0) { if (base->object != obedit) - draw_object(eval_ctx, scene, view_layer, ar, v3d, base, 0); + draw_object(depsgraph, scene, view_layer, ar, v3d, base, 0); } } } @@ -1613,7 +1615,7 @@ static void view3d_draw_objects( for (base = view_layer->object_bases.first; base; base = base->next) { if ((base->flag & BASE_VISIBLED) != 0) { if (base->object == obedit || (base->flag & BASE_SELECTED)) { - draw_object(eval_ctx, scene, view_layer, ar, v3d, base, 0); + draw_object(depsgraph, scene, view_layer, ar, v3d, base, 0); } } } @@ -1635,10 +1637,10 @@ static void view3d_draw_objects( } /* transp and X-ray afterdraw stuff */ - if (v3d->afterdraw_transp.first) view3d_draw_transp(eval_ctx, scene, view_layer, ar, v3d); + if (v3d->afterdraw_transp.first) view3d_draw_transp(depsgraph, scene, view_layer, ar, v3d); - if (v3d->afterdraw_xray.first) view3d_draw_xray(eval_ctx, scene, view_layer, ar, v3d, &xrayclear); - if (v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(eval_ctx, scene, view_layer, ar, v3d, xrayclear); + if (v3d->afterdraw_xray.first) view3d_draw_xray(depsgraph, scene, view_layer, ar, v3d, &xrayclear); + if (v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(depsgraph, scene, view_layer, ar, v3d, xrayclear); if (!draw_offscreen) { ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); @@ -1768,7 +1770,7 @@ static bool view3d_main_region_do_render_draw(const Scene *scene) return (type && type->view_update && type->render_to_view); } -bool ED_view3d_calc_render_border(const Scene *scene, const Depsgraph *depsgraph, View3D *v3d, ARegion *ar, rcti *rect) +bool ED_view3d_calc_render_border(const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *ar, rcti *rect) { RegionView3D *rv3d = ar->regiondata; bool use_border; @@ -1814,11 +1816,10 @@ bool ED_view3d_calc_render_border(const Scene *scene, const Depsgraph *depsgraph * be mirrored in view3d_draw_render_draw() in view3d_draw.c */ static bool view3d_main_region_draw_engine( - const bContext *C, const EvaluationContext *eval_ctx, Scene *scene, + const bContext *C, Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d, bool clip_border, const rcti *border_rect) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); RegionView3D *rv3d = ar->regiondata; RenderEngineType *type; GLint scissor[4]; @@ -1842,7 +1843,7 @@ static bool view3d_main_region_draw_engine( } /* setup view matrices */ - VP_legacy_view3d_main_region_setup_view(eval_ctx, scene, v3d, ar, NULL, NULL); + VP_legacy_view3d_main_region_setup_view(depsgraph, scene, v3d, ar, NULL, NULL); /* background draw */ ED_region_pixelspace(ar); @@ -1941,15 +1942,13 @@ static void view3d_main_region_draw_objects(const bContext *C, Scene *scene, Vie ARegion *ar, const char **grid_unit) { wmWindow *win = CTX_wm_window(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); RegionView3D *rv3d = ar->regiondata; unsigned int lay_used = v3d->lay_used; - CTX_data_eval_ctx(C, &eval_ctx); - /* shadow buffers, before we setup matrices */ if (draw_glsl_material(scene, view_layer, NULL, v3d, v3d->drawtype)) - gpu_update_lamps_shadows_world(&eval_ctx, scene, v3d); + gpu_update_lamps_shadows_world(depsgraph, scene, v3d); /* reset default OpenGL lights if needed (i.e. after preferences have been altered) */ if (rv3d->rflag & RV3D_GPULIGHT_UPDATE) { @@ -1959,10 +1958,10 @@ static void view3d_main_region_draw_objects(const bContext *C, Scene *scene, Vie /* setup the view matrix */ if (VP_legacy_view3d_stereo3d_active(win, scene, v3d, rv3d)) { - VP_legacy_view3d_stereo3d_setup(&eval_ctx, scene, v3d, ar); + VP_legacy_view3d_stereo3d_setup(depsgraph, scene, v3d, ar); } else { - VP_legacy_view3d_main_region_setup_view(&eval_ctx, scene, v3d, ar, NULL, NULL); + VP_legacy_view3d_main_region_setup_view(depsgraph, scene, v3d, ar, NULL, NULL); } rv3d->rflag &= ~RV3D_IS_GAME_ENGINE; @@ -1976,7 +1975,7 @@ static void view3d_main_region_draw_objects(const bContext *C, Scene *scene, Vie #endif /* main drawing call */ - view3d_draw_objects(C, &eval_ctx, scene, v3d, ar, grid_unit, true, false); + view3d_draw_objects(C, depsgraph, scene, v3d, ar, grid_unit, true, false); if (v3d->lay_used != lay_used) { /* happens when loading old files or loading with UI load */ /* find header and force tag redraw */ @@ -1994,7 +1993,7 @@ static void view3d_main_region_draw_info(const bContext *C, Scene *scene, ARegion *ar, View3D *v3d, const char *grid_unit, bool render_border) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ViewLayer *view_layer = CTX_data_view_layer(C); wmWindowManager *wm = CTX_wm_manager(C); RegionView3D *rv3d = ar->regiondata; @@ -2004,7 +2003,7 @@ static void view3d_main_region_draw_info(const bContext *C, Scene *scene, ED_region_visible_rect(ar, &rect); if (rv3d->persp == RV3D_CAMOB) { - VP_drawviewborder(scene, CTX_data_depsgraph(C), ar, v3d); + VP_drawviewborder(scene, depsgraph, ar, v3d); } else if (v3d->flag2 & V3D_RENDER_BORDER) { VP_drawrenderborder(ar, v3d); @@ -2059,8 +2058,7 @@ static void view3d_main_region_draw_info(const bContext *C, Scene *scene, void view3d_main_region_draw_legacy(const bContext *C, ARegion *ar) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); - EvaluationContext eval_ctx; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); @@ -2077,8 +2075,6 @@ void view3d_main_region_draw_legacy(const bContext *C, ARegion *ar) gpuPushMatrix(); gpuLoadIdentity(); - CTX_data_eval_ctx(C, &eval_ctx); - /* draw viewport using opengl */ if (v3d->drawtype != OB_RENDER || !view3d_main_region_do_render_draw(scene) || clip_border) { VP_view3d_main_region_clear(scene, v3d, ar); /* background */ @@ -2093,10 +2089,10 @@ void view3d_main_region_draw_legacy(const bContext *C, ARegion *ar) /* draw viewport using external renderer */ if (v3d->drawtype == OB_RENDER) { - view3d_main_region_draw_engine(C, &eval_ctx, scene, ar, v3d, clip_border, &border_rect); + view3d_main_region_draw_engine(C, depsgraph, scene, ar, v3d, clip_border, &border_rect); } - VP_legacy_view3d_main_region_setup_view(&eval_ctx, scene, v3d, ar, NULL, NULL); + VP_legacy_view3d_main_region_setup_view(depsgraph, scene, v3d, ar, NULL, NULL); glClear(GL_DEPTH_BUFFER_BIT); WM_manipulatormap_draw(ar->manipulator_map, C, WM_MANIPULATORMAP_DRAWSTEP_3D); @@ -2130,17 +2126,17 @@ void view3d_main_region_draw_legacy(const bContext *C, ARegion *ar) void VP_deprecated_view3d_draw_objects( const bContext *C, - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, const char **grid_unit, const bool do_bgpic, const bool draw_offscreen) { - view3d_draw_objects(C, eval_ctx, scene, v3d, ar, grid_unit, do_bgpic, draw_offscreen); + view3d_draw_objects(C, depsgraph, scene, v3d, ar, grid_unit, do_bgpic, draw_offscreen); } -void VP_deprecated_gpu_update_lamps_shadows_world(const EvaluationContext *eval_ctx, Scene *scene, View3D *v3d) +void VP_deprecated_gpu_update_lamps_shadows_world(Depsgraph *depsgraph, Scene *scene, View3D *v3d) { - gpu_update_lamps_shadows_world(eval_ctx, scene, v3d); + gpu_update_lamps_shadows_world(depsgraph, scene, v3d); } /** \} */ diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 4a50cbcd12a..a2066ee51c7 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -377,18 +377,15 @@ static void viewops_data_create( /* we need the depth info before changing any viewport options */ if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) { - EvaluationContext eval_ctx; struct Depsgraph *graph = CTX_data_depsgraph(C); float fallback_depth_pt[3]; - CTX_data_eval_ctx(C, &eval_ctx); - view3d_operator_needs_opengl(C); /* needed for zbuf drawing */ negate_v3_v3(fallback_depth_pt, rv3d->ofs); vod->use_dyn_ofs = ED_view3d_autodist( - &eval_ctx, graph, vod->ar, vod->v3d, + graph, vod->ar, vod->v3d, event->mval, vod->dyn_ofs, true, fallback_depth_pt); } else { @@ -1800,7 +1797,7 @@ void viewzoom_modal_keymap(wmKeyConfig *keyconf) * \param zoom_xy: Optionally zoom to window location (coords compatible w/ #wmEvent.x, y). Use when not NULL. */ static void view_zoom_to_window_xy_camera( - Scene *scene, const Depsgraph *depsgraph, View3D *v3d, + Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *ar, float dfac, const int zoom_xy[2]) { RegionView3D *rv3d = ar->regiondata; @@ -2117,7 +2114,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) static int viewzoom_exec(bContext *C, wmOperator *op) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); View3D *v3d; RegionView3D *rv3d; @@ -2795,6 +2792,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); ViewLayer *view_layer = CTX_data_view_layer(C); bGPdata *gpd = CTX_data_gpencil_data(C); const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE)); @@ -2873,7 +2871,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) } /* account for duplis */ - if (BKE_object_minmax_dupli(scene, base->object, min, max, false) == 0) + if (BKE_object_minmax_dupli(depsgraph, scene, base->object, min, max, false) == 0) BKE_object_minmax(base->object, min, max, false); /* use if duplis not found */ ok = 1; @@ -3066,18 +3064,15 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev ARegion *ar = CTX_wm_region(C); if (rv3d) { - EvaluationContext eval_ctx; struct Depsgraph *graph = CTX_data_depsgraph(C); float new_ofs[3]; const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - CTX_data_eval_ctx(C, &eval_ctx); - ED_view3d_smooth_view_force_finish(C, v3d, ar); view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(&eval_ctx, graph, ar, v3d, event->mval, new_ofs, false, NULL)) { + if (ED_view3d_autodist(graph, ar, v3d, event->mval, new_ofs, false, NULL)) { /* pass */ } else { @@ -3117,7 +3112,7 @@ void VIEW3D_OT_view_center_pick(wmOperatorType *ot) static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was view3d_home() in 2.4x */ { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); float xfac, yfac; float size[2]; @@ -3201,7 +3196,7 @@ void VIEW3D_OT_view_center_lock(wmOperatorType *ot) static int render_border_exec(bContext *C, wmOperator *op) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); View3D *v3d = CTX_wm_view3d(C); ARegion *ar = CTX_wm_region(C); RegionView3D *rv3d = ED_view3d_context_rv3d(C); @@ -3356,7 +3351,6 @@ void VIEW3D_OT_clear_render_border(wmOperatorType *ot) static int view3d_zoom_border_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); @@ -3378,8 +3372,6 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) /* note; otherwise opengl won't work */ view3d_operator_needs_opengl(C); - CTX_data_eval_ctx(C, &eval_ctx); - /* get border select values using rna */ WM_operator_properties_border_to_rcti(op, &rect); @@ -3389,7 +3381,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) ED_view3d_dist_range_get(v3d, dist_range); /* Get Z Depths, needed for perspective, nice for ortho */ - ED_view3d_draw_depth(&eval_ctx, CTX_data_depsgraph(C), ar, v3d, true); + ED_view3d_draw_depth(CTX_data_depsgraph(C), ar, v3d, true); { /* avoid allocating the whole depth buffer */ @@ -3529,7 +3521,7 @@ void VIEW3D_OT_zoom_border(wmOperatorType *ot) * Sets the view to 1:1 camera/render-pixel. * \{ */ -static void view3d_set_1_to_1_viewborder(Scene *scene, const Depsgraph *depsgraph, ARegion *ar, View3D *v3d) +static void view3d_set_1_to_1_viewborder(Scene *scene, Depsgraph *depsgraph, ARegion *ar, View3D *v3d) { RegionView3D *rv3d = ar->regiondata; float size[2]; @@ -3543,7 +3535,7 @@ static void view3d_set_1_to_1_viewborder(Scene *scene, const Depsgraph *depsgrap static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op)) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); View3D *v3d; @@ -4548,13 +4540,10 @@ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2]) } if (U.uiflag & USER_DEPTH_CURSOR) { /* maybe this should be accessed some other way */ - EvaluationContext eval_ctx; struct Depsgraph *graph = CTX_data_depsgraph(C); - CTX_data_eval_ctx(C, &eval_ctx); - view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(&eval_ctx, graph, ar, v3d, mval, fp, true, NULL)) { + if (ED_view3d_autodist(graph, ar, v3d, mval, fp, true, NULL)) { depth_used = true; } } diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index d2aa19509d7..3715f4672d7 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -195,7 +195,7 @@ typedef struct FlyInfo { RegionView3D *rv3d; View3D *v3d; ARegion *ar; - const struct Depsgraph *depsgraph; + struct Depsgraph *depsgraph; Scene *scene; wmTimer *timer; /* needed for redraws */ @@ -346,9 +346,6 @@ enum { static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent *event) { wmWindow *win = CTX_wm_window(C); - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); rctf viewborder; @@ -425,7 +422,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent } fly->v3d_camera_control = ED_view3d_cameracontrol_acquire( - &eval_ctx, fly->scene, fly->v3d, fly->rv3d, + CTX_data_depsgraph(C), fly->scene, fly->v3d, fly->rv3d, (U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0); /* calculate center */ diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 0f56f1265bc..4b005185638 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -40,6 +40,7 @@ struct ARegionType; struct Base; struct BoundBox; struct Gwn_Batch; +struct Depsgraph; struct DerivedMesh; struct Object; struct SmokeDomainSettings; @@ -148,17 +149,17 @@ void draw_motion_paths_cleanup(View3D *v3d); /* drawobject.c */ void draw_object( - const struct EvaluationContext *eval_ctx, Scene *scene, struct ViewLayer *view_layer, struct ARegion *ar, View3D *v3d, + struct Depsgraph *depsgraph, Scene *scene, struct ViewLayer *view_layer, struct ARegion *ar, View3D *v3d, struct Base *base, const short dflag); void draw_object_select( - const struct EvaluationContext *eval_ctx, Scene *scene, struct ViewLayer *view_layer, struct ARegion *ar, View3D *v3d, + struct Depsgraph *depsgraph, Scene *scene, struct ViewLayer *view_layer, struct ARegion *ar, View3D *v3d, Base *base, const short dflag); void draw_mesh_object_outline(View3D *v3d, struct Object *ob, struct DerivedMesh *dm, const unsigned char ob_wire_col[4]); bool draw_glsl_material(Scene *scene, struct ViewLayer *view_layer, struct Object *ob, View3D *v3d, const char dt); -void draw_object_instance(const struct EvaluationContext *eval_ctx, Scene *scene, struct ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, struct Object *ob, const char dt, int outline, const float wire_col[4]); -void draw_object_backbufsel(const struct EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, RegionView3D *rv3d, struct Object *ob); +void draw_object_instance(struct Depsgraph *depsgraph, Scene *scene, struct ViewLayer *view_layer, View3D *v3d, RegionView3D *rv3d, struct Object *ob, const char dt, int outline, const float wire_col[4]); +void draw_object_backbufsel(struct Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d, struct Object *ob); void draw_object_wire_color(struct ViewLayer *, Base *base, unsigned char r_ob_wire_col[4]); void drawaxes(const float viewmat_local[4][4], float size, char drawtype, const unsigned char color[4]); @@ -191,7 +192,7 @@ int view3d_effective_drawtype(const struct View3D *v3d); /* drawarmature.c */ bool draw_armature( - const struct EvaluationContext *eval_ctx, Scene *scene, struct ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base, + struct Depsgraph *depsgraph, Scene *scene, struct ViewLayer *view_layer, View3D *v3d, ARegion *ar, Base *base, const short dt, const short dflag, const unsigned char ob_wire_col[4], const bool is_outline); @@ -220,19 +221,19 @@ void view3d_main_region_draw(const struct bContext *C, struct ARegion *ar); void view3d_draw_region_info(const struct bContext *C, struct ARegion *ar, const int offset); void ED_view3d_draw_depth( - const struct EvaluationContext *eval_ctx, struct Depsgraph *graph, + struct Depsgraph *depsgraph, struct ARegion *ar, View3D *v3d, bool alphaoverride); /* view3d_draw_legacy.c */ void view3d_main_region_draw_legacy(const struct bContext *C, struct ARegion *ar); -void ED_view3d_draw_depth_gpencil(const struct EvaluationContext *eval_ctx, Scene *scene, ARegion *ar, View3D *v3d); +void ED_view3d_draw_depth_gpencil(struct Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d); void ED_view3d_draw_select_loop( - const struct EvaluationContext *eval_ctx, ViewContext *vc, Scene *scene, struct ViewLayer *view_layer, View3D *v3d, ARegion *ar, + struct Depsgraph *depsgraph, ViewContext *vc, Scene *scene, struct ViewLayer *view_layer, View3D *v3d, ARegion *ar, bool use_obedit_skip, bool use_nearest); void ED_view3d_draw_depth_loop( - const struct EvaluationContext *eval_ctx, Scene *scene, ARegion *ar, View3D *v3d); + struct Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d); void ED_view3d_after_add(ListBase *lb, Base *base, const short dflag); @@ -278,10 +279,10 @@ void ED_view3d_smooth_view_force_finish( struct View3D *v3d, struct ARegion *ar); void view3d_winmatrix_set( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, ARegion *ar, const View3D *v3d, const rcti *rect); void view3d_viewmatrix_set( - const struct EvaluationContext *eval_ctx, Scene *scene, + struct Depsgraph *depsgraph, Scene *scene, const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2]); void fly_modal_keymap(struct wmKeyConfig *keyconf); @@ -297,7 +298,7 @@ void view3d_buttons_register(struct ARegionType *art); /* view3d_camera_control.c */ struct View3DCameraControl *ED_view3d_cameracontrol_acquire( - const struct EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, RegionView3D *rv3d, + struct Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d, const bool use_parent_root); void ED_view3d_cameracontrol_update( struct View3DCameraControl *vctrl, @@ -373,22 +374,22 @@ void VP_legacy_draw_viewport_name(ARegion *ar, View3D *v3d, const rcti *rect); void VP_legacy_draw_selected_name(Scene *scene, struct Object *ob, rcti *rect); void VP_legacy_drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **grid_unit); void VP_legacy_drawfloor(Scene *scene, View3D *v3d, const char **grid_unit, bool write_depth); -void VP_legacy_view3d_main_region_setup_view(const struct EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4]); +void VP_legacy_view3d_main_region_setup_view(struct Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4]); bool VP_legacy_view3d_stereo3d_active(struct wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d); -void VP_legacy_view3d_stereo3d_setup(const struct EvaluationContext *eval_ctx, Scene *scene, View3D *v3d, ARegion *ar); -void draw_dupli_objects(const struct EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Base *base); +void VP_legacy_view3d_stereo3d_setup(struct Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar); +void draw_dupli_objects(struct Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, ARegion *ar, View3D *v3d, Base *base); bool VP_legacy_use_depth(View3D *v3d, struct Object *obedit); -void VP_drawviewborder(Scene *scene, const struct Depsgraph *depsgraph, ARegion *ar, View3D *v3d); +void VP_drawviewborder(Scene *scene, struct Depsgraph *depsgraph, ARegion *ar, View3D *v3d); void VP_drawrenderborder(ARegion *ar, View3D *v3d); void VP_view3d_draw_background_none(void); void VP_view3d_draw_background_world(Scene *scene, RegionView3D *rv3d); void VP_view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar); /* temporary legacy calls, only when there is a switch between new/old draw calls */ -void VP_deprecated_gpu_update_lamps_shadows_world(const struct EvaluationContext *eval_ctx, Scene *scene, View3D *v3d); +void VP_deprecated_gpu_update_lamps_shadows_world(struct Depsgraph *depsgraph, Scene *scene, View3D *v3d); void VP_deprecated_view3d_draw_objects( const struct bContext *C, - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, const char **grid_unit, const bool do_bgpic, const bool draw_offscreen); diff --git a/source/blender/editors/space_view3d/view3d_iterators.c b/source/blender/editors/space_view3d/view3d_iterators.c index 4f80270e1e7..35127c7c8c6 100644 --- a/source/blender/editors/space_view3d/view3d_iterators.c +++ b/source/blender/editors/space_view3d/view3d_iterators.c @@ -107,14 +107,14 @@ static void meshobject_foreachScreenVert__mapFunc(void *userData, int index, con } void meshobject_foreachScreenVert( - const EvaluationContext *eval_ctx, ViewContext *vc, + ViewContext *vc, void (*func)(void *userData, MVert *eve, const float screen_co[2], int index), void *userData, eV3DProjTest clip_flag) { foreachScreenObjectVert_userData data; DerivedMesh *dm; - dm = mesh_get_derived_deform(eval_ctx, vc->scene, vc->obact, CD_MASK_BAREMESH); + dm = mesh_get_derived_deform(vc->depsgraph, vc->scene, vc->obact, CD_MASK_BAREMESH); ED_view3d_check_mats_rv3d(vc->rv3d); @@ -150,14 +150,14 @@ static void mesh_foreachScreenVert__mapFunc(void *userData, int index, const flo } void mesh_foreachScreenVert( - const EvaluationContext *eval_ctx, ViewContext *vc, + ViewContext *vc, void (*func)(void *userData, BMVert *eve, const float screen_co[2], int index), void *userData, eV3DProjTest clip_flag) { foreachScreenVert_userData data; DerivedMesh *dm; - dm = editbmesh_get_derived_cage(eval_ctx, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); + dm = editbmesh_get_derived_cage(vc->depsgraph, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); ED_view3d_check_mats_rv3d(vc->rv3d); @@ -206,14 +206,14 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, const flo } void mesh_foreachScreenEdge( - const EvaluationContext *eval_ctx, ViewContext *vc, + ViewContext *vc, void (*func)(void *userData, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index), void *userData, eV3DProjTest clip_flag) { foreachScreenEdge_userData data; DerivedMesh *dm; - dm = editbmesh_get_derived_cage(eval_ctx, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); + dm = editbmesh_get_derived_cage(vc->depsgraph, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); ED_view3d_check_mats_rv3d(vc->rv3d); @@ -254,14 +254,14 @@ static void mesh_foreachScreenFace__mapFunc(void *userData, int index, const flo } void mesh_foreachScreenFace( - const EvaluationContext *eval_ctx, ViewContext *vc, + ViewContext *vc, void (*func)(void *userData, BMFace *efa, const float screen_co_b[2], int index), void *userData, const eV3DProjTest clip_flag) { foreachScreenFace_userData data; DerivedMesh *dm; - dm = editbmesh_get_derived_cage(eval_ctx, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); + dm = editbmesh_get_derived_cage(vc->depsgraph, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); ED_view3d_check_mats_rv3d(vc->rv3d); diff --git a/source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c b/source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c index c3f8d92ed7f..06ac2f83ea7 100644 --- a/source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c +++ b/source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c @@ -143,9 +143,10 @@ static void axis_geom_draw( madd_v3_v3fl( center, (float [3]){ - mpr->matrix_offset[0][2], - mpr->matrix_offset[1][2], - mpr->matrix_offset[2][2]}, + mpr->matrix_offset[0][2], + mpr->matrix_offset[1][2], + mpr->matrix_offset[2][2], + }, 0.08f); imm_draw_cube_wire_3d(pos_id, center, size); glDisable(GL_BLEND); diff --git a/source/blender/editors/space_view3d/view3d_manipulator_ruler.c b/source/blender/editors/space_view3d/view3d_manipulator_ruler.c index f9955f29774..cdbb867321e 100644 --- a/source/blender/editors/space_view3d/view3d_manipulator_ruler.c +++ b/source/blender/editors/space_view3d/view3d_manipulator_ruler.c @@ -277,7 +277,7 @@ static void ruler_state_set(bContext *C, RulerInfo *ruler_info, int state) } else if (state == RULER_STATE_DRAG) { ruler_info->snap_context = ED_transform_snap_object_context_create_view3d( - CTX_data_main(C), CTX_data_scene(C), CTX_data_view_layer(C), 0, + CTX_data_main(C), CTX_data_scene(C), 0, ruler_info->ar, CTX_wm_view3d(C)); } else { @@ -924,8 +924,8 @@ static void manipulator_ruler_exit(bContext *C, wmManipulator *mpr, const bool c ruler_item->flag &= ~RULERITEM_USE_ANGLE; } else { - /* Not ideal, since the ruler isn't a mode and we don't want to override delete key - * use dragging out of the view for removal. */ + /* Not ideal, since the ruler isn't a mode and we don't want to override delete key + * use dragging out of the view for removal. */ ruler_item_remove(C, mgroup, ruler_item); ruler_item = NULL; mpr = NULL; diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index ba3e78b25b9..8a52542b2fb 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -309,7 +309,7 @@ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_f } static void view3d_win_to_ray_segment( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, const ARegion *ar, const View3D *v3d, const float mval[2], float r_ray_co[3], float r_ray_dir[3], float r_ray_start[3], float r_ray_end[3]) { @@ -366,7 +366,7 @@ bool ED_view3d_clip_segment(const RegionView3D *rv3d, float ray_start[3], float * \return success, false if the ray is totally clipped. */ bool ED_view3d_win_to_ray_ex( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, const ARegion *ar, const View3D *v3d, const float mval[2], float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip) { @@ -396,7 +396,7 @@ bool ED_view3d_win_to_ray_ex( * \return success, false if the ray is totally clipped. */ bool ED_view3d_win_to_ray( - const struct Depsgraph *depsgraph, + struct Depsgraph *depsgraph, const ARegion *ar, const View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_normal[3], const bool do_clip) { @@ -630,7 +630,7 @@ void ED_view3d_win_to_vector(const ARegion *ar, const float mval[2], float out[3 * \param do_clip Optionally clip the ray by the view clipping planes. * \return success, false if the segment is totally clipped. */ -bool ED_view3d_win_to_segment(const struct Depsgraph *depsgraph, +bool ED_view3d_win_to_segment(struct Depsgraph *depsgraph, const ARegion *ar, View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], const bool do_clip) { diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c index f61aad2806e..36b626bbd97 100644 --- a/source/blender/editors/space_view3d/view3d_ruler.c +++ b/source/blender/editors/space_view3d/view3d_ruler.c @@ -282,7 +282,7 @@ static void ruler_state_set(bContext *C, RulerInfo *ruler_info, int state) } else if (state == RULER_STATE_DRAG) { ruler_info->snap_context = ED_transform_snap_object_context_create_view3d( - CTX_data_main(C), CTX_data_scene(C), CTX_data_view_layer(C), 0, + CTX_data_main(C), CTX_data_scene(C), 0, ruler_info->ar, CTX_wm_view3d(C)); } else { diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 6833dac558d..adf41fcf5af 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -47,6 +47,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_array.h" #include "BLI_math.h" #include "BLI_lasso_2d.h" #include "BLI_rect.h" @@ -126,6 +127,21 @@ void ED_view3d_viewcontext_init(bContext *C, ViewContext *vc) vc->obedit = CTX_data_edit_object(C); } +void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact) +{ + vc->obact = obact; + if (vc->obedit) { + BLI_assert(BKE_object_is_in_editmode(obact)); + vc->obedit = obact; + /* previous selections are now invalid. */ + vc->v3d->flag |= V3D_INVALID_BACKBUF; + + if (vc->em) { + vc->em = BKE_editmesh_from_object(vc->obedit); + } + } +} + /* ********************** view3d_select: selection manipulations ********************* */ /* local prototypes */ @@ -398,6 +414,7 @@ static void do_lasso_select_objects( ViewContext *vc, const int mcords[][2], const short moves, const bool extend, const bool select) { + bool is_pose_mode = vc->obact ? (vc->obact->mode & OB_MODE_POSE) : false; Base *base; if (extend == false && select) @@ -411,7 +428,10 @@ static void do_lasso_select_objects( ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT); } } - if (vc->obact == base->object && (base->object->mode & OB_MODE_POSE)) { + if (is_pose_mode && + ((vc->obact == base->object) || (base->flag & BASE_SELECTED)) && + (base->object->mode & OB_MODE_POSE)) + { do_lasso_select_pose(vc, base->object, mcords, moves, select); } } @@ -467,7 +487,7 @@ static void do_lasso_select_mesh__doSelectFace(void *userData, BMFace *efa, cons } static void do_lasso_select_mesh( - const struct EvaluationContext *eval_ctx, ViewContext *vc, + ViewContext *vc, const int mcords[][2], short moves, bool extend, bool select) { LassoSelectUserData data; @@ -489,24 +509,24 @@ static void do_lasso_select_mesh( ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); gpuLoadMatrix(vc->rv3d->viewmat); - bbsel = EDBM_backbuf_border_mask_init(eval_ctx, vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); + bbsel = EDBM_backbuf_border_mask_init(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); if (ts->selectmode & SCE_SELECT_VERTEX) { if (bbsel) { edbm_backbuf_check_and_select_verts(vc->em, select); } else { - mesh_foreachScreenVert(eval_ctx, vc, do_lasso_select_mesh__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + mesh_foreachScreenVert(vc, do_lasso_select_mesh__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } } if (ts->selectmode & SCE_SELECT_EDGE) { /* Does both bbsel and non-bbsel versions (need screen cos for both) */ data.pass = 0; - mesh_foreachScreenEdge(eval_ctx, vc, do_lasso_select_mesh__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); + mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); if (data.is_done == false) { data.pass = 1; - mesh_foreachScreenEdge(eval_ctx, vc, do_lasso_select_mesh__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); + mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); } } @@ -515,7 +535,7 @@ static void do_lasso_select_mesh( edbm_backbuf_check_and_select_faces(vc->em, select); } else { - mesh_foreachScreenFace(eval_ctx, vc, do_lasso_select_mesh__doSelectFace, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + mesh_foreachScreenFace(vc, do_lasso_select_mesh__doSelectFace, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } } @@ -714,7 +734,7 @@ static void do_lasso_select_meshobject__doSelectVert(void *userData, MVert *mv, SET_FLAG_FROM_TEST(mv->flag, data->select, SELECT); } } -static void do_lasso_select_paintvert(const struct EvaluationContext *eval_ctx, ViewContext *vc, const int mcords[][2], short moves, bool extend, bool select) +static void do_lasso_select_paintvert(ViewContext *vc, const int mcords[][2], short moves, bool extend, bool select) { const bool use_zbuf = (vc->v3d->flag & V3D_ZBUF_SELECT) != 0; Object *ob = vc->obact; @@ -732,7 +752,7 @@ static void do_lasso_select_paintvert(const struct EvaluationContext *eval_ctx, if (use_zbuf) { bm_vertoffs = me->totvert + 1; /* max index array */ - EDBM_backbuf_border_mask_init(eval_ctx, vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); + EDBM_backbuf_border_mask_init(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); edbm_backbuf_check_and_select_verts_obmode(me, select); @@ -745,7 +765,7 @@ static void do_lasso_select_paintvert(const struct EvaluationContext *eval_ctx, ED_view3d_init_mats_rv3d(vc->obact, vc->rv3d); - meshobject_foreachScreenVert(eval_ctx, vc, do_lasso_select_meshobject__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + meshobject_foreachScreenVert(vc, do_lasso_select_meshobject__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } @@ -754,7 +774,7 @@ static void do_lasso_select_paintvert(const struct EvaluationContext *eval_ctx, } paintvert_flush_flags(ob); } -static void do_lasso_select_paintface(const struct EvaluationContext *eval_ctx, ViewContext *vc, const int mcords[][2], short moves, bool extend, bool select) +static void do_lasso_select_paintface(ViewContext *vc, const int mcords[][2], short moves, bool extend, bool select) { Object *ob = vc->obact; Mesh *me = ob->data; @@ -769,7 +789,7 @@ static void do_lasso_select_paintface(const struct EvaluationContext *eval_ctx, bm_vertoffs = me->totpoly + 1; /* max index array */ BLI_lasso_boundbox(&rect, mcords, moves); - EDBM_backbuf_border_mask_init(eval_ctx, vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); + EDBM_backbuf_border_mask_init(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); edbm_backbuf_check_and_select_tfaces(me, select); @@ -816,15 +836,12 @@ static void view3d_lasso_select( { Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - if (vc->obedit == NULL) { /* Object Mode */ if (BKE_paint_select_face_test(ob)) { - do_lasso_select_paintface(&eval_ctx, vc, mcords, moves, extend, select); + do_lasso_select_paintface(vc, mcords, moves, extend, select); } else if (BKE_paint_select_vert_test(ob)) { - do_lasso_select_paintvert(&eval_ctx, vc, mcords, moves, extend, select); + do_lasso_select_paintvert(vc, mcords, moves, extend, select); } else if (ob && (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))) { /* pass */ @@ -838,29 +855,35 @@ static void view3d_lasso_select( } } else { /* Edit Mode */ - switch (vc->obedit->type) { - case OB_MESH: - do_lasso_select_mesh(&eval_ctx, vc, mcords, moves, extend, select); - break; - case OB_CURVE: - case OB_SURF: - do_lasso_select_curve(vc, mcords, moves, extend, select); - break; - case OB_LATTICE: - do_lasso_select_lattice(vc, mcords, moves, extend, select); - break; - case OB_ARMATURE: - do_lasso_select_armature(vc, mcords, moves, extend, select); - break; - case OB_MBALL: - do_lasso_select_meta(vc, mcords, moves, extend, select); - break; - default: - assert(!"lasso select on incorrect object type"); - break; - } - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc->obedit->data); + FOREACH_OBJECT_IN_MODE_BEGIN (vc->view_layer, ob->mode, ob_iter) { + ED_view3d_viewcontext_init_object(vc, ob_iter); + + switch (vc->obedit->type) { + case OB_MESH: + do_lasso_select_mesh(vc, mcords, moves, extend, select); + break; + case OB_CURVE: + case OB_SURF: + do_lasso_select_curve(vc, mcords, moves, extend, select); + break; + case OB_LATTICE: + do_lasso_select_lattice(vc, mcords, moves, extend, select); + break; + case OB_ARMATURE: + do_lasso_select_armature(vc, mcords, moves, extend, select); + break; + case OB_MBALL: + do_lasso_select_meta(vc, mcords, moves, extend, select); + break; + default: + assert(!"lasso select on incorrect object type"); + break; + } + + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc->obedit->data); + } + FOREACH_OBJECT_IN_MODE_END; } } @@ -1142,7 +1165,7 @@ static int selectbuffer_ret_hits_5(unsigned int *buffer, const int hits15, const /* we want a select buffer with bones, if there are... */ /* so check three selection levels and compare */ static int mixed_bones_object_selectbuffer( - const EvaluationContext *eval_ctx, ViewContext *vc, unsigned int *buffer, const int mval[2], + ViewContext *vc, unsigned int *buffer, const int mval[2], bool use_cycle, bool enumerate, bool *r_do_nearest) { @@ -1182,7 +1205,7 @@ static int mixed_bones_object_selectbuffer( view3d_opengl_select_cache_begin(); BLI_rcti_init_pt_radius(&rect, mval, 14); - hits15 = view3d_opengl_select(eval_ctx, vc, buffer, MAXPICKBUF, &rect, select_mode); + hits15 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode); if (hits15 == 1) { hits = selectbuffer_ret_hits_15(buffer, hits15); goto finally; @@ -1193,7 +1216,7 @@ static int mixed_bones_object_selectbuffer( offs = 4 * hits15; BLI_rcti_init_pt_radius(&rect, mval, 9); - hits9 = view3d_opengl_select(eval_ctx, vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode); + hits9 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode); if (hits9 == 1) { hits = selectbuffer_ret_hits_9(buffer, hits15, hits9); goto finally; @@ -1203,7 +1226,7 @@ static int mixed_bones_object_selectbuffer( offs += 4 * hits9; BLI_rcti_init_pt_radius(&rect, mval, 5); - hits5 = view3d_opengl_select(eval_ctx, vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode); + hits5 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode); if (hits5 == 1) { hits = selectbuffer_ret_hits_5(buffer, hits15, hits9, hits5); goto finally; @@ -1316,7 +1339,6 @@ static Base *mouse_select_eval_buffer( /* mval comes from event->mval, only use within region handlers */ Base *ED_view3d_give_base_under_cursor(bContext *C, const int mval[2]) { - EvaluationContext eval_ctx; ViewContext vc; Base *basact = NULL; unsigned int buffer[MAXPICKBUF]; @@ -1326,10 +1348,9 @@ Base *ED_view3d_give_base_under_cursor(bContext *C, const int mval[2]) /* setup view context for argument to callbacks */ view3d_operator_needs_opengl(C); - CTX_data_eval_ctx(C, &eval_ctx); ED_view3d_viewcontext_init(C, &vc); - hits = mixed_bones_object_selectbuffer(&eval_ctx, &vc, buffer, mval, false, false, &do_nearest); + hits = mixed_bones_object_selectbuffer(&vc, buffer, mval, false, false, &do_nearest); if (hits > 0) { const bool has_bones = selectbuffer_has_bones(buffer, hits); @@ -1363,7 +1384,6 @@ static bool ed_object_select_pick( bContext *C, const int mval[2], bool extend, bool deselect, bool toggle, bool obcenter, bool enumerate, bool object) { - EvaluationContext eval_ctx; ViewContext vc; ARegion *ar = CTX_wm_region(C); Scene *scene = CTX_data_scene(C); @@ -1377,7 +1397,6 @@ static bool ed_object_select_pick( /* setup view context for argument to callbacks */ - CTX_data_eval_ctx(C, &eval_ctx); ED_view3d_viewcontext_init(C, &vc); is_obedit = (vc.obedit != NULL); @@ -1385,7 +1404,10 @@ static bool ed_object_select_pick( /* signal for view3d_opengl_select to skip editmode objects */ vc.obedit = NULL; } - + + /* In pose mode we don't want to mess with object selection. */ + const bool is_pose_mode = (vc.obact && vc.obact->mode & OB_MODE_POSE); + /* always start list from basact in wire mode */ startbase = FIRSTBASE(view_layer); if (BASACT(view_layer) && BASACT(view_layer)->next) startbase = BASACT(view_layer)->next; @@ -1429,7 +1451,7 @@ static bool ed_object_select_pick( // TIMEIT_START(select_time); /* if objects have posemode set, the bones are in the same selection buffer */ - hits = mixed_bones_object_selectbuffer(&eval_ctx, &vc, buffer, mval, true, enumerate, &do_nearest); + hits = mixed_bones_object_selectbuffer(&vc, buffer, mval, true, enumerate, &do_nearest); // TIMEIT_END(select_time); @@ -1504,7 +1526,9 @@ static bool ed_object_select_pick( } } } - else if (ED_armature_pose_select_pick_with_buffer(view_layer, basact, buffer, hits, extend, deselect, toggle, do_nearest)) { + else if (ED_armature_pose_select_pick_with_buffer( + view_layer, basact, buffer, hits, extend, deselect, toggle, do_nearest)) + { /* then bone is found */ /* we make the armature selected: @@ -1561,8 +1585,11 @@ static bool ed_object_select_pick( } } else { - deselectall_except(view_layer, basact); - ED_object_base_select(basact, BA_SELECT); + /* When enabled, this puts other objects out of multi pose-mode. */ + if (is_pose_mode == false) { + deselectall_except(view_layer, basact); + ED_object_base_select(basact, BA_SELECT); + } } if ((oldbasact != basact) && (is_obedit == false)) { @@ -1624,7 +1651,7 @@ static void do_paintvert_box_select__doSelectVert(void *userData, MVert *mv, con } } static int do_paintvert_box_select( - const EvaluationContext *eval_ctx, ViewContext *vc, rcti *rect, bool select, bool extend) + ViewContext *vc, rcti *rect, bool select, bool extend) { const bool use_zbuf = (vc->v3d->flag & V3D_ZBUF_SELECT) != 0; Mesh *me; @@ -1648,7 +1675,7 @@ static int do_paintvert_box_select( if (use_zbuf) { selar = MEM_callocN(me->totvert + 1, "selar"); - ED_view3d_backbuf_validate(eval_ctx, vc); + ED_view3d_backbuf_validate(vc); ibuf = IMB_allocImBuf(size[0], size[1], 32, IB_rect); rt = ibuf->rect; @@ -1696,7 +1723,7 @@ static int do_paintvert_box_select( ED_view3d_init_mats_rv3d(vc->obact, vc->rv3d); - meshobject_foreachScreenVert(eval_ctx, vc, do_paintvert_box_select__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + meshobject_foreachScreenVert(vc, do_paintvert_box_select__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } if (select == false) { @@ -1814,7 +1841,7 @@ static void do_mesh_box_select__doSelectFace(void *userData, BMFace *efa, const } } static int do_mesh_box_select( - const struct EvaluationContext *eval_ctx, ViewContext *vc, rcti *rect, bool select, bool extend) + ViewContext *vc, rcti *rect, bool select, bool extend) { BoxSelectUserData data; ToolSettings *ts = vc->scene->toolsettings; @@ -1829,25 +1856,25 @@ static int do_mesh_box_select( ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); gpuLoadMatrix(vc->rv3d->viewmat); - bbsel = EDBM_backbuf_border_init(eval_ctx, vc, rect->xmin, rect->ymin, rect->xmax, rect->ymax); + bbsel = EDBM_backbuf_border_init(vc, rect->xmin, rect->ymin, rect->xmax, rect->ymax); if (ts->selectmode & SCE_SELECT_VERTEX) { if (bbsel) { edbm_backbuf_check_and_select_verts(vc->em, select); } else { - mesh_foreachScreenVert(eval_ctx, vc, do_mesh_box_select__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + mesh_foreachScreenVert(vc, do_mesh_box_select__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } } if (ts->selectmode & SCE_SELECT_EDGE) { /* Does both bbsel and non-bbsel versions (need screen cos for both) */ data.pass = 0; - mesh_foreachScreenEdge(eval_ctx, vc, do_mesh_box_select__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); + mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); if (data.is_done == 0) { data.pass = 1; - mesh_foreachScreenEdge(eval_ctx, vc, do_mesh_box_select__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); + mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); } } @@ -1856,7 +1883,7 @@ static int do_mesh_box_select( edbm_backbuf_check_and_select_faces(vc->em, select); } else { - mesh_foreachScreenFace(eval_ctx, vc, do_mesh_box_select__doSelectFace, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + mesh_foreachScreenFace(vc, do_mesh_box_select__doSelectFace, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } } @@ -1868,7 +1895,7 @@ static int do_mesh_box_select( } static int do_meta_box_select( - const struct EvaluationContext *eval_ctx, ViewContext *vc, + ViewContext *vc, const rcti *rect, bool select, bool extend) { MetaBall *mb = (MetaBall *)vc->obedit->data; @@ -1878,7 +1905,7 @@ static int do_meta_box_select( unsigned int buffer[MAXPICKBUF]; int hits; - hits = view3d_opengl_select(eval_ctx, vc, buffer, MAXPICKBUF, rect, VIEW3D_SELECT_ALL); + hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, rect, VIEW3D_SELECT_ALL); if (extend == false && select) BKE_mball_deselect_all(mb); @@ -1904,23 +1931,31 @@ static int do_meta_box_select( } static int do_armature_box_select( - const struct EvaluationContext *eval_ctx, ViewContext *vc, + ViewContext *vc, const rcti *rect, bool select, bool extend) { - bArmature *arm = vc->obedit->data; int a; unsigned int buffer[MAXPICKBUF]; int hits; - hits = view3d_opengl_select(eval_ctx, vc, buffer, MAXPICKBUF, rect, VIEW3D_SELECT_ALL); - + hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, rect, VIEW3D_SELECT_ALL); + + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc->view_layer, &objects_len); + /* clear flag we use to detect point was affected */ - for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) - ebone->flag &= ~BONE_DONE; - - if (extend == false && select) - ED_armature_edit_deselect_all_visible(vc->obedit); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + bArmature *arm = obedit->data; + for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) { + ebone->flag &= ~BONE_DONE; + } + } + + if (extend == false && select) { + ED_armature_edit_deselect_all_visible_multi(objects, objects_len); + } /* first we only check points inside the border */ for (a = 0; a < hits; a++) { @@ -1929,7 +1964,9 @@ static int do_armature_box_select( if ((index & 0xFFFF0000) == 0) { continue; } - EditBone *ebone = BLI_findlink(arm->edbo, index & ~(BONESEL_ANY)); + + EditBone *ebone; + ED_armature_object_and_ebone_from_select_buffer(objects, objects_len, index, &ebone); if ((select == false) || ((ebone->flag & BONE_UNSELECTABLE) == 0)) { if (index & BONESEL_TIP) { ebone->flag |= BONE_DONE; @@ -1947,10 +1984,14 @@ static int do_armature_box_select( } /* now we have to flush tag from parents... */ - for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) { - if (ebone->parent && (ebone->flag & BONE_CONNECTED)) { - if (ebone->parent->flag & BONE_DONE) { - ebone->flag |= BONE_DONE; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + bArmature *arm = obedit->data; + for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) { + if (ebone->parent && (ebone->flag & BONE_CONNECTED)) { + if (ebone->parent->flag & BONE_DONE) { + ebone->flag |= BONE_DONE; + } } } } @@ -1960,7 +2001,8 @@ static int do_armature_box_select( int index = buffer[(4 * a) + 3]; if (index != -1) { if (index & BONESEL_BONE) { - EditBone *ebone = BLI_findlink(arm->edbo, index & ~(BONESEL_ANY)); + EditBone *ebone; + ED_armature_object_and_ebone_from_select_buffer(objects, objects_len, index, &ebone); if ((select == false) || ((ebone->flag & BONE_UNSELECTABLE) == 0)) { if (!(ebone->flag & BONE_DONE)) { if (select) { @@ -1974,9 +2016,15 @@ static int do_armature_box_select( } } } - - ED_armature_edit_sync_selection(arm->edbo); - + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + bArmature *arm = obedit->data; + ED_armature_edit_sync_selection(arm->edbo); + } + + MEM_freeN(objects); + return hits > 0 ? OPERATOR_FINISHED : OPERATOR_CANCELLED; } @@ -2008,32 +2056,29 @@ static int opengl_bone_select_buffer_cmp(const void *sel_a_p, const void *sel_b_ static int do_object_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, bool select, bool extend) { - EvaluationContext eval_ctx; - Bone *bone; - Object *ob = vc->obact; unsigned int *vbuffer = NULL; /* selection buffer */ - unsigned int *col; /* color in buffer */ int bone_only; - int bone_selected = 0; int totobj = MAXPICKBUF; /* XXX solve later */ int hits; - CTX_data_eval_ctx(C, &eval_ctx); - - if ((ob) && (ob->mode & OB_MODE_POSE)) + if (vc->obact && (vc->obact->mode & OB_MODE_POSE)) bone_only = 1; else bone_only = 0; if (extend == false && select) { if (bone_only) { - CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones) - { - if ((select == false) || ((pchan->bone->flag & BONE_UNSELECTABLE) == 0)) { - pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); + FOREACH_OBJECT_IN_MODE_BEGIN (vc->view_layer, OB_MODE_POSE, ob_iter) { + bArmature *arm = ob_iter->data; + for (bPoseChannel *pchan = ob_iter->pose->chanbase.first; pchan; pchan = pchan->next) { + if (PBONE_VISIBLE(arm, pchan->bone)) { + if ((select == false) || ((pchan->bone->flag & BONE_UNSELECTABLE) == 0)) { + pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); + } + } } } - CTX_DATA_END; + FOREACH_OBJECT_IN_MODE_END; } else { object_deselect_all_visible(vc->view_layer); @@ -2042,7 +2087,7 @@ static int do_object_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, b /* selection buffer now has bones potentially too, so we add MAXPICKBUF */ vbuffer = MEM_mallocN(4 * (totobj + MAXPICKELEMS) * sizeof(unsigned int), "selection buffer"); - hits = view3d_opengl_select(&eval_ctx, vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL); + hits = view3d_opengl_select(vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL); /* * LOGIC NOTES (theeth): * The buffer and ListBase have the same relative order, which makes the selection @@ -2053,60 +2098,83 @@ static int do_object_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, b */ if (hits > 0) { /* no need to loop if there's no hit */ - Base *base; - col = vbuffer + 3; /* The draw order doesn't always match the order we populate the engine, see: T51695. */ qsort(vbuffer, hits, sizeof(uint[4]), opengl_bone_select_buffer_cmp); - /* - * Even though 'DRW_draw_select_loop' uses 'DEG_OBJECT_ITER_BEGIN', - * we can be sure the order remains the same between both. - */ - for (base = vc->view_layer->object_bases.first; base && hits; base = base->next) { + Base **bases = NULL; + BLI_array_declare(bases); + + for (Base *base = vc->view_layer->object_bases.first; base && hits; base = base->next) { if (BASE_SELECTABLE(base)) { - while (base->object->select_color == (*col & 0xFFFF)) { /* we got an object */ - if (*col & 0xFFFF0000) { /* we got a bone */ - bone = ED_armature_bone_find_index(base->object, *col & ~(BONESEL_ANY)); - if (bone) { - if (select) { - if ((bone->flag & BONE_UNSELECTABLE) == 0) { - bone->flag |= BONE_SELECTED; - bone_selected = 1; - } - } - else { - bArmature *arm = base->object->data; - bone->flag &= ~BONE_SELECTED; - if (arm->act_bone == bone) - arm->act_bone = NULL; - } + if ((base->object->select_color & 0x0000FFFF) != 0) { + BLI_array_append(bases, base); + } + } + } + + for (const uint *col = vbuffer + 3, *col_end = col + (hits * 4); col < col_end; col += 4) { + Bone *bone; + Base *base = ED_armature_base_and_bone_from_select_buffer(bases, BLI_array_len(bases), *col, &bone); + + if (base == NULL) { + continue; + } + /* Loop over contiguous bone hits for 'base'. */ + bool bone_selected = false; + for (; col != col_end; col += 4) { + /* should never fail */ + if (bone != NULL) { + if (select) { + if ((bone->flag & BONE_UNSELECTABLE) == 0) { + bone->flag |= BONE_SELECTED; + bone_selected = true; } } - else if (!bone_only) { - ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT); + else { + bArmature *arm = base->object->data; + bone->flag &= ~BONE_SELECTED; + if (arm->act_bone == bone) + arm->act_bone = NULL; + } + } + else if (!bone_only) { + ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT); + } + + /* Select the next bone if we're not switching bases. */ + if (col + 4 != col_end) { + if ((base->object->select_color & 0x0000FFFF) != (col[4] & 0x0000FFFF)) { + break; + } + + if ((base->object->pose != NULL) && bone_only) { + const uint hit_bone = (col[4] & ~BONESEL_ANY) >> 16; + bPoseChannel *pchan = BLI_findlink(&base->object->pose->chanbase, hit_bone);; + bone = pchan ? pchan->bone : NULL; + } + else { + bone = NULL; } - - col += 4; /* next color */ - hits--; - if (hits == 0) break; } } - + if (bone_selected) { if (base->object && (base->object->type == OB_ARMATURE)) { bArmature *arm = base->object->data; - + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, base->object); - - if (arm && (arm->flag & ARM_HAS_VIZ_DEPS)) { + + if (vc->obact && arm && (arm->flag & ARM_HAS_VIZ_DEPS)) { /* mask modifier ('armature' mode), etc. */ - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + DEG_id_tag_update(&vc->obact->id, OB_RECALC_DATA); } } } } - + + MEM_freeN(bases); + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, vc->scene); } MEM_freeN(vbuffer); @@ -2116,7 +2184,6 @@ static int do_object_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, b static int view3d_borderselect_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; ViewContext vc; rcti rect; bool extend; @@ -2127,7 +2194,6 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op) view3d_operator_needs_opengl(C); /* setup view context for argument to callbacks */ - CTX_data_eval_ctx(C, &eval_ctx); ED_view3d_viewcontext_init(C, &vc); select = !RNA_boolean_get(op->ptr, "deselect"); @@ -2135,63 +2201,75 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op) WM_operator_properties_border_to_rcti(op, &rect); if (vc.obedit) { - switch (vc.obedit->type) { - case OB_MESH: - vc.em = BKE_editmesh_from_object(vc.obedit); - ret = do_mesh_box_select(&eval_ctx, &vc, &rect, select, extend); -// if (EM_texFaceCheck()) - if (ret & OPERATOR_FINISHED) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); - } - break; - case OB_CURVE: - case OB_SURF: - ret = do_nurbs_box_select(&vc, &rect, select, extend); - if (ret & OPERATOR_FINISHED) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); - } - break; - case OB_MBALL: - ret = do_meta_box_select(&eval_ctx, &vc, &rect, select, extend); - if (ret & OPERATOR_FINISHED) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); - } - break; - case OB_ARMATURE: - ret = do_armature_box_select(&eval_ctx, &vc, &rect, select, extend); - if (ret & OPERATOR_FINISHED) { - WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, vc.obedit); - } - break; - case OB_LATTICE: - ret = do_lattice_box_select(&vc, &rect, select, extend); - if (ret & OPERATOR_FINISHED) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); - } - break; - default: - assert(!"border select on incorrect object type"); - break; + + FOREACH_OBJECT_IN_MODE_BEGIN (vc.view_layer, vc.obedit->mode, ob_iter) { + ED_view3d_viewcontext_init_object(&vc, ob_iter); + + switch (vc.obedit->type) { + case OB_MESH: + vc.em = BKE_editmesh_from_object(vc.obedit); + ret |= do_mesh_box_select(&vc, &rect, select, extend); + if (ret & OPERATOR_FINISHED) { + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); + } + break; + case OB_CURVE: + case OB_SURF: + ret |= do_nurbs_box_select(&vc, &rect, select, extend); + if (ret & OPERATOR_FINISHED) { + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); + } + break; + case OB_MBALL: + ret |= do_meta_box_select(&vc, &rect, select, extend); + if (ret & OPERATOR_FINISHED) { + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); + } + break; + case OB_ARMATURE: + ret |= do_armature_box_select(&vc, &rect, select, extend); + if (ret & OPERATOR_FINISHED) { + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, vc.obedit); + } + break; + case OB_LATTICE: + ret |= do_lattice_box_select(&vc, &rect, select, extend); + if (ret & OPERATOR_FINISHED) { + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); + } + break; + default: + assert(!"border select on incorrect object type"); + break; + } } + FOREACH_OBJECT_IN_MODE_END; } else { /* no editmode, unified for bones and objects */ if (vc.obact && vc.obact->mode & OB_MODE_SCULPT) { - ret = ED_sculpt_mask_box_select(C, &vc, &rect, select, extend); + ret |= ED_sculpt_mask_box_select(C, &vc, &rect, select, extend); } else if (vc.obact && BKE_paint_select_face_test(vc.obact)) { - ret = do_paintface_box_select(&eval_ctx, &vc, &rect, select, extend); + ret |= do_paintface_box_select(&vc, &rect, select, extend); } else if (vc.obact && BKE_paint_select_vert_test(vc.obact)) { - ret = do_paintvert_box_select(&eval_ctx, &vc, &rect, select, extend); + ret |= do_paintvert_box_select(&vc, &rect, select, extend); } else if (vc.obact && vc.obact->mode & OB_MODE_PARTICLE_EDIT) { - ret = PE_border_select(C, &rect, select, extend); + ret |= PE_border_select(C, &rect, select, extend); } else { /* object mode with none active */ - ret = do_object_pose_box_select(C, &vc, &rect, select, extend); + ret |= do_object_pose_box_select(C, &vc, &rect, select, extend); } } + if (ret & OPERATOR_FINISHED) { + ret = OPERATOR_FINISHED; + } + else { + ret = OPERATOR_CANCELLED; + } + return ret; } @@ -2428,13 +2506,13 @@ static void mesh_circle_doSelectFace(void *userData, BMFace *efa, const float sc } } -static void mesh_circle_select(const struct EvaluationContext *eval_ctx, ViewContext *vc, const bool select, const int mval[2], float rad) +static void mesh_circle_select(ViewContext *vc, const bool select, const int mval[2], float rad) { ToolSettings *ts = vc->scene->toolsettings; int bbsel; CircleSelectUserData data; - bbsel = EDBM_backbuf_circle_init(eval_ctx, vc, mval[0], mval[1], (short)(rad + 1.0f)); + bbsel = EDBM_backbuf_circle_init(vc, mval[0], mval[1], (short)(rad + 1.0f)); ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */ vc->em = BKE_editmesh_from_object(vc->obedit); @@ -2446,7 +2524,7 @@ static void mesh_circle_select(const struct EvaluationContext *eval_ctx, ViewCon edbm_backbuf_check_and_select_verts(vc->em, select); } else { - mesh_foreachScreenVert(eval_ctx, vc, mesh_circle_doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + mesh_foreachScreenVert(vc, mesh_circle_doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } } @@ -2455,7 +2533,7 @@ static void mesh_circle_select(const struct EvaluationContext *eval_ctx, ViewCon edbm_backbuf_check_and_select_edges(vc->em, select); } else { - mesh_foreachScreenEdge(eval_ctx, vc, mesh_circle_doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); + mesh_foreachScreenEdge(vc, mesh_circle_doSelectEdge, &data, V3D_PROJ_TEST_CLIP_NEAR); } } @@ -2464,7 +2542,7 @@ static void mesh_circle_select(const struct EvaluationContext *eval_ctx, ViewCon edbm_backbuf_check_and_select_faces(vc->em, select); } else { - mesh_foreachScreenFace(eval_ctx, vc, mesh_circle_doSelectFace, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + mesh_foreachScreenFace(vc, mesh_circle_doSelectFace, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } } @@ -2472,7 +2550,7 @@ static void mesh_circle_select(const struct EvaluationContext *eval_ctx, ViewCon EDBM_selectmode_flush(vc->em); } -static void paint_facesel_circle_select(const struct EvaluationContext *eval_ctx, ViewContext *vc, const bool select, const int mval[2], float rad) +static void paint_facesel_circle_select(ViewContext *vc, const bool select, const int mval[2], float rad) { Object *ob = vc->obact; Mesh *me = ob->data; @@ -2480,7 +2558,7 @@ static void paint_facesel_circle_select(const struct EvaluationContext *eval_ctx bm_vertoffs = me->totpoly + 1; /* max index array */ - bbsel = EDBM_backbuf_circle_init(eval_ctx, vc, mval[0], mval[1], (short)(rad + 1.0f)); + bbsel = EDBM_backbuf_circle_init(vc, mval[0], mval[1], (short)(rad + 1.0f)); if (bbsel) { edbm_backbuf_check_and_select_tfaces(me, select); EDBM_backbuf_free(); @@ -2496,7 +2574,7 @@ static void paint_vertsel_circle_select_doSelectVert(void *userData, MVert *mv, SET_FLAG_FROM_TEST(mv->flag, data->select, SELECT); } } -static void paint_vertsel_circle_select(const struct EvaluationContext *eval_ctx, ViewContext *vc, const bool select, const int mval[2], float rad) +static void paint_vertsel_circle_select(ViewContext *vc, const bool select, const int mval[2], float rad) { const bool use_zbuf = (vc->v3d->flag & V3D_ZBUF_SELECT) != 0; Object *ob = vc->obact; @@ -2507,7 +2585,7 @@ static void paint_vertsel_circle_select(const struct EvaluationContext *eval_ctx if (use_zbuf) { bm_vertoffs = me->totvert + 1; /* max index array */ - bbsel = EDBM_backbuf_circle_init(eval_ctx, vc, mval[0], mval[1], (short)(rad + 1.0f)); + bbsel = EDBM_backbuf_circle_init(vc, mval[0], mval[1], (short)(rad + 1.0f)); if (bbsel) { edbm_backbuf_check_and_select_verts_obmode(me, select); EDBM_backbuf_free(); @@ -2519,7 +2597,7 @@ static void paint_vertsel_circle_select(const struct EvaluationContext *eval_ctx ED_view3d_init_mats_rv3d(vc->obact, vc->rv3d); /* for foreach's screen/vert projection */ view3d_userdata_circleselect_init(&data, vc, select, mval, rad); - meshobject_foreachScreenVert(eval_ctx, vc, paint_vertsel_circle_select_doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); + meshobject_foreachScreenVert(vc, paint_vertsel_circle_select_doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT); } if (select != LEFTMOUSE) { @@ -2777,11 +2855,11 @@ static void mball_circle_select(ViewContext *vc, const bool select, const int mv /** Callbacks for circle selection in Editmode */ static void obedit_circle_select( - const struct EvaluationContext *eval_ctx, ViewContext *vc, const bool select, const int mval[2], float rad) + ViewContext *vc, const bool select, const int mval[2], float rad) { switch (vc->obedit->type) { case OB_MESH: - mesh_circle_select(eval_ctx, vc, select, mval, rad); + mesh_circle_select(vc, select, mval, rad); break; case OB_CURVE: case OB_SURF: @@ -2832,50 +2910,56 @@ static bool object_circle_select(ViewContext *vc, const bool select, const int m /* not a real operator, only for circle test */ static int view3d_circle_select_exec(bContext *C, wmOperator *op) { - Scene *scene = CTX_data_scene(C); - Object *obact = CTX_data_active_object(C); + ViewContext vc; const int radius = RNA_int_get(op->ptr, "radius"); const bool select = !RNA_boolean_get(op->ptr, "deselect"); const int mval[2] = {RNA_int_get(op->ptr, "x"), RNA_int_get(op->ptr, "y")}; - if (CTX_data_edit_object(C) || BKE_paint_select_elem_test(obact) || + + ED_view3d_viewcontext_init(C, &vc); + + Object *obact = vc.obact; + Object *obedit = vc.obedit; + + if (obedit || BKE_paint_select_elem_test(obact) || (obact && (obact->mode & (OB_MODE_PARTICLE_EDIT | OB_MODE_POSE))) ) { - EvaluationContext eval_ctx; - ViewContext vc; - view3d_operator_needs_opengl(C); - - CTX_data_eval_ctx(C, &eval_ctx); - ED_view3d_viewcontext_init(C, &vc); - if (CTX_data_edit_object(C)) { - obedit_circle_select(&eval_ctx, &vc, select, mval, (float)radius); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data); - } - else if (BKE_paint_select_face_test(obact)) { - paint_facesel_circle_select(&eval_ctx, &vc, select, mval, (float)radius); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data); - } - else if (BKE_paint_select_vert_test(obact)) { - paint_vertsel_circle_select(&eval_ctx, &vc, select, mval, (float)radius); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data); + FOREACH_OBJECT_IN_MODE_BEGIN (vc.view_layer, obact->mode, ob_iter) { + ED_view3d_viewcontext_init_object(&vc, ob_iter); + + obact = vc.obact; + obedit = vc.obedit; + + if (CTX_data_edit_object(C)) { + obedit_circle_select(&vc, select, mval, (float)radius); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data); + } + else if (BKE_paint_select_face_test(obact)) { + paint_facesel_circle_select(&vc, select, mval, (float)radius); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data); + } + else if (BKE_paint_select_vert_test(obact)) { + paint_vertsel_circle_select(&vc, select, mval, (float)radius); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data); + } + else if (obact->mode & OB_MODE_POSE) { + pose_circle_select(&vc, select, mval, (float)radius); + } + else { + return PE_circle_select(C, select, mval, (float)radius); + } } - else if (obact->mode & OB_MODE_POSE) - pose_circle_select(&vc, select, mval, (float)radius); - else - return PE_circle_select(C, select, mval, (float)radius); + FOREACH_OBJECT_IN_MODE_END; } else if (obact && obact->mode & OB_MODE_SCULPT) { return OPERATOR_CANCELLED; } else { - ViewContext vc; - ED_view3d_viewcontext_init(C, &vc); - if (object_circle_select(&vc, select, mval, (float)radius)) { - WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, vc.scene); } } diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 1df29201bf6..970fb5f5b9d 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -69,17 +69,15 @@ static bool snap_calc_active_center(bContext *C, const bool select_only, float r static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Object *obedit = CTX_data_edit_object(C); Scene *scene = CTX_data_scene(C); RegionView3D *rv3d = CTX_wm_region_data(C); TransVertStore tvs = {NULL}; TransVert *tv; - EvaluationContext eval_ctx; float gridf, imat[3][3], bmat[3][3], vec[3]; int a; - CTX_data_eval_ctx(C, &eval_ctx); - gridf = rv3d->gridview; if (obedit) { @@ -166,7 +164,7 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) if (ob->parent) { float originmat[3][3]; - BKE_object_where_is_calc_ex(&eval_ctx, scene, NULL, ob, originmat); + BKE_object_where_is_calc_ex(depsgraph, scene, NULL, ob, originmat); invert_m3_m3(imat, originmat); mul_m3_v3(imat, vec); @@ -211,20 +209,18 @@ void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot) static int snap_selected_to_location(bContext *C, const float snap_target_global[3], const bool use_offset) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *obedit = CTX_data_edit_object(C); Object *obact = CTX_data_active_object(C); View3D *v3d = CTX_wm_view3d(C); TransVertStore tvs = {NULL}; TransVert *tv; - EvaluationContext eval_ctx; float imat[3][3], bmat[3][3]; float center_global[3]; float offset_global[3]; int a; - CTX_data_eval_ctx(C, &eval_ctx); - if (use_offset) { if ((v3d && v3d->around == V3D_AROUND_ACTIVE) && snap_calc_active_center(C, true, center_global)) @@ -377,7 +373,7 @@ static int snap_selected_to_location(bContext *C, const float snap_target_global if (ob->parent) { float originmat[3][3]; - BKE_object_where_is_calc_ex(&eval_ctx, scene, NULL, ob, originmat); + BKE_object_where_is_calc_ex(depsgraph, scene, NULL, ob, originmat); invert_m3_m3(imat, originmat); mul_m3_v3(imat, cursor_parent); diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c index 92b3ec19acb..09a3202c85e 100644 --- a/source/blender/editors/space_view3d/view3d_utils.c +++ b/source/blender/editors/space_view3d/view3d_utils.c @@ -100,7 +100,7 @@ void ED_view3d_dist_range_get( * \note copies logic of #ED_view3d_viewplane_get(), keep in sync. */ bool ED_view3d_clip_range_get( - const Depsgraph *depsgraph, + Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d, float *r_clipsta, float *r_clipend, const bool use_ortho_factor) @@ -123,7 +123,7 @@ bool ED_view3d_clip_range_get( } bool ED_view3d_viewplane_get( - const Depsgraph *depsgraph, + Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d, int winx, int winy, rctf *r_viewplane, float *r_clipsta, float *r_clipend, float *r_pixsize) { @@ -878,7 +878,7 @@ static float view_autodist_depth_margin(ARegion *ar, const int mval[2], int marg * \param fallback_depth_pt: Use this points depth when no depth can be found. */ bool ED_view3d_autodist( - const EvaluationContext *eval_ctx, struct Depsgraph *graph, ARegion *ar, View3D *v3d, + struct Depsgraph *graph, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3], const bool alphaoverride, const float fallback_depth_pt[3]) { @@ -888,7 +888,7 @@ bool ED_view3d_autodist( bool depth_ok = false; /* Get Z Depths, needed for perspective, nice for ortho */ - ED_view3d_draw_depth(eval_ctx, graph, ar, v3d, alphaoverride); + ED_view3d_draw_depth(graph, ar, v3d, alphaoverride); /* Attempt with low margin's first */ i = 0; @@ -916,18 +916,18 @@ bool ED_view3d_autodist( } void ED_view3d_autodist_init( - const EvaluationContext *eval_ctx, struct Depsgraph *graph, + struct Depsgraph *graph, ARegion *ar, View3D *v3d, int mode) { /* Get Z Depths, needed for perspective, nice for ortho */ switch (mode) { case 0: - ED_view3d_draw_depth(eval_ctx, graph, ar, v3d, true); + ED_view3d_draw_depth(graph, ar, v3d, true); break; case 1: { Scene *scene = DEG_get_evaluated_scene(graph); - ED_view3d_draw_depth_gpencil(eval_ctx, scene, ar, v3d); + ED_view3d_draw_depth_gpencil(graph, scene, ar, v3d); break; } } diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 1a547d07b80..1d44f3d3fd5 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -403,9 +403,6 @@ void ED_view3d_smooth_view_force_finish( View3D *v3d, ARegion *ar) { RegionView3D *rv3d = ar->regiondata; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); if (rv3d && rv3d->sms) { rv3d->sms->time_allowed = 0.0; /* force finishing */ @@ -413,8 +410,9 @@ void ED_view3d_smooth_view_force_finish( /* force update of view matrix so tools that run immediately after * can use them without redrawing first */ + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); - ED_view3d_update_viewmat(&eval_ctx, scene, v3d, ar, NULL, NULL, NULL); + ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL); } } @@ -512,6 +510,7 @@ void VIEW3D_OT_camera_to_view(wmOperatorType *ot) * meant to take into account vertex/bone selection for eg. */ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op) { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); /* can be NULL */ @@ -526,7 +525,7 @@ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op) } /* this function does all the important stuff */ - if (BKE_camera_view_frame_fit_to_scene(scene, view_layer, camera_ob, r_co, &r_scale)) { + if (BKE_camera_view_frame_fit_to_scene(depsgraph, scene, view_layer, camera_ob, r_co, &r_scale)) { ObjectTfmProtectedChannels obtfm; float obmat_new[4][4]; @@ -698,7 +697,7 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot) /** * \param rect optional for picking (can be NULL). */ -void view3d_winmatrix_set(const Depsgraph *depsgraph, ARegion *ar, const View3D *v3d, const rcti *rect) +void view3d_winmatrix_set(Depsgraph *depsgraph, ARegion *ar, const View3D *v3d, const rcti *rect) { RegionView3D *rv3d = ar->regiondata; rctf viewplane; @@ -750,7 +749,7 @@ static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob) /** * Sets #RegionView3D.viewmat * - * \param eval_ctx: Context. + * \param depsgraph: Depsgraph. * \param scene: Scene for camera and cursor location. * \param v3d: View 3D space data. * \param rv3d: 3D region which stores the final matrices. @@ -760,14 +759,13 @@ static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob) * \note don't set windows active in here, is used by renderwin too. */ void view3d_viewmatrix_set( - const EvaluationContext *eval_ctx, Scene *scene, + Depsgraph *depsgraph, Scene *scene, const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2]) { if (rv3d->persp == RV3D_CAMOB) { /* obs/camera */ if (v3d->camera) { - const Depsgraph *depsgraph = eval_ctx->depsgraph; Object *camera_object = DEG_get_evaluated_object(depsgraph, v3d->camera); - BKE_object_where_is_calc(eval_ctx, scene, camera_object); + BKE_object_where_is_calc(depsgraph, scene, camera_object); obmat_to_viewmat(rv3d, camera_object); } else { @@ -908,7 +906,7 @@ static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data) * \note (vc->obedit == NULL) can be set to explicitly skip edit-object selection. */ int view3d_opengl_select( - const EvaluationContext *eval_ctx, ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const rcti *input, + ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const rcti *input, eV3DSelectMode select_mode) { struct bThemeState theme_state; @@ -979,7 +977,7 @@ int view3d_opengl_select( /* Important we use the 'viewmat' and don't re-calculate since * the object & bone view locking takes 'rect' into account, see: T51629. */ - ED_view3d_draw_setup_view(vc->win, eval_ctx, scene, ar, v3d, vc->rv3d->viewmat, NULL, &rect); + ED_view3d_draw_setup_view(vc->win, graph, scene, ar, v3d, vc->rv3d->viewmat, NULL, &rect); if (v3d->drawtype > OB_WIRE) { v3d->zbuf = true; @@ -1024,7 +1022,7 @@ int view3d_opengl_select( #endif /* WITH_OPENGL_LEGACY */ G.f &= ~G_PICKSEL; - ED_view3d_draw_setup_view(vc->win, eval_ctx, scene, ar, v3d, vc->rv3d->viewmat, NULL, NULL); + ED_view3d_draw_setup_view(vc->win, graph, scene, ar, v3d, vc->rv3d->viewmat, NULL, NULL); if (v3d->drawtype > OB_WIRE) { v3d->zbuf = 0; @@ -1234,7 +1232,7 @@ static int game_engine_exec(bContext *C, wmOperator *op) (startscene->gm.framing.type == SCE_GAMEFRAMING_BARS) && (startscene->gm.stereoflag != STEREO_DOME)) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); /* Letterbox */ rctf cam_framef; ED_view3d_calc_camera_border(startscene, depsgraph, ar, CTX_wm_view3d(C), rv3d, &cam_framef, false); @@ -1276,7 +1274,7 @@ static int game_engine_exec(bContext *C, wmOperator *op) //XXX restore_all_scene_cfra(scene_cfra_store); BKE_scene_set_background(CTX_data_main(C), startscene); - //XXX BKE_scene_graph_update_for_newframe(bmain->eval_ctx, bmain, scene, depsgraph); + //XXX BKE_scene_graph_update_for_newframe(depsgraph, bmain); BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_POST); diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c index 3bf0e579bb3..ef63f647ec8 100644 --- a/source/blender/editors/space_view3d/view3d_walk.c +++ b/source/blender/editors/space_view3d/view3d_walk.c @@ -249,9 +249,8 @@ typedef struct WalkInfo { RegionView3D *rv3d; View3D *v3d; ARegion *ar; - const struct Depsgraph *depsgraph; + struct Depsgraph *depsgraph; Scene *scene; - ViewLayer *view_layer; wmTimer *timer; /* needed for redraws */ @@ -509,16 +508,12 @@ static float userdef_speed = -1.f; static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op) { wmWindow *win = CTX_wm_window(C); - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); walk->rv3d = CTX_wm_region_view3d(C); walk->v3d = CTX_wm_view3d(C); walk->ar = CTX_wm_region(C); walk->depsgraph = CTX_data_depsgraph(C); walk->scene = CTX_data_scene(C); - walk->view_layer = CTX_data_view_layer(C); #ifdef NDOF_WALK_DEBUG puts("\n-- walk begin --"); @@ -607,11 +602,11 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op) walk->rv3d->rflag |= RV3D_NAVIGATING; walk->snap_context = ED_transform_snap_object_context_create_view3d( - CTX_data_main(C), walk->scene, walk->view_layer, 0, + CTX_data_main(C), walk->scene, 0, walk->ar, walk->v3d); walk->v3d_camera_control = ED_view3d_cameracontrol_acquire( - &eval_ctx, walk->scene, walk->v3d, walk->rv3d, + walk->depsgraph, walk->scene, walk->v3d, walk->rv3d, (U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0); /* center the mouse */ diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 3aeb38970d2..3752d7f6c26 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -110,7 +110,7 @@ static void drawEdgeSlide(TransInfo *t); static void drawVertSlide(TransInfo *t); static void postInputRotation(TransInfo *t, float values[3]); -static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], const short around); +static void ElementRotation(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3], const short around); static void initSnapSpatial(TransInfo *t, float r_snap[3]); @@ -211,7 +211,8 @@ static bool transdata_check_local_center(TransInfo *t, short around) { return ((around == V3D_AROUND_LOCAL_ORIGINS) && ( (t->flag & (T_OBJECT | T_POSE)) || - (t->obedit && ELEM(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)) || + /* implicit: (t->flag & T_EDIT) */ + (ELEM(t->obedit_type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)) || (t->spacetype == SPACE_IPO) || (t->options & (CTX_MOVIECLIP | CTX_MASK | CTX_PAINT_CURVE))) ); @@ -220,7 +221,7 @@ static bool transdata_check_local_center(TransInfo *t, short around) bool transdata_check_local_islands(TransInfo *t, short around) { return ((around == V3D_AROUND_LOCAL_ORIGINS) && ( - (t->obedit && ELEM(t->obedit->type, OB_MESH)))); + (ELEM(t->obedit_type, OB_MESH)))); } /* ************************** SPACE DEPENDANT CODE **************************** */ @@ -245,6 +246,7 @@ void setTransformViewMatrices(TransInfo *t) } calculateCenter2D(t); + calculateCenterLocal(t, t->center_global); } void setTransformViewAspect(TransInfo *t, float r_aspect[3]) @@ -619,8 +621,12 @@ static void viewRedrawForce(const bContext *C, TransInfo *t) else { // XXX how to deal with lock? SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first; - if (sima->lock) WM_event_add_notifier(C, NC_GEOM | ND_DATA, t->obedit->data); - else ED_area_tag_redraw(t->sa); + if (sima->lock) { + WM_event_add_notifier(C, NC_GEOM | ND_DATA, OBEDIT_FROM_VIEW_LAYER(t->view_layer)->data); + } + else { + ED_area_tag_redraw(t->sa); + } } } else if (t->spacetype == SPACE_CLIP) { @@ -1024,7 +1030,7 @@ int transformEvent(TransInfo *t, const wmEvent *event) handled = true; } else { - if (t->obedit && t->obedit->type == OB_MESH) { + if (t->obedit_type == OB_MESH) { if ((t->mode == TFM_TRANSLATION) && (t->spacetype == SPACE_VIEW3D)) { restoreTransObjects(t); resetTransModal(t); @@ -1570,7 +1576,7 @@ bool calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], floa t->around = centerMode; // override userdefined mode - if (t->total == 0) { + if (t->data_len_all == 0) { success = false; } else { @@ -1971,7 +1977,7 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) ts->proportional_fcurve = proportional; else if (t->spacetype == SPACE_ACTION) ts->proportional_action = proportional; - else if (t->obedit) + else if (t->obedit_type != -1) ts->proportional = proportional; else if (t->options & CTX_MASK) ts->proportional_mask = (proportional != PROP_EDIT_OFF); @@ -2161,7 +2167,7 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve createTransData(C, t); // make TransData structs from selection - if (t->total == 0) { + if (t->data_len_all == 0) { postTrans(C, t); return 0; } @@ -2265,7 +2271,9 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve break; case TFM_BONESIZE: { /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */ - bArmature *arm = t->poseobj->data; + /* Note: we have to pick one, use the active object. */ + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_OK(t); + bArmature *arm = tc->poseobj->data; if (arm->drawtype == ARM_ENVELOPE) { initBoneEnvelope(t); t->mode = TFM_BONE_ENVELOPE_DIST; @@ -2663,7 +2671,7 @@ static void constraintTransLim(TransInfo *t, TransData *td) } /* get constraint targets if needed */ - BKE_constraint_targets_for_solving_get(&t->eval_ctx, con, &cob, &targets, ctime); + BKE_constraint_targets_for_solving_get(t->depsgraph, con, &cob, &targets, ctime); /* do constraint */ cti->evaluate_constraint(con, &cob, &targets); @@ -2870,6 +2878,7 @@ static void constraintSizeLim(TransInfo *t, TransData *td) * \{ */ struct BendCustomData { + /* All values are in global space. */ float warp_sta[3]; float warp_end[3]; @@ -2910,9 +2919,9 @@ static void initBend(TransInfo *t) //copy_v3_v3(t->center, ED_view3d_cursor3d_get(t->scene, t->view)); if ((t->flag & T_OVERRIDE_CENTER) == 0) { - calculateCenterCursor(t, t->center); + calculateCenterCursor(t, t->center_global); } - calculateCenterGlobal(t, t->center, t->center_global); + calculateCenterLocal(t, t->center_global); t->val = 0.0f; @@ -2923,10 +2932,6 @@ static void initBend(TransInfo *t) ED_view3d_win_to_3d(t->sa->spacedata.first, t->ar, curs, mval_fl, data->warp_end); copy_v3_v3(data->warp_nor, t->viewinv[2]); - if (t->flag & T_EDIT) { - sub_v3_v3(data->warp_sta, t->obedit->obmat[3]); - sub_v3_v3(data->warp_end, t->obedit->obmat[3]); - } normalize_v3(data->warp_nor); /* tangent */ @@ -2953,10 +2958,9 @@ static eRedrawFlag handleEventBend(TransInfo *UNUSED(t), const wmEvent *event) static void Bend(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float vec[3]; - float pivot[3]; - float warp_end_radius[3]; + float pivot_global[3]; + float warp_end_radius_global[3]; int i; char str[UI_MAX_DRAW_STR]; const struct BendCustomData *data = t->custom.mode.data; @@ -3011,66 +3015,89 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2])) values.scale *= data->warp_init_dist; /* calc 'data->warp_end' from 'data->warp_end_init' */ - copy_v3_v3(warp_end_radius, data->warp_end); - dist_ensure_v3_v3fl(warp_end_radius, data->warp_sta, values.scale); + copy_v3_v3(warp_end_radius_global, data->warp_end); + dist_ensure_v3_v3fl(warp_end_radius_global, data->warp_sta, values.scale); /* done */ /* calculate pivot */ - copy_v3_v3(pivot, data->warp_sta); + copy_v3_v3(pivot_global, data->warp_sta); if (values.angle > 0.0f) { - madd_v3_v3fl(pivot, data->warp_tan, -values.scale * shell_angle_to_dist((float)M_PI_2 - values.angle)); + madd_v3_v3fl(pivot_global, data->warp_tan, -values.scale * shell_angle_to_dist((float)M_PI_2 - values.angle)); } else { - madd_v3_v3fl(pivot, data->warp_tan, +values.scale * shell_angle_to_dist((float)M_PI_2 + values.angle)); + madd_v3_v3fl(pivot_global, data->warp_tan, +values.scale * shell_angle_to_dist((float)M_PI_2 + values.angle)); } - for (i = 0; i < t->total; i++, td++) { - float mat[3][3]; - float delta[3]; - float fac, fac_scaled; + /* TODO(campbell): xform, compensate object center. */ + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; + float warp_sta_local[3]; + float warp_end_local[3]; + float warp_end_radius_local[3]; + float pivot_local[3]; - if (UNLIKELY(values.angle == 0.0f)) { - copy_v3_v3(td->loc, td->iloc); - continue; + if (t->flag & T_EDIT) { + sub_v3_v3v3(warp_sta_local, data->warp_sta, tc->obedit->obmat[3]); + sub_v3_v3v3(warp_end_local, data->warp_end, tc->obedit->obmat[3]); + sub_v3_v3v3(warp_end_radius_local, warp_end_radius_global, tc->obedit->obmat[3]); + sub_v3_v3v3(pivot_local, pivot_global, tc->obedit->obmat[3]); + } + else { + copy_v3_v3(warp_sta_local, data->warp_sta); + copy_v3_v3(warp_end_local, data->warp_end); + copy_v3_v3(warp_end_radius_local, warp_end_radius_global); + copy_v3_v3(pivot_local, pivot_global); } - copy_v3_v3(vec, td->iloc); - mul_m3_v3(td->mtx, vec); + for (i = 0; i < tc->data_len; i++, td++) { + float mat[3][3]; + float delta[3]; + float fac, fac_scaled; - fac = line_point_factor_v3(vec, data->warp_sta, warp_end_radius); - if (is_clamp) { - CLAMP(fac, 0.0f, 1.0f); - } + if (td->flag & TD_NOACTION) + break; - fac_scaled = fac * td->factor; - axis_angle_normalized_to_mat3(mat, data->warp_nor, values.angle * fac_scaled); - interp_v3_v3v3(delta, data->warp_sta, warp_end_radius, fac_scaled); - sub_v3_v3(delta, data->warp_sta); + if (td->flag & TD_SKIP) + continue; - /* delta is subtracted, rotation adds back this offset */ - sub_v3_v3(vec, delta); + if (UNLIKELY(values.angle == 0.0f)) { + copy_v3_v3(td->loc, td->iloc); + continue; + } - sub_v3_v3(vec, pivot); - mul_m3_v3(mat, vec); - add_v3_v3(vec, pivot); + copy_v3_v3(vec, td->iloc); + mul_m3_v3(td->mtx, vec); - mul_m3_v3(td->smtx, vec); + fac = line_point_factor_v3(vec, warp_sta_local, warp_end_radius_local); + if (is_clamp) { + CLAMP(fac, 0.0f, 1.0f); + } - /* rotation */ - if ((t->flag & T_POINTS) == 0) { - ElementRotation(t, td, mat, V3D_AROUND_LOCAL_ORIGINS); - } + fac_scaled = fac * td->factor; + axis_angle_normalized_to_mat3(mat, data->warp_nor, values.angle * fac_scaled); + interp_v3_v3v3(delta, warp_sta_local, warp_end_radius_local, fac_scaled); + sub_v3_v3(delta, warp_sta_local); - /* location */ - copy_v3_v3(td->loc, vec); + /* delta is subtracted, rotation adds back this offset */ + sub_v3_v3(vec, delta); + + sub_v3_v3(vec, pivot_local); + mul_m3_v3(mat, vec); + add_v3_v3(vec, pivot_local); + + mul_m3_v3(td->smtx, vec); + + /* rotation */ + if ((t->flag & T_POINTS) == 0) { + ElementRotation(t, tc, td, mat, V3D_AROUND_LOCAL_ORIGINS); + } + + /* location */ + copy_v3_v3(td->loc, vec); + } } - + recalcData(t); ED_area_headerprint(t->sa, str); @@ -3141,7 +3168,6 @@ static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event) static void applyShear(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float vec[3]; float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3]; float value; @@ -3184,45 +3210,48 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2])) mul_m3_m3m3(tmat, smat, persmat); mul_m3_m3m3(totmat, persinv, tmat); - for (i = 0; i < t->total; i++, td++) { - const float *center, *co; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + const float *center, *co; - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - - if (t->obedit) { - float mat3[3][3]; - mul_m3_m3m3(mat3, totmat, td->mtx); - mul_m3_m3m3(tmat, td->smtx, mat3); - } - else { - copy_m3_m3(tmat, totmat); - } + if (td->flag & TD_NOACTION) + break; - if (is_local_center) { - center = td->center; - co = td->loc; - } - else { - center = t->center; - co = td->center; - } + if (td->flag & TD_SKIP) + continue; - sub_v3_v3v3(vec, co, center); - - mul_m3_v3(tmat, vec); - - add_v3_v3(vec, center); - sub_v3_v3(vec, co); - - mul_v3_fl(vec, td->factor); - - add_v3_v3v3(td->loc, td->iloc, vec); + if (t->flag & T_EDIT) { + float mat3[3][3]; + mul_m3_m3m3(mat3, totmat, td->mtx); + mul_m3_m3m3(tmat, td->smtx, mat3); + } + else { + copy_m3_m3(tmat, totmat); + } + + if (is_local_center) { + center = td->center; + co = td->loc; + } + else { + center = tc->center_local; + co = td->center; + } + + sub_v3_v3v3(vec, co, center); + + mul_m3_v3(tmat, vec); + + add_v3_v3(vec, center); + sub_v3_v3(vec, co); + + mul_v3_fl(vec, td->factor); + + add_v3_v3v3(td->loc, td->iloc, vec); + } } - + recalcData(t); ED_area_headerprint(t->sa, str); @@ -3248,7 +3277,7 @@ static void initResize(TransInfo *t) t->num.val_flag[1] |= NUM_NULL_ONE; t->num.val_flag[2] |= NUM_NULL_ONE; t->num.flag |= NUM_AFFECT_ALL; - if (!t->obedit) { + if ((t->flag & T_EDIT) == 0) { t->flag |= T_NO_ZERO; #ifdef USE_NUM_NO_ZERO t->num.val_flag[0] |= NUM_NO_ZERO; @@ -3332,7 +3361,7 @@ static void TransMat3ToSize(float mat[3][3], float smat[3][3], float size[3]) if (dot_v3v3(rmat[2], smat[2]) < 0.0f) size[2] = -size[2]; } -static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) +static void ElementResize(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3]) { float tmat[3][3], smat[3][3], center[3]; float vec[3]; @@ -3346,7 +3375,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) } if (t->con.applySize) { - t->con.applySize(t, td, tmat); + t->con.applySize(t, tc, td, tmat); } /* local constraint shouldn't alter center */ @@ -3358,11 +3387,11 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) copy_v3_v3(center, td->center); } else { - copy_v3_v3(center, t->center); + copy_v3_v3(center, tc->center_local); } } else { - copy_v3_v3(center, t->center); + copy_v3_v3(center, tc->center_local); } if (td->ext) { @@ -3435,7 +3464,6 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3]) static void applyResize(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td; float mat[3][3]; int i; char str[UI_MAX_DRAW_STR]; @@ -3460,39 +3488,46 @@ static void applyResize(TransInfo *t, const int UNUSED(mval[2])) size_to_mat3(mat, t->values); if (t->con.applySize) { - t->con.applySize(t, NULL, mat); + t->con.applySize(t, NULL, NULL, mat); } copy_m3_m3(t->mat, mat); // used in manipulator headerResize(t, t->values, str); - - for (i = 0, td = t->data; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - - ElementResize(t, td, mat); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + ElementResize(t, tc, td, mat); + } } - + /* evil hack - redo resize if cliping needed */ if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 1)) { size_to_mat3(mat, t->values); - + if (t->con.applySize) - t->con.applySize(t, NULL, mat); - - for (i = 0, td = t->data; i < t->total; i++, td++) - ElementResize(t, td, mat); + t->con.applySize(t, NULL, NULL, mat); - /* In proportional edit it can happen that */ - /* vertices in the radius of the brush end */ - /* outside the clipping area */ - /* XXX HACK - dg */ - if (t->flag & T_PROP_EDIT_ALL) { - clipUVData(t); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) + ElementResize(t, tc, td, mat); + + /* In proportional edit it can happen that */ + /* vertices in the radius of the brush end */ + /* outside the clipping area */ + /* XXX HACK - dg */ + if (t->flag & T_PROP_EDIT_ALL) { + clipUVData(t); + } } } @@ -3521,7 +3556,7 @@ static void initSkinResize(TransInfo *t) t->num.val_flag[1] |= NUM_NULL_ONE; t->num.val_flag[2] |= NUM_NULL_ONE; t->num.flag |= NUM_AFFECT_ALL; - if (!t->obedit) { + if ((t->flag & T_EDIT) == 0) { t->flag |= T_NO_ZERO; #ifdef USE_NUM_NO_ZERO t->num.val_flag[0] |= NUM_NO_ZERO; @@ -3545,7 +3580,6 @@ static void initSkinResize(TransInfo *t) static void applySkinResize(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td; float size[3], mat[3][3]; int i; char str[UI_MAX_DRAW_STR]; @@ -3569,34 +3603,37 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2])) size_to_mat3(mat, size); headerResize(t, size, str); - - for (i = 0, td = t->data; i < t->total; i++, td++) { - float tmat[3][3], smat[3][3]; - float fsize[3]; - - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - if (t->flag & T_EDIT) { - mul_m3_m3m3(smat, mat, td->mtx); - mul_m3_m3m3(tmat, td->smtx, smat); - } - else { - copy_m3_m3(tmat, mat); - } - - if (t->con.applySize) { - t->con.applySize(t, NULL, tmat); - } + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + float tmat[3][3], smat[3][3]; + float fsize[3]; + + if (td->flag & TD_NOACTION) + break; - mat3_to_size(fsize, tmat); - td->val[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor); - td->val[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor); + if (td->flag & TD_SKIP) + continue; + + if (t->flag & T_EDIT) { + mul_m3_m3m3(smat, mat, td->mtx); + mul_m3_m3m3(tmat, td->smtx, smat); + } + else { + copy_m3_m3(tmat, mat); + } + + if (t->con.applySize) { + t->con.applySize(t, NULL, NULL, tmat); + } + + mat3_to_size(fsize, tmat); + td->val[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor); + td->val[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor); + } } - + recalcData(t); ED_area_headerprint(t->sa, str); @@ -3612,7 +3649,6 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2])) static void initToSphere(TransInfo *t) { - TransData *td = t->data; int i; t->mode = TFM_TOSPHERE; @@ -3632,13 +3668,16 @@ static void initToSphere(TransInfo *t) t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE; t->flag |= T_NO_CONSTRAINT; - + // Calculate average radius - for (i = 0; i < t->total; i++, td++) { - t->val += len_v3v3(t->center, td->iloc); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + t->val += len_v3v3(tc->center_local, td->iloc); + } } - - t->val /= (float)t->total; + + t->val /= (float)t->data_len_all; } static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) @@ -3647,8 +3686,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) float ratio, radius; int i; char str[UI_MAX_DRAW_STR]; - TransData *td = t->data; - + ratio = t->values[0]; snapGridIncrement(t, &ratio); @@ -3671,28 +3709,29 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) /* default header print */ BLI_snprintf(str, sizeof(str), IFACE_("To Sphere: %.4f %s"), ratio, t->proptext); } - - - for (i = 0; i < t->total; i++, td++) { - float tratio; - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - - sub_v3_v3v3(vec, td->iloc, t->center); - - radius = normalize_v3(vec); - - tratio = ratio * td->factor; - - mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio); - - add_v3_v3v3(td->loc, t->center, vec); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + float tratio; + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + sub_v3_v3v3(vec, td->iloc, tc->center_local); + + radius = normalize_v3(vec); + + tratio = ratio * td->factor; + + mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio); + + add_v3_v3v3(td->loc, tc->center_local, vec); + } } - - + recalcData(t); ED_area_headerprint(t->sa, str); @@ -3709,7 +3748,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) static void postInputRotation(TransInfo *t, float values[3]) { if ((t->con.mode & CON_APPLY) && t->con.applyRot) { - t->con.applyRot(t, NULL, t->axis, values); + t->con.applyRot(t, NULL, NULL, t->axis, values); } } @@ -3754,7 +3793,7 @@ static void initRotation(TransInfo *t) * * Protected axis and other transform settings are taken into account. */ -static void ElementRotation_ex(TransInfo *t, TransData *td, float mat[3][3], const float *center) +static void ElementRotation_ex(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3], const float *center) { float vec[3], totmat[3][3], smat[3][3]; float eul[3], fmat[3][3], quat[4]; @@ -3801,7 +3840,7 @@ static void ElementRotation_ex(TransInfo *t, TransData *td, float mat[3][3], con float pmtx[3][3], imtx[3][3]; // Extract and invert armature object matrix - copy_m3_m4(pmtx, t->poseobj->obmat); + copy_m3_m4(pmtx, tc->poseobj->obmat); invert_m3_m3(imtx, pmtx); if ((td->flag & TD_NO_LOC) == 0) { @@ -3967,7 +4006,7 @@ static void ElementRotation_ex(TransInfo *t, TransData *td, float mat[3][3], con } } -static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], const short around) +static void ElementRotation(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3], const short around) { const float *center; @@ -3976,37 +4015,39 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], const center = td->center; } else { - center = t->center; + center = tc->center_local; } - ElementRotation_ex(t, td, mat, center); + ElementRotation_ex(t, tc, td, mat, center); } static void applyRotationValue(TransInfo *t, float angle, float axis[3]) { - TransData *td = t->data; float mat[3][3]; int i; axis_angle_normalized_to_mat3(mat, axis, angle); - - for (i = 0; i < t->total; i++, td++) { - - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - - if (t->con.applyRot) { - t->con.applyRot(t, td, axis, NULL); - axis_angle_normalized_to_mat3(mat, axis, angle * td->factor); - } - else if (t->flag & T_PROP_EDIT) { - axis_angle_normalized_to_mat3(mat, axis, angle * td->factor); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + if (t->con.applyRot) { + t->con.applyRot(t, tc, td, axis, NULL); + axis_angle_normalized_to_mat3(mat, axis, angle * td->factor); + } + else if (t->flag & T_PROP_EDIT) { + axis_angle_normalized_to_mat3(mat, axis, angle * td->factor); + } + + ElementRotation(t, tc, td, mat, t->around); } - - ElementRotation(t, td, mat, t->around); } } @@ -4022,7 +4063,7 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2])) snapGridIncrement(t, &final); if ((t->con.mode & CON_APPLY) && t->con.applyRot) { - t->con.applyRot(t, NULL, t->axis, NULL); + t->con.applyRot(t, NULL, NULL, t->axis, NULL); } else { /* reset axis if constraint is not set */ @@ -4091,7 +4132,6 @@ static void initTrackball(TransInfo *t) static void applyTrackballValue(TransInfo *t, const float axis1[3], const float axis2[3], float angles[2]) { - TransData *td = t->data; float mat[3][3]; float axis[3]; float angle; @@ -4102,18 +4142,21 @@ static void applyTrackballValue(TransInfo *t, const float axis1[3], const float angle = normalize_v3(axis); axis_angle_normalized_to_mat3(mat, axis, angle); - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - if (t->flag & T_PROP_EDIT) { - axis_angle_normalized_to_mat3(mat, axis, td->factor * angle); - } + if (t->flag & T_PROP_EDIT) { + axis_angle_normalized_to_mat3(mat, axis, td->factor * angle); + } - ElementRotation(t, td, mat, t->around); + ElementRotation(t, tc, td, mat, t->around); + } } } @@ -4368,81 +4411,84 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_ static void applyTranslationValue(TransInfo *t, const float vec[3]) { - TransData *td = t->data; + const bool apply_snap_align_rotation = usingSnappingNormal(t);// && (t->tsnap.status & POINT_INIT); float tvec[3]; /* The ideal would be "apply_snap_align_rotation" only when a snap point is found * so, maybe inside this function is not the best place to apply this rotation. * but you need "handle snapping rotation before doing the translation" (really?) */ - const bool apply_snap_align_rotation = usingSnappingNormal(t);// && (t->tsnap.status & POINT_INIT); - float pivot[3]; - if (apply_snap_align_rotation) { - copy_v3_v3(pivot, t->tsnap.snapTarget); - /* The pivot has to be in local-space (see T49494) */ - if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - mul_m4_v3(ob->imat, pivot); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + + float pivot[3]; + if (apply_snap_align_rotation) { + copy_v3_v3(pivot, t->tsnap.snapTarget); + /* The pivot has to be in local-space (see T49494) */ + if (t->flag & (T_EDIT | T_POSE)) { + Object *ob = tc->obedit ? tc->obedit : tc->poseobj; + mul_m4_v3(ob->imat, pivot); + } } - } - for (int i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; + TransData *td = tc->data; + for (int i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - float rotate_offset[3] = {0}; - bool use_rotate_offset = false; + if (td->flag & TD_SKIP) + continue; - /* handle snapping rotation before doing the translation */ - if (apply_snap_align_rotation) { - float mat[3][3]; + float rotate_offset[3] = {0}; + bool use_rotate_offset = false; - if (validSnappingNormal(t)) { - const float *original_normal; + /* handle snapping rotation before doing the translation */ + if (apply_snap_align_rotation) { + float mat[3][3]; - /* In pose mode, we want to align normals with Y axis of bones... */ - if (t->flag & T_POSE) - original_normal = td->axismtx[1]; - else - original_normal = td->axismtx[2]; + if (validSnappingNormal(t)) { + const float *original_normal; - rotation_between_vecs_to_mat3(mat, original_normal, t->tsnap.snapNormal); + /* In pose mode, we want to align normals with Y axis of bones... */ + if (t->flag & T_POSE) + original_normal = td->axismtx[1]; + else + original_normal = td->axismtx[2]; + + rotation_between_vecs_to_mat3(mat, original_normal, t->tsnap.snapNormal); + } + else { + unit_m3(mat); + } + + ElementRotation_ex(t, tc, td, mat, pivot); + + if (td->loc) { + use_rotate_offset = true; + sub_v3_v3v3(rotate_offset, td->loc, td->iloc); + } + } + + if (t->con.applyVec) { + float pvec[3]; + t->con.applyVec(t, tc, td, vec, tvec, pvec); } else { - unit_m3(mat); + copy_v3_v3(tvec, vec); } - ElementRotation_ex(t, td, mat, pivot); - - if (td->loc) { - use_rotate_offset = true; - sub_v3_v3v3(rotate_offset, td->loc, td->iloc); + if (use_rotate_offset) { + add_v3_v3(tvec, rotate_offset); } - } - if (t->con.applyVec) { - float pvec[3]; - t->con.applyVec(t, td, vec, tvec, pvec); - } - else { - copy_v3_v3(tvec, vec); - } + mul_m3_v3(td->smtx, tvec); + mul_v3_fl(tvec, td->factor); - if (use_rotate_offset) { - add_v3_v3(tvec, rotate_offset); - } - - mul_m3_v3(td->smtx, tvec); - mul_v3_fl(tvec, td->factor); - - protectedTransBits(td->protectflag, tvec); - - if (td->loc) - add_v3_v3v3(td->loc, td->iloc, tvec); + protectedTransBits(td->protectflag, tvec); - constraintTransLim(t, td); + if (td->loc) + add_v3_v3v3(td->loc, td->iloc, tvec); + + constraintTransLim(t, td); + } } } @@ -4468,7 +4514,7 @@ static void applyTranslation(TransInfo *t, const int UNUSED(mval[2])) if (t->con.mode & CON_APPLY) { float pvec[3] = {0.0f, 0.0f, 0.0f}; - t->con.applyVec(t, NULL, t->values, value_final, pvec); + t->con.applyVec(t, NULL, NULL, t->values, value_final, pvec); headerTranslation(t, pvec, str); /* only so we have re-usable value with redo, see T46741. */ @@ -4512,7 +4558,7 @@ static void applyTranslation(TransInfo *t, const int UNUSED(mval[2])) static void initShrinkFatten(TransInfo *t) { // If not in mesh edit mode, fallback to Resize - if (t->obedit == NULL || t->obedit->type != OB_MESH) { + if ((t->flag & T_EDIT) == 0 || (t->obedit_type != OB_MESH)) { initResize(t); } else { @@ -4542,7 +4588,6 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) int i; char str[UI_MAX_DRAW_STR]; size_t ofs = 0; - TransData *td = t->data; distance = -t->values[0]; @@ -4579,21 +4624,24 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0)); /* done with header string */ - for (i = 0; i < t->total; i++, td++) { - float tdistance; /* temp dist */ - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + float tdistance; /* temp dist */ + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - /* get the final offset */ - tdistance = distance * td->factor; - if (td->ext && (t->flag & T_ALT_TRANSFORM)) { - tdistance *= td->ext->isize[0]; /* shell factor */ - } + /* get the final offset */ + tdistance = distance * td->factor; + if (td->ext && (t->flag & T_ALT_TRANSFORM)) { + tdistance *= td->ext->isize[0]; /* shell factor */ + } - madd_v3_v3v3fl(td->loc, td->iloc, td->axismtx[2], tdistance); + madd_v3_v3v3fl(td->loc, td->iloc, td->axismtx[2], tdistance); + } } recalcData(t); @@ -4633,7 +4681,6 @@ static void initTilt(TransInfo *t) static void applyTilt(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; int i; char str[UI_MAX_DRAW_STR]; @@ -4661,15 +4708,18 @@ static void applyTilt(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Tilt: %.2f° %s"), RAD2DEGF(final), t->proptext); } - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - if (td->val) { - *td->val = td->ival + final * td->factor; + if (td->val) { + *td->val = td->ival + final * td->factor; + } } } @@ -4713,7 +4763,6 @@ static void initCurveShrinkFatten(TransInfo *t) static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float ratio; int i; char str[UI_MAX_DRAW_STR]; @@ -4737,18 +4786,21 @@ static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %3f"), ratio); } - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - if (td->val) { - *td->val = td->ival * ratio; - /* apply PET */ - *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); - if (*td->val <= 0.0f) *td->val = 0.001f; + if (td->val) { + *td->val = td->ival * ratio; + /* apply PET */ + *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); + if (*td->val <= 0.0f) *td->val = 0.001f; + } } } @@ -4792,7 +4844,6 @@ static void initMaskShrinkFatten(TransInfo *t) static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td; float ratio; int i; bool initial_feather = false; @@ -4821,35 +4872,41 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) if (ratio > 1.0f) { initial_feather = true; - for (td = t->data, i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - if (td->ival >= 0.001f) - initial_feather = false; + if (td->ival >= 0.001f) + initial_feather = false; + } } } /* apply shrink/fatten */ - for (td = t->data, i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (td = tc->data, i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - if (td->val) { - if (initial_feather) - *td->val = td->ival + (ratio - 1.0f) * 0.01f; - else - *td->val = td->ival * ratio; + if (td->val) { + if (initial_feather) + *td->val = td->ival + (ratio - 1.0f) * 0.01f; + else + *td->val = td->ival * ratio; - /* apply PET */ - *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); - if (*td->val <= 0.0f) *td->val = 0.001f; + /* apply PET */ + *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); + if (*td->val <= 0.0f) *td->val = 0.001f; + } } } @@ -4893,7 +4950,6 @@ static void initGPShrinkFatten(TransInfo *t) static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float ratio; int i; char str[UI_MAX_DRAW_STR]; @@ -4917,18 +4973,21 @@ static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %3f"), ratio); } - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - if (td->val) { - *td->val = td->ival * ratio; - /* apply PET */ - *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); - if (*td->val <= 0.0f) *td->val = 0.001f; + if (td->val) { + *td->val = td->ival * ratio; + /* apply PET */ + *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival); + if (*td->val <= 0.0f) *td->val = 0.001f; + } } } @@ -4970,7 +5029,6 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2])) float distance; int i; char str[UI_MAX_DRAW_STR]; - TransData *td = t->data; distance = t->values[0]; @@ -4994,35 +5052,38 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2])) } if (t->con.applyRot && t->con.mode & CON_APPLY) { - t->con.applyRot(t, NULL, axis_global, NULL); + t->con.applyRot(t, NULL, NULL, axis_global, NULL); } - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - sub_v3_v3v3(vec, t->center, td->center); - if (t->con.applyRot && t->con.mode & CON_APPLY) { - float axis[3]; - copy_v3_v3(axis, axis_global); - t->con.applyRot(t, td, axis, NULL); + if (td->flag & TD_SKIP) + continue; - mul_m3_v3(td->smtx, axis); - if (isLockConstraint(t)) { - float dvec[3]; - project_v3_v3v3(dvec, vec, axis); - sub_v3_v3(vec, dvec); - } - else { - project_v3_v3v3(vec, vec, axis); + sub_v3_v3v3(vec, tc->center_local, td->center); + if (t->con.applyRot && t->con.mode & CON_APPLY) { + float axis[3]; + copy_v3_v3(axis, axis_global); + t->con.applyRot(t, tc, td, axis, NULL); + + mul_m3_v3(td->smtx, axis); + if (isLockConstraint(t)) { + float dvec[3]; + project_v3_v3v3(dvec, vec, axis); + sub_v3_v3(vec, dvec); + } + else { + project_v3_v3v3(vec, vec, axis); + } } - } - normalize_v3_length(vec, distance * td->factor); + normalize_v3_length(vec, distance * td->factor); - add_v3_v3v3(td->loc, td->iloc, vec); + add_v3_v3v3(td->loc, td->iloc, vec); + } } recalcData(t); @@ -5060,7 +5121,6 @@ static void initBevelWeight(TransInfo *t) static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float weight; int i; char str[UI_MAX_DRAW_STR]; @@ -5094,14 +5154,17 @@ static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: %.3f %s"), weight, t->proptext); } - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->val) { - *td->val = td->ival + weight * td->factor; - if (*td->val < 0.0f) *td->val = 0.0f; - if (*td->val > 1.0f) *td->val = 1.0f; + if (td->val) { + *td->val = td->ival + weight * td->factor; + if (*td->val < 0.0f) *td->val = 0.0f; + if (*td->val > 1.0f) *td->val = 1.0f; + } } } @@ -5140,7 +5203,6 @@ static void initCrease(TransInfo *t) static void applyCrease(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float crease; int i; char str[UI_MAX_DRAW_STR]; @@ -5174,17 +5236,20 @@ static void applyCrease(TransInfo *t, const int UNUSED(mval[2])) BLI_snprintf(str, sizeof(str), IFACE_("Crease: %.3f %s"), crease, t->proptext); } - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - if (td->val) { - *td->val = td->ival + crease * td->factor; - if (*td->val < 0.0f) *td->val = 0.0f; - if (*td->val > 1.0f) *td->val = 1.0f; + if (td->val) { + *td->val = td->ival + crease * td->factor; + if (*td->val < 0.0f) *td->val = 0.0f; + if (*td->val > 1.0f) *td->val = 1.0f; + } } } @@ -5251,7 +5316,7 @@ static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRA } } -static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3]) +static void ElementBoneSize(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3]) { float tmat[3][3], smat[3][3], oldy; float sizemat[3][3]; @@ -5260,7 +5325,7 @@ static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3]) mul_m3_m3m3(tmat, td->smtx, smat); if (t->con.applySize) { - t->con.applySize(t, td, tmat); + t->con.applySize(t, tc, td, tmat); } /* we've tucked the scale in loc */ @@ -5273,7 +5338,6 @@ static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3]) static void applyBoneSize(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float size[3], mat[3][3]; float ratio = t->values[0]; int i; @@ -5292,23 +5356,26 @@ static void applyBoneSize(TransInfo *t, const int UNUSED(mval[2])) size_to_mat3(mat, size); if (t->con.applySize) { - t->con.applySize(t, NULL, mat); + t->con.applySize(t, NULL, NULL, mat); } copy_m3_m3(t->mat, mat); // used in manipulator headerBoneSize(t, size, str); - - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - - ElementBoneSize(t, td, mat); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + ElementBoneSize(t, tc, td, mat); + } } - + recalcData(t); ED_area_headerprint(t->sa, str); @@ -5344,7 +5411,6 @@ static void initBoneEnvelope(TransInfo *t) static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float ratio; int i; char str[UI_MAX_DRAW_STR]; @@ -5367,23 +5433,26 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) else { BLI_snprintf(str, sizeof(str), IFACE_("Envelope: %3f"), ratio); } - - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - - if (td->val) { - /* if the old/original value was 0.0f, then just use ratio */ - if (td->ival) - *td->val = td->ival * ratio; - else - *td->val = ratio; + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + if (td->val) { + /* if the old/original value was 0.0f, then just use ratio */ + if (td->ival) + *td->val = td->ival * ratio; + else + *td->val = ratio; + } } } - + recalcData(t); ED_area_headerprint(t->sa, str); @@ -5397,9 +5466,9 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2])) * \{ */ static void slide_origdata_init_flag( - TransInfo *t, SlideOrigData *sod) + TransInfo *t, TransDataContainer *tc, SlideOrigData *sod) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; const bool has_layer_math = CustomData_has_math(&bm->ldata); const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS); @@ -5420,10 +5489,10 @@ static void slide_origdata_init_flag( } static void slide_origdata_init_data( - TransInfo *t, SlideOrigData *sod) + TransDataContainer *tc, SlideOrigData *sod) { if (sod->use_origfaces) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; sod->origfaces = BLI_ghash_ptr_new(__func__); @@ -5484,11 +5553,11 @@ static void slide_origdata_create_data_vert( } static void slide_origdata_create_data( - TransInfo *t, SlideOrigData *sod, + TransInfo *t, TransDataContainer *tc, SlideOrigData *sod, TransDataGenericSlideVert *sv_array, unsigned int v_stride, unsigned int v_num) { if (sod->use_origfaces) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; unsigned int i; TransDataGenericSlideVert *sv; @@ -5520,15 +5589,15 @@ static void slide_origdata_create_data( } if (t->flag & T_MIRROR) { - TransData *td = t->data; + TransData *td = tc->data; TransDataGenericSlideVert *sv_mirror; - sod->sv_mirror = MEM_callocN(sizeof(*sv_mirror) * t->total, __func__); - sod->totsv_mirror = t->total; + sod->sv_mirror = MEM_callocN(sizeof(*sv_mirror) * tc->data_len, __func__); + sod->totsv_mirror = tc->data_len; sv_mirror = sod->sv_mirror; - for (i = 0; i < t->total; i++, td++) { + for (i = 0; i < tc->data_len; i++, td++) { BMVert *eve = td->extra; if (eve) { sv_mirror->v = eve; @@ -5577,7 +5646,7 @@ static void slide_origdata_interp_data_vert( project_plane_normalized_v3_v3v3(v_proj[1], sv->co_orig_3d, v_proj_axis); } - // BM_ITER_ELEM (l, &liter, sv->v, BM_LOOPS_OF_VERT) { + // BM_ITER_ELEM (l, &liter, sv->v, BM_LOOPS_OF_VERT) BM_iter_init(&liter, bm, BM_LOOPS_OF_VERT, sv->v); l_num = liter.count; loop_weights = do_loop_weight ? BLI_array_alloca(loop_weights, l_num) : NULL; @@ -5682,12 +5751,12 @@ static void slide_origdata_interp_data_vert( } static void slide_origdata_interp_data( - TransInfo *t, SlideOrigData *sod, + Object *obedit, SlideOrigData *sod, TransDataGenericSlideVert *sv, unsigned int v_stride, unsigned int v_num, bool is_final) { if (sod->use_origfaces) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + BMEditMesh *em = BKE_editmesh_from_object(obedit); BMesh *bm = em->bm; unsigned int i; const bool has_mdisps = (sod->cd_loop_mdisp_offset != -1); @@ -5750,7 +5819,7 @@ static void slide_origdata_free_date( static void calcEdgeSlideCustomPoints(struct TransInfo *t) { - EdgeSlideData *sld = t->custom.mode.data; + EdgeSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data; setCustomPoints(t, &t->mouse, sld->mval_end, sld->mval_start); @@ -5947,11 +6016,11 @@ static BMLoop *get_next_loop(BMVert *v, BMLoop *l, * Calculate screenspace `mval_start` / `mval_end`, optionally slide direction. */ static void calcEdgeSlide_mval_range( - TransInfo *t, EdgeSlideData *sld, const int *sv_table, const int loop_nr, + TransInfo *t, TransDataContainer *tc, EdgeSlideData *sld, const int *sv_table, const int loop_nr, const float mval[2], const bool use_occlude_geometry, const bool use_calc_direction) { TransDataEdgeSlideVert *sv_array = sld->sv; - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; ARegion *ar = t->ar; View3D *v3d = NULL; @@ -5978,7 +6047,7 @@ static void calcEdgeSlide_mval_range( unit_m4(projectMat); } else { - ED_view3d_ob_project_mat_get(rv3d, t->obedit, projectMat); + ED_view3d_ob_project_mat_get(rv3d, tc->obedit, projectMat); } if (use_occlude_geometry) { @@ -6021,7 +6090,7 @@ static void calcEdgeSlide_mval_range( /* This test is only relevant if object is not wire-drawn! See [#32068]. */ if (use_occlude_geometry && - !BMBVH_EdgeVisible(bmbvh, e_other, t->depsgraph, ar, v3d, t->obedit)) + !BMBVH_EdgeVisible(bmbvh, e_other, t->depsgraph, ar, v3d, tc->obedit)) { continue; } @@ -6109,7 +6178,7 @@ static void calcEdgeSlide_mval_range( } static void calcEdgeSlide_even( - TransInfo *t, EdgeSlideData *sld, const float mval[2]) + TransInfo *t, TransDataContainer *tc, EdgeSlideData *sld, const float mval[2]) { TransDataEdgeSlideVert *sv = sld->sv; @@ -6134,7 +6203,7 @@ static void calcEdgeSlide_even( unit_m4(projectMat); } else { - ED_view3d_ob_project_mat_get(rv3d, t->obedit, projectMat); + ED_view3d_ob_project_mat_get(rv3d, tc->obedit, projectMat); } for (i = 0; i < sld->totsv; i++, sv++) { @@ -6154,9 +6223,9 @@ static void calcEdgeSlide_even( } } -static bool createEdgeSlideVerts_double_side(TransInfo *t, bool use_even, bool flipped, bool use_clamp) +static bool createEdgeSlideVerts_double_side(TransInfo *t, TransDataContainer *tc) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; BMIter iter; BMEdge *e; @@ -6171,13 +6240,9 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, bool use_even, bool f View3D *v3d = NULL; RegionView3D *rv3d = NULL; - slide_origdata_init_flag(t, &sld->orig_data); + slide_origdata_init_flag(t, tc, &sld->orig_data); - sld->use_even = use_even; sld->curr_sv_index = 0; - sld->flipped = flipped; - if (!use_clamp) - t->flag |= T_ALT_TRANSFORM; /*ensure valid selection*/ BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { @@ -6493,26 +6558,24 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, bool use_even, bool f if (t->spacetype == SPACE_VIEW3D) { v3d = t->sa ? t->sa->spacedata.first : NULL; rv3d = t->ar ? t->ar->regiondata : NULL; - use_occlude_geometry = (v3d && t->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE); + use_occlude_geometry = (v3d && TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE); } - calcEdgeSlide_mval_range(t, sld, sv_table, loop_nr, mval, use_occlude_geometry, true); + calcEdgeSlide_mval_range(t, tc, sld, sv_table, loop_nr, mval, use_occlude_geometry, true); /* create copies of faces for customdata projection */ bmesh_edit_begin(bm, BMO_OPTYPE_FLAG_UNTAN_MULTIRES); - slide_origdata_init_data(t, &sld->orig_data); - slide_origdata_create_data(t, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv); + slide_origdata_init_data(tc, &sld->orig_data); + slide_origdata_create_data(t, tc, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv); if (rv3d) { - calcEdgeSlide_even(t, sld, mval); + calcEdgeSlide_even(t, tc, sld, mval); } sld->em = em; - - sld->perc = 0.0f; - - t->custom.mode.data = sld; - + + tc->custom.mode.data = sld; + MEM_freeN(sv_table); return true; @@ -6522,9 +6585,9 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, bool use_even, bool f * A simple version of #createEdgeSlideVerts_double_side * Which assumes the longest unselected. */ -static bool createEdgeSlideVerts_single_side(TransInfo *t, bool use_even, bool flipped, bool use_clamp) +static bool createEdgeSlideVerts_single_side(TransInfo *t, TransDataContainer *tc) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; BMIter iter; BMEdge *e; @@ -6544,15 +6607,9 @@ static bool createEdgeSlideVerts_single_side(TransInfo *t, bool use_even, bool f rv3d = t->ar ? t->ar->regiondata : NULL; } - slide_origdata_init_flag(t, &sld->orig_data); + slide_origdata_init_flag(t, tc, &sld->orig_data); - sld->use_even = use_even; sld->curr_sv_index = 0; - /* happens to be best for single-sided */ - sld->flipped = !flipped; - if (!use_clamp) - t->flag |= T_ALT_TRANSFORM; - /* ensure valid selection */ { int i = 0, j = 0; @@ -6696,25 +6753,23 @@ static bool createEdgeSlideVerts_single_side(TransInfo *t, bool use_even, bool f if (t->spacetype == SPACE_VIEW3D) { v3d = t->sa ? t->sa->spacedata.first : NULL; rv3d = t->ar ? t->ar->regiondata : NULL; - use_occlude_geometry = (v3d && t->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE); + use_occlude_geometry = (v3d && TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE); } - calcEdgeSlide_mval_range(t, sld, sv_table, loop_nr, mval, use_occlude_geometry, false); + calcEdgeSlide_mval_range(t, tc, sld, sv_table, loop_nr, mval, use_occlude_geometry, false); /* create copies of faces for customdata projection */ bmesh_edit_begin(bm, BMO_OPTYPE_FLAG_UNTAN_MULTIRES); - slide_origdata_init_data(t, &sld->orig_data); - slide_origdata_create_data(t, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv); + slide_origdata_init_data(tc, &sld->orig_data); + slide_origdata_create_data(t, tc, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv); if (rv3d) { - calcEdgeSlide_even(t, sld, mval); + calcEdgeSlide_even(t, tc, sld, mval); } sld->em = em; - sld->perc = 0.0f; - - t->custom.mode.data = sld; + tc->custom.mode.data = sld; MEM_freeN(sv_table); @@ -6723,14 +6778,16 @@ static bool createEdgeSlideVerts_single_side(TransInfo *t, bool use_even, bool f void projectEdgeSlideData(TransInfo *t, bool is_final) { - EdgeSlideData *sld = t->custom.mode.data; - SlideOrigData *sod = &sld->orig_data; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + EdgeSlideData *sld = tc->custom.mode.data; + SlideOrigData *sod = &sld->orig_data; - if (sod->use_origfaces == false) { - return; - } + if (sod->use_origfaces == false) { + return; + } - slide_origdata_interp_data(t, sod, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv, is_final); + slide_origdata_interp_data(tc->obedit, sod, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv, is_final); + } } void freeEdgeSlideTempFaces(EdgeSlideData *sld) @@ -6738,7 +6795,7 @@ void freeEdgeSlideTempFaces(EdgeSlideData *sld) slide_origdata_free_date(&sld->orig_data); } -void freeEdgeSlideVerts(TransInfo *UNUSED(t), TransCustomData *custom_data) +void freeEdgeSlideVerts(TransInfo *UNUSED(t), TransDataContainer *UNUSED(tc), TransCustomData *custom_data) { EdgeSlideData *sld = custom_data->data; @@ -6758,30 +6815,53 @@ void freeEdgeSlideVerts(TransInfo *UNUSED(t), TransCustomData *custom_data) static void initEdgeSlide_ex(TransInfo *t, bool use_double_side, bool use_even, bool flipped, bool use_clamp) { EdgeSlideData *sld; - bool ok; + bool ok = false; t->mode = TFM_EDGE_SLIDE; t->transform = applyEdgeSlide; t->handleEvent = handleEventEdgeSlide; + { + EdgeSlideParams *slp = MEM_callocN(sizeof(*slp), __func__); + slp->use_even = use_even; + slp->flipped = flipped; + /* happens to be best for single-sided */ + if (use_double_side == false) { + slp->flipped = !flipped; + } + slp->perc = 0.0f; + + if (!use_clamp) { + t->flag |= T_ALT_TRANSFORM; + } + + t->custom.mode.data = slp; + t->custom.mode.use_free = true; + } + if (use_double_side) { - ok = createEdgeSlideVerts_double_side(t, use_even, flipped, use_clamp); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + ok |= createEdgeSlideVerts_double_side(t, tc); + } } else { - ok = createEdgeSlideVerts_single_side(t, use_even, flipped, use_clamp); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + ok |= createEdgeSlideVerts_single_side(t, tc); + } } if (!ok) { t->state = TRANS_CANCEL; return; } - - sld = t->custom.mode.data; - - if (!sld) - return; - t->custom.mode.free_cb = freeEdgeSlideVerts; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + sld = tc->custom.mode.data; + if (!sld) { + continue; + } + tc->custom.mode.free_cb = freeEdgeSlideVerts; + } /* set custom point first if you want value to be initialized by init */ calcEdgeSlideCustomPoints(t); @@ -6808,20 +6888,20 @@ static void initEdgeSlide(TransInfo *t) static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event) { if (t->mode == TFM_EDGE_SLIDE) { - EdgeSlideData *sld = t->custom.mode.data; + EdgeSlideParams *slp = t->custom.mode.data; - if (sld) { + if (slp) { switch (event->type) { case EKEY: if (event->val == KM_PRESS) { - sld->use_even = !sld->use_even; + slp->use_even = !slp->use_even; calcEdgeSlideCustomPoints(t); return TREDRAW_HARD; } break; case FKEY: if (event->val == KM_PRESS) { - sld->flipped = !sld->flipped; + slp->flipped = !slp->flipped; calcEdgeSlideCustomPoints(t); return TREDRAW_HARD; } @@ -6835,6 +6915,7 @@ static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEven } break; case EVT_MODAL_MAP: +#if 0 switch (event->val) { case TFM_MODAL_EDGESLIDE_DOWN: sld->curr_sv_index = ((sld->curr_sv_index - 1) + sld->totsv) % sld->totsv; @@ -6843,6 +6924,7 @@ static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEven sld->curr_sv_index = (sld->curr_sv_index + 1) % sld->totsv; return TREDRAW_HARD; } +#endif break; case MOUSEMOVE: calcEdgeSlideCustomPoints(t); @@ -6857,12 +6939,13 @@ static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEven static void drawEdgeSlide(TransInfo *t) { - if ((t->mode == TFM_EDGE_SLIDE) && t->custom.mode.data) { - EdgeSlideData *sld = t->custom.mode.data; + if ((t->mode == TFM_EDGE_SLIDE) && TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data) { + EdgeSlideParams *slp = t->custom.mode.data; + EdgeSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data; const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); /* Even mode */ - if ((sld->use_even == true) || (is_clamp == false)) { + if ((slp->use_even == true) || (is_clamp == false)) { View3D *v3d = t->view; const float line_size = UI_GetThemeValuef(TH_OUTLINE_WIDTH) + 0.5f; @@ -6873,16 +6956,16 @@ static void drawEdgeSlide(TransInfo *t) glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); gpuPushMatrix(); - gpuMultMatrix(t->obedit->obmat); + gpuMultMatrix(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat); unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); - if (sld->use_even == true) { + if (slp->use_even == true) { float co_a[3], co_b[3], co_mark[3]; TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index]; - const float fac = (sld->perc + 1.0f) / 2.0f; + const float fac = (slp->perc + 1.0f) / 2.0f; const float ctrl_size = UI_GetThemeValuef(TH_FACEDOT_SIZE) + 1.5f; const float guide_size = ctrl_size - 0.5f; const int alpha_shade = -30; @@ -6906,7 +6989,7 @@ static void drawEdgeSlide(TransInfo *t) immUniformThemeColorShadeAlpha(TH_SELECT, -30, alpha_shade); glPointSize(ctrl_size); immBegin(GWN_PRIM_POINTS, 1); - if (sld->flipped) { + if (slp->flipped) { if (curr_sv->v_side[1]) immVertex3fv(pos, curr_sv->v_side[1]->co); } else { @@ -6932,6 +7015,7 @@ static void drawEdgeSlide(TransInfo *t) immUniformThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade); immBegin(GWN_PRIM_LINES, sld->totsv * 2); + /* TODO(campbell): Loop over all verts */ sv = sld->sv; for (i = 0; i < sld->totsv; i++, sv++) { float a[3], b[3]; @@ -6972,38 +7056,43 @@ static void drawEdgeSlide(TransInfo *t) static void doEdgeSlide(TransInfo *t, float perc) { - EdgeSlideData *sld = t->custom.mode.data; - TransDataEdgeSlideVert *svlist = sld->sv, *sv; - int i; + EdgeSlideParams *slp = t->custom.mode.data; + EdgeSlideData *sld_active = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data; - sld->perc = perc; - sv = svlist; + slp->perc = perc; - if (sld->use_even == false) { + if (slp->use_even == false) { const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); if (is_clamp) { const int side_index = (perc < 0.0f); const float perc_final = fabsf(perc); - for (i = 0; i < sld->totsv; i++, sv++) { - madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, sv->dir_side[side_index], perc_final); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + EdgeSlideData *sld = tc->custom.mode.data; + TransDataEdgeSlideVert *sv = sld->sv; + for (int i = 0; i < sld->totsv; i++, sv++) { + madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, sv->dir_side[side_index], perc_final); + } + sld->curr_side_unclamp = side_index; } - - sld->curr_side_unclamp = side_index; } else { - const int side_index = sld->curr_side_unclamp; - const float perc_init = fabsf(perc) * ((sld->curr_side_unclamp == (perc < 0.0f)) ? 1 : -1); - for (i = 0; i < sld->totsv; i++, sv++) { - float dir_flip[3]; - float perc_final = perc_init; - if (!is_zero_v3(sv->dir_side[side_index])) { - copy_v3_v3(dir_flip, sv->dir_side[side_index]); - } - else { - copy_v3_v3(dir_flip, sv->dir_side[!side_index]); - perc_final *= -1; + const float perc_init = fabsf(perc) * ((sld_active->curr_side_unclamp == (perc < 0.0f)) ? 1 : -1); + const int side_index = sld_active->curr_side_unclamp; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + EdgeSlideData *sld = tc->custom.mode.data; + TransDataEdgeSlideVert *sv = sld->sv; + for (int i = 0; i < sld->totsv; i++, sv++) { + float dir_flip[3]; + float perc_final = perc_init; + if (!is_zero_v3(sv->dir_side[side_index])) { + copy_v3_v3(dir_flip, sv->dir_side[side_index]); + } + else { + copy_v3_v3(dir_flip, sv->dir_side[!side_index]); + perc_final *= -1; + } + madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, dir_flip, perc_final); } - madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, dir_flip, perc_final); } } } @@ -7016,24 +7105,28 @@ static void doEdgeSlide(TransInfo *t, float perc) * \note len_v3v3(curr_sv->dir_side[0], curr_sv->dir_side[1]) * is the same as the distance between the original vert locations, same goes for the lines below. */ - TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index]; - const float curr_length_perc = curr_sv->edge_len * (((sld->flipped ? perc : -perc) + 1.0f) / 2.0f); + TransDataEdgeSlideVert *curr_sv = &sld_active->sv[sld_active->curr_sv_index]; + const float curr_length_perc = curr_sv->edge_len * (((slp->flipped ? perc : -perc) + 1.0f) / 2.0f); float co_a[3]; float co_b[3]; - for (i = 0; i < sld->totsv; i++, sv++) { - if (sv->edge_len > FLT_EPSILON) { - const float fac = min_ff(sv->edge_len, curr_length_perc) / sv->edge_len; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + EdgeSlideData *sld = tc->custom.mode.data; + TransDataEdgeSlideVert *sv = sld->sv; + for (int i = 0; i < sld->totsv; i++, sv++) { + if (sv->edge_len > FLT_EPSILON) { + const float fac = min_ff(sv->edge_len, curr_length_perc) / sv->edge_len; - add_v3_v3v3(co_a, sv->v_co_orig, sv->dir_side[0]); - add_v3_v3v3(co_b, sv->v_co_orig, sv->dir_side[1]); + add_v3_v3v3(co_a, sv->v_co_orig, sv->dir_side[0]); + add_v3_v3v3(co_b, sv->v_co_orig, sv->dir_side[1]); - if (sld->flipped) { - interp_line_v3_v3v3v3(sv->v->co, co_b, sv->v_co_orig, co_a, fac); - } - else { - interp_line_v3_v3v3v3(sv->v->co, co_a, sv->v_co_orig, co_b, fac); + if (slp->flipped) { + interp_line_v3_v3v3v3(sv->v->co, co_b, sv->v_co_orig, co_a, fac); + } + else { + interp_line_v3_v3v3v3(sv->v->co, co_a, sv->v_co_orig, co_b, fac); + } } } } @@ -7045,9 +7138,9 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2])) char str[UI_MAX_DRAW_STR]; size_t ofs = 0; float final; - EdgeSlideData *sld = t->custom.mode.data; - bool flipped = sld->flipped; - bool use_even = sld->use_even; + EdgeSlideParams *slp = t->custom.mode.data; + bool flipped = slp->flipped; + bool use_even = slp->use_even; const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); const bool is_constrained = !(is_clamp == false || hasNumInput(&t->num)); @@ -7099,7 +7192,7 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2])) static void calcVertSlideCustomPoints(struct TransInfo *t) { - VertSlideData *sld = t->custom.mode.data; + VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data; TransDataVertSlideVert *sv = &sld->sv[sld->curr_sv_index]; const float *co_orig_3d = sv->co_orig_3d; @@ -7134,7 +7227,8 @@ static void calcVertSlideCustomPoints(struct TransInfo *t) */ static void calcVertSlideMouseActiveVert(struct TransInfo *t, const int mval[2]) { - VertSlideData *sld = t->custom.mode.data; + /* Active object may have no selected vertices. */ + VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data; float mval_fl[2] = {UNPACK2(mval)}; TransDataVertSlideVert *sv; @@ -7161,7 +7255,7 @@ static void calcVertSlideMouseActiveVert(struct TransInfo *t, const int mval[2]) */ static void calcVertSlideMouseActiveEdges(struct TransInfo *t, const int mval[2]) { - VertSlideData *sld = t->custom.mode.data; + VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data; float imval_fl[2] = {UNPACK2(t->mouse.imval)}; float mval_fl[2] = {UNPACK2(mval)}; @@ -7189,7 +7283,7 @@ static void calcVertSlideMouseActiveEdges(struct TransInfo *t, const int mval[2] float dir_dot; sub_v3_v3v3(tdir, sv->co_orig_3d, sv->co_link_orig_3d[j]); - mul_mat3_m4_v3(t->obedit->obmat, tdir); + mul_mat3_m4_v3(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat, tdir); project_plane_v3_v3v3(tdir, tdir, t->viewinv[2]); normalize_v3(tdir); @@ -7207,9 +7301,9 @@ static void calcVertSlideMouseActiveEdges(struct TransInfo *t, const int mval[2] } } -static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool use_clamp) +static bool createVertSlideVerts(TransInfo *t, TransDataContainer *tc) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); BMesh *bm = em->bm; BMIter iter; BMIter eiter; @@ -7219,13 +7313,9 @@ static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool VertSlideData *sld = MEM_callocN(sizeof(*sld), "sld"); int j; - slide_origdata_init_flag(t, &sld->orig_data); + slide_origdata_init_flag(t, tc, &sld->orig_data); - sld->use_even = use_even; sld->curr_sv_index = 0; - sld->flipped = flipped; - if (!use_clamp) - t->flag |= T_ALT_TRANSFORM; j = 0; BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { @@ -7288,14 +7378,12 @@ static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool sld->totsv = j; bmesh_edit_begin(bm, BMO_OPTYPE_FLAG_UNTAN_MULTIRES); - slide_origdata_init_data(t, &sld->orig_data); - slide_origdata_create_data(t, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv); + slide_origdata_init_data(tc, &sld->orig_data); + slide_origdata_create_data(t, tc, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv); sld->em = em; - sld->perc = 0.0f; - - t->custom.mode.data = sld; + tc->custom.mode.data = sld; /* most likely will be set below */ unit_m4(sld->proj_mat); @@ -7307,9 +7395,12 @@ static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool rv3d = ar ? ar->regiondata : NULL; if (rv3d) { - ED_view3d_ob_project_mat_get(rv3d, t->obedit, sld->proj_mat); + ED_view3d_ob_project_mat_get(rv3d, tc->obedit, sld->proj_mat); } + } + /* XXX, calc vert slide across all objects */ + if (tc == t->data_container) { calcVertSlideMouseActiveVert(t, t->mval); calcVertSlideMouseActiveEdges(t, t->mval); } @@ -7319,14 +7410,13 @@ static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool void projectVertSlideData(TransInfo *t, bool is_final) { - VertSlideData *sld = t->custom.mode.data; - SlideOrigData *sod = &sld->orig_data; - - if (sod->use_origfaces == false) { - return; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + VertSlideData *sld = tc->custom.mode.data; + SlideOrigData *sod = &sld->orig_data; + if (sod->use_origfaces == true) { + slide_origdata_interp_data(tc->obedit, sod, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv, is_final); + } } - - slide_origdata_interp_data(t, sod, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv, is_final); } void freeVertSlideTempFaces(VertSlideData *sld) @@ -7334,7 +7424,7 @@ void freeVertSlideTempFaces(VertSlideData *sld) slide_origdata_free_date(&sld->orig_data); } -void freeVertSlideVerts(TransInfo *UNUSED(t), TransCustomData *custom_data) +void freeVertSlideVerts(TransInfo *UNUSED(t), TransDataContainer *UNUSED(tc), TransCustomData *custom_data) { VertSlideData *sld = custom_data->data; @@ -7361,23 +7451,38 @@ void freeVertSlideVerts(TransInfo *UNUSED(t), TransCustomData *custom_data) static void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp) { - VertSlideData *sld; t->mode = TFM_VERT_SLIDE; t->transform = applyVertSlide; t->handleEvent = handleEventVertSlide; - if (!createVertSlideVerts(t, use_even, flipped, use_clamp)) { - t->state = TRANS_CANCEL; - return; + { + VertSlideParams *slp = MEM_callocN(sizeof(*slp), __func__); + slp->use_even = use_even; + slp->flipped = flipped; + slp->perc = 0.0f; + + if (!use_clamp) { + t->flag |= T_ALT_TRANSFORM; + } + + t->custom.mode.data = slp; + t->custom.mode.use_free = true; } - sld = t->custom.mode.data; + bool ok = false; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + ok |= createVertSlideVerts(t, tc); + VertSlideData *sld = tc->custom.mode.data; + if (sld) { + tc->custom.mode.free_cb = freeVertSlideVerts; + } + } - if (!sld) + if (ok == false) { + t->state = TRANS_CANCEL; return; - - t->custom.mode.free_cb = freeVertSlideVerts; + } /* set custom point first if you want value to be initialized by init */ calcVertSlideCustomPoints(t); @@ -7404,14 +7509,14 @@ static void initVertSlide(TransInfo *t) static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event) { if (t->mode == TFM_VERT_SLIDE) { - VertSlideData *sld = t->custom.mode.data; + VertSlideParams *slp = t->custom.mode.data; - if (sld) { + if (slp) { switch (event->type) { case EKEY: if (event->val == KM_PRESS) { - sld->use_even = !sld->use_even; - if (sld->flipped) { + slp->use_even = !slp->use_even; + if (slp->flipped) { calcVertSlideCustomPoints(t); } return TREDRAW_HARD; @@ -7419,7 +7524,7 @@ static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEven break; case FKEY: if (event->val == KM_PRESS) { - sld->flipped = !sld->flipped; + slp->flipped = !slp->flipped; calcVertSlideCustomPoints(t); return TREDRAW_HARD; } @@ -7464,8 +7569,8 @@ static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEven static void drawVertSlide(TransInfo *t) { - if ((t->mode == TFM_VERT_SLIDE) && t->custom.mode.data) { - VertSlideData *sld = t->custom.mode.data; + if ((t->mode == TFM_VERT_SLIDE) && TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data) { + VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data; const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); /* Non-Prop mode */ @@ -7485,12 +7590,12 @@ static void drawVertSlide(TransInfo *t) glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); gpuPushMatrix(); - gpuMultMatrix(t->obedit->obmat); + gpuMultMatrix(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat); glLineWidth(line_size); const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); - + immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); immUniformThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade); @@ -7540,13 +7645,13 @@ static void drawVertSlide(TransInfo *t) mval_ofs[0] = t->mval[0] - t->mouse.imval[0]; mval_ofs[1] = t->mval[1] - t->mouse.imval[1]; - mul_v3_m4v3(co_orig_3d, t->obedit->obmat, curr_sv->co_orig_3d); + mul_v3_m4v3(co_orig_3d, TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat, curr_sv->co_orig_3d); zfac = ED_view3d_calc_zfac(t->ar->regiondata, co_orig_3d, NULL); ED_view3d_win_to_delta(t->ar, mval_ofs, co_dest_3d, zfac); - invert_m4_m4(t->obedit->imat, t->obedit->obmat); - mul_mat3_m4_v3(t->obedit->imat, co_dest_3d); + invert_m4_m4(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->imat, TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat); + mul_mat3_m4_v3(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->imat, co_dest_3d); add_v3_v3(co_dest_3d, curr_sv->co_orig_3d); @@ -7581,41 +7686,43 @@ static void drawVertSlide(TransInfo *t) static void doVertSlide(TransInfo *t, float perc) { - VertSlideData *sld = t->custom.mode.data; - TransDataVertSlideVert *svlist = sld->sv, *sv; - int i; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + VertSlideData *sld = tc->custom.mode.data; + TransDataVertSlideVert *svlist = sld->sv, *sv; + int i; - sld->perc = perc; - sv = svlist; + sld->perc = perc; + sv = svlist; - if (sld->use_even == false) { - for (i = 0; i < sld->totsv; i++, sv++) { - interp_v3_v3v3(sv->v->co, sv->co_orig_3d, sv->co_link_orig_3d[sv->co_link_curr], perc); + if (sld->use_even == false) { + for (i = 0; i < sld->totsv; i++, sv++) { + interp_v3_v3v3(sv->v->co, sv->co_orig_3d, sv->co_link_orig_3d[sv->co_link_curr], perc); + } } - } - else { - TransDataVertSlideVert *sv_curr = &sld->sv[sld->curr_sv_index]; - const float edge_len_curr = len_v3v3(sv_curr->co_orig_3d, sv_curr->co_link_orig_3d[sv_curr->co_link_curr]); - const float tperc = perc * edge_len_curr; + else { + TransDataVertSlideVert *sv_curr = &sld->sv[sld->curr_sv_index]; + const float edge_len_curr = len_v3v3(sv_curr->co_orig_3d, sv_curr->co_link_orig_3d[sv_curr->co_link_curr]); + const float tperc = perc * edge_len_curr; - for (i = 0; i < sld->totsv; i++, sv++) { - float edge_len; - float dir[3]; + for (i = 0; i < sld->totsv; i++, sv++) { + float edge_len; + float dir[3]; - sub_v3_v3v3(dir, sv->co_link_orig_3d[sv->co_link_curr], sv->co_orig_3d); - edge_len = normalize_v3(dir); + sub_v3_v3v3(dir, sv->co_link_orig_3d[sv->co_link_curr], sv->co_orig_3d); + edge_len = normalize_v3(dir); - if (edge_len > FLT_EPSILON) { - if (sld->flipped) { - madd_v3_v3v3fl(sv->v->co, sv->co_link_orig_3d[sv->co_link_curr], dir, -tperc); + if (edge_len > FLT_EPSILON) { + if (sld->flipped) { + madd_v3_v3v3fl(sv->v->co, sv->co_link_orig_3d[sv->co_link_curr], dir, -tperc); + } + else { + madd_v3_v3v3fl(sv->v->co, sv->co_orig_3d, dir, tperc); + } } else { - madd_v3_v3v3fl(sv->v->co, sv->co_orig_3d, dir, tperc); + copy_v3_v3(sv->v->co, sv->co_orig_3d); } } - else { - copy_v3_v3(sv->v->co, sv->co_orig_3d); - } } } } @@ -7625,9 +7732,9 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2])) char str[UI_MAX_DRAW_STR]; size_t ofs = 0; float final; - VertSlideData *sld = t->custom.mode.data; - const bool flipped = sld->flipped; - const bool use_even = sld->use_even; + VertSlideData *slp = t->custom.mode.data; + const bool flipped = slp->flipped; + const bool use_even = slp->use_even; const bool is_clamp = !(t->flag & T_ALT_TRANSFORM); const bool is_constrained = !(is_clamp == false || hasNumInput(&t->num)); @@ -7700,7 +7807,6 @@ static void initBoneRoll(TransInfo *t) static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; int i; char str[UI_MAX_DRAW_STR]; @@ -7726,14 +7832,17 @@ static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2])) } /* set roll values */ - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - *(td->val) = td->ival - final; + *(td->val) = td->ival - final; + } } recalcData(t); @@ -7767,7 +7876,6 @@ static void initBakeTime(TransInfo *t) static void applyBakeTime(TransInfo *t, const int mval[2]) { - TransData *td = t->data; float time; int i; char str[UI_MAX_DRAW_STR]; @@ -7811,17 +7919,20 @@ static void applyBakeTime(TransInfo *t, const int mval[2]) BLI_snprintf(str, sizeof(str), IFACE_("Time: %.3f %s"), time, t->proptext); } - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - if (td->val) { - *td->val = td->ival + time * td->factor; - if (td->ext->size && *td->val < *td->ext->size) *td->val = *td->ext->size; - if (td->ext->quat && *td->val > *td->ext->quat) *td->val = *td->ext->quat; + if (td->val) { + *td->val = td->ival + time * td->factor; + if (td->ext->size && *td->val < *td->ext->size) *td->val = *td->ext->size; + if (td->ext->quat && *td->val > *td->ext->quat) *td->val = *td->ext->quat; + } } } @@ -7844,14 +7955,13 @@ static void initMirror(TransInfo *t) initMouseInputMode(t, &t->mouse, INPUT_NONE); t->flag |= T_NULL_ONE; - if (!t->obedit) { + if ((t->flag & T_EDIT) == 0) { t->flag |= T_NO_ZERO; } } static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td; float size[3], mat[3][3]; int i; char str[UI_MAX_DRAW_STR]; @@ -7869,19 +7979,22 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) size_to_mat3(mat, size); if (t->con.applySize) { - t->con.applySize(t, NULL, mat); + t->con.applySize(t, NULL, NULL, mat); } BLI_snprintf(str, sizeof(str), IFACE_("Mirror%s"), t->con.text); - for (i = 0, td = t->data; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - ElementResize(t, td, mat); + ElementResize(t, tc, td, mat); + } } recalcData(t); @@ -7893,14 +8006,17 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2])) size_to_mat3(mat, size); - for (i = 0, td = t->data; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - ElementResize(t, td, mat); + ElementResize(t, tc, td, mat); + } } recalcData(t); @@ -7931,42 +8047,43 @@ static void initAlign(TransInfo *t) static void applyAlign(TransInfo *t, const int UNUSED(mval[2])) { - TransData *td = t->data; float center[3]; int i; - /* saving original center */ - copy_v3_v3(center, t->center); - for (i = 0; i < t->total; i++, td++) { - float mat[3][3], invmat[3][3]; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + /* saving original center */ + copy_v3_v3(center, tc->center_local); + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + float mat[3][3], invmat[3][3]; - if (td->flag & TD_NOACTION) - break; + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - /* around local centers */ - if (t->flag & (T_OBJECT | T_POSE)) { - copy_v3_v3(t->center, td->center); - } - else { - if (t->settings->selectmode & SCE_SELECT_FACE) { - copy_v3_v3(t->center, td->center); + /* around local centers */ + if (t->flag & (T_OBJECT | T_POSE)) { + copy_v3_v3(tc->center_local, td->center); + } + else { + if (t->settings->selectmode & SCE_SELECT_FACE) { + copy_v3_v3(tc->center_local, td->center); + } } - } - invert_m3_m3(invmat, td->axismtx); + invert_m3_m3(invmat, td->axismtx); - mul_m3_m3m3(mat, t->spacemtx, invmat); + mul_m3_m3m3(mat, t->spacemtx, invmat); - ElementRotation(t, td, mat, t->around); + ElementRotation(t, tc, td, mat, t->around); + } + /* restoring original center */ + copy_v3_v3(tc->center_local, center); } - /* restoring original center */ - copy_v3_v3(t->center, center); - recalcData(t); ED_area_headerprint(t->sa, IFACE_("Align")); @@ -8027,17 +8144,19 @@ static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRA static void applySeqSlideValue(TransInfo *t, const float val[2]) { - TransData *td = t->data; int i; - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; - if (td->flag & TD_SKIP) - continue; + if (td->flag & TD_SKIP) + continue; - madd_v2_v2v2fl(td->loc, td->iloc, val, td->factor); + madd_v2_v2v2fl(td->loc, td->iloc, val, td->factor); + } } } @@ -8050,7 +8169,7 @@ static void applySeqSlide(TransInfo *t, const int mval[2]) if (t->con.mode & CON_APPLY) { float pvec[3] = {0.0f, 0.0f, 0.0f}; float tvec[3]; - t->con.applyVec(t, NULL, t->values, tvec, pvec); + t->con.applyVec(t, NULL, NULL, t->values, tvec, pvec); copy_v3_v3(t->values, tvec); } else { @@ -8270,56 +8389,58 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR]) static void applyTimeTranslateValue(TransInfo *t) { - TransData *td = t->data; - TransData2D *td2d = t->data2d; Scene *scene = t->scene; int i; - + const short autosnap = getAnimEdit_SnapMode(t); const double secf = FPS; float deltax, val /* , valprev */; - /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */ - for (i = 0; i < t->total; i++, td++, td2d++) { - /* it is assumed that td->extra is a pointer to the AnimData, - * whose active action is where this keyframe comes from - * (this is only valid when not in NLA) - */ - AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + TransData2D *td2d = tc->data_2d; + /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */ + for (i = 0; i < tc->data_len; i++, td++, td2d++) { + /* it is assumed that td->extra is a pointer to the AnimData, + * whose active action is where this keyframe comes from + * (this is only valid when not in NLA) + */ + AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; - /* valprev = *td->val; */ /* UNUSED */ + /* valprev = *td->val; */ /* UNUSED */ - /* check if any need to apply nla-mapping */ - if (adt && (t->spacetype != SPACE_SEQ)) { - deltax = t->values[0]; + /* check if any need to apply nla-mapping */ + if (adt && (t->spacetype != SPACE_SEQ)) { + deltax = t->values[0]; - if (autosnap == SACTSNAP_TSTEP) { - deltax = (float)(floor(((double)deltax / secf) + 0.5) * secf); - } - else if (autosnap == SACTSNAP_STEP) { - deltax = floorf(deltax + 0.5f); + if (autosnap == SACTSNAP_TSTEP) { + deltax = (float)(floor(((double)deltax / secf) + 0.5) * secf); + } + else if (autosnap == SACTSNAP_STEP) { + deltax = floorf(deltax + 0.5f); + } + + val = BKE_nla_tweakedit_remap(adt, td->ival, NLATIME_CONVERT_MAP); + val += deltax * td->factor; + *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP); } + else { + deltax = val = t->values[0]; - val = BKE_nla_tweakedit_remap(adt, td->ival, NLATIME_CONVERT_MAP); - val += deltax * td->factor; - *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP); - } - else { - deltax = val = t->values[0]; + if (autosnap == SACTSNAP_TSTEP) { + val = (float)(floor(((double)deltax / secf) + 0.5) * secf); + } + else if (autosnap == SACTSNAP_STEP) { + val = floorf(val + 0.5f); + } - if (autosnap == SACTSNAP_TSTEP) { - val = (float)(floor(((double)deltax / secf) + 0.5) * secf); - } - else if (autosnap == SACTSNAP_STEP) { - val = floorf(val + 0.5f); + *(td->val) = td->ival + val; } - *(td->val) = td->ival + val; + /* apply nearest snapping */ + doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap); } - - /* apply nearest snapping */ - doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap); } } @@ -8386,18 +8507,19 @@ static void initTimeSlide(TransInfo *t) float min = 999999999.0f, max = -999999999.0f; int i; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; + float val = *(td->val); - TransData *td = t->data; - for (i = 0; i < t->total; i++, td++) { - AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; - float val = *(td->val); - - /* strip/action time to global (mapped) time */ - if (adt) - val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_MAP); - - if (min > val) min = val; - if (max < val) max = val; + /* strip/action time to global (mapped) time */ + if (adt) + val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_MAP); + + if (min > val) min = val; + if (max < val) max = val; + } } if (min == max) { @@ -8450,7 +8572,6 @@ static void headerTimeSlide(TransInfo *t, const float sval, char str[UI_MAX_DRAW static void applyTimeSlideValue(TransInfo *t, float sval) { - TransData *td = t->data; int i; const float *range = t->custom.mode.data; float minx = range[0]; @@ -8465,44 +8586,47 @@ static void applyTimeSlideValue(TransInfo *t, float sval) } /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */ - for (i = 0; i < t->total; i++, td++) { - /* it is assumed that td->extra is a pointer to the AnimData, - * whose active action is where this keyframe comes from - * (this is only valid when not in NLA) - */ - AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; - float cval = t->values[0]; - - /* only apply to data if in range */ - if ((sval > minx) && (sval < maxx)) { - float cvalc = CLAMPIS(cval, minx, maxx); - float ival = td->ival; - float timefac; - - /* NLA mapping magic here works as follows: - * - "ival" goes from strip time to global time - * - calculation is performed into td->val in global time - * (since sval and min/max are all in global time) - * - "td->val" then gets put back into strip time + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + /* it is assumed that td->extra is a pointer to the AnimData, + * whose active action is where this keyframe comes from + * (this is only valid when not in NLA) */ - if (adt) { - /* strip to global */ - ival = BKE_nla_tweakedit_remap(adt, ival, NLATIME_CONVERT_MAP); - } - - /* left half? */ - if (ival < sval) { - timefac = (sval - ival) / (sval - minx); - *(td->val) = cvalc - timefac * (cvalc - minx); - } - else { - timefac = (ival - sval) / (maxx - sval); - *(td->val) = cvalc + timefac * (maxx - cvalc); - } - - if (adt) { - /* global to strip */ - *(td->val) = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_UNMAP); + AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; + float cval = t->values[0]; + + /* only apply to data if in range */ + if ((sval > minx) && (sval < maxx)) { + float cvalc = CLAMPIS(cval, minx, maxx); + float ival = td->ival; + float timefac; + + /* NLA mapping magic here works as follows: + * - "ival" goes from strip time to global time + * - calculation is performed into td->val in global time + * (since sval and min/max are all in global time) + * - "td->val" then gets put back into strip time + */ + if (adt) { + /* strip to global */ + ival = BKE_nla_tweakedit_remap(adt, ival, NLATIME_CONVERT_MAP); + } + + /* left half? */ + if (ival < sval) { + timefac = (sval - ival) / (sval - minx); + *(td->val) = cvalc - timefac * (cvalc - minx); + } + else { + timefac = (ival - sval) / (maxx - sval); + *(td->val) = cvalc + timefac * (maxx - cvalc); + } + + if (adt) { + /* global to strip */ + *(td->val) = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_UNMAP); + } } } } @@ -8563,8 +8687,8 @@ static void initTimeScale(TransInfo *t) /* recalculate center2d to use CFRA and mouse Y, since that's * what is used in time scale */ if ((t->flag & T_OVERRIDE_CENTER) == 0) { - t->center[0] = t->scene->r.cfra; - projectFloatView(t, t->center, center); + t->center_global[0] = t->scene->r.cfra; + projectFloatView(t, t->center_global, center); center[1] = t->mouse.imval[1]; } @@ -8605,39 +8729,40 @@ static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR]) static void applyTimeScaleValue(TransInfo *t) { Scene *scene = t->scene; - TransData *td = t->data; - TransData2D *td2d = t->data2d; int i; const short autosnap = getAnimEdit_SnapMode(t); const double secf = FPS; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + TransData2D *td2d = tc->data_2d; + for (i = 0; i < tc->data_len; i++, td++, td2d++) { + /* it is assumed that td->extra is a pointer to the AnimData, + * whose active action is where this keyframe comes from + * (this is only valid when not in NLA) + */ + AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; + float startx = CFRA; + float fac = t->values[0]; - for (i = 0; i < t->total; i++, td++, td2d++) { - /* it is assumed that td->extra is a pointer to the AnimData, - * whose active action is where this keyframe comes from - * (this is only valid when not in NLA) - */ - AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL; - float startx = CFRA; - float fac = t->values[0]; - - if (autosnap == SACTSNAP_TSTEP) { - fac = (float)(floor((double)fac / secf + 0.5) * secf); - } - else if (autosnap == SACTSNAP_STEP) { - fac = floorf(fac + 0.5f); - } + if (autosnap == SACTSNAP_TSTEP) { + fac = (float)(floor((double)fac / secf + 0.5) * secf); + } + else if (autosnap == SACTSNAP_STEP) { + fac = floorf(fac + 0.5f); + } - /* check if any need to apply nla-mapping */ - if (adt) - startx = BKE_nla_tweakedit_remap(adt, startx, NLATIME_CONVERT_UNMAP); + /* check if any need to apply nla-mapping */ + if (adt) + startx = BKE_nla_tweakedit_remap(adt, startx, NLATIME_CONVERT_UNMAP); - /* now, calculate the new value */ - *(td->val) = ((td->ival - startx) * fac) + startx; + /* now, calculate the new value */ + *(td->val) = ((td->ival - startx) * fac) + startx; - /* apply nearest snapping */ - doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap); + /* apply nearest snapping */ + doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap); + } } } @@ -8666,7 +8791,7 @@ bool checkUseAxisMatrix(TransInfo *t) /* currently only checks for editmode */ if (t->flag & T_EDIT) { if ((t->around == V3D_AROUND_LOCAL_ORIGINS) && - (ELEM(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE))) + (ELEM(t->obedit_type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE))) { /* not all editmode supports axis-matrix */ return true; diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index fe05207e645..f1daa831869 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -47,6 +47,7 @@ struct Depsgraph; struct TransInfo; +struct TransDataContainer; struct TransData; struct TransformOrientation; struct TransSnap; @@ -109,7 +110,7 @@ typedef struct TransSnap { * \note Return value can be anything, * where the smallest absolute value defines whats closest. */ - float (*distance)(struct TransInfo *, const float p1[3], const float p2[3]); + float (*distance)(struct TransInfo *t, const float p1[3], const float p2[3]); /** * Re-usable snap context data. @@ -127,14 +128,16 @@ typedef struct TransCon { /* the one in TransInfo is not garanty to stay the same (Rotates change it) */ int mode; /* Mode flags of the Constraint */ void (*drawExtra)(struct TransInfo *t); + + /* Note: if 'tc' is NULL, 'td' must also be NULL. */ /* For constraints that needs to draw differently from the other * uses this instead of the generic draw function */ - void (*applyVec)(struct TransInfo *t, struct TransData *td, const float in[3], float out[3], float pvec[3]); + void (*applyVec)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, const float in[3], float out[3], float pvec[3]); /* Apply function pointer for linear vectorial transformation */ /* The last three parameters are pointers to the in/out/printable vectors */ - void (*applySize)(struct TransInfo *t, struct TransData *td, float smat[3][3]); + void (*applySize)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, float smat[3][3]); /* Apply function pointer for size transformation */ - void (*applyRot)(struct TransInfo *t, struct TransData *td, float vec[3], float *angle); + void (*applyRot)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, float vec[3], float *angle); /* Apply function pointer for rotation transformation */ } TransCon; @@ -270,10 +273,6 @@ typedef struct EdgeSlideData { SlideOrigData orig_data; - float perc; - - bool use_even; - bool flipped; int curr_sv_index; @@ -281,6 +280,12 @@ typedef struct EdgeSlideData { int curr_side_unclamp; } EdgeSlideData; +typedef struct EdgeSlideParams { + float perc; + + bool use_even; + bool flipped; +} EdgeSlideParams; typedef struct TransDataVertSlideVert { /* TransDataGenericSlideVert */ @@ -313,6 +318,13 @@ typedef struct VertSlideData { float proj_mat[4][4]; } VertSlideData; +typedef struct VertSlideParams { + float perc; + + bool use_even; + bool flipped; +} VertSlideParams; + typedef struct BoneInitData { struct EditBone *bone; float tail[3]; @@ -373,16 +385,68 @@ typedef struct MouseInput { typedef struct TransCustomData { void *data; - void (*free_cb)(struct TransInfo *, struct TransCustomData *); + void (*free_cb)(struct TransInfo *, struct TransDataContainer *tc, struct TransCustomData *custom_data); unsigned int use_free : 1; } TransCustomData; typedef struct TransCenterData { - float local[3], global[3]; + float global[3]; unsigned int is_set : 1; } TransCenterData; +/** + * Rule of thumb for choosing between mode/type: + * - If transform mode uses the data, assign to `mode` + * (typically in transform.c). + * - If conversion uses the data as an extension to the #TransData, assign to `type` + * (typically in transform_conversion.c). + */ +typedef struct TransCustomDataContainer { + /** Owned by the mode (grab, scale, bend... ).*/ + union { + TransCustomData mode, first_elem; + }; + TransCustomData type; +} TransCustomDataContainer; +#define TRANS_CUSTOM_DATA_ELEM_MAX (sizeof(TransCustomDataContainer) / sizeof(TransCustomData)) + +typedef struct TransDataContainer { + /** + * Use for cases we care about the active, eg: active vert of active mesh. + * if set this will _always_ be the first item in the array. + */ + bool is_active; + + /** Transformed data (array). */ + TransData *data; + /** Total number of transformed data. */ + int data_len; + + /** Transformed data extension (array). */ + TransDataExtension *data_ext; + /** Transformed data for 2d (array). */ + TransData2D *data_2d; + + struct Object *obedit; + /** Normalized editmode matrix ('T_EDIT' only). */ + float obedit_mat[3][3]; + + /** if 't->flag & T_POSE', this denotes pose object */ + struct Object *poseobj; + + /** Center of transformation (in local-space), Calculated from #TransInfo.center_global. */ + float center_local[3]; + + TransCustomDataContainer custom; +} TransDataContainer; + typedef struct TransInfo { + TransDataContainer *data_container; + int data_container_len; + /** Combine length of all #TransDataContainer.data_len + * Use to check if nothing is selected or if we have a single selection. */ + int data_len_all; + int mode; /* current mode */ int flag; /* generic flags for special behaviors */ int modifiers; /* special modifiers, by function, not key */ @@ -393,10 +457,6 @@ typedef struct TransInfo { /* transform function pointer */ eRedrawFlag (*handleEvent)(struct TransInfo *, const struct wmEvent *); /* event handler function pointer RETURN 1 if redraw is needed */ - int total; /* total number of transformed data */ - TransData *data; /* transformed data (array) */ - TransDataExtension *ext; /* transformed data extension (array) */ - TransData2D *data2d; /* transformed data for 2d (array) */ TransCon con; /* transformed constraint */ TransSnap tsnap; NumInput num; /* numerical input */ @@ -406,7 +466,6 @@ typedef struct TransInfo { char proptext[20]; /* proportional falloff text */ float aspect[3]; /* spaces using non 1:1 aspect, (uv's, f-curve, movie-clip... etc) * use for conversion and snapping. */ - float center[3]; /* center of transformation (in local-space) */ float center_global[3]; /* center of transformation (in global-space) */ float center2d[2]; /* center in screen coordinates */ /* Lazy initialize center data for when we need other center values. @@ -425,6 +484,7 @@ typedef struct TransInfo { short around; char spacetype; /* spacetype where transforming is */ char helpline; /* helpline modes (not to be confused with hotline) */ + short obedit_type; /* Avoid looking inside TransDataContainer obedit. */ float vec[3]; /* translation, to show for widget */ float mat[3][3]; /* rot/rescale, to show for widget */ @@ -432,25 +492,6 @@ typedef struct TransInfo { float spacemtx[3][3]; /* orientation matrix of the current space */ char spacename[64]; /* name of the current space, MAX_NAME */ - struct Object *poseobj; /* if t->flag & T_POSE, this denotes pose object */ - - /** - * Rule of thumb for choosing between mode/type: - * - If transform mode uses the data, assign to `mode` - * (typically in transform.c). - * - If conversion uses the data as an extension to the #TransData, assign to `type` - * (typically in transform_conversion.c). - */ - struct { - /* owned by the mode (grab, scale, bend... )*/ - union { - TransCustomData mode, first_elem; - }; - /* owned by the type (mesh, armature, nla...) */ - TransCustomData type; - } custom; -#define TRANS_CUSTOM_DATA_ELEM_MAX (sizeof(((TransInfo *)NULL)->custom) / sizeof(TransCustomData)) - /*************** NEW STUFF *********************/ short launch_event; /* event type used to launch transform */ @@ -469,7 +510,6 @@ typedef struct TransInfo { bool remove_on_cancel; /* remove elements if operator is canceled */ - EvaluationContext eval_ctx; void *view; struct bContext *context; /* Only valid (non null) during an operator called function. */ struct ScrArea *sa; @@ -484,12 +524,13 @@ typedef struct TransInfo { struct ReportList *reports; /* assign from the operator, or can be NULL */ int mval[2]; /* current mouse position */ float zfac; /* use for 3d view */ - struct Object *obedit; - float obedit_mat[3][3]; /* normalized editmode matrix (T_EDIT only) */ void *draw_handle_apply; void *draw_handle_view; void *draw_handle_pixel; void *draw_handle_cursor; + + /** Typically for mode settings. */ + TransCustomDataContainer custom; } TransInfo; @@ -648,7 +689,7 @@ void flushTransSeq(TransInfo *t); void flushTransTracking(TransInfo *t); void flushTransMasking(TransInfo *t); void flushTransPaintCurve(TransInfo *t); -void restoreBones(TransInfo *t); +void restoreBones(TransDataContainer *tc); /*********************** transform_manipulator.c ********** */ @@ -758,6 +799,7 @@ void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float val /*********************** Generics ********************************/ +void initTransDataContainers_FromObjectData(TransInfo *t); void initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, const struct wmEvent *event); void postTrans(struct bContext *C, TransInfo *t); void resetTransModal(TransInfo *t); @@ -773,9 +815,7 @@ void restoreTransObjects(TransInfo *t); void recalcData(TransInfo *t); void calculateCenter2D(TransInfo *t); -void calculateCenterGlobal( - TransInfo *t, const float center_local[3], - float r_center_global[3]); +void calculateCenterLocal(TransInfo *t, const float center_global[3]); const TransCenterData *transformCenter_from_type(TransInfo *t, int around); void calculateCenter(TransInfo *t); @@ -816,11 +856,11 @@ int getTransformOrientation_ex(const struct bContext *C, float normal[3], float int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3]); void freeEdgeSlideTempFaces(EdgeSlideData *sld); -void freeEdgeSlideVerts(TransInfo *t, TransCustomData *custom_data); +void freeEdgeSlideVerts(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data); void projectEdgeSlideData(TransInfo *t, bool is_final); void freeVertSlideTempFaces(VertSlideData *sld); -void freeVertSlideVerts(TransInfo *t, TransCustomData *custom_data); +void freeVertSlideVerts(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data); void projectVertSlideData(TransInfo *t, bool is_final); @@ -831,4 +871,22 @@ bool checkUseAxisMatrix(TransInfo *t); #define TRANSFORM_SNAP_MAX_PX 100.0f #define TRANSFORM_DIST_INVALID -FLT_MAX +/* Temp macros. */ + +/* This is to be replaced, just to get things compiling early on. */ +#define TRANS_DATA_CONTAINER_FIRST_EVIL(t) (&(t)->data_container[0]) +#define TRANS_DATA_CONTAINER_FIRST_OK(t) (&(t)->data_container[0]) +/* For cases we _know_ there is only one handle. */ +#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t) (BLI_assert((t)->data_container_len == 1), (&(t)->data_container[0])) + +#define FOREACH_TRANS_DATA_CONTAINER(t, th) \ + for (TransDataContainer *tc = t->data_container, *tc_end = t->data_container + t->data_container_len; \ + th != tc_end; \ + th++) + +#define FOREACH_TRANS_DATA_CONTAINER_INDEX(t, th, i) \ + for (TransDataContainer *tc = ((i = 0), t->data_container), *tc_end = t->data_container + t->data_container_len; \ + th != tc_end; \ + th++, i++) + #endif diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index f612dc0e474..bc9d0f19389 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -333,7 +333,8 @@ static void planeProjection(TransInfo *t, const float in[3], float out[3]) * */ -static void applyAxisConstraintVec(TransInfo *t, TransData *td, const float in[3], float out[3], float pvec[3]) +static void applyAxisConstraintVec( + TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, const float in[3], float out[3], float pvec[3]) { copy_v3_v3(out, in); if (!td && t->con.mode & CON_APPLY) { @@ -380,7 +381,8 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, const float in[3 * Further down, that vector is mapped to each data's space. */ -static void applyObjectConstraintVec(TransInfo *t, TransData *td, const float in[3], float out[3], float pvec[3]) +static void applyObjectConstraintVec( + TransInfo *t, TransDataContainer *tc, TransData *td, const float in[3], float out[3], float pvec[3]) { copy_v3_v3(out, in); if (t->con.mode & CON_APPLY) { @@ -428,7 +430,7 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, const float in mul_m3_v3(td->axismtx, out); if (t->flag & T_EDIT) { - mul_m3_v3(t->obedit_mat, out); + mul_m3_v3(tc->obedit_mat, out); } } } @@ -438,7 +440,8 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, const float in * Generic callback for constant spatial constraints applied to resize motion */ -static void applyAxisConstraintSize(TransInfo *t, TransData *td, float smat[3][3]) +static void applyAxisConstraintSize( + TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, float smat[3][3]) { if (!td && t->con.mode & CON_APPLY) { float tmat[3][3]; @@ -462,7 +465,8 @@ static void applyAxisConstraintSize(TransInfo *t, TransData *td, float smat[3][3 * Callback for object based spatial constraints applied to resize motion */ -static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3][3]) +static void applyObjectConstraintSize( + TransInfo *t, TransDataContainer *tc, TransData *td, float smat[3][3]) { if (td && t->con.mode & CON_APPLY) { float tmat[3][3]; @@ -482,7 +486,7 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3] mul_m3_m3m3(tmat, smat, imat); if (t->flag & T_EDIT) { - mul_m3_m3m3(smat, t->obedit_mat, smat); + mul_m3_m3m3(smat, tc->obedit_mat, smat); } mul_m3_m3m3(smat, td->axismtx, tmat); } @@ -502,7 +506,7 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3] * (ie: not doing counterclockwise rotations when the mouse moves clockwise). */ -static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], float *angle) +static void applyAxisConstraintRot(TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, float vec[3], float *angle) { if (!td && t->con.mode & CON_APPLY) { int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2); @@ -544,7 +548,8 @@ static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], fl * (ie: not doing counterclockwise rotations when the mouse moves clockwise). */ -static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3], float *angle) +static void applyObjectConstraintRot( + TransInfo *t, TransDataContainer *tc, TransData *td, float vec[3], float *angle) { if (t->con.mode & CON_APPLY) { int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2); @@ -553,11 +558,11 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3], /* on setup call, use first object */ if (td == NULL) { - td = t->data; + td = tc->data; } if (t->flag & T_EDIT) { - mul_m3_m3m3(tmp_axismtx, t->obedit_mat, td->axismtx); + mul_m3_m3m3(tmp_axismtx, tc->obedit_mat, td->axismtx); axismtx = tmp_axismtx; } else { @@ -607,20 +612,21 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]) /* applies individual td->axismtx constraints */ void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[]) { - if (t->total == 1) { + TransDataContainer *tc = t->data_container; + if (t->data_len_all == 1) { float axismtx[3][3]; if (t->flag & T_EDIT) { - mul_m3_m3m3(axismtx, t->obedit_mat, t->data->axismtx); + mul_m3_m3m3(axismtx, tc->obedit_mat, tc->data->axismtx); } else { - copy_m3_m3(axismtx, t->data->axismtx); + copy_m3_m3(axismtx, tc->data->axismtx); } setConstraint(t, axismtx, mode, text); } else { BLI_strncpy(t->con.text + 1, text, sizeof(t->con.text) - 1); - copy_m3_m3(t->con.mtx, t->data->axismtx); + copy_m3_m3(t->con.mtx, tc->data->axismtx); t->con.mode = mode; getConstraintMatrix(t); @@ -638,7 +644,9 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) { /* edit-mode now allows local transforms too */ if (t->flag & T_EDIT) { - setConstraint(t, t->obedit_mat, mode, text); + /* Use the active (first) edit object. */ + TransDataContainer *tc = t->data_container; + setConstraint(t, tc->obedit_mat, mode, text); } else { setAxisMatrixConstraint(t, mode, text); @@ -836,57 +844,59 @@ static void drawObjectConstraint(TransInfo *t) * Without drawing the first light, users have little clue what they are doing. */ short options = DRAWLIGHT; - TransData *td = t->data; int i; float tmp_axismtx[3][3]; - for (i = 0; i < t->total; i++, td++) { - float co[3]; - float (*axismtx)[3]; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + float co[3]; + float (*axismtx)[3]; - if (t->flag & T_PROP_EDIT) { - /* we're sorted, so skip the rest */ - if (td->factor == 0.0f) { - break; + if (t->flag & T_PROP_EDIT) { + /* we're sorted, so skip the rest */ + if (td->factor == 0.0f) { + break; + } } - } - if (t->options & CTX_GPENCIL_STROKES) { - /* only draw a constraint line for one point, otherwise we can't see anything */ - if ((options & DRAWLIGHT) == 0) { - break; + if (t->options & CTX_GPENCIL_STROKES) { + /* only draw a constraint line for one point, otherwise we can't see anything */ + if ((options & DRAWLIGHT) == 0) { + break; + } } - } - if (t->flag & T_OBJECT) { - copy_v3_v3(co, td->ob->obmat[3]); - axismtx = td->axismtx; - } - else if (t->flag & T_EDIT) { - mul_v3_m4v3(co, t->obedit->obmat, td->center); + if (t->flag & T_OBJECT) { + copy_v3_v3(co, td->ob->obmat[3]); + axismtx = td->axismtx; + } + else if (t->flag & T_EDIT) { + mul_v3_m4v3(co, tc->obedit->obmat, td->center); - mul_m3_m3m3(tmp_axismtx, t->obedit_mat, td->axismtx); - axismtx = tmp_axismtx; - } - else if (t->flag & T_POSE) { - mul_v3_m4v3(co, t->poseobj->obmat, td->center); - axismtx = td->axismtx; - } - else { - copy_v3_v3(co, td->center); - axismtx = td->axismtx; - } + mul_m3_m3m3(tmp_axismtx, tc->obedit_mat, td->axismtx); + axismtx = tmp_axismtx; + } + else if (t->flag & T_POSE) { + mul_v3_m4v3(co, tc->poseobj->obmat, td->center); + axismtx = td->axismtx; + } + else { + copy_v3_v3(co, td->center); + axismtx = td->axismtx; + } - if (t->con.mode & CON_AXIS0) { - drawLine(t, co, axismtx[0], 'X', options); - } - if (t->con.mode & CON_AXIS1) { - drawLine(t, co, axismtx[1], 'Y', options); - } - if (t->con.mode & CON_AXIS2) { - drawLine(t, co, axismtx[2], 'Z', options); + if (t->con.mode & CON_AXIS0) { + drawLine(t, co, axismtx[0], 'X', options); + } + if (t->con.mode & CON_AXIS1) { + drawLine(t, co, axismtx[1], 'Y', options); + } + if (t->con.mode & CON_AXIS2) { + drawLine(t, co, axismtx[2], 'Z', options); + } + options &= ~DRAWLIGHT; } - options &= ~DRAWLIGHT; } } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index fff124c8995..91b5be2f81c 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -130,7 +130,7 @@ */ static void transform_around_single_fallback(TransInfo *t) { - if ((t->total == 1) && + if ((t->data_len_all == 1) && (ELEM(t->around, V3D_AROUND_CENTER_BOUNDS, V3D_AROUND_CENTER_MEAN, V3D_AROUND_ACTIVE)) && (ELEM(t->mode, TFM_RESIZE, TFM_ROTATION, TFM_TRACKBALL))) { @@ -171,45 +171,50 @@ static int trans_data_compare_rdist(const void *a, const void *b) void sort_trans_data_dist(TransInfo *t) { - TransData *start = t->data; - int i; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *start = tc->data; + int i; - for (i = 0; i < t->total && start->flag & TD_SELECTED; i++) - start++; - - if (i < t->total) { - if (t->flag & T_PROP_CONNECTED) - qsort(start, t->total - i, sizeof(TransData), trans_data_compare_dist); - else - qsort(start, t->total - i, sizeof(TransData), trans_data_compare_rdist); + for (i = 0; i < tc->data_len && start->flag & TD_SELECTED; i++) { + start++; + } + + if (i < tc->data_len) { + if (t->flag & T_PROP_CONNECTED) + qsort(start, tc->data_len - i, sizeof(TransData), trans_data_compare_dist); + else + qsort(start, tc->data_len - i, sizeof(TransData), trans_data_compare_rdist); + } } } static void sort_trans_data(TransInfo *t) { - TransData *sel, *unsel; - TransData temp; - unsel = t->data; - sel = t->data; - sel += t->total - 1; - while (sel > unsel) { - while (unsel->flag & TD_SELECTED) { - unsel++; - if (unsel == sel) { - return; - } - } - while (!(sel->flag & TD_SELECTED)) { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *sel, *unsel; + TransData temp; + unsel = tc->data; + sel = tc->data; + sel += tc->data_len - 1; + while (sel > unsel) { + while (unsel->flag & TD_SELECTED) { + unsel++; + if (unsel == sel) { + return; + } + } + while (!(sel->flag & TD_SELECTED)) { + sel--; + if (unsel == sel) { + return; + } + } + temp = *unsel; + *unsel = *sel; + *sel = temp; sel--; - if (unsel == sel) { - return; - } + unsel++; } - temp = *unsel; - *unsel = *sel; - *sel = temp; - sel--; - unsel++; } } @@ -217,7 +222,6 @@ static void sort_trans_data(TransInfo *t) * warning; this is loops inside loop, has minor N^2 issues, but by sorting list it is OK */ static void set_prop_dist(TransInfo *t, const bool with_dist) { - TransData *tob; int a; float _proj_vec[3]; @@ -234,49 +238,52 @@ static void set_prop_dist(TransInfo *t, const bool with_dist) } } - for (a = 0, tob = t->data; a < t->total; a++, tob++) { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *tob = tc->data; + for (a = 0; a < tc->data_len; a++, tob++) { - tob->rdist = 0.0f; // init, it was mallocced + tob->rdist = 0.0f; // init, it was mallocced - if ((tob->flag & TD_SELECTED) == 0) { - TransData *td; - int i; - float dist_sq, vec[3]; + if ((tob->flag & TD_SELECTED) == 0) { + TransData *td; + int i; + float dist_sq, vec[3]; - tob->rdist = -1.0f; // signal for next loop + tob->rdist = -1.0f; // signal for next loop - for (i = 0, td = t->data; i < t->total; i++, td++) { - if (td->flag & TD_SELECTED) { - if (use_island) { - sub_v3_v3v3(vec, tob->iloc, td->iloc); - } - else { - sub_v3_v3v3(vec, tob->center, td->center); - } - mul_m3_v3(tob->mtx, vec); + for (i = 0, td = tc->data; i < tc->data_len; i++, td++) { + if (td->flag & TD_SELECTED) { + if (use_island) { + sub_v3_v3v3(vec, tob->iloc, td->iloc); + } + else { + sub_v3_v3v3(vec, tob->center, td->center); + } + mul_m3_v3(tob->mtx, vec); - if (proj_vec) { - float vec_p[3]; - project_v3_v3v3(vec_p, vec, proj_vec); - sub_v3_v3(vec, vec_p); - } + if (proj_vec) { + float vec_p[3]; + project_v3_v3v3(vec_p, vec, proj_vec); + sub_v3_v3(vec, vec_p); + } - dist_sq = len_squared_v3(vec); - if ((tob->rdist == -1.0f) || (dist_sq < SQUARE(tob->rdist))) { - tob->rdist = sqrtf(dist_sq); - if (use_island) { - copy_v3_v3(tob->center, td->center); - copy_m3_m3(tob->axismtx, td->axismtx); + dist_sq = len_squared_v3(vec); + if ((tob->rdist == -1.0f) || (dist_sq < SQUARE(tob->rdist))) { + tob->rdist = sqrtf(dist_sq); + if (use_island) { + copy_v3_v3(tob->center, td->center); + copy_m3_m3(tob->axismtx, td->axismtx); + } } } + else { + break; /* by definition transdata has selected items in beginning */ + } } - else { - break; /* by definition transdata has selected items in beginning */ + if (with_dist) { + tob->dist = tob->rdist; } } - if (with_dist) { - tob->dist = tob->rdist; - } } } } @@ -296,26 +303,32 @@ static void createTransTexspace(TransInfo *t) ob = OBACT(view_layer); if (ob == NULL) { // Shouldn't logically happen, but still... - t->total = 0; + t->data_len_all = 0; return; } id = ob->data; if (id == NULL || !ELEM(GS(id->name), ID_ME, ID_CU, ID_MB)) { BKE_report(t->reports, RPT_ERROR, "Unsupported object type for text-space transform"); - t->total = 0; + t->data_len_all = 0; return; } if (BKE_object_obdata_is_libdata(ob)) { BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform"); - t->total = 0; + t->data_len_all = 0; return; } - t->total = 1; - td = t->data = MEM_callocN(sizeof(TransData), "TransTexspace"); - td->ext = t->ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace"); + + { + TransDataContainer *tc = t->data_container = MEM_callocN(sizeof(*t->data_container), __func__); + tc->data_len = 1; + td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace"); + td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace"); + } + + t->data_len_all = 1; td->flag = TD_SELECTED; copy_v3_v3(td->center, ob->obmat[3]); @@ -340,72 +353,77 @@ static void createTransTexspace(TransInfo *t) static void createTransEdge(TransInfo *t) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); - TransData *td = NULL; - BMEdge *eed; - BMIter iter; - float mtx[3][3], smtx[3][3]; - int count = 0, countsel = 0; - const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; - int cd_edge_float_offset; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { - if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { - if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) countsel++; - if (is_prop_edit) count++; + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); + TransData *td = NULL; + BMEdge *eed; + BMIter iter; + float mtx[3][3], smtx[3][3]; + int count = 0, countsel = 0; + const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; + int cd_edge_float_offset; + + BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { + if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { + if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) countsel++; + if (is_prop_edit) count++; + } } - } - if (countsel == 0) - return; + if (countsel == 0) { + tc->data_len = 0; + continue; + } - if (is_prop_edit) { - t->total = count; - } - else { - t->total = countsel; - } + if (is_prop_edit) { + tc->data_len = count; + } + else { + tc->data_len = countsel; + } - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransCrease"); + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransCrease"); - copy_m3_m4(mtx, t->obedit->obmat); - pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); + copy_m3_m4(mtx, tc->obedit->obmat); + pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); - /* create data we need */ - if (t->mode == TFM_BWEIGHT) { - BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_EDGE_BWEIGHT); - cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT); - } - else { //if (t->mode == TFM_CREASE) { - BLI_assert(t->mode == TFM_CREASE); - BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_EDGE_CREASE); - cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE); - } + /* create data we need */ + if (t->mode == TFM_BWEIGHT) { + BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_EDGE_BWEIGHT); + cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT); + } + else { //if (t->mode == TFM_CREASE) { + BLI_assert(t->mode == TFM_CREASE); + BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_EDGE_CREASE); + cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE); + } - BLI_assert(cd_edge_float_offset != -1); + BLI_assert(cd_edge_float_offset != -1); - BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { - if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && (BM_elem_flag_test(eed, BM_ELEM_SELECT) || is_prop_edit)) { - float *fl_ptr; - /* need to set center for center calculations */ - mid_v3_v3v3(td->center, eed->v1->co, eed->v2->co); + BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { + if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && (BM_elem_flag_test(eed, BM_ELEM_SELECT) || is_prop_edit)) { + float *fl_ptr; + /* need to set center for center calculations */ + mid_v3_v3v3(td->center, eed->v1->co, eed->v2->co); - td->loc = NULL; - if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) - td->flag = TD_SELECTED; - else - td->flag = 0; + td->loc = NULL; + if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) + td->flag = TD_SELECTED; + else + td->flag = 0; - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - td->ext = NULL; + td->ext = NULL; - fl_ptr = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_float_offset); - td->val = fl_ptr; - td->ival = *fl_ptr; + fl_ptr = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_float_offset); + td->val = fl_ptr; + td->ival = *fl_ptr; - td++; + td++; + } } } } @@ -523,7 +541,7 @@ static short apply_targetless_ik(Object *ob) return apply; } -static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, TransData *td) +static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, TransDataContainer *tc, TransData *td) { Bone *bone = pchan->bone; float pmat[3][3], omat[3][3]; @@ -634,7 +652,7 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr normalize_m3(td->axismtx); if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) { - bArmature *arm = t->poseobj->data; + bArmature *arm = tc->poseobj->data; if ((t->mode == TFM_BONE_ENVELOPE_DIST) || (arm->drawtype == ARM_ENVELOPE)) { td->loc = NULL; @@ -828,14 +846,19 @@ void transform_autoik_update(TransInfo *t, short mode) } } - /* sanity checks (don't assume t->poseobj is set, or that it is an armature) */ - if (ELEM(NULL, t->poseobj, t->poseobj->pose)) - return; - /* apply to all pose-channels */ bool changed = false; - for (pchan = t->poseobj->pose->chanbase.first; pchan; pchan = pchan->next) { - changed |= pchan_autoik_adjust(pchan, *chainlen); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + + /* sanity checks (don't assume t->poseobj is set, or that it is an armature) */ + if (ELEM(NULL, tc->poseobj, tc->poseobj->pose)) { + continue; + } + + for (pchan = tc->poseobj->pose->chanbase.first; pchan; pchan = pchan->next) { + changed |= pchan_autoik_adjust(pchan, *chainlen); + } } if (changed) { @@ -1045,75 +1068,101 @@ static short pose_grab_with_ik(Object *ob) } -/* only called with pose mode active object now */ -static void createTransPose(TransInfo *t, Object *ob) +/** + * When objects array is NULL, use 't->data_container' as is. + */ +static void createTransPose(TransInfo *t, Object **objects, uint objects_len) { - bArmature *arm; - bPoseChannel *pchan; - TransData *td; - TransDataExtension *tdx; - short ik_on = 0; - int i; + if (objects != NULL) { + if (t->data_container) { + MEM_freeN(t->data_container); + } + t->data_container = MEM_callocN(sizeof(*t->data_container) * objects_len, __func__); + t->data_container_len = objects_len; + int th_index; + FOREACH_TRANS_DATA_CONTAINER_INDEX (t, tc, th_index) { + tc->poseobj = objects[th_index]; + } + } - t->total = 0; + t->data_len_all = 0; - /* check validity of state */ - arm = BKE_armature_from_object(ob); - if ((arm == NULL) || (ob->pose == NULL)) return; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Object *ob = tc->poseobj; - if (arm->flag & ARM_RESTPOS) { - if (ELEM(t->mode, TFM_DUMMY, TFM_BONESIZE) == 0) { - BKE_report(t->reports, RPT_ERROR, "Cannot change Pose when 'Rest Position' is enabled"); - return; + bArmature *arm; + bPoseChannel *pchan; + TransData *td; + TransDataExtension *tdx; + short ik_on = 0; + int i; + + + /* check validity of state */ + arm = BKE_armature_from_object(tc->poseobj); + if ((arm == NULL) || (ob->pose == NULL)) { + continue; } - } - /* do we need to add temporal IK chains? */ - if ((arm->flag & ARM_AUTO_IK) && t->mode == TFM_TRANSLATION) { - ik_on = pose_grab_with_ik(ob); - if (ik_on) t->flag |= T_AUTOIK; - } + if (arm->flag & ARM_RESTPOS) { + if (ELEM(t->mode, TFM_DUMMY, TFM_BONESIZE) == 0) { + BKE_report(t->reports, RPT_ERROR, "Cannot change Pose when 'Rest Position' is enabled"); + return; + } + } - /* set flags and count total (warning, can change transform to rotate) */ - t->total = count_set_pose_transflags(&t->mode, t->around, ob); + /* do we need to add temporal IK chains? */ + if ((arm->flag & ARM_AUTO_IK) && t->mode == TFM_TRANSLATION) { + ik_on = pose_grab_with_ik(ob); + if (ik_on) t->flag |= T_AUTOIK; + } - if (t->total == 0) return; + /* set flags and count total (warning, can change transform to rotate) */ + tc->data_len = count_set_pose_transflags(&t->mode, t->around, ob); - t->flag |= T_POSE; - t->poseobj = ob; /* we also allow non-active objects to be transformed, in weightpaint */ + if (tc->data_len == 0) { + continue; + } - /* disable PET, its not usable in pose mode yet [#32444] */ - t->flag &= ~T_PROP_EDIT_ALL; + tc->poseobj = ob; /* we also allow non-active objects to be transformed, in weightpaint */ - /* init trans data */ - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransPoseBone"); - tdx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "TransPoseBoneExt"); - for (i = 0; i < t->total; i++, td++, tdx++) { - td->ext = tdx; - td->val = NULL; - } + /* init trans data */ + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransPoseBone"); + tdx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "TransPoseBoneExt"); + for (i = 0; i < tc->data_len; i++, td++, tdx++) { + td->ext = tdx; + td->val = NULL; + } - /* use pose channels to fill trans data */ - td = t->data; - for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - if (pchan->bone->flag & BONE_TRANSFORM) { - add_pose_transdata(t, pchan, ob, td); - td++; + /* use pose channels to fill trans data */ + td = tc->data; + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + if (pchan->bone->flag & BONE_TRANSFORM) { + add_pose_transdata(t, pchan, ob, tc, td); + td++; + } + } + + if (td != (tc->data + tc->data_len)) { + BKE_report(t->reports, RPT_DEBUG, "Bone selection count error"); } - } - if (td != (t->data + t->total)) { - BKE_report(t->reports, RPT_DEBUG, "Bone selection count error"); + /* initialize initial auto=ik chainlen's? */ + if (ik_on) { + transform_autoik_update(t, 0); + } } - /* initialize initial auto=ik chainlen's? */ - if (ik_on) transform_autoik_update(t, 0); + t->flag |= T_POSE; + /* disable PET, its not usable in pose mode yet [#32444] */ + t->flag &= ~T_PROP_EDIT_ALL; + } -void restoreBones(TransInfo *t) +void restoreBones(TransDataContainer *tc) { - bArmature *arm = t->obedit->data; - BoneInitData *bid = t->custom.type.data; + bArmature *arm = tc->obedit->data; + BoneInitData *bid = tc->custom.type.data; EditBone *ebo; while (bid->bone) { @@ -1154,226 +1203,230 @@ void restoreBones(TransInfo *t) /* ********************* armature ************** */ static void createTransArmatureVerts(TransInfo *t) { - EditBone *ebo, *eboflip; - bArmature *arm = t->obedit->data; - ListBase *edbo = arm->edbo; - TransData *td, *td_old; - float mtx[3][3], smtx[3][3], bonemat[3][3]; - bool mirror = ((arm->flag & ARM_MIRROR_EDIT) != 0); - int total_mirrored = 0, i; - int oldtot; - BoneInitData *bid; - - t->total = 0; - for (ebo = edbo->first; ebo; ebo = ebo->next) { - oldtot = t->total; - - if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) { - if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) { - if (ebo->flag & BONE_SELECTED) - t->total++; - } - else if (t->mode == TFM_BONE_ROLL) { - if (ebo->flag & BONE_SELECTED) - t->total++; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + EditBone *ebo, *eboflip; + bArmature *arm = tc->obedit->data; + ListBase *edbo = arm->edbo; + TransData *td, *td_old; + float mtx[3][3], smtx[3][3], bonemat[3][3]; + bool mirror = ((arm->flag & ARM_MIRROR_EDIT) != 0); + int total_mirrored = 0, i; + int oldtot; + BoneInitData *bid; + + tc->data_len = 0; + for (ebo = edbo->first; ebo; ebo = ebo->next) { + oldtot = tc->data_len; + + if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) { + if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) { + if (ebo->flag & BONE_SELECTED) + tc->data_len++; + } + else if (t->mode == TFM_BONE_ROLL) { + if (ebo->flag & BONE_SELECTED) + tc->data_len++; + } + else { + if (ebo->flag & BONE_TIPSEL) + tc->data_len++; + if (ebo->flag & BONE_ROOTSEL) + tc->data_len++; + } } - else { - if (ebo->flag & BONE_TIPSEL) - t->total++; - if (ebo->flag & BONE_ROOTSEL) - t->total++; + + if (mirror && (oldtot < tc->data_len)) { + eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); + if (eboflip) + total_mirrored++; } } - if (mirror && (oldtot < t->total)) { - eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); - if (eboflip) - total_mirrored++; + if (!tc->data_len) { + continue; } - } - if (!t->total) return; + transform_around_single_fallback(t); - transform_around_single_fallback(t); + copy_m3_m4(mtx, tc->obedit->obmat); + pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); - copy_m3_m4(mtx, t->obedit->obmat); - pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransEditBone"); - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransEditBone"); + if (mirror) { + tc->custom.type.data = bid = MEM_mallocN((total_mirrored + 1) * sizeof(BoneInitData), "BoneInitData"); + tc->custom.type.use_free = true; + } - if (mirror) { - t->custom.type.data = bid = MEM_mallocN((total_mirrored + 1) * sizeof(BoneInitData), "BoneInitData"); - t->custom.type.use_free = true; - } + i = 0; - i = 0; + for (ebo = edbo->first; ebo; ebo = ebo->next) { + td_old = td; + ebo->oldlength = ebo->length; // length==0.0 on extrude, used for scaling radius of bone points - for (ebo = edbo->first; ebo; ebo = ebo->next) { - td_old = td; - ebo->oldlength = ebo->length; // length==0.0 on extrude, used for scaling radius of bone points + if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) { + if (t->mode == TFM_BONE_ENVELOPE) { + if (ebo->flag & BONE_ROOTSEL) { + td->val = &ebo->rad_head; + td->ival = *td->val; - if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) { - if (t->mode == TFM_BONE_ENVELOPE) { - if (ebo->flag & BONE_ROOTSEL) { - td->val = &ebo->rad_head; - td->ival = *td->val; + copy_v3_v3(td->center, ebo->head); + td->flag = TD_SELECTED; - copy_v3_v3(td->center, ebo->head); - td->flag = TD_SELECTED; + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); + td->loc = NULL; + td->ext = NULL; + td->ob = tc->obedit; - td->loc = NULL; - td->ext = NULL; - td->ob = t->obedit; + td++; + } + if (ebo->flag & BONE_TIPSEL) { + td->val = &ebo->rad_tail; + td->ival = *td->val; + copy_v3_v3(td->center, ebo->tail); + td->flag = TD_SELECTED; - td++; - } - if (ebo->flag & BONE_TIPSEL) { - td->val = &ebo->rad_tail; - td->ival = *td->val; - copy_v3_v3(td->center, ebo->tail); - td->flag = TD_SELECTED; + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); + td->loc = NULL; + td->ext = NULL; + td->ob = tc->obedit; - td->loc = NULL; - td->ext = NULL; - td->ob = t->obedit; + td++; + } - td++; } + else if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) { + if (ebo->flag & BONE_SELECTED) { + if ((t->mode == TFM_BONE_ENVELOPE_DIST) || (arm->drawtype == ARM_ENVELOPE)) { + td->loc = NULL; + td->val = &ebo->dist; + td->ival = ebo->dist; + } + else { + // abusive storage of scale in the loc pointer :) + td->loc = &ebo->xwidth; + copy_v3_v3(td->iloc, td->loc); + td->val = NULL; + } + copy_v3_v3(td->center, ebo->head); + td->flag = TD_SELECTED; - } - else if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) { - if (ebo->flag & BONE_SELECTED) { - if ((t->mode == TFM_BONE_ENVELOPE_DIST) || (arm->drawtype == ARM_ENVELOPE)) { - td->loc = NULL; - td->val = &ebo->dist; - td->ival = ebo->dist; - } - else { - // abusive storage of scale in the loc pointer :) - td->loc = &ebo->xwidth; - copy_v3_v3(td->iloc, td->loc); - td->val = NULL; - } - copy_v3_v3(td->center, ebo->head); - td->flag = TD_SELECTED; - - /* use local bone matrix */ - ED_armature_ebone_to_mat3(ebo, bonemat); - mul_m3_m3m3(td->mtx, mtx, bonemat); - invert_m3_m3(td->smtx, td->mtx); + /* use local bone matrix */ + ED_armature_ebone_to_mat3(ebo, bonemat); + mul_m3_m3m3(td->mtx, mtx, bonemat); + invert_m3_m3(td->smtx, td->mtx); - copy_m3_m3(td->axismtx, td->mtx); - normalize_m3(td->axismtx); + copy_m3_m3(td->axismtx, td->mtx); + normalize_m3(td->axismtx); - td->ext = NULL; - td->ob = t->obedit; + td->ext = NULL; + td->ob = tc->obedit; - td++; + td++; + } } - } - else if (t->mode == TFM_BONE_ROLL) { - if (ebo->flag & BONE_SELECTED) { - td->loc = NULL; - td->val = &(ebo->roll); - td->ival = ebo->roll; + else if (t->mode == TFM_BONE_ROLL) { + if (ebo->flag & BONE_SELECTED) { + td->loc = NULL; + td->val = &(ebo->roll); + td->ival = ebo->roll; - copy_v3_v3(td->center, ebo->head); - td->flag = TD_SELECTED; + copy_v3_v3(td->center, ebo->head); + td->flag = TD_SELECTED; - td->ext = NULL; - td->ob = t->obedit; + td->ext = NULL; + td->ob = tc->obedit; - td++; - } - } - else { - if (ebo->flag & BONE_TIPSEL) { - copy_v3_v3(td->iloc, ebo->tail); - - /* Don't allow single selected tips to have a modified center, - * causes problem with snapping (see T45974). - * However, in rotation mode, we want to keep that 'rotate bone around root with - * only its tip selected' behavior (see T46325). */ - if ((t->around == V3D_AROUND_LOCAL_ORIGINS) && - ((t->mode == TFM_ROTATION) || (ebo->flag & BONE_ROOTSEL))) - { - copy_v3_v3(td->center, ebo->head); - } - else { - copy_v3_v3(td->center, td->iloc); + td++; } + } + else { + if (ebo->flag & BONE_TIPSEL) { + copy_v3_v3(td->iloc, ebo->tail); + + /* Don't allow single selected tips to have a modified center, + * causes problem with snapping (see T45974). + * However, in rotation mode, we want to keep that 'rotate bone around root with + * only its tip selected' behavior (see T46325). */ + if ((t->around == V3D_AROUND_LOCAL_ORIGINS) && + ((t->mode == TFM_ROTATION) || (ebo->flag & BONE_ROOTSEL))) + { + copy_v3_v3(td->center, ebo->head); + } + else { + copy_v3_v3(td->center, td->iloc); + } - td->loc = ebo->tail; - td->flag = TD_SELECTED; - if (ebo->flag & BONE_EDITMODE_LOCKED) - td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE; + td->loc = ebo->tail; + td->flag = TD_SELECTED; + if (ebo->flag & BONE_EDITMODE_LOCKED) + td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE; - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - ED_armature_ebone_to_mat3(ebo, td->axismtx); + ED_armature_ebone_to_mat3(ebo, td->axismtx); - if ((ebo->flag & BONE_ROOTSEL) == 0) { - td->extra = ebo; - td->ival = ebo->roll; - } + if ((ebo->flag & BONE_ROOTSEL) == 0) { + td->extra = ebo; + td->ival = ebo->roll; + } - td->ext = NULL; - td->val = NULL; - td->ob = t->obedit; + td->ext = NULL; + td->val = NULL; + td->ob = tc->obedit; - td++; - } - if (ebo->flag & BONE_ROOTSEL) { - copy_v3_v3(td->iloc, ebo->head); - copy_v3_v3(td->center, td->iloc); - td->loc = ebo->head; - td->flag = TD_SELECTED; - if (ebo->flag & BONE_EDITMODE_LOCKED) - td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE; + td++; + } + if (ebo->flag & BONE_ROOTSEL) { + copy_v3_v3(td->iloc, ebo->head); + copy_v3_v3(td->center, td->iloc); + td->loc = ebo->head; + td->flag = TD_SELECTED; + if (ebo->flag & BONE_EDITMODE_LOCKED) + td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE; - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - ED_armature_ebone_to_mat3(ebo, td->axismtx); + ED_armature_ebone_to_mat3(ebo, td->axismtx); - td->extra = ebo; /* to fix roll */ - td->ival = ebo->roll; + td->extra = ebo; /* to fix roll */ + td->ival = ebo->roll; - td->ext = NULL; - td->val = NULL; - td->ob = t->obedit; + td->ext = NULL; + td->val = NULL; + td->ob = tc->obedit; - td++; + td++; + } } } - } - if (mirror && (td_old != td)) { - eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); - if (eboflip) { - bid[i].bone = eboflip; - bid[i].dist = eboflip->dist; - bid[i].rad_tail = eboflip->rad_tail; - bid[i].roll = eboflip->roll; - bid[i].xwidth = eboflip->xwidth; - bid[i].zwidth = eboflip->zwidth; - copy_v3_v3(bid[i].head, eboflip->head); - copy_v3_v3(bid[i].tail, eboflip->tail); - i++; + if (mirror && (td_old != td)) { + eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo); + if (eboflip) { + bid[i].bone = eboflip; + bid[i].dist = eboflip->dist; + bid[i].rad_tail = eboflip->rad_tail; + bid[i].roll = eboflip->roll; + bid[i].xwidth = eboflip->xwidth; + bid[i].zwidth = eboflip->zwidth; + copy_v3_v3(bid[i].head, eboflip->head); + copy_v3_v3(bid[i].tail, eboflip->tail); + i++; + } } } - } - if (mirror) { - /* trick to terminate iteration */ - bid[total_mirrored].bone = NULL; + if (mirror) { + /* trick to terminate iteration */ + bid[total_mirrored].bone = NULL; + } } } @@ -1381,72 +1434,76 @@ static void createTransArmatureVerts(TransInfo *t) static void createTransMBallVerts(TransInfo *t) { - MetaBall *mb = (MetaBall *)t->obedit->data; - MetaElem *ml; - TransData *td; - TransDataExtension *tx; - float mtx[3][3], smtx[3][3]; - int count = 0, countsel = 0; - const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; - - /* count totals */ - for (ml = mb->editelems->first; ml; ml = ml->next) { - if (ml->flag & SELECT) countsel++; - if (is_prop_edit) count++; - } + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + MetaBall *mb = (MetaBall *)tc->obedit->data; + MetaElem *ml; + TransData *td; + TransDataExtension *tx; + float mtx[3][3], smtx[3][3]; + int count = 0, countsel = 0; + const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; + + /* count totals */ + for (ml = mb->editelems->first; ml; ml = ml->next) { + if (ml->flag & SELECT) countsel++; + if (is_prop_edit) count++; + } - /* note: in prop mode we need at least 1 selected */ - if (countsel == 0) return; + /* note: in prop mode we need at least 1 selected */ + if (countsel == 0) { + continue; + } - if (is_prop_edit) t->total = count; - else t->total = countsel; + if (is_prop_edit) tc->data_len = count; + else tc->data_len = countsel; - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(MBall EditMode)"); - tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "MetaElement_TransExtension"); + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(MBall EditMode)"); + tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "MetaElement_TransExtension"); - copy_m3_m4(mtx, t->obedit->obmat); - pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); + copy_m3_m4(mtx, tc->obedit->obmat); + pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); - for (ml = mb->editelems->first; ml; ml = ml->next) { - if (is_prop_edit || (ml->flag & SELECT)) { - td->loc = &ml->x; - copy_v3_v3(td->iloc, td->loc); - copy_v3_v3(td->center, td->loc); + for (ml = mb->editelems->first; ml; ml = ml->next) { + if (is_prop_edit || (ml->flag & SELECT)) { + td->loc = &ml->x; + copy_v3_v3(td->iloc, td->loc); + copy_v3_v3(td->center, td->loc); - quat_to_mat3(td->axismtx, ml->quat); + quat_to_mat3(td->axismtx, ml->quat); - if (ml->flag & SELECT) td->flag = TD_SELECTED | TD_USEQUAT | TD_SINGLESIZE; - else td->flag = TD_USEQUAT; + if (ml->flag & SELECT) td->flag = TD_SELECTED | TD_USEQUAT | TD_SINGLESIZE; + else td->flag = TD_USEQUAT; - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - td->ext = tx; + td->ext = tx; - /* Radius of MetaElem (mass of MetaElem influence) */ - if (ml->flag & MB_SCALE_RAD) { - td->val = &ml->rad; - td->ival = ml->rad; - } - else { - td->val = &ml->s; - td->ival = ml->s; - } + /* Radius of MetaElem (mass of MetaElem influence) */ + if (ml->flag & MB_SCALE_RAD) { + td->val = &ml->rad; + td->ival = ml->rad; + } + else { + td->val = &ml->s; + td->ival = ml->s; + } - /* expx/expy/expz determine "shape" of some MetaElem types */ - tx->size = &ml->expx; - tx->isize[0] = ml->expx; - tx->isize[1] = ml->expy; - tx->isize[2] = ml->expz; + /* expx/expy/expz determine "shape" of some MetaElem types */ + tx->size = &ml->expx; + tx->isize[0] = ml->expx; + tx->isize[1] = ml->expy; + tx->isize[2] = ml->expz; - /* quat is used for rotation of MetaElem */ - tx->quat = ml->quat; - copy_qt_qt(tx->iquat, ml->quat); + /* quat is used for rotation of MetaElem */ + tx->quat = ml->quat; + copy_qt_qt(tx->iquat, ml->quat); - tx->rot = NULL; + tx->rot = NULL; - td++; - tx++; + td++; + tx++; + } } } } @@ -1555,271 +1612,276 @@ static int bezt_select_to_transform_triple_flag( static void createTransCurveVerts(TransInfo *t) { - Curve *cu = t->obedit->data; - TransData *td = NULL; - Nurb *nu; - BezTriple *bezt; - BPoint *bp; - float mtx[3][3], smtx[3][3]; - int a; - int count = 0, countsel = 0; - const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; - short hide_handles = (cu->drawflag & CU_HIDE_HANDLES); - ListBase *nurbs; - - /* to be sure */ - if (cu->editnurb == NULL) return; - -#define SEL_F1 (1 << 0) -#define SEL_F2 (1 << 1) -#define SEL_F3 (1 << 2) - - /* count total of vertices, check identical as in 2nd loop for making transdata! */ - nurbs = BKE_curve_editNurbs_get(cu); - for (nu = nurbs->first; nu; nu = nu->next) { - if (nu->type == CU_BEZIER) { - for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) { - if (bezt->hide == 0) { - const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles); - if (bezt_tx & SEL_F1) { countsel++; } - if (bezt_tx & SEL_F2) { countsel++; } - if (bezt_tx & SEL_F3) { countsel++; } - if (is_prop_edit) count += 3; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + + Curve *cu = tc->obedit->data; + TransData *td = NULL; + Nurb *nu; + BezTriple *bezt; + BPoint *bp; + float mtx[3][3], smtx[3][3]; + int a; + int count = 0, countsel = 0; + const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; + short hide_handles = (cu->drawflag & CU_HIDE_HANDLES); + ListBase *nurbs; + + /* to be sure */ + if (cu->editnurb == NULL) return; + + #define SEL_F1 (1 << 0) + #define SEL_F2 (1 << 1) + #define SEL_F3 (1 << 2) + + /* count total of vertices, check identical as in 2nd loop for making transdata! */ + nurbs = BKE_curve_editNurbs_get(cu); + for (nu = nurbs->first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) { + for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) { + if (bezt->hide == 0) { + const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles); + if (bezt_tx & SEL_F1) { countsel++; } + if (bezt_tx & SEL_F2) { countsel++; } + if (bezt_tx & SEL_F3) { countsel++; } + if (is_prop_edit) count += 3; + } } } - } - else { - for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) { - if (bp->hide == 0) { - if (is_prop_edit) count++; - if (bp->f1 & SELECT) countsel++; + else { + for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) { + if (bp->hide == 0) { + if (is_prop_edit) count++; + if (bp->f1 & SELECT) countsel++; + } } } } - } - /* note: in prop mode we need at least 1 selected */ - if (countsel == 0) return; + /* note: in prop mode we need at least 1 selected */ + if (countsel == 0) { + tc->data_len = 0; + continue; + } - if (is_prop_edit) t->total = count; - else t->total = countsel; - t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Curve EditMode)"); + if (is_prop_edit) tc->data_len = count; + else tc->data_len = countsel; + tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Curve EditMode)"); - transform_around_single_fallback(t); + transform_around_single_fallback(t); - copy_m3_m4(mtx, t->obedit->obmat); - pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); + copy_m3_m4(mtx, tc->obedit->obmat); + pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); - td = t->data; - for (nu = nurbs->first; nu; nu = nu->next) { - if (nu->type == CU_BEZIER) { - TransData *head, *tail; - head = tail = td; - for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) { - if (bezt->hide == 0) { - TransDataCurveHandleFlags *hdata = NULL; - float axismtx[3][3]; + td = tc->data; + for (nu = nurbs->first; nu; nu = nu->next) { + if (nu->type == CU_BEZIER) { + TransData *head, *tail; + head = tail = td; + for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) { + if (bezt->hide == 0) { + TransDataCurveHandleFlags *hdata = NULL; + float axismtx[3][3]; - if (t->around == V3D_AROUND_LOCAL_ORIGINS) { - float normal[3], plane[3]; + if (t->around == V3D_AROUND_LOCAL_ORIGINS) { + float normal[3], plane[3]; - BKE_nurb_bezt_calc_normal(nu, bezt, normal); - BKE_nurb_bezt_calc_plane(nu, bezt, plane); + BKE_nurb_bezt_calc_normal(nu, bezt, normal); + BKE_nurb_bezt_calc_plane(nu, bezt, plane); - if (createSpaceNormalTangent(axismtx, normal, plane)) { - /* pass */ - } - else { - normalize_v3(normal); - axis_dominant_v3_to_m3(axismtx, normal); - invert_m3(axismtx); + if (createSpaceNormalTangent(axismtx, normal, plane)) { + /* pass */ + } + else { + normalize_v3(normal); + axis_dominant_v3_to_m3(axismtx, normal); + invert_m3(axismtx); + } } - } - /* Elements that will be transform (not always a match to selection). */ - const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles); + /* Elements that will be transform (not always a match to selection). */ + const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles); + + if (is_prop_edit || bezt_tx & SEL_F1) { + copy_v3_v3(td->iloc, bezt->vec[0]); + td->loc = bezt->vec[0]; + copy_v3_v3(td->center, bezt->vec[(hide_handles || + (t->around == V3D_AROUND_LOCAL_ORIGINS) || + (bezt->f2 & SELECT)) ? 1 : 0]); + if (hide_handles) { + if (bezt->f2 & SELECT) td->flag = TD_SELECTED; + else td->flag = 0; + } + else { + if (bezt->f1 & SELECT) td->flag = TD_SELECTED; + else td->flag = 0; + } + td->ext = NULL; + td->val = NULL; - if (is_prop_edit || bezt_tx & SEL_F1) { - copy_v3_v3(td->iloc, bezt->vec[0]); - td->loc = bezt->vec[0]; - copy_v3_v3(td->center, bezt->vec[(hide_handles || - (t->around == V3D_AROUND_LOCAL_ORIGINS) || - (bezt->f2 & SELECT)) ? 1 : 0]); - if (hide_handles) { - if (bezt->f2 & SELECT) td->flag = TD_SELECTED; - else td->flag = 0; - } - else { - if (bezt->f1 & SELECT) td->flag = TD_SELECTED; - else td->flag = 0; - } - td->ext = NULL; - td->val = NULL; + hdata = initTransDataCurveHandles(td, bezt); - hdata = initTransDataCurveHandles(td, bezt); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); + if (t->around == V3D_AROUND_LOCAL_ORIGINS) { + copy_m3_m3(td->axismtx, axismtx); + } - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); - if (t->around == V3D_AROUND_LOCAL_ORIGINS) { - copy_m3_m3(td->axismtx, axismtx); + td++; + count++; + tail++; } - td++; - count++; - tail++; - } + /* This is the Curve Point, the other two are handles */ + if (is_prop_edit || bezt_tx & SEL_F2) { + copy_v3_v3(td->iloc, bezt->vec[1]); + td->loc = bezt->vec[1]; + copy_v3_v3(td->center, td->loc); + if (bezt->f2 & SELECT) td->flag = TD_SELECTED; + else td->flag = 0; + td->ext = NULL; - /* This is the Curve Point, the other two are handles */ - if (is_prop_edit || bezt_tx & SEL_F2) { - copy_v3_v3(td->iloc, bezt->vec[1]); - td->loc = bezt->vec[1]; - copy_v3_v3(td->center, td->loc); - if (bezt->f2 & SELECT) td->flag = TD_SELECTED; - else td->flag = 0; - td->ext = NULL; + if (t->mode == TFM_CURVE_SHRINKFATTEN) { /* || t->mode==TFM_RESIZE) {*/ /* TODO - make points scale */ + td->val = &(bezt->radius); + td->ival = bezt->radius; + } + else if (t->mode == TFM_TILT) { + td->val = &(bezt->alfa); + td->ival = bezt->alfa; + } + else { + td->val = NULL; + } - if (t->mode == TFM_CURVE_SHRINKFATTEN) { /* || t->mode==TFM_RESIZE) {*/ /* TODO - make points scale */ - td->val = &(bezt->radius); - td->ival = bezt->radius; - } - else if (t->mode == TFM_TILT) { - td->val = &(bezt->alfa); - td->ival = bezt->alfa; - } - else { - td->val = NULL; - } + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); + if (t->around == V3D_AROUND_LOCAL_ORIGINS) { + copy_m3_m3(td->axismtx, axismtx); + } - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); - if (t->around == V3D_AROUND_LOCAL_ORIGINS) { - copy_m3_m3(td->axismtx, axismtx); + if ((bezt_tx & SEL_F1) == 0 && (bezt_tx & SEL_F3) == 0) + /* If the middle is selected but the sides arnt, this is needed */ + if (hdata == NULL) { /* if the handle was not saved by the previous handle */ + hdata = initTransDataCurveHandles(td, bezt); + } + + td++; + count++; + tail++; } + if (is_prop_edit || bezt_tx & SEL_F3) { + copy_v3_v3(td->iloc, bezt->vec[2]); + td->loc = bezt->vec[2]; + copy_v3_v3(td->center, bezt->vec[(hide_handles || + (t->around == V3D_AROUND_LOCAL_ORIGINS) || + (bezt->f2 & SELECT)) ? 1 : 2]); + if (hide_handles) { + if (bezt->f2 & SELECT) td->flag = TD_SELECTED; + else td->flag = 0; + } + else { + if (bezt->f3 & SELECT) td->flag = TD_SELECTED; + else td->flag = 0; + } + td->ext = NULL; + td->val = NULL; - if ((bezt_tx & SEL_F1) == 0 && (bezt_tx & SEL_F3) == 0) - /* If the middle is selected but the sides arnt, this is needed */ if (hdata == NULL) { /* if the handle was not saved by the previous handle */ hdata = initTransDataCurveHandles(td, bezt); } - td++; - count++; - tail++; - } - if (is_prop_edit || bezt_tx & SEL_F3) { - copy_v3_v3(td->iloc, bezt->vec[2]); - td->loc = bezt->vec[2]; - copy_v3_v3(td->center, bezt->vec[(hide_handles || - (t->around == V3D_AROUND_LOCAL_ORIGINS) || - (bezt->f2 & SELECT)) ? 1 : 2]); - if (hide_handles) { - if (bezt->f2 & SELECT) td->flag = TD_SELECTED; - else td->flag = 0; - } - else { - if (bezt->f3 & SELECT) td->flag = TD_SELECTED; - else td->flag = 0; - } - td->ext = NULL; - td->val = NULL; - - if (hdata == NULL) { /* if the handle was not saved by the previous handle */ - hdata = initTransDataCurveHandles(td, bezt); - } + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); + if (t->around == V3D_AROUND_LOCAL_ORIGINS) { + copy_m3_m3(td->axismtx, axismtx); + } - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); - if (t->around == V3D_AROUND_LOCAL_ORIGINS) { - copy_m3_m3(td->axismtx, axismtx); + td++; + count++; + tail++; } - td++; - count++; - tail++; + (void)hdata; /* quiet warning */ + } + else if (is_prop_edit && head != tail) { + calc_distanceCurveVerts(head, tail - 1); + head = tail; } - - (void)hdata; /* quiet warning */ } - else if (is_prop_edit && head != tail) { + if (is_prop_edit && head != tail) calc_distanceCurveVerts(head, tail - 1); - head = tail; - } - } - if (is_prop_edit && head != tail) - calc_distanceCurveVerts(head, tail - 1); - /* TODO - in the case of tilt and radius we can also avoid allocating the initTransDataCurveHandles - * but for now just don't change handle types */ - if (ELEM(t->mode, TFM_CURVE_SHRINKFATTEN, TFM_TILT, TFM_DUMMY) == 0) { - /* sets the handles based on their selection, do this after the data is copied to the TransData */ - BKE_nurb_handles_test(nu, !hide_handles); + /* TODO - in the case of tilt and radius we can also avoid allocating the initTransDataCurveHandles + * but for now just don't change handle types */ + if (ELEM(t->mode, TFM_CURVE_SHRINKFATTEN, TFM_TILT, TFM_DUMMY) == 0) { + /* sets the handles based on their selection, do this after the data is copied to the TransData */ + BKE_nurb_handles_test(nu, !hide_handles); + } } - } - else { - TransData *head, *tail; - head = tail = td; - for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) { - if (bp->hide == 0) { - if (is_prop_edit || (bp->f1 & SELECT)) { - float axismtx[3][3]; - - if (t->around == V3D_AROUND_LOCAL_ORIGINS) { - if (nu->pntsv == 1) { - float normal[3], plane[3]; - - BKE_nurb_bpoint_calc_normal(nu, bp, normal); - BKE_nurb_bpoint_calc_plane(nu, bp, plane); - - if (createSpaceNormalTangent(axismtx, normal, plane)) { - /* pass */ - } - else { - normalize_v3(normal); - axis_dominant_v3_to_m3(axismtx, normal); - invert_m3(axismtx); + else { + TransData *head, *tail; + head = tail = td; + for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) { + if (bp->hide == 0) { + if (is_prop_edit || (bp->f1 & SELECT)) { + float axismtx[3][3]; + + if (t->around == V3D_AROUND_LOCAL_ORIGINS) { + if (nu->pntsv == 1) { + float normal[3], plane[3]; + + BKE_nurb_bpoint_calc_normal(nu, bp, normal); + BKE_nurb_bpoint_calc_plane(nu, bp, plane); + + if (createSpaceNormalTangent(axismtx, normal, plane)) { + /* pass */ + } + else { + normalize_v3(normal); + axis_dominant_v3_to_m3(axismtx, normal); + invert_m3(axismtx); + } } } - } - copy_v3_v3(td->iloc, bp->vec); - td->loc = bp->vec; - copy_v3_v3(td->center, td->loc); - if (bp->f1 & SELECT) td->flag = TD_SELECTED; - else td->flag = 0; - td->ext = NULL; + copy_v3_v3(td->iloc, bp->vec); + td->loc = bp->vec; + copy_v3_v3(td->center, td->loc); + if (bp->f1 & SELECT) td->flag = TD_SELECTED; + else td->flag = 0; + td->ext = NULL; - if (t->mode == TFM_CURVE_SHRINKFATTEN || t->mode == TFM_RESIZE) { - td->val = &(bp->radius); - td->ival = bp->radius; - } - else { - td->val = &(bp->alfa); - td->ival = bp->alfa; - } + if (t->mode == TFM_CURVE_SHRINKFATTEN || t->mode == TFM_RESIZE) { + td->val = &(bp->radius); + td->ival = bp->radius; + } + else { + td->val = &(bp->alfa); + td->ival = bp->alfa; + } - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); - if (t->around == V3D_AROUND_LOCAL_ORIGINS) { - if (nu->pntsv == 1) { - copy_m3_m3(td->axismtx, axismtx); + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); + if (t->around == V3D_AROUND_LOCAL_ORIGINS) { + if (nu->pntsv == 1) { + copy_m3_m3(td->axismtx, axismtx); + } } - } - td++; - count++; - tail++; + td++; + count++; + tail++; + } + } + else if (is_prop_edit && head != tail) { + calc_distanceCurveVerts(head, tail - 1); + head = tail; } } - else if (is_prop_edit && head != tail) { + if (is_prop_edit && head != tail) calc_distanceCurveVerts(head, tail - 1); - head = tail; - } } - if (is_prop_edit && head != tail) - calc_distanceCurveVerts(head, tail - 1); } } - #undef SEL_F1 #undef SEL_F2 #undef SEL_F3 @@ -1829,227 +1891,236 @@ static void createTransCurveVerts(TransInfo *t) static void createTransLatticeVerts(TransInfo *t) { - Lattice *latt = ((Lattice *)t->obedit->data)->editlatt->latt; - TransData *td = NULL; - BPoint *bp; - float mtx[3][3], smtx[3][3]; - int a; - int count = 0, countsel = 0; - const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - bp = latt->def; - a = latt->pntsu * latt->pntsv * latt->pntsw; - while (a--) { - if (bp->hide == 0) { - if (bp->f1 & SELECT) countsel++; - if (is_prop_edit) count++; + Lattice *latt = ((Lattice *)tc->obedit->data)->editlatt->latt; + TransData *td = NULL; + BPoint *bp; + float mtx[3][3], smtx[3][3]; + int a; + int count = 0, countsel = 0; + const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; + + bp = latt->def; + a = latt->pntsu * latt->pntsv * latt->pntsw; + while (a--) { + if (bp->hide == 0) { + if (bp->f1 & SELECT) countsel++; + if (is_prop_edit) count++; + } + bp++; } - bp++; - } - /* note: in prop mode we need at least 1 selected */ - if (countsel == 0) return; + /* note: in prop mode we need at least 1 selected */ + if (countsel == 0) return; - if (is_prop_edit) t->total = count; - else t->total = countsel; - t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Lattice EditMode)"); + if (is_prop_edit) tc->data_len = count; + else tc->data_len = countsel; + tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Lattice EditMode)"); - copy_m3_m4(mtx, t->obedit->obmat); - pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); + copy_m3_m4(mtx, tc->obedit->obmat); + pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); - td = t->data; - bp = latt->def; - a = latt->pntsu * latt->pntsv * latt->pntsw; - while (a--) { - if (is_prop_edit || (bp->f1 & SELECT)) { - if (bp->hide == 0) { - copy_v3_v3(td->iloc, bp->vec); - td->loc = bp->vec; - copy_v3_v3(td->center, td->loc); - if (bp->f1 & SELECT) { - td->flag = TD_SELECTED; - } - else { - td->flag = 0; - } - copy_m3_m3(td->smtx, smtx); - copy_m3_m3(td->mtx, mtx); + td = tc->data; + bp = latt->def; + a = latt->pntsu * latt->pntsv * latt->pntsw; + while (a--) { + if (is_prop_edit || (bp->f1 & SELECT)) { + if (bp->hide == 0) { + copy_v3_v3(td->iloc, bp->vec); + td->loc = bp->vec; + copy_v3_v3(td->center, td->loc); + if (bp->f1 & SELECT) { + td->flag = TD_SELECTED; + } + else { + td->flag = 0; + } + copy_m3_m3(td->smtx, smtx); + copy_m3_m3(td->mtx, mtx); - td->ext = NULL; - td->val = NULL; + td->ext = NULL; + td->val = NULL; - td++; - count++; + td++; + count++; + } } + bp++; } - bp++; } } /* ******************* particle edit **************** */ static void createTransParticleVerts(bContext *C, TransInfo *t) { - TransData *td = NULL; - TransDataExtension *tx; - Object *ob = CTX_data_active_object(C); - ParticleEditSettings *pset = PE_settings(t->scene); - PTCacheEdit *edit = PE_get_current(t->scene, ob); - ParticleSystem *psys = NULL; - ParticleSystemModifierData *psmd = NULL; - PTCacheEditPoint *point; - PTCacheEditKey *key; - float mat[4][4]; - int i, k, transformparticle; - int count = 0, hasselected = 0; - const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; - - if (edit == NULL || t->settings->particle.selectmode == SCE_SELECT_PATH) return; - - psys = edit->psys; - - if (psys) - psmd = psys_get_modifier(ob, psys); - - for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) { - point->flag &= ~PEP_TRANSFORM; - transformparticle = 0; - - if ((point->flag & PEP_HIDE) == 0) { - for (k = 0, key = point->keys; k < point->totkey; k++, key++) { - if ((key->flag & PEK_HIDE) == 0) { - if (key->flag & PEK_SELECT) { - hasselected = 1; - transformparticle = 1; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + + TransData *td = NULL; + TransDataExtension *tx; + Object *ob = CTX_data_active_object(C); + ParticleEditSettings *pset = PE_settings(t->scene); + PTCacheEdit *edit = PE_get_current(t->scene, ob); + ParticleSystem *psys = NULL; + ParticleSystemModifierData *psmd = NULL; + PTCacheEditPoint *point; + PTCacheEditKey *key; + float mat[4][4]; + int i, k, transformparticle; + int count = 0, hasselected = 0; + const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; + + if (edit == NULL || t->settings->particle.selectmode == SCE_SELECT_PATH) return; + + psys = edit->psys; + + if (psys) + psmd = psys_get_modifier(ob, psys); + + for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) { + point->flag &= ~PEP_TRANSFORM; + transformparticle = 0; + + if ((point->flag & PEP_HIDE) == 0) { + for (k = 0, key = point->keys; k < point->totkey; k++, key++) { + if ((key->flag & PEK_HIDE) == 0) { + if (key->flag & PEK_SELECT) { + hasselected = 1; + transformparticle = 1; + } + else if (is_prop_edit) + transformparticle = 1; } - else if (is_prop_edit) - transformparticle = 1; } } - } - if (transformparticle) { - count += point->totkey; - point->flag |= PEP_TRANSFORM; + if (transformparticle) { + count += point->totkey; + point->flag |= PEP_TRANSFORM; + } } - } - /* note: in prop mode we need at least 1 selected */ - if (hasselected == 0) return; + /* note: in prop mode we need at least 1 selected */ + if (hasselected == 0) return; - t->total = count; - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Particle Mode)"); + tc->data_len = count; + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Particle Mode)"); - if (t->mode == TFM_BAKE_TIME) - tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "Particle_TransExtension"); - else - tx = t->ext = NULL; + if (t->mode == TFM_BAKE_TIME) + tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "Particle_TransExtension"); + else + tx = tc->data_ext = NULL; - unit_m4(mat); + unit_m4(mat); - invert_m4_m4(ob->imat, ob->obmat); + invert_m4_m4(ob->imat, ob->obmat); - for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) { - TransData *head, *tail; - head = tail = td; + for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) { + TransData *head, *tail; + head = tail = td; - if (!(point->flag & PEP_TRANSFORM)) continue; + if (!(point->flag & PEP_TRANSFORM)) continue; - if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) - psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, psys->particles + i, mat); + if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) + psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, psys->particles + i, mat); - for (k = 0, key = point->keys; k < point->totkey; k++, key++) { - if (key->flag & PEK_USE_WCO) { - copy_v3_v3(key->world_co, key->co); - mul_m4_v3(mat, key->world_co); - td->loc = key->world_co; - } - else - td->loc = key->co; + for (k = 0, key = point->keys; k < point->totkey; k++, key++) { + if (key->flag & PEK_USE_WCO) { + copy_v3_v3(key->world_co, key->co); + mul_m4_v3(mat, key->world_co); + td->loc = key->world_co; + } + else + td->loc = key->co; - copy_v3_v3(td->iloc, td->loc); - copy_v3_v3(td->center, td->loc); + copy_v3_v3(td->iloc, td->loc); + copy_v3_v3(td->center, td->loc); - if (key->flag & PEK_SELECT) - td->flag |= TD_SELECTED; - else if (!is_prop_edit) - td->flag |= TD_SKIP; + if (key->flag & PEK_SELECT) + td->flag |= TD_SELECTED; + else if (!is_prop_edit) + td->flag |= TD_SKIP; - unit_m3(td->mtx); - unit_m3(td->smtx); + unit_m3(td->mtx); + unit_m3(td->smtx); - /* don't allow moving roots */ - if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) - td->protectflag |= OB_LOCK_LOC; + /* don't allow moving roots */ + if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) + td->protectflag |= OB_LOCK_LOC; - td->ob = ob; - td->ext = tx; - if (t->mode == TFM_BAKE_TIME) { - td->val = key->time; - td->ival = *(key->time); - /* abuse size and quat for min/max values */ - td->flag |= TD_NO_EXT; - if (k == 0) tx->size = NULL; - else tx->size = (key - 1)->time; + td->ob = ob; + td->ext = tx; + if (t->mode == TFM_BAKE_TIME) { + td->val = key->time; + td->ival = *(key->time); + /* abuse size and quat for min/max values */ + td->flag |= TD_NO_EXT; + if (k == 0) tx->size = NULL; + else tx->size = (key - 1)->time; - if (k == point->totkey - 1) tx->quat = NULL; - else tx->quat = (key + 1)->time; - } + if (k == point->totkey - 1) tx->quat = NULL; + else tx->quat = (key + 1)->time; + } - td++; - if (tx) - tx++; - tail++; + td++; + if (tx) + tx++; + tail++; + } + if (is_prop_edit && head != tail) + calc_distanceCurveVerts(head, tail - 1); } - if (is_prop_edit && head != tail) - calc_distanceCurveVerts(head, tail - 1); } } void flushTransParticles(TransInfo *t) { - Scene *scene = t->scene; - ViewLayer *view_layer = t->view_layer; - Object *ob = OBACT(view_layer); - PTCacheEdit *edit = PE_get_current(scene, ob); - ParticleSystem *psys = edit->psys; - ParticleSystemModifierData *psmd = NULL; - PTCacheEditPoint *point; - PTCacheEditKey *key; - TransData *td; - float mat[4][4], imat[4][4], co[3]; - int i, k; - const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; - - if (psys) - psmd = psys_get_modifier(ob, psys); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - /* we do transform in world space, so flush world space position - * back to particle local space (only for hair particles) */ - td = t->data; - for (i = 0, point = edit->points; i < edit->totpoint; i++, point++, td++) { - if (!(point->flag & PEP_TRANSFORM)) continue; - - if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { - psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, psys->particles + i, mat); - invert_m4_m4(imat, mat); - - for (k = 0, key = point->keys; k < point->totkey; k++, key++) { - copy_v3_v3(co, key->world_co); - mul_m4_v3(imat, co); - - - /* optimization for proportional edit */ - if (!is_prop_edit || !compare_v3v3(key->co, co, 0.0001f)) { - copy_v3_v3(key->co, co); - point->flag |= PEP_EDIT_RECALC; + Scene *scene = t->scene; + ViewLayer *view_layer = t->view_layer; + Object *ob = OBACT(view_layer); + PTCacheEdit *edit = PE_get_current(scene, ob); + ParticleSystem *psys = edit->psys; + ParticleSystemModifierData *psmd = NULL; + PTCacheEditPoint *point; + PTCacheEditKey *key; + TransData *td; + float mat[4][4], imat[4][4], co[3]; + int i, k; + const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; + + if (psys) + psmd = psys_get_modifier(ob, psys); + + /* we do transform in world space, so flush world space position + * back to particle local space (only for hair particles) */ + td = tc->data; + for (i = 0, point = edit->points; i < edit->totpoint; i++, point++, td++) { + if (!(point->flag & PEP_TRANSFORM)) continue; + + if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { + psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, psys->particles + i, mat); + invert_m4_m4(imat, mat); + + for (k = 0, key = point->keys; k < point->totkey; k++, key++) { + copy_v3_v3(co, key->world_co); + mul_m4_v3(imat, co); + + + /* optimization for proportional edit */ + if (!is_prop_edit || !compare_v3v3(key->co, co, 0.0001f)) { + copy_v3_v3(key->co, co); + point->flag |= PEP_EDIT_RECALC; + } } } + else + point->flag |= PEP_EDIT_RECALC; } - else - point->flag |= PEP_EDIT_RECALC; - } - PE_update_object(&t->eval_ctx, scene, OBACT(view_layer), 1); + PE_update_object(t->depsgraph, scene, OBACT(view_layer), 1); + } } /* ********************* mesh ****************** */ @@ -2459,243 +2530,248 @@ static void VertsToTransData(TransInfo *t, TransData *td, TransDataExtension *tx static void createTransEditVerts(TransInfo *t) { - TransData *tob = NULL; - TransDataExtension *tx = NULL; - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); - Mesh *me = t->obedit->data; - BMesh *bm = em->bm; - BMVert *eve; - BMIter iter; - float (*mappedcos)[3] = NULL, (*quats)[4] = NULL; - float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL; - float *dists = NULL; - int a; - const int prop_mode = (t->flag & T_PROP_EDIT) ? (t->flag & T_PROP_EDIT_ALL) : 0; - int mirror = 0; - int cd_vert_bweight_offset = -1; - bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0; - - struct TransIslandData *island_info = NULL; - int island_info_tot; - int *island_vert_map = NULL; - - /* Even for translation this is needed because of island-orientation, see: T51651. */ - const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS); - /* Original index of our connected vertex when connected distances are calculated. - * Optional, allocate if needed. */ - int *dists_index = NULL; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - if (t->flag & T_MIRROR) { - EDBM_verts_mirror_cache_begin(em, 0, false, (t->flag & T_PROP_EDIT) == 0, use_topology); - mirror = 1; - } + TransData *tob = NULL; + TransDataExtension *tx = NULL; + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); + Mesh *me = tc->obedit->data; + BMesh *bm = em->bm; + BMVert *eve; + BMIter iter; + float (*mappedcos)[3] = NULL, (*quats)[4] = NULL; + float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL; + float *dists = NULL; + int a; + const int prop_mode = (t->flag & T_PROP_EDIT) ? (t->flag & T_PROP_EDIT_ALL) : 0; + int mirror = 0; + int cd_vert_bweight_offset = -1; + bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0; - /** - * Quick check if we can transform. - * - * \note ignore modes here, even in edge/face modes, transform data is created by selected vertices. - * \note in prop mode we need at least 1 selected. - */ - if (bm->totvertsel == 0) { - goto cleanup; - } + struct TransIslandData *island_info = NULL; + int island_info_tot; + int *island_vert_map = NULL; - if (t->mode == TFM_BWEIGHT) { - BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_VERT_BWEIGHT); - cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT); - } + /* Even for translation this is needed because of island-orientation, see: T51651. */ + const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS); + /* Original index of our connected vertex when connected distances are calculated. + * Optional, allocate if needed. */ + int *dists_index = NULL; - if (prop_mode) { - unsigned int count = 0; - BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { - count++; + if (t->flag & T_MIRROR) { + /* TODO(campbell): xform: We need support for many mirror objects at once! */ + if (tc->is_active) { + EDBM_verts_mirror_cache_begin(em, 0, false, (t->flag & T_PROP_EDIT) == 0, use_topology); + mirror = 1; } } - t->total = count; + /** + * Quick check if we can transform. + * + * \note ignore modes here, even in edge/face modes, transform data is created by selected vertices. + * \note in prop mode we need at least 1 selected. + */ + if (bm->totvertsel == 0) { + goto cleanup; + } - /* allocating scratch arrays */ - if (prop_mode & T_PROP_CONNECTED) { - dists = MEM_mallocN(em->bm->totvert * sizeof(float), __func__); - if (is_island_center) { - dists_index = MEM_mallocN(em->bm->totvert * sizeof(int), __func__); - } + if (t->mode == TFM_BWEIGHT) { + BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_VERT_BWEIGHT); + cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT); } - } - else { - t->total = bm->totvertsel; - } - tob = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Mesh EditMode)"); - if (ELEM(t->mode, TFM_SKIN_RESIZE, TFM_SHRINKFATTEN)) { - /* warning, this is overkill, we only need 2 extra floats, - * but this stores loads of extra stuff, for TFM_SHRINKFATTEN its even more overkill - * since we may not use the 'alt' transform mode to maintain shell thickness, - * but with generic transform code its hard to lazy init vars */ - tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), - "TransObData ext"); - } + if (prop_mode) { + unsigned int count = 0; + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { + count++; + } + } - copy_m3_m4(mtx, t->obedit->obmat); - /* we use a pseudoinverse so that when one of the axes is scaled to 0, - * matrix inversion still works and we can still moving along the other */ - pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); + tc->data_len = count; - if (prop_mode & T_PROP_CONNECTED) { - editmesh_set_connectivity_distance(em->bm, mtx, dists, dists_index); - } + /* allocating scratch arrays */ + if (prop_mode & T_PROP_CONNECTED) { + dists = MEM_mallocN(em->bm->totvert * sizeof(float), __func__); + if (is_island_center) { + dists_index = MEM_mallocN(em->bm->totvert * sizeof(int), __func__); + } + } + } + else { + tc->data_len = bm->totvertsel; + } - if (is_island_center) { - /* In this specific case, near-by vertices will need to know the island of the nearest connected vertex. */ - const bool calc_single_islands = ( - (prop_mode & T_PROP_CONNECTED) && - (t->around == V3D_AROUND_LOCAL_ORIGINS) && - (em->selectmode & SCE_SELECT_VERTEX)); + tob = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Mesh EditMode)"); + if (ELEM(t->mode, TFM_SKIN_RESIZE, TFM_SHRINKFATTEN)) { + /* warning, this is overkill, we only need 2 extra floats, + * but this stores loads of extra stuff, for TFM_SHRINKFATTEN its even more overkill + * since we may not use the 'alt' transform mode to maintain shell thickness, + * but with generic transform code its hard to lazy init vars */ + tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "TransObData ext"); + } - island_info = editmesh_islands_info_calc(em, &island_info_tot, &island_vert_map, calc_single_islands); - } + copy_m3_m4(mtx, tc->obedit->obmat); + /* we use a pseudoinverse so that when one of the axes is scaled to 0, + * matrix inversion still works and we can still moving along the other */ + pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); - /* detect CrazySpace [tm] */ - if (modifiers_getCageIndex(t->scene, t->obedit, NULL, 1) != -1) { - int totleft = -1; - if (modifiers_isCorrectableDeformed(t->scene, t->obedit)) { - /* check if we can use deform matrices for modifier from the - * start up to stack, they are more accurate than quats */ - totleft = BKE_crazyspace_get_first_deform_matrices_editbmesh(&t->eval_ctx, t->scene, t->obedit, em, &defmats, &defcos); + if (prop_mode & T_PROP_CONNECTED) { + editmesh_set_connectivity_distance(em->bm, mtx, dists, dists_index); } - /* if we still have more modifiers, also do crazyspace - * correction with quats, relative to the coordinates after - * the modifiers that support deform matrices (defcos) */ + if (is_island_center) { + /* In this specific case, near-by vertices will need to know the island of the nearest connected vertex. */ + const bool calc_single_islands = ( + (prop_mode & T_PROP_CONNECTED) && + (t->around == V3D_AROUND_LOCAL_ORIGINS) && + (em->selectmode & SCE_SELECT_VERTEX)); -#if 0 /* TODO, fix crazyspace+extrude so it can be enabled for general use - campbell */ - if ((totleft > 0) || (totleft == -1)) -#else - if (totleft > 0) -#endif - { - mappedcos = BKE_crazyspace_get_mapped_editverts(&t->eval_ctx, t->scene, t->obedit); - quats = MEM_mallocN(em->bm->totvert * sizeof(*quats), "crazy quats"); - BKE_crazyspace_set_quats_editmesh(em, defcos, mappedcos, quats, !prop_mode); - if (mappedcos) - MEM_freeN(mappedcos); + island_info = editmesh_islands_info_calc(em, &island_info_tot, &island_vert_map, calc_single_islands); } - if (defcos) { - MEM_freeN(defcos); + /* detect CrazySpace [tm] */ + if (modifiers_getCageIndex(t->scene, tc->obedit, NULL, 1) != -1) { + int totleft = -1; + if (modifiers_isCorrectableDeformed(t->scene, tc->obedit)) { + /* check if we can use deform matrices for modifier from the + * start up to stack, they are more accurate than quats */ + totleft = BKE_crazyspace_get_first_deform_matrices_editbmesh(t->depsgraph, t->scene, tc->obedit, em, &defmats, &defcos); + } + + /* if we still have more modifiers, also do crazyspace + * correction with quats, relative to the coordinates after + * the modifiers that support deform matrices (defcos) */ + + #if 0 /* TODO, fix crazyspace+extrude so it can be enabled for general use - campbell */ + if ((totleft > 0) || (totleft == -1)) + #else + if (totleft > 0) + #endif + { + mappedcos = BKE_crazyspace_get_mapped_editverts(t->depsgraph, t->scene, tc->obedit); + quats = MEM_mallocN(em->bm->totvert * sizeof(*quats), "crazy quats"); + BKE_crazyspace_set_quats_editmesh(em, defcos, mappedcos, quats, !prop_mode); + if (mappedcos) + MEM_freeN(mappedcos); + } + + if (defcos) { + MEM_freeN(defcos); + } } - } - /* find out which half we do */ - if (mirror) { - BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(eve, BM_ELEM_SELECT) && eve->co[0] != 0.0f) { - if (eve->co[0] < 0.0f) { - t->mirror = -1; - mirror = -1; + /* find out which half we do */ + if (mirror) { + BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { + if (BM_elem_flag_test(eve, BM_ELEM_SELECT) && eve->co[0] != 0.0f) { + if (eve->co[0] < 0.0f) { + t->mirror = -1; + mirror = -1; + } + break; } - break; } } - } - BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, a) { - if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { - if (prop_mode || BM_elem_flag_test(eve, BM_ELEM_SELECT)) { - struct TransIslandData *v_island = NULL; - float *bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_VOID_P(eve, cd_vert_bweight_offset) : NULL; - - if (island_info) { - const int connected_index = (dists_index && dists_index[a] != -1) ? dists_index[a] : a; - v_island = (island_vert_map[connected_index] != -1) ? - &island_info[island_vert_map[connected_index]] : NULL; - } + BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, a) { + if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { + if (prop_mode || BM_elem_flag_test(eve, BM_ELEM_SELECT)) { + struct TransIslandData *v_island = NULL; + float *bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_VOID_P(eve, cd_vert_bweight_offset) : NULL; + + if (island_info) { + const int connected_index = (dists_index && dists_index[a] != -1) ? dists_index[a] : a; + v_island = (island_vert_map[connected_index] != -1) ? + &island_info[island_vert_map[connected_index]] : NULL; + } - VertsToTransData(t, tob, tx, em, eve, bweight, v_island); - if (tx) - tx++; + VertsToTransData(t, tob, tx, em, eve, bweight, v_island); + if (tx) + tx++; - /* selected */ - if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) - tob->flag |= TD_SELECTED; + /* selected */ + if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) + tob->flag |= TD_SELECTED; - if (prop_mode) { - if (prop_mode & T_PROP_CONNECTED) { - tob->dist = dists[a]; - } - else { - tob->flag |= TD_NOTCONNECTED; - tob->dist = FLT_MAX; + if (prop_mode) { + if (prop_mode & T_PROP_CONNECTED) { + tob->dist = dists[a]; + } + else { + tob->flag |= TD_NOTCONNECTED; + tob->dist = FLT_MAX; + } } - } - /* CrazySpace */ - if (defmats || (quats && BM_elem_flag_test(eve, BM_ELEM_TAG))) { - float mat[3][3], qmat[3][3], imat[3][3]; + /* CrazySpace */ + if (defmats || (quats && BM_elem_flag_test(eve, BM_ELEM_TAG))) { + float mat[3][3], qmat[3][3], imat[3][3]; - /* use both or either quat and defmat correction */ - if (quats && BM_elem_flag_test(eve, BM_ELEM_TAG)) { - quat_to_mat3(qmat, quats[BM_elem_index_get(eve)]); + /* use both or either quat and defmat correction */ + if (quats && BM_elem_flag_test(eve, BM_ELEM_TAG)) { + quat_to_mat3(qmat, quats[BM_elem_index_get(eve)]); - if (defmats) - mul_m3_series(mat, defmats[a], qmat, mtx); + if (defmats) + mul_m3_series(mat, defmats[a], qmat, mtx); + else + mul_m3_m3m3(mat, mtx, qmat); + } else - mul_m3_m3m3(mat, mtx, qmat); - } - else - mul_m3_m3m3(mat, mtx, defmats[a]); + mul_m3_m3m3(mat, mtx, defmats[a]); - invert_m3_m3(imat, mat); + invert_m3_m3(imat, mat); - copy_m3_m3(tob->smtx, imat); - copy_m3_m3(tob->mtx, mat); - } - else { - copy_m3_m3(tob->smtx, smtx); - copy_m3_m3(tob->mtx, mtx); - } + copy_m3_m3(tob->smtx, imat); + copy_m3_m3(tob->mtx, mat); + } + else { + copy_m3_m3(tob->smtx, smtx); + copy_m3_m3(tob->mtx, mtx); + } - /* Mirror? */ - if ((mirror > 0 && tob->iloc[0] > 0.0f) || (mirror < 0 && tob->iloc[0] < 0.0f)) { - BMVert *vmir = EDBM_verts_mirror_get(em, eve); //t->obedit, em, eve, tob->iloc, a); - if (vmir && vmir != eve) { - tob->extra = vmir; + /* Mirror? */ + if ((mirror > 0 && tob->iloc[0] > 0.0f) || (mirror < 0 && tob->iloc[0] < 0.0f)) { + BMVert *vmir = EDBM_verts_mirror_get(em, eve); //t->obedit, em, eve, tob->iloc, a); + if (vmir && vmir != eve) { + tob->extra = vmir; + } } + tob++; } - tob++; } } - } - - if (island_info) { - MEM_freeN(island_info); - MEM_freeN(island_vert_map); - } - if (mirror != 0) { - tob = t->data; - for (a = 0; a < t->total; a++, tob++) { - if (ABS(tob->loc[0]) <= 0.00001f) { - tob->flag |= TD_MIRROR_EDGE; + if (island_info) { + MEM_freeN(island_info); + MEM_freeN(island_vert_map); + } + + if (mirror != 0) { + tob = tc->data; + for (a = 0; a < tc->data_len; a++, tob++) { + if (ABS(tob->loc[0]) <= 0.00001f) { + tob->flag |= TD_MIRROR_EDGE; + } } } - } cleanup: - /* crazy space free */ - if (quats) - MEM_freeN(quats); - if (defmats) - MEM_freeN(defmats); - if (dists) - MEM_freeN(dists); - if (dists_index) - MEM_freeN(dists_index); - - if (t->flag & T_MIRROR) { - EDBM_verts_mirror_cache_end(em); + /* crazy space free */ + if (quats) + MEM_freeN(quats); + if (defmats) + MEM_freeN(defmats); + if (dists) + MEM_freeN(dists); + if (dists_index) + MEM_freeN(dists_index); + + if (t->flag & T_MIRROR) { + EDBM_verts_mirror_cache_end(em); + } } } @@ -2703,40 +2779,43 @@ cleanup: void flushTransNodes(TransInfo *t) { const float dpi_fac = UI_DPI_FAC; - int a; - TransData *td; - TransData2D *td2d; - - applyGridAbsolute(t); - - /* flush to 2d vector from internally used 3d vector */ - for (a = 0, td = t->data, td2d = t->data2d; a < t->total; a++, td++, td2d++) { - bNode *node = td->extra; - float locx, locy; - /* weirdo - but the node system is a mix of free 2d elements and dpi sensitive UI */ -#ifdef USE_NODE_CENTER - locx = (td2d->loc[0] - (BLI_rctf_size_x(&node->totr)) * +0.5f) / dpi_fac; - locy = (td2d->loc[1] - (BLI_rctf_size_y(&node->totr)) * -0.5f) / dpi_fac; -#else - locx = td2d->loc[0] / dpi_fac; - locy = td2d->loc[1] / dpi_fac; -#endif - - /* account for parents (nested nodes) */ - if (node->parent) { - nodeFromView(node->parent, locx, locy, &node->locx, &node->locy); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + int a; + TransData *td; + TransData2D *td2d; + + applyGridAbsolute(t); + + /* flush to 2d vector from internally used 3d vector */ + for (a = 0, td = tc->data, td2d = tc->data_2d; a < tc->data_len; a++, td++, td2d++) { + bNode *node = td->extra; + float locx, locy; + + /* weirdo - but the node system is a mix of free 2d elements and dpi sensitive UI */ + #ifdef USE_NODE_CENTER + locx = (td2d->loc[0] - (BLI_rctf_size_x(&node->totr)) * +0.5f) / dpi_fac; + locy = (td2d->loc[1] - (BLI_rctf_size_y(&node->totr)) * -0.5f) / dpi_fac; + #else + locx = td2d->loc[0] / dpi_fac; + locy = td2d->loc[1] / dpi_fac; + #endif + + /* account for parents (nested nodes) */ + if (node->parent) { + nodeFromView(node->parent, locx, locy, &node->locx, &node->locy); + } + else { + node->locx = locx; + node->locy = locy; + } } - else { - node->locx = locx; - node->locy = locy; + + /* handle intersection with noodles */ + if (tc->data_len == 1) { + ED_node_link_intersect_test(t->sa, 1); } } - - /* handle intersection with noodles */ - if (t->total == 1) { - ED_node_link_intersect_test(t->sa, 1); - } } /* *** SEQUENCE EDITOR *** */ @@ -2765,13 +2844,14 @@ BLI_INLINE void trans_update_seq(Scene *sce, Sequence *seq, int old_start, int s void flushTransSeq(TransInfo *t) { ListBase *seqbasep = BKE_sequencer_editing_get(t->scene, false)->seqbasep; /* Editing null check already done */ + int a, new_frame; TransData *td = NULL; TransData2D *td2d = NULL; TransDataSeq *tdsq = NULL; Sequence *seq; - + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); /* prevent updating the same seq twice * if the transdata order is changed this will mess up @@ -2780,7 +2860,7 @@ void flushTransSeq(TransInfo *t) int old_start_prev = 0, sel_flag_prev = 0; /* flush to 2d vector from internally used 3d vector */ - for (a = 0, td = t->data, td2d = t->data2d; a < t->total; a++, td++, td2d++) { + for (a = 0, td = tc->data, td2d = tc->data_2d; a < tc->data_len; a++, td++, td2d++) { int old_start; tdsq = (TransDataSeq *)td->extra; seq = tdsq->seq; @@ -2853,8 +2933,8 @@ void flushTransSeq(TransInfo *t) } /* update effects inside meta's */ - for (a = 0, seq_prev = NULL, td = t->data, td2d = t->data2d; - a < t->total; + for (a = 0, seq_prev = NULL, td = tc->data, td2d = tc->data_2d; + a < tc->data_len; a++, td++, td2d++, seq_prev = seq) { tdsq = (TransDataSeq *)td->extra; @@ -2870,7 +2950,7 @@ void flushTransSeq(TransInfo *t) /* need to do the overlap check in a new loop otherwise adjacent strips * will not be updated and we'll get false positives */ seq_prev = NULL; - for (a = 0, td = t->data, td2d = t->data2d; a < t->total; a++, td++, td2d++) { + for (a = 0, td = tc->data, td2d = tc->data_2d; a < tc->data_len; a++, td++, td2d++) { tdsq = (TransDataSeq *)td->extra; seq = tdsq->seq; @@ -2931,157 +3011,167 @@ static void createTransUVs(bContext *C, TransInfo *t) Image *ima = CTX_data_edit_image(C); Scene *scene = t->scene; ToolSettings *ts = CTX_data_tool_settings(C); - TransData *td = NULL; - TransData2D *td2d = NULL; - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); - BMFace *efa; - BMIter iter, liter; - UvElementMap *elementmap = NULL; - BLI_bitmap *island_enabled = NULL; - struct { float co[2]; int co_num; } *island_center = NULL; - int count = 0, countsel = 0, count_rejected = 0; + const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; const bool is_prop_connected = (t->flag & T_PROP_CONNECTED) != 0; const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS); - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - if (!ED_space_image_show_uvedit(sima, t->obedit)) - return; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - /* count */ - if (is_prop_connected || is_island_center) { - /* create element map with island information */ - const bool use_facesel = (ts->uv_flag & UV_SYNC_SELECTION) == 0; - elementmap = BM_uv_element_map_create(em->bm, use_facesel, false, true); - if (elementmap == NULL) { - return; - } + TransData *td = NULL; + TransData2D *td2d = NULL; + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); + BMFace *efa; + BMIter iter, liter; + UvElementMap *elementmap = NULL; + BLI_bitmap *island_enabled = NULL; + struct { float co[2]; int co_num; } *island_center = NULL; + int count = 0, countsel = 0, count_rejected = 0; + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - if (is_prop_connected) { - island_enabled = BLI_BITMAP_NEW(elementmap->totalIslands, "TransIslandData(UV Editing)"); + if (!ED_space_image_show_uvedit(sima, tc->obedit)) { + continue; } - if (is_island_center) { - island_center = MEM_callocN(sizeof(*island_center) * elementmap->totalIslands, __func__); - } - } + /* count */ + if (is_prop_connected || is_island_center) { + /* create element map with island information */ + const bool use_facesel = (ts->uv_flag & UV_SYNC_SELECTION) == 0; + elementmap = BM_uv_element_map_create(em->bm, use_facesel, false, true); + if (elementmap == NULL) { + return; + } - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - BMLoop *l; + if (is_prop_connected) { + island_enabled = BLI_BITMAP_NEW(elementmap->totalIslands, "TransIslandData(UV Editing)"); + } - if (!uvedit_face_visible_test(scene, t->obedit, ima, efa)) { - BM_elem_flag_disable(efa, BM_ELEM_TAG); - continue; + if (is_island_center) { + island_center = MEM_callocN(sizeof(*island_center) * elementmap->totalIslands, __func__); + } } - BM_elem_flag_enable(efa, BM_ELEM_TAG); - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { - countsel++; + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + BMLoop *l; - if (is_prop_connected || island_center) { - UvElement *element = BM_uv_element_get(elementmap, efa, l); + if (!uvedit_face_visible_test(scene, tc->obedit, ima, efa)) { + BM_elem_flag_disable(efa, BM_ELEM_TAG); + continue; + } - if (is_prop_connected) { - BLI_BITMAP_ENABLE(island_enabled, element->island); - } + BM_elem_flag_enable(efa, BM_ELEM_TAG); + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { + countsel++; - if (is_island_center) { - if (element->flag == false) { - MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - add_v2_v2(island_center[element->island].co, luv->uv); - island_center[element->island].co_num++; - element->flag = true; + if (is_prop_connected || island_center) { + UvElement *element = BM_uv_element_get(elementmap, efa, l); + + if (is_prop_connected) { + BLI_BITMAP_ENABLE(island_enabled, element->island); + } + + if (is_island_center) { + if (element->flag == false) { + MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + add_v2_v2(island_center[element->island].co, luv->uv); + island_center[element->island].co_num++; + element->flag = true; + } } } } - } - if (is_prop_edit) { - count++; + if (is_prop_edit) { + count++; + } } } - } - /* note: in prop mode we need at least 1 selected */ - if (countsel == 0) { - goto finally; - } + /* note: in prop mode we need at least 1 selected */ + if (countsel == 0) { + goto finally; + } - if (is_island_center) { - int i; + if (is_island_center) { + int i; - for (i = 0; i < elementmap->totalIslands; i++) { - mul_v2_fl(island_center[i].co, 1.0f / island_center[i].co_num); - mul_v2_v2(island_center[i].co, t->aspect); + for (i = 0; i < elementmap->totalIslands; i++) { + mul_v2_fl(island_center[i].co, 1.0f / island_center[i].co_num); + mul_v2_v2(island_center[i].co, t->aspect); + } } - } - t->total = (is_prop_edit) ? count : countsel; - t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(UV Editing)"); - /* for each 2d uv coord a 3d vector is allocated, so that they can be - * treated just as if they were 3d verts */ - t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransObData2D(UV Editing)"); + tc->data_len = (is_prop_edit) ? count : countsel; + tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(UV Editing)"); + /* for each 2d uv coord a 3d vector is allocated, so that they can be + * treated just as if they were 3d verts */ + tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransObData2D(UV Editing)"); - if (sima->flag & SI_CLIP_UV) - t->flag |= T_CLIP_UV; + if (sima->flag & SI_CLIP_UV) + t->flag |= T_CLIP_UV; - td = t->data; - td2d = t->data2d; + td = tc->data; + td2d = tc->data_2d; - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - BMLoop *l; + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + BMLoop *l; - if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) - continue; + if (!BM_elem_flag_test(efa, BM_ELEM_TAG)) + continue; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - const bool selected = uvedit_uv_select_test(scene, l, cd_loop_uv_offset); - MLoopUV *luv; - const float *center = NULL; + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + const bool selected = uvedit_uv_select_test(scene, l, cd_loop_uv_offset); + MLoopUV *luv; + const float *center = NULL; - if (!is_prop_edit && !selected) - continue; + if (!is_prop_edit && !selected) + continue; - if (is_prop_connected || is_island_center) { - UvElement *element = BM_uv_element_get(elementmap, efa, l); + if (is_prop_connected || is_island_center) { + UvElement *element = BM_uv_element_get(elementmap, efa, l); - if (is_prop_connected) { - if (!BLI_BITMAP_TEST(island_enabled, element->island)) { - count_rejected++; - continue; + if (is_prop_connected) { + if (!BLI_BITMAP_TEST(island_enabled, element->island)) { + count_rejected++; + continue; + } } - } - if (is_island_center) { - center = island_center[element->island].co; + if (is_island_center) { + center = island_center[element->island].co; + } } + + BM_elem_flag_enable(l, BM_ELEM_TAG); + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + UVsToTransData(t->aspect, td++, td2d++, luv->uv, center, selected); } - - BM_elem_flag_enable(l, BM_ELEM_TAG); - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - UVsToTransData(t->aspect, td++, td2d++, luv->uv, center, selected); } - } - if (is_prop_connected) { - t->total -= count_rejected; - } - - if (sima->flag & SI_LIVE_UNWRAP) - ED_uvedit_live_unwrap_begin(t->scene, t->obedit); + if (is_prop_connected) { + tc->data_len -= count_rejected; + } + if (sima->flag & SI_LIVE_UNWRAP) { + /* TODO(campbell): xform: Only active object currently! + * it uses a static variable. */ + if (tc->is_active) { + ED_uvedit_live_unwrap_begin(t->scene, tc->obedit); + } + } finally: - if (is_prop_connected || is_island_center) { - BM_uv_element_map_free(elementmap); + if (is_prop_connected || is_island_center) { + BM_uv_element_map_free(elementmap); - if (is_prop_connected) { - MEM_freeN(island_enabled); - } + if (is_prop_connected) { + MEM_freeN(island_enabled); + } - if (island_center) { - MEM_freeN(island_center); + if (island_center) { + MEM_freeN(island_center); + } } } } @@ -3089,37 +3179,38 @@ finally: void flushTransUVs(TransInfo *t) { SpaceImage *sima = t->sa->spacedata.first; - TransData2D *td; - int a; - float aspect_inv[2], size[2]; const bool use_pixel_snap = ((sima->flag & SI_PIXELSNAP) && (t->state != TRANS_CANCEL)); - aspect_inv[0] = 1.0f / t->aspect[0]; - aspect_inv[1] = 1.0f / t->aspect[1]; - - if (use_pixel_snap) { - int size_i[2]; - ED_space_image_get_size(sima, &size_i[0], &size_i[1]); - size[0] = size_i[0]; - size[1] = size_i[1]; - } + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData2D *td; + int a; + float aspect_inv[2], size[2]; - /* flush to 2d vector from internally used 3d vector */ - for (a = 0, td = t->data2d; a < t->total; a++, td++) { - td->loc2d[0] = td->loc[0] * aspect_inv[0]; - td->loc2d[1] = td->loc[1] * aspect_inv[1]; + aspect_inv[0] = 1.0f / t->aspect[0]; + aspect_inv[1] = 1.0f / t->aspect[1]; if (use_pixel_snap) { - td->loc2d[0] = roundf(td->loc2d[0] * size[0]) / size[0]; - td->loc2d[1] = roundf(td->loc2d[1] * size[1]) / size[1]; + int size_i[2]; + ED_space_image_get_size(sima, &size_i[0], &size_i[1]); + size[0] = size_i[0]; + size[1] = size_i[1]; + } + + /* flush to 2d vector from internally used 3d vector */ + for (a = 0, td = tc->data_2d; a < tc->data_len; a++, td++) { + td->loc2d[0] = td->loc[0] * aspect_inv[0]; + td->loc2d[1] = td->loc[1] * aspect_inv[1]; + + if (use_pixel_snap) { + td->loc2d[0] = roundf(td->loc2d[0] * size[0]) / size[0]; + td->loc2d[1] = roundf(td->loc2d[1] * size[1]) / size[1]; + } } } } bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) { - TransData *td; - int a; bool clipx = true, clipy = true; float min[2], max[2]; @@ -3127,39 +3218,45 @@ bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) max[0] = t->aspect[0]; max[1] = t->aspect[1]; - for (a = 0, td = t->data; a < t->total; a++, td++) { - minmax_v2v2_v2(min, max, td->loc); - } + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - if (resize) { - if (min[0] < 0.0f && t->center[0] > 0.0f && t->center[0] < t->aspect[0] * 0.5f) - vec[0] *= t->center[0] / (t->center[0] - min[0]); - else if (max[0] > t->aspect[0] && t->center[0] < t->aspect[0]) - vec[0] *= (t->center[0] - t->aspect[0]) / (t->center[0] - max[0]); - else - clipx = 0; + TransData *td; + int a; - if (min[1] < 0.0f && t->center[1] > 0.0f && t->center[1] < t->aspect[1] * 0.5f) - vec[1] *= t->center[1] / (t->center[1] - min[1]); - else if (max[1] > t->aspect[1] && t->center[1] < t->aspect[1]) - vec[1] *= (t->center[1] - t->aspect[1]) / (t->center[1] - max[1]); - else - clipy = 0; - } - else { - if (min[0] < 0.0f) - vec[0] -= min[0]; - else if (max[0] > t->aspect[0]) - vec[0] -= max[0] - t->aspect[0]; - else - clipx = 0; + for (a = 0, td = tc->data; a < tc->data_len; a++, td++) { + minmax_v2v2_v2(min, max, td->loc); + } - if (min[1] < 0.0f) - vec[1] -= min[1]; - else if (max[1] > t->aspect[1]) - vec[1] -= max[1] - t->aspect[1]; - else - clipy = 0; + if (resize) { + if (min[0] < 0.0f && t->center_global[0] > 0.0f && t->center_global[0] < t->aspect[0] * 0.5f) + vec[0] *= t->center_global[0] / (t->center_global[0] - min[0]); + else if (max[0] > t->aspect[0] && t->center_global[0] < t->aspect[0]) + vec[0] *= (t->center_global[0] - t->aspect[0]) / (t->center_global[0] - max[0]); + else + clipx = 0; + + if (min[1] < 0.0f && t->center_global[1] > 0.0f && t->center_global[1] < t->aspect[1] * 0.5f) + vec[1] *= t->center_global[1] / (t->center_global[1] - min[1]); + else if (max[1] > t->aspect[1] && t->center_global[1] < t->aspect[1]) + vec[1] *= (t->center_global[1] - t->aspect[1]) / (t->center_global[1] - max[1]); + else + clipy = 0; + } + else { + if (min[0] < 0.0f) + vec[0] -= min[0]; + else if (max[0] > t->aspect[0]) + vec[0] -= max[0] - t->aspect[0]; + else + clipx = 0; + + if (min[1] < 0.0f) + vec[1] -= min[1]; + else if (max[1] > t->aspect[1]) + vec[1] -= max[1] - t->aspect[1]; + else + clipy = 0; + } } return (clipx || clipy); @@ -3167,18 +3264,18 @@ bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) void clipUVData(TransInfo *t) { - TransData *td = NULL; - int a; - - for (a = 0, td = t->data; a < t->total; a++, td++) { - if (td->flag & TD_NOACTION) - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (int a = 0; a < tc->data_len; a++, td++) { + if (td->flag & TD_NOACTION) + break; - if ((td->flag & TD_SKIP) || (!td->loc)) - continue; + if ((td->flag & TD_SKIP) || (!td->loc)) + continue; - td->loc[0] = min_ff(max_ff(0.0f, td->loc[0]), t->aspect[0]); - td->loc[1] = min_ff(max_ff(0.0f, td->loc[1]), t->aspect[1]); + td->loc[0] = min_ff(max_ff(0.0f, td->loc[0]), t->aspect[0]); + td->loc[1] = min_ff(max_ff(0.0f, td->loc[1]), t->aspect[1]); + } } } @@ -3212,7 +3309,9 @@ static void createTransNlaData(bContext *C, TransInfo *t) int filter; int count = 0; - + + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* determine what type of data we are operating on */ if (ANIM_animdata_get_context(C, &ac) == 0) return; @@ -3272,12 +3371,12 @@ static void createTransNlaData(bContext *C, TransInfo *t) } /* allocate memory for data */ - t->total = count; + tc->data_len = count; - t->data = MEM_callocN(t->total * sizeof(TransData), "TransData(NLA Editor)"); - td = t->data; - t->custom.type.data = tdn = MEM_callocN(t->total * sizeof(TransDataNla), "TransDataNla (NLA Editor)"); - t->custom.type.use_free = true; + tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData(NLA Editor)"); + td = tc->data; + tc->custom.type.data = tdn = MEM_callocN(tc->data_len * sizeof(TransDataNla), "TransDataNla (NLA Editor)"); + tc->custom.type.use_free = true; /* loop 2: build transdata array */ for (ale = anim_data.first; ale; ale = ale->next) { @@ -3807,11 +3906,11 @@ typedef struct tGPFtransdata { /* This function helps flush transdata written to tempdata into the gp-frames */ void flushTransIntFrameActionData(TransInfo *t) { + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); tGPFtransdata *tfd = t->custom.type.data; - int i; /* flush data! */ - for (i = 0; i < t->total; i++, tfd++) { + for (int i = 0; i < tc->data_len; i++, tfd++) { *(tfd->sdata) = round_fl_to_int(tfd->val); } } @@ -3967,18 +4066,20 @@ static void createTransActionData(bContext *C, TransInfo *t) ANIM_animdata_freelist(&anim_data); return; } - + + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* allocate memory for data */ - t->total = count; + tc->data_len = count; - t->data = MEM_callocN(t->total * sizeof(TransData), "TransData(Action Editor)"); - t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "transdata2d"); - td = t->data; - td2d = t->data2d; + tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData(Action Editor)"); + tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "transdata2d"); + td = tc->data; + td2d = tc->data_2d; if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { - t->custom.type.data = tfd = MEM_callocN(sizeof(tGPFtransdata) * count, "tGPFtransdata"); - t->custom.type.use_free = true; + tc->custom.type.data = tfd = MEM_callocN(sizeof(tGPFtransdata) * count, "tGPFtransdata"); + tc->custom.type.use_free = true; } /* loop 2: build transdata array */ @@ -4023,7 +4124,7 @@ static void createTransActionData(bContext *C, TransInfo *t) /* calculate distances for proportional editing */ if (is_prop_edit) { - td = t->data; + td = tc->data; for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt; @@ -4365,19 +4466,21 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) ANIM_animdata_freelist(&anim_data); return; } - + + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* allocate memory for data */ - t->total = count; + tc->data_len = count; - t->data = MEM_callocN(t->total * sizeof(TransData), "TransData (Graph Editor)"); + tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData (Graph Editor)"); /* for each 2d vert a 3d vector is allocated, so that they can be treated just as if they were 3d verts */ - t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransData2D (Graph Editor)"); - t->custom.type.data = MEM_callocN(t->total * sizeof(TransDataGraph), "TransDataGraph"); - t->custom.type.use_free = true; + tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D (Graph Editor)"); + tc->custom.type.data = MEM_callocN(tc->data_len * sizeof(TransDataGraph), "TransDataGraph"); + tc->custom.type.use_free = true; - td = t->data; - td2d = t->data2d; - tdg = t->custom.type.data; + td = tc->data; + td2d = tc->data_2d; + tdg = tc->custom.type.data; /* precompute space-conversion matrices for dealing with non-uniform scaling of Graph Editor */ unit_m3(mtx); @@ -4504,7 +4607,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) if (is_prop_edit) { /* loop 2: build transdata arrays */ - td = t->data; + td = tc->data; for (ale = anim_data.first; ale; ale = ale->next) { AnimData *adt = ANIM_nla_mapping_get(&ac, ale); @@ -4660,12 +4763,14 @@ static void beztmap_to_data(TransInfo *t, FCurve *fcu, BeztMap *bezms, int totve TransData *td; int i, j; char *adjusted; - + + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* dynamically allocate an array of chars to mark whether an TransData's * pointers have been fixed already, so that we don't override ones that are * already done */ - adjusted = MEM_callocN(t->total, "beztmap_adjusted_map"); + adjusted = MEM_callocN(tc->data_len, "beztmap_adjusted_map"); /* for each beztmap item, find if it is used anywhere */ bezm = bezms; @@ -4673,9 +4778,9 @@ static void beztmap_to_data(TransInfo *t, FCurve *fcu, BeztMap *bezms, int totve /* loop through transdata, testing if we have a hit * for the handles (vec[0]/vec[2]), we must also check if they need to be swapped... */ - td2d = t->data2d; - td = t->data; - for (j = 0; j < t->total; j++, td2d++, td++) { + td2d = tc->data_2d; + td = tc->data; + for (j = 0; j < tc->data_len; j++, td2d++, td++) { /* skip item if already marked */ if (adjusted[j] != 0) continue; @@ -4778,9 +4883,11 @@ void flushTransGraphData(TransInfo *t) double secf = FPS; int a; + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* flush to 2d vector from internally used 3d vector */ - for (a = 0, td = t->data, td2d = t->data2d, tdg = t->custom.type.data; - a < t->total; + for (a = 0, td = tc->data, td2d = tc->data_2d, tdg = tc->custom.type.data; + a < tc->data_len; a++, td++, td2d++, tdg++) { AnimData *adt = (AnimData *)td->extra; /* pointers to relevant AnimData blocks are stored in the td->extra pointers */ @@ -5142,13 +5249,15 @@ static void SeqTransDataBounds(TransInfo *t, ListBase *seqbase, TransSeq *ts) } -static void freeSeqData(TransInfo *t, TransCustomData *custom_data) +static void freeSeqData(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data) { Editing *ed = BKE_sequencer_editing_get(t->scene, false); if (ed != NULL) { + + ListBase *seqbasep = ed->seqbasep; - TransData *td = t->data; + TransData *td = tc->data; int a; /* prevent updating the same seq twice @@ -5176,7 +5285,7 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data) { int overlap = 0; - for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) { + for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev) && (seq->depth == 0) && (seq->flag & SEQ_OVERLAP)) { overlap = 1; @@ -5189,8 +5298,8 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data) for (seq = seqbasep->first; seq; seq = seq->next) seq->tmp = NULL; - td = t->data; - for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) { + td = tc->data; + for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev)) { /* check effects strips, we cant change their time */ @@ -5213,8 +5322,8 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data) if (t->flag & T_ALT_TRANSFORM) { int minframe = MAXFRAME; - td = t->data; - for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) { + td = tc->data; + for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev) && (seq->depth == 0)) { minframe = min_ii(minframe, seq->startdisp); @@ -5250,8 +5359,8 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data) if (has_effect_any) { /* update effects strips based on strips just moved in time */ - td = t->data; - for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) { + td = tc->data; + for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev)) { if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) { @@ -5263,8 +5372,8 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data) if (has_effect_root) { /* now if any effects _still_ overlap, we need to move them up */ - td = t->data; - for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) { + td = tc->data; + for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev) && (seq->depth == 0)) { if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) { @@ -5293,7 +5402,7 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data) } else { /* Canceled, need to update the strips display */ - for (a = 0; a < t->total; a++, td++) { + for (a = 0; a < tc->data_len; a++, td++) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev) && (seq->depth == 0)) { if (seq->flag & SEQ_OVERLAP) @@ -5312,9 +5421,9 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data) MEM_freeN(custom_data->data); custom_data->data = NULL; } - if (t->data) { - MEM_freeN(t->data); // XXX postTrans usually does this - t->data = NULL; + if (tc->data) { + MEM_freeN(tc->data); // XXX postTrans usually does this + tc->data = NULL; } } @@ -5333,12 +5442,14 @@ static void createTransSeqData(bContext *C, TransInfo *t) int count = 0; + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + if (ed == NULL) { - t->total = 0; + tc->data_len = 0; return; } - t->custom.type.free_cb = freeSeqData; + tc->custom.type.free_cb = freeSeqData; xmouse = (int)UI_view2d_region_to_view_x(v2d, t->mouse.imval[0]); @@ -5377,18 +5488,18 @@ static void createTransSeqData(bContext *C, TransInfo *t) count = SeqTransCount(t, NULL, ed->seqbasep, 0); /* allocate memory for data */ - t->total = count; + tc->data_len = count; /* stop if trying to build list if nothing selected */ if (count == 0) { return; } - t->custom.type.data = ts = MEM_callocN(sizeof(TransSeq), "transseq"); - t->custom.type.use_free = true; - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransSeq TransData"); - td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransSeq TransData2D"); - ts->tdseq = tdsq = MEM_callocN(t->total * sizeof(TransDataSeq), "TransSeq TransDataSeq"); + tc->custom.type.data = ts = MEM_callocN(sizeof(TransSeq), "transseq"); + tc->custom.type.use_free = true; + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransSeq TransData"); + td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransSeq TransData2D"); + ts->tdseq = tdsq = MEM_callocN(tc->data_len * sizeof(TransDataSeq), "TransSeq TransDataSeq"); /* loop 2: build transdata array */ SeqToTransData_Recursive(t, ed->seqbasep, td, td2d, tdsq); @@ -5517,11 +5628,11 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob) if (skip_invert == false && constinv == false) { ob->transflag |= OB_NO_CONSTRAINTS; /* BKE_object_where_is_calc_time checks this */ - BKE_object_where_is_calc(&t->eval_ctx, t->scene, ob); + BKE_object_where_is_calc(t->depsgraph, t->scene, ob); ob->transflag &= ~OB_NO_CONSTRAINTS; } else - BKE_object_where_is_calc(&t->eval_ctx, t->scene, ob); + BKE_object_where_is_calc(t->depsgraph, t->scene, ob); td->ob = ob; @@ -6118,39 +6229,42 @@ static void special_aftertrans_update__mesh(bContext *UNUSED(C), TransInfo *t) { /* so automerge supports mirror */ if ((t->scene->toolsettings->automerge) && - (t->obedit && t->obedit->type == OB_MESH)) + ((t->flag & T_EDIT) && t->obedit_type == OB_MESH)) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); - BMesh *bm = em->bm; - char hflag; - bool has_face_sel = (bm->totfacesel != 0); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - if (t->flag & T_MIRROR) { - TransData *td; - int i; + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); + BMesh *bm = em->bm; + char hflag; + bool has_face_sel = (bm->totfacesel != 0); - /* rather then adjusting the selection (which the user would notice) - * tag all mirrored verts, then automerge those */ - BM_mesh_elem_hflag_disable_all(bm, BM_VERT, BM_ELEM_TAG, false); + if (t->flag & T_MIRROR) { + TransData *td; + int i; - for (i = 0, td = t->data; i < t->total; i++, td++) { - if (td->extra) { - BM_elem_flag_enable((BMVert *)td->extra, BM_ELEM_TAG); + /* rather then adjusting the selection (which the user would notice) + * tag all mirrored verts, then automerge those */ + BM_mesh_elem_hflag_disable_all(bm, BM_VERT, BM_ELEM_TAG, false); + + for (i = 0, td = tc->data; i < tc->data_len; i++, td++) { + if (td->extra) { + BM_elem_flag_enable((BMVert *)td->extra, BM_ELEM_TAG); + } } - } - hflag = BM_ELEM_SELECT | BM_ELEM_TAG; - } - else { - hflag = BM_ELEM_SELECT; - } + hflag = BM_ELEM_SELECT | BM_ELEM_TAG; + } + else { + hflag = BM_ELEM_SELECT; + } - EDBM_automerge(t->scene, t->obedit, true, hflag); + EDBM_automerge(t->scene, tc->obedit, true, hflag); - /* Special case, this is needed or faces won't re-select. - * Flush selected edges to faces. */ - if (has_face_sel && (em->selectmode == SCE_SELECT_FACE)) { - EDBM_selectmode_flush_ex(em, SCE_SELECT_EDGE); + /* Special case, this is needed or faces won't re-select. + * Flush selected edges to faces. */ + if (has_face_sel && (em->selectmode == SCE_SELECT_FACE)) { + EDBM_selectmode_flush_ex(em, SCE_SELECT_EDGE); + } } } } @@ -6168,50 +6282,53 @@ void special_aftertrans_update(bContext *C, TransInfo *t) const bool duplicate = (t->mode == TFM_TIME_DUPLICATE); /* early out when nothing happened */ - if (t->total == 0 || t->mode == TFM_DUMMY) + if (t->data_len_all == 0 || t->mode == TFM_DUMMY) { return; - + } + if (t->spacetype == SPACE_VIEW3D) { - if (t->obedit) { + if (t->flag & T_EDIT) { /* Special Exception: * We don't normally access 't->custom.mode' here, but its needed in this case. */ if (canceled == 0) { /* we need to delete the temporary faces before automerging */ if (t->mode == TFM_EDGE_SLIDE) { - EdgeSlideData *sld = t->custom.mode.data; - /* handle multires re-projection, done * on transform completion since it's * really slow -joeedh */ projectEdgeSlideData(t, true); - /* free temporary faces to avoid automerging and deleting - * during cleanup - psy-fi */ - freeEdgeSlideTempFaces(sld); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + EdgeSlideData *sld = tc->custom.mode.data; + + /* free temporary faces to avoid automerging and deleting + * during cleanup - psy-fi */ + freeEdgeSlideTempFaces(sld); + } } else if (t->mode == TFM_VERT_SLIDE) { /* as above */ - VertSlideData *sld = t->custom.mode.data; projectVertSlideData(t, true); - freeVertSlideTempFaces(sld); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + VertSlideData *sld = tc->custom.mode.data; + freeVertSlideTempFaces(sld); + } } - if (t->obedit->type == OB_MESH) { + if (t->obedit_type == OB_MESH) { special_aftertrans_update__mesh(C, t); } } else { if (t->mode == TFM_EDGE_SLIDE) { - EdgeSlideData *sld = t->custom.mode.data; - - sld->perc = 0.0; + EdgeSlideParams *slp = t->custom.mode.data; + slp->perc = 0.0; projectEdgeSlideData(t, false); } else if (t->mode == TFM_VERT_SLIDE) { - VertSlideData *sld = t->custom.mode.data; - - sld->perc = 0.0; + EdgeSlideParams *slp = t->custom.mode.data; + slp->perc = 0.0; projectVertSlideData(t, false); } } @@ -6485,64 +6602,71 @@ void special_aftertrans_update(bContext *C, TransInfo *t) ED_nla_postop_refresh(&ac); } } - else if (t->obedit) { - if (t->obedit->type == OB_MESH) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); - /* table needs to be created for each edit command, since vertices can move etc */ - ED_mesh_mirror_spatial_table(t->obedit, em, NULL, NULL, 'e'); + else if (t->flag & T_EDIT) { + if (t->obedit_type == OB_MESH) { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); + /* table needs to be created for each edit command, since vertices can move etc */ + ED_mesh_mirror_spatial_table(tc->obedit, em, NULL, NULL, 'e'); + /* TODO(campbell): xform: We need support for many mirror objects at once! */ + break; + } } } - else if ((t->flag & T_POSE) && (t->poseobj)) { - bArmature *arm; - bPoseChannel *pchan; - short targetless_ik = 0; + else if (t->flag & T_POSE) { - ob = t->poseobj; - arm = ob->data; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - if ((t->flag & T_AUTOIK) && (t->options & CTX_AUTOCONFIRM)) { - /* when running transform non-interactively (operator exec), - * we need to update the pose otherwise no updates get called during - * transform and the auto-ik is not applied. see [#26164] */ - struct Object *pose_ob = t->poseobj; - BKE_pose_where_is(&t->eval_ctx, t->scene, pose_ob); - } + bArmature *arm; + bPoseChannel *pchan; + short targetless_ik = 0; - /* set BONE_TRANSFORM flags for autokey, manipulator draw might have changed them */ - if (!canceled && (t->mode != TFM_DUMMY)) - count_set_pose_transflags(&t->mode, t->around, ob); + ob = tc->poseobj; + arm = ob->data; - /* if target-less IK grabbing, we calculate the pchan transforms and clear flag */ - if (!canceled && t->mode == TFM_TRANSLATION) - targetless_ik = apply_targetless_ik(ob); - else { - /* not forget to clear the auto flag */ - for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - bKinematicConstraint *data = has_targetless_ik(pchan); - if (data) data->flag &= ~CONSTRAINT_IK_AUTO; + if ((t->flag & T_AUTOIK) && (t->options & CTX_AUTOCONFIRM)) { + /* when running transform non-interactively (operator exec), + * we need to update the pose otherwise no updates get called during + * transform and the auto-ik is not applied. see [#26164] */ + struct Object *pose_ob = tc->poseobj; + BKE_pose_where_is(t->depsgraph, t->scene, pose_ob); } - } - if (t->mode == TFM_TRANSLATION) - pose_grab_with_ik_clear(ob); - - /* automatic inserting of keys and unkeyed tagging - only if transform wasn't canceled (or TFM_DUMMY) */ - if (!canceled && (t->mode != TFM_DUMMY)) { - autokeyframe_pose_cb_func(C, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik); - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); - } - else if (arm->flag & ARM_DELAYDEFORM) { - /* TODO(sergey): Armature is already updated by recalcData(), so we - * might save some time by skipping re-evaluating it. But this isn't - * possible yet within new dependency graph, and also other contexts - * might need to update their CoW copies. - */ - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); - } - else { - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); - } + /* set BONE_TRANSFORM flags for autokey, manipulator draw might have changed them */ + if (!canceled && (t->mode != TFM_DUMMY)) + count_set_pose_transflags(&t->mode, t->around, ob); + + /* if target-less IK grabbing, we calculate the pchan transforms and clear flag */ + if (!canceled && t->mode == TFM_TRANSLATION) + targetless_ik = apply_targetless_ik(ob); + else { + /* not forget to clear the auto flag */ + for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + bKinematicConstraint *data = has_targetless_ik(pchan); + if (data) data->flag &= ~CONSTRAINT_IK_AUTO; + } + } + + if (t->mode == TFM_TRANSLATION) + pose_grab_with_ik_clear(ob); + /* automatic inserting of keys and unkeyed tagging - only if transform wasn't canceled (or TFM_DUMMY) */ + if (!canceled && (t->mode != TFM_DUMMY)) { + autokeyframe_pose_cb_func(C, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik); + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + } + else if (arm->flag & ARM_DELAYDEFORM) { + /* TODO(sergey): Armature is already updated by recalcData(), so we + * might save some time by skipping re-evaluating it. But this isn't + * possible yet within new dependency graph, and also other contexts + * might need to update their CoW copies. + */ + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + } + else { + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + } + } } else if (t->options & CTX_PAINT_CURVE) { /* pass */ @@ -6559,8 +6683,10 @@ void special_aftertrans_update(bContext *C, TransInfo *t) BLI_assert(t->flag & (T_OBJECT | T_TEXTURE)); - for (i = 0; i < t->total; i++) { - TransData *td = t->data + i; + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + + for (i = 0; i < tc->data_len; i++) { + TransData *td = tc->data + i; ListBase pidlist; PTCacheID *pid; ob = td->ob; @@ -6614,7 +6740,7 @@ int special_transform_moving(TransInfo *t) else if (t->spacetype == SPACE_IPO) { return G_TRANSFORM_FCURVES; } - else if (t->obedit || ((t->flag & T_POSE) && (t->poseobj))) { + else if ((t->flag & T_EDIT) || (t->flag & T_POSE)) { return G_TRANSFORM_EDIT; } else if (t->flag & (T_OBJECT | T_TEXTURE)) { @@ -6632,21 +6758,23 @@ static void createTransObject(bContext *C, TransInfo *t) set_trans_object_base_flags(t); + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* count */ - t->total = CTX_DATA_COUNT(C, selected_objects); + tc->data_len = CTX_DATA_COUNT(C, selected_objects); - if (!t->total) { + if (!tc->data_len) { /* clear here, main transform function escapes too */ clear_trans_object_base_flags(t); return; } if (is_prop_edit) { - t->total += count_proportional_objects(t); + tc->data_len += count_proportional_objects(t); } - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransOb"); - tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "TransObExtension"); + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransOb"); + tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "TransObExtension"); CTX_DATA_BEGIN(C, Base *, base, selected_bases) { @@ -6766,7 +6894,9 @@ static void createTransNodeData(bContext *UNUSED(C), TransInfo *t) SpaceNode *snode = t->sa->spacedata.first; bNode *node; - t->total = 0; + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + + tc->data_len = 0; if (!snode->edittree) { return; @@ -6779,15 +6909,15 @@ static void createTransNodeData(bContext *UNUSED(C), TransInfo *t) for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_SELECT && is_node_parent_select(node) == false) { node->flag |= NODE_TRANSFORM; - t->total++; + tc->data_len++; } else { node->flag &= ~NODE_TRANSFORM; } } - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransNode TransData"); - td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransNode TransData2D"); + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransNode TransData"); + td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransNode TransData2D"); for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_TRANSFORM) { @@ -6972,7 +7102,7 @@ static void planeTrackToTransData(const int framenr, TransData *td, TransData2D } } -static void transDataTrackingFree(TransInfo *UNUSED(t), TransCustomData *custom_data) +static void transDataTrackingFree(TransInfo *UNUSED(t), TransDataContainer *UNUSED(tc), TransCustomData *custom_data) { if (custom_data->data) { TransDataTracking *tdt = custom_data->data; @@ -6997,22 +7127,24 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t) TransDataTracking *tdt; int framenr = ED_space_clip_get_clip_frame_number(sc); + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* count */ - t->total = 0; + tc->data_len = 0; track = tracksbase->first; while (track) { if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) { - t->total++; /* offset */ + tc->data_len++; /* offset */ if (track->flag & SELECT) - t->total++; + tc->data_len++; if (track->pat_flag & SELECT) - t->total += 4; + tc->data_len += 4; if (track->search_flag & SELECT) - t->total += 2; + tc->data_len += 2; } track = track->next; @@ -7023,18 +7155,18 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t) plane_track = plane_track->next) { if (PLANE_TRACK_VIEW_SELECTED(plane_track)) { - t->total += 4; + tc->data_len += 4; } } - if (t->total == 0) + if (tc->data_len == 0) return; - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransTracking TransData"); - td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransTracking TransData2D"); - tdt = t->custom.type.data = MEM_callocN(t->total * sizeof(TransDataTracking), "TransTracking TransDataTracking"); + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransTracking TransData"); + td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransTracking TransData2D"); + tdt = tc->custom.type.data = MEM_callocN(tc->data_len * sizeof(TransDataTracking), "TransTracking TransDataTracking"); - t->custom.type.free_cb = transDataTrackingFree; + tc->custom.type.free_cb = transDataTrackingFree; /* create actual data */ track = tracksbase->first; @@ -7136,8 +7268,10 @@ static void createTransTrackingCurvesData(bContext *C, TransInfo *t) BKE_movieclip_get_size(clip, &sc->user, &width, &height); + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* count */ - t->total = 0; + tc->data_len = 0; if ((sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) == 0) { return; @@ -7154,23 +7288,23 @@ static void createTransTrackingCurvesData(bContext *C, TransInfo *t) continue; if (marker->flag & MARKER_GRAPH_SEL_X) - t->total += 1; + tc->data_len += 1; if (marker->flag & MARKER_GRAPH_SEL_Y) - t->total += 1; + tc->data_len += 1; } } track = track->next; } - if (t->total == 0) + if (tc->data_len == 0) return; - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransTracking TransData"); - td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransTracking TransData2D"); - t->custom.type.data = tdt = MEM_callocN(t->total * sizeof(TransDataTracking), "TransTracking TransDataTracking"); - t->custom.type.free_cb = transDataTrackingFree; + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransTracking TransData"); + td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransTracking TransData2D"); + tc->custom.type.data = tdt = MEM_callocN(tc->data_len * sizeof(TransDataTracking), "TransTracking TransDataTracking"); + tc->custom.type.free_cb = transDataTrackingFree; /* create actual data */ track = tracksbase->first; @@ -7211,7 +7345,9 @@ static void createTransTrackingData(bContext *C, TransInfo *t) MovieClip *clip = ED_space_clip_get_clip(sc); int width, height; - t->total = 0; + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + + tc->data_len = 0; if (!clip) return; @@ -7232,12 +7368,14 @@ static void createTransTrackingData(bContext *C, TransInfo *t) static void cancelTransTracking(TransInfo *t) { + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); SpaceClip *sc = t->sa->spacedata.first; int i, framenr = ED_space_clip_get_clip_frame_number(sc); - TransDataTracking *tdt_array = t->custom.type.data; + TransDataTracking *tdt_array = tc->custom.type.data; + i = 0; - while (i < t->total) { + while (i < tc->data_len) { TransDataTracking *tdt = &tdt_array[i]; if (tdt->mode == transDataTracking_ModeTracks) { @@ -7294,8 +7432,10 @@ void flushTransTracking(TransInfo *t) if (t->state == TRANS_CANCEL) cancelTransTracking(t); + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* flush to 2d vector from internally used 3d vector */ - for (a = 0, td = t->data, td2d = t->data2d, tdt = t->custom.type.data; a < t->total; a++, td2d++, td++, tdt++) { + for (a = 0, td = tc->data, td2d = tc->data_2d, tdt = tc->custom.type.data; a < tc->data_len; a++, td2d++, td++, tdt++) { if (tdt->mode == transDataTracking_ModeTracks) { float loc2d[2]; @@ -7561,7 +7701,9 @@ static void createTransMaskingData(bContext *C, TransInfo *t) const bool is_prop_edit = (t->flag & T_PROP_EDIT); float asp[2]; - t->total = 0; + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + + tc->data_len = 0; if (!mask) return; @@ -7621,13 +7763,13 @@ static void createTransMaskingData(bContext *C, TransInfo *t) ED_mask_get_aspect(t->sa, t->ar, &asp[0], &asp[1]); - t->total = (is_prop_edit) ? count : countsel; - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Mask Editing)"); + tc->data_len = (is_prop_edit) ? count : countsel; + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Mask Editing)"); /* for each 2d uv coord a 3d vector is allocated, so that they can be * treated just as if they were 3d verts */ - td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransObData2D(Mask Editing)"); - t->custom.type.data = tdm = MEM_callocN(t->total * sizeof(TransDataMasking), "TransDataMasking(Mask Editing)"); - t->custom.type.use_free = true; + td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransObData2D(Mask Editing)"); + tc->custom.type.data = tdm = MEM_callocN(tc->data_len * sizeof(TransDataMasking), "TransDataMasking(Mask Editing)"); + tc->custom.type.use_free = true; /* create data */ for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { @@ -7684,12 +7826,14 @@ void flushTransMasking(TransInfo *t) int a; float asp[2], inv[2]; + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + ED_mask_get_aspect(t->sa, t->ar, &asp[0], &asp[1]); inv[0] = 1.0f / asp[0]; inv[1] = 1.0f / asp[1]; /* flush to 2d vector from internally used 3d vector */ - for (a = 0, td = t->data2d, tdm = t->custom.type.data; a < t->total; a++, td++, tdm++) { + for (a = 0, td = tc->data_2d, tdm = tc->custom.type.data; a < tc->data_len; a++, td++, tdm++) { td->loc2d[0] = td->loc[0] * inv[0]; td->loc2d[1] = td->loc[1] * inv[1]; mul_m3_v2(tdm->parent_inverse_matrix, td->loc2d); @@ -7808,7 +7952,9 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t) int i; int total = 0; - t->total = 0; + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + + tc->data_len = 0; if (!paint || !paint->brush || !paint->brush->paint_curve) return; @@ -7834,11 +7980,11 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t) if (!total) return; - t->total = total; - td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransData2D"); - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransData"); - t->custom.type.data = tdpc = MEM_callocN(t->total * sizeof(TransDataPaintCurve), "TransDataPaintCurve"); - t->custom.type.use_free = true; + tc->data_len = total; + td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D"); + td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData"); + tc->custom.type.data = tdpc = MEM_callocN(tc->data_len * sizeof(TransDataPaintCurve), "TransDataPaintCurve"); + tc->custom.type.use_free = true; for (pcp = pc->points, i = 0; i < pc->tot_points; i++, pcp++) { if (PC_IS_ANY_SEL(pcp)) { @@ -7869,10 +8015,13 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t) void flushTransPaintCurve(TransInfo *t) { int i; - TransData2D *td2d = t->data2d; - TransDataPaintCurve *tdpc = t->custom.type.data; - for (i = 0; i < t->total; i++, tdpc++, td2d++) { + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + + TransData2D *td2d = tc->data_2d; + TransDataPaintCurve *tdpc = tc->custom.type.data; + + for (i = 0; i < tc->data_len; i++, tdpc++, td2d++) { PaintCurvePoint *pcp = tdpc->pcp; copy_v2_v2(pcp->bez.vec[tdpc->id], td2d->loc); } @@ -7891,15 +8040,16 @@ static void createTransGPencil(bContext *C, TransInfo *t) const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; const bool is_prop_edit_connected = (t->flag & T_PROP_CONNECTED) != 0; - - + + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* == Grease Pencil Strokes to Transform Data == * Grease Pencil stroke points can be a mixture of 2D (screen-space), * or 3D coordinates. However, they're always saved as 3D points. * For now, we just do these without creating TransData2D for the 2D * strokes. This may cause issues in future though. */ - t->total = 0; + tc->data_len = 0; if (gpd == NULL) return; @@ -7928,11 +8078,11 @@ static void createTransGPencil(bContext *C, TransInfo *t) if (is_prop_edit_connected) { /* connected only - so only if selected */ if (gps->flag & GP_STROKE_SELECT) - t->total += gps->totpoints; + tc->data_len += gps->totpoints; } else { /* everything goes - connection status doesn't matter */ - t->total += gps->totpoints; + tc->data_len += gps->totpoints; } } else { @@ -7944,7 +8094,7 @@ static void createTransGPencil(bContext *C, TransInfo *t) // TODO: 2D vs 3D? for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { if (pt->flag & GP_SPOINT_SELECT) - t->total++; + tc->data_len++; } } } @@ -7953,13 +8103,13 @@ static void createTransGPencil(bContext *C, TransInfo *t) } /* Stop trying if nothing selected */ - if (t->total == 0) { + if (tc->data_len == 0) { return; } /* Allocate memory for data */ - t->data = MEM_callocN(t->total * sizeof(TransData), "TransData(GPencil)"); - td = t->data; + tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData(GPencil)"); + td = tc->data; unit_m3(smtx); unit_m3(mtx); @@ -8127,6 +8277,29 @@ static void createTransGPencil(bContext *C, TransInfo *t) } } +static int countAndCleanTransDataContainer(TransInfo *t) +{ + BLI_assert(ELEM(t->data_len_all, 0, -1)); + t->data_len_all = 0; + uint data_container_len_orig = t->data_container_len; + for (TransDataContainer *th_end = t->data_container - 1, *tc = t->data_container + (t->data_container_len - 1); tc != th_end; tc--) { + if (tc->data_len == 0) { + uint index = tc - t->data_container; + if (index + 1 != t->data_container_len) { + SWAP(TransDataContainer, t->data_container[index], t->data_container[t->data_container_len - 1]); + } + t->data_container_len -= 1; + } + else { + t->data_len_all += tc->data_len; + } + } + if (data_container_len_orig != t->data_container_len) { + t->data_container = MEM_reallocN(t->data_container, sizeof(*t->data_container) * t->data_container_len); + } + return t->data_len_all; +} + void createTransData(bContext *C, TransInfo *t) { @@ -8134,16 +8307,27 @@ void createTransData(bContext *C, TransInfo *t) ViewLayer *view_layer = t->view_layer; Object *ob = OBACT(view_layer); + t->data_len_all = -1; + /* if tests must match recalcData for correct updates */ if (t->options & CTX_TEXTURE) { t->flag |= T_TEXTURE; + createTransTexspace(t); + countAndCleanTransDataContainer(t); } else if (t->options & CTX_EDGE) { - t->ext = NULL; + /* Multi object editing. */ + initTransDataContainers_FromObjectData(t); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + tc->data_ext = NULL; + } t->flag |= T_EDIT; + createTransEdge(t); - if (t->data && t->flag & T_PROP_EDIT) { + countAndCleanTransDataContainer(t); + + if (t->data_len_all && t->flag & T_PROP_EDIT) { sort_trans_data(t); // makes selected become first in array set_prop_dist(t, 1); sort_trans_data_dist(t); @@ -8152,9 +8336,11 @@ void createTransData(bContext *C, TransInfo *t) else if (t->options & CTX_GPENCIL_STROKES) { t->options |= CTX_GPENCIL_STROKES; t->flag |= T_POINTS; + createTransGPencil(C, t); + countAndCleanTransDataContainer(t); - if (t->data && (t->flag & T_PROP_EDIT)) { + if (t->data_len_all && (t->flag & T_PROP_EDIT)) { sort_trans_data(t); // makes selected become first in array set_prop_dist(t, 1); sort_trans_data_dist(t); @@ -8163,22 +8349,32 @@ void createTransData(bContext *C, TransInfo *t) else if (t->spacetype == SPACE_IMAGE) { t->flag |= T_POINTS | T_2D_EDIT; if (t->options & CTX_MASK) { + /* copied from below */ createTransMaskingData(C, t); + countAndCleanTransDataContainer(t); - if (t->data && (t->flag & T_PROP_EDIT)) { + if (t->data_len_all && (t->flag & T_PROP_EDIT)) { sort_trans_data(t); // makes selected become first in array set_prop_dist(t, true); sort_trans_data_dist(t); } } else if (t->options & CTX_PAINT_CURVE) { - if (!ELEM(t->mode, TFM_SHEAR, TFM_SHRINKFATTEN)) + if (!ELEM(t->mode, TFM_SHEAR, TFM_SHRINKFATTEN)) { createTransPaintCurveVerts(C, t); + countAndCleanTransDataContainer(t); + } } - else if (t->obedit) { + else if (t->obedit_type == OB_MESH) { + + initTransDataContainers_FromObjectData(t); createTransUVs(C, t); - if (t->data && (t->flag & T_PROP_EDIT)) { + countAndCleanTransDataContainer(t); + + t->flag |= T_EDIT; + + if (t->data_len_all && (t->flag & T_PROP_EDIT)) { sort_trans_data(t); // makes selected become first in array set_prop_dist(t, 1); sort_trans_data_dist(t); @@ -8187,9 +8383,11 @@ void createTransData(bContext *C, TransInfo *t) } else if (t->spacetype == SPACE_ACTION) { t->flag |= T_POINTS | T_2D_EDIT; + createTransActionData(C, t); + countAndCleanTransDataContainer(t); - if (t->data && (t->flag & T_PROP_EDIT)) { + if (t->data_len_all && (t->flag & T_PROP_EDIT)) { sort_trans_data(t); // makes selected become first in array //set_prop_dist(t, false); /* don't do that, distance has been set in createTransActionData already */ sort_trans_data_dist(t); @@ -8198,17 +8396,20 @@ void createTransData(bContext *C, TransInfo *t) else if (t->spacetype == SPACE_NLA) { t->flag |= T_POINTS | T_2D_EDIT; createTransNlaData(C, t); + countAndCleanTransDataContainer(t); } else if (t->spacetype == SPACE_SEQ) { t->flag |= T_POINTS | T_2D_EDIT; t->num.flag |= NUM_NO_FRACTION; /* sequencer has no use for floating point transformations */ createTransSeqData(C, t); + countAndCleanTransDataContainer(t); } else if (t->spacetype == SPACE_IPO) { t->flag |= T_POINTS | T_2D_EDIT; createTransGraphEditData(C, t); + countAndCleanTransDataContainer(t); - if (t->data && (t->flag & T_PROP_EDIT)) { + if (t->data_len_all && (t->flag & T_PROP_EDIT)) { sort_trans_data(t); // makes selected become first in array set_prop_dist(t, false); /* don't do that, distance has been set in createTransGraphEditData already */ sort_trans_data_dist(t); @@ -8216,8 +8417,11 @@ void createTransData(bContext *C, TransInfo *t) } else if (t->spacetype == SPACE_NODE) { t->flag |= T_POINTS | T_2D_EDIT; + createTransNodeData(C, t); - if (t->data && (t->flag & T_PROP_EDIT)) { + countAndCleanTransDataContainer(t); + + if (t->data_len_all && (t->flag & T_PROP_EDIT)) { sort_trans_data(t); // makes selected become first in array set_prop_dist(t, 1); sort_trans_data_dist(t); @@ -8225,34 +8429,42 @@ void createTransData(bContext *C, TransInfo *t) } else if (t->spacetype == SPACE_CLIP) { t->flag |= T_POINTS | T_2D_EDIT; - if (t->options & CTX_MOVIECLIP) + if (t->options & CTX_MOVIECLIP) { createTransTrackingData(C, t); + countAndCleanTransDataContainer(t); + } else if (t->options & CTX_MASK) { /* copied from above */ createTransMaskingData(C, t); + countAndCleanTransDataContainer(t); - if (t->data && (t->flag & T_PROP_EDIT)) { + if (t->data_len_all && (t->flag & T_PROP_EDIT)) { sort_trans_data(t); // makes selected become first in array set_prop_dist(t, true); sort_trans_data_dist(t); } } } - else if (t->obedit) { - t->ext = NULL; - if (t->obedit->type == OB_MESH) { + else if (t->obedit_type != -1) { + /* Multi object editing. */ + initTransDataContainers_FromObjectData(t); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + tc->data_ext = NULL; + } + if (t->obedit_type == OB_MESH) { createTransEditVerts(t); } - else if (ELEM(t->obedit->type, OB_CURVE, OB_SURF)) { + else if (ELEM(t->obedit_type, OB_CURVE, OB_SURF)) { createTransCurveVerts(t); } - else if (t->obedit->type == OB_LATTICE) { + else if (t->obedit_type == OB_LATTICE) { createTransLatticeVerts(t); } - else if (t->obedit->type == OB_MBALL) { + else if (t->obedit_type == OB_MBALL) { createTransMBallVerts(t); } - else if (t->obedit->type == OB_ARMATURE) { + else if (t->obedit_type == OB_ARMATURE) { t->flag &= ~T_PROP_EDIT; createTransArmatureVerts(t); } @@ -8260,12 +8472,14 @@ void createTransData(bContext *C, TransInfo *t) printf("edit type not implemented!\n"); } + countAndCleanTransDataContainer(t); + t->flag |= T_EDIT | T_POINTS; - if (t->data && t->flag & T_PROP_EDIT) { - if (ELEM(t->obedit->type, OB_CURVE, OB_MESH)) { + if (t->data_len_all && t->flag & T_PROP_EDIT) { + if (ELEM(t->obedit_type, OB_CURVE, OB_MESH)) { sort_trans_data(t); // makes selected become first in array - if ((t->obedit->type == OB_MESH) && (t->flag & T_PROP_CONNECTED)) { + if ((t->obedit_type == OB_MESH) && (t->flag & T_PROP_CONNECTED)) { /* already calculated by editmesh_set_connectivity_distance */ } else { @@ -8284,13 +8498,21 @@ void createTransData(bContext *C, TransInfo *t) if (t->mode == TFM_BONESIZE) { t->flag &= ~(T_EDIT | T_POINTS); t->flag |= T_POSE; - t->poseobj = ob; /* <- tsk tsk, this is going to give issues one day */ + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + tc->poseobj = tc->obedit; + tc->obedit = NULL; + } } } else if (ob && (ob->mode & OB_MODE_POSE)) { // XXX this is currently limited to active armature only... // XXX active-layer checking isn't done as that should probably be checked through context instead - createTransPose(t, ob); + + /* Multi object editing. */ + initTransDataContainers_FromObjectData(t); + createTransPose(t, NULL, 0); + countAndCleanTransDataContainer(t); } else if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT) && !(t->options & CTX_PAINT_CURVE)) { /* important that ob_armature can be set even when its not selected [#23412] @@ -8300,7 +8522,11 @@ void createTransData(bContext *C, TransInfo *t) Base *base_arm = BKE_view_layer_base_find(t->view_layer, ob_armature); if (base_arm) { if (BASE_VISIBLE(base_arm)) { - createTransPose(t, ob_armature); + Object *objects[1]; + objects[0] = ob_armature; + uint objects_len = 1; + createTransPose(t, objects, objects_len); + countAndCleanTransDataContainer(t); } } @@ -8308,9 +8534,10 @@ void createTransData(bContext *C, TransInfo *t) } else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT) && PE_start_edit(PE_get_current(scene, ob))) { createTransParticleVerts(C, t); + countAndCleanTransDataContainer(t); t->flag |= T_POINTS; - if (t->data && t->flag & T_PROP_EDIT) { + if (t->data_len_all && t->flag & T_PROP_EDIT) { sort_trans_data(t); // makes selected become first in array set_prop_dist(t, 1); sort_trans_data_dist(t); @@ -8320,13 +8547,15 @@ void createTransData(bContext *C, TransInfo *t) if ((t->options & CTX_PAINT_CURVE) && !ELEM(t->mode, TFM_SHEAR, TFM_SHRINKFATTEN)) { t->flag |= T_POINTS | T_2D_EDIT; createTransPaintCurveVerts(C, t); + countAndCleanTransDataContainer(t); } } else { createTransObject(C, t); + countAndCleanTransDataContainer(t); t->flag |= T_OBJECT; - if (t->data && t->flag & T_PROP_EDIT) { + if (t->data_len_all && t->flag & T_PROP_EDIT) { // selected objects are already first, no need to presort set_prop_dist(t, 1); sort_trans_data_dist(t); @@ -8344,4 +8573,7 @@ void createTransData(bContext *C, TransInfo *t) } } } + + /* Check that 'countAndCleanTransDataContainer' ran. */ + BLI_assert(t->data_len_all != -1); } diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 08e8e8fe175..8f369aea0c8 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -82,6 +82,7 @@ #include "BKE_tracking.h" #include "BKE_mask.h" #include "BKE_workspace.h" +#include "BKE_layer.h" #include "DEG_depsgraph.h" @@ -127,98 +128,101 @@ void getViewVector(TransInfo *t, float coord[3], float vec[3]) /* ************************** GENERICS **************************** */ -static void clipMirrorModifier(TransInfo *t, Object *ob) +static void clipMirrorModifier(TransInfo *t) { - ModifierData *md = ob->modifiers.first; - float tolerance[3] = {0.0f, 0.0f, 0.0f}; - int axis = 0; - - for (; md; md = md->next) { - if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) { - MirrorModifierData *mmd = (MirrorModifierData *) md; - - if (mmd->flag & MOD_MIR_CLIPPING) { - axis = 0; - if (mmd->flag & MOD_MIR_AXIS_X) { - axis |= 1; - tolerance[0] = mmd->tolerance; - } - if (mmd->flag & MOD_MIR_AXIS_Y) { - axis |= 2; - tolerance[1] = mmd->tolerance; - } - if (mmd->flag & MOD_MIR_AXIS_Z) { - axis |= 4; - tolerance[2] = mmd->tolerance; - } - if (axis) { - float mtx[4][4], imtx[4][4]; - int i; - TransData *td = t->data; - - if (mmd->mirror_ob) { - float obinv[4][4]; - - invert_m4_m4(obinv, mmd->mirror_ob->obmat); - mul_m4_m4m4(mtx, obinv, ob->obmat); - invert_m4_m4(imtx, mtx); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Object *ob = tc->obedit; + ModifierData *md = ob->modifiers.first; + float tolerance[3] = {0.0f, 0.0f, 0.0f}; + int axis = 0; + + for (; md; md = md->next) { + if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) { + MirrorModifierData *mmd = (MirrorModifierData *) md; + + if (mmd->flag & MOD_MIR_CLIPPING) { + axis = 0; + if (mmd->flag & MOD_MIR_AXIS_X) { + axis |= 1; + tolerance[0] = mmd->tolerance; } - - for (i = 0; i < t->total; i++, td++) { - int clip; - float loc[3], iloc[3]; - - if (td->flag & TD_NOACTION) - break; - if (td->loc == NULL) - break; - - if (td->flag & TD_SKIP) - continue; - - copy_v3_v3(loc, td->loc); - copy_v3_v3(iloc, td->iloc); - + if (mmd->flag & MOD_MIR_AXIS_Y) { + axis |= 2; + tolerance[1] = mmd->tolerance; + } + if (mmd->flag & MOD_MIR_AXIS_Z) { + axis |= 4; + tolerance[2] = mmd->tolerance; + } + if (axis) { + float mtx[4][4], imtx[4][4]; + int i; + if (mmd->mirror_ob) { - mul_m4_v3(mtx, loc); - mul_m4_v3(mtx, iloc); + float obinv[4][4]; + + invert_m4_m4(obinv, mmd->mirror_ob->obmat); + mul_m4_m4m4(mtx, obinv, ob->obmat); + invert_m4_m4(imtx, mtx); } - - clip = 0; - if (axis & 1) { - if (fabsf(iloc[0]) <= tolerance[0] || - loc[0] * iloc[0] < 0.0f) - { - loc[0] = 0.0f; - clip = 1; + + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + int clip; + float loc[3], iloc[3]; + + if (td->flag & TD_NOACTION) + break; + if (td->loc == NULL) + break; + + if (td->flag & TD_SKIP) + continue; + + copy_v3_v3(loc, td->loc); + copy_v3_v3(iloc, td->iloc); + + if (mmd->mirror_ob) { + mul_m4_v3(mtx, loc); + mul_m4_v3(mtx, iloc); } - } - - if (axis & 2) { - if (fabsf(iloc[1]) <= tolerance[1] || - loc[1] * iloc[1] < 0.0f) - { - loc[1] = 0.0f; - clip = 1; + + clip = 0; + if (axis & 1) { + if (fabsf(iloc[0]) <= tolerance[0] || + loc[0] * iloc[0] < 0.0f) + { + loc[0] = 0.0f; + clip = 1; + } } - } - if (axis & 4) { - if (fabsf(iloc[2]) <= tolerance[2] || - loc[2] * iloc[2] < 0.0f) - { - loc[2] = 0.0f; - clip = 1; + + if (axis & 2) { + if (fabsf(iloc[1]) <= tolerance[1] || + loc[1] * iloc[1] < 0.0f) + { + loc[1] = 0.0f; + clip = 1; + } } - } - if (clip) { - if (mmd->mirror_ob) { - mul_m4_v3(imtx, loc); + if (axis & 4) { + if (fabsf(iloc[2]) <= tolerance[2] || + loc[2] * iloc[2] < 0.0f) + { + loc[2] = 0.0f; + clip = 1; + } + } + if (clip) { + if (mmd->mirror_ob) { + mul_m4_v3(imtx, loc); + } + copy_v3_v3(td->loc, loc); } - copy_v3_v3(td->loc, loc); } } + } - } } } @@ -227,27 +231,29 @@ static void clipMirrorModifier(TransInfo *t, Object *ob) /* assumes obedit set to mesh object */ static void editbmesh_apply_to_mirror(TransInfo *t) { - TransData *td = t->data; - BMVert *eve; - int i; - - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_NOACTION) - break; - if (td->loc == NULL) - break; - if (td->flag & TD_SKIP) - continue; - - eve = td->extra; - if (eve) { - eve->co[0] = -td->loc[0]; - eve->co[1] = td->loc[1]; - eve->co[2] = td->loc[2]; - } - - if (td->flag & TD_MIRROR_EDGE) { - td->loc[0] = 0; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + BMVert *eve; + int i; + + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_NOACTION) + break; + if (td->loc == NULL) + break; + if (td->flag & TD_SKIP) + continue; + + eve = td->extra; + if (eve) { + eve->co[0] = -td->loc[0]; + eve->co[1] = td->loc[1]; + eve->co[2] = td->loc[2]; + } + + if (td->flag & TD_MIRROR_EDGE) { + td->loc[0] = 0; + } } } } @@ -432,12 +438,14 @@ static void recalcData_nla(TransInfo *t) Scene *scene = t->scene; double secf = FPS; int i; - + + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + /* for each strip we've got, perform some additional validation of the values that got set before * using RNA to set the value (which does some special operations when setting these values to make * sure that everything works ok) */ - for (i = 0; i < t->total; i++, tdn++) { + for (i = 0; i < tc->data_len; i++, tdn++) { NlaStrip *strip = tdn->strip; PointerRNA strip_ptr; short pExceeded, nExceeded, iter; @@ -654,14 +662,18 @@ static void recalcData_image(TransInfo *t) else if (t->options & CTX_PAINT_CURVE) { flushTransPaintCurve(t); } - else if (t->obedit && t->obedit->type == OB_MESH) { + else if ((t->flag & T_EDIT) && t->obedit_type == OB_MESH) { SpaceImage *sima = t->sa->spacedata.first; flushTransUVs(t); if (sima->flag & SI_LIVE_UNWRAP) ED_uvedit_live_unwrap_re_solve(); - - DEG_id_tag_update(t->obedit->data, 0); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + if (tc->data_len) { + DEG_id_tag_update(tc->obedit->data, 0); + } + } } } @@ -716,52 +728,57 @@ static void recalcData_objects(TransInfo *t) { Base *base = t->view_layer->basact; - if (t->obedit) { - if (ELEM(t->obedit->type, OB_CURVE, OB_SURF)) { - Curve *cu = t->obedit->data; - ListBase *nurbs = BKE_curve_editNurbs_get(cu); - Nurb *nu = nurbs->first; - + if (t->obedit_type != -1) { + if (ELEM(t->obedit_type, OB_CURVE, OB_SURF)) { + if (t->state != TRANS_CANCEL) { - clipMirrorModifier(t, t->obedit); + clipMirrorModifier(t); applyProject(t); } - - DEG_id_tag_update(t->obedit->data, 0); /* sets recalc flags */ - - if (t->state == TRANS_CANCEL) { - while (nu) { - BKE_nurb_handles_calc(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */ - nu = nu->next; + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Curve *cu = tc->obedit->data; + ListBase *nurbs = BKE_curve_editNurbs_get(cu); + Nurb *nu = nurbs->first; + + DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */ + + if (t->state == TRANS_CANCEL) { + while (nu) { + BKE_nurb_handles_calc(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */ + nu = nu->next; + } } - } - else { - /* Normal updating */ - while (nu) { - BKE_nurb_test2D(nu); - BKE_nurb_handles_calc(nu); - nu = nu->next; + else { + /* Normal updating */ + while (nu) { + BKE_nurb_test2D(nu); + BKE_nurb_handles_calc(nu); + nu = nu->next; + } } } } - else if (t->obedit->type == OB_LATTICE) { - Lattice *la = t->obedit->data; - + else if (t->obedit_type == OB_LATTICE) { + if (t->state != TRANS_CANCEL) { applyProject(t); } - - DEG_id_tag_update(t->obedit->data, 0); /* sets recalc flags */ - - if (la->editlatt->latt->flag & LT_OUTSIDE) outside_lattice(la->editlatt->latt); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Lattice *la = tc->obedit->data; + DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */ + if (la->editlatt->latt->flag & LT_OUTSIDE) { + outside_lattice(la->editlatt->latt); + } + } } - else if (t->obedit->type == OB_MESH) { - BMEditMesh *em = BKE_editmesh_from_object(t->obedit); + else if (t->obedit_type == OB_MESH) { /* mirror modifier clipping? */ if (t->state != TRANS_CANCEL) { /* apply clipping after so we never project past the clip plane [#25423] */ applyProject(t); - clipMirrorModifier(t, t->obedit); + clipMirrorModifier(t); } if ((t->options & CTX_NO_MIRROR) == 0 && (t->flag & T_MIRROR)) editbmesh_apply_to_mirror(t); @@ -773,133 +790,148 @@ static void recalcData_objects(TransInfo *t) projectVertSlideData(t, false); } - DEG_id_tag_update(t->obedit->data, 0); /* sets recalc flags */ - - EDBM_mesh_normals_update(em); - BKE_editmesh_tessface_calc(em); - } - else if (t->obedit->type == OB_ARMATURE) { /* no recalc flag, does pose */ - bArmature *arm = t->obedit->data; - ListBase *edbo = arm->edbo; - EditBone *ebo, *ebo_parent; - TransData *td = t->data; - int i; - + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */ + BMEditMesh *em = BKE_editmesh_from_object(tc->obedit); + EDBM_mesh_normals_update(em); + BKE_editmesh_tessface_calc(em); + } + } + else if (t->obedit_type == OB_ARMATURE) { /* no recalc flag, does pose */ + if (t->state != TRANS_CANCEL) { applyProject(t); } - - /* Ensure all bones are correctly adjusted */ - for (ebo = edbo->first; ebo; ebo = ebo->next) { - ebo_parent = (ebo->flag & BONE_CONNECTED) ? ebo->parent : NULL; - - if (ebo_parent) { - /* If this bone has a parent tip that has been moved */ - if (ebo_parent->flag & BONE_TIPSEL) { - copy_v3_v3(ebo->head, ebo_parent->tail); - if (t->mode == TFM_BONE_ENVELOPE) ebo->rad_head = ebo_parent->rad_tail; + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + bArmature *arm = tc->obedit->data; + ListBase *edbo = arm->edbo; + EditBone *ebo, *ebo_parent; + TransData *td = tc->data; + int i; + + /* Ensure all bones are correctly adjusted */ + for (ebo = edbo->first; ebo; ebo = ebo->next) { + ebo_parent = (ebo->flag & BONE_CONNECTED) ? ebo->parent : NULL; + + if (ebo_parent) { + /* If this bone has a parent tip that has been moved */ + if (ebo_parent->flag & BONE_TIPSEL) { + copy_v3_v3(ebo->head, ebo_parent->tail); + if (t->mode == TFM_BONE_ENVELOPE) ebo->rad_head = ebo_parent->rad_tail; + } + /* If this bone has a parent tip that has NOT been moved */ + else { + copy_v3_v3(ebo_parent->tail, ebo->head); + if (t->mode == TFM_BONE_ENVELOPE) ebo_parent->rad_tail = ebo->rad_head; + } } - /* If this bone has a parent tip that has NOT been moved */ - else { - copy_v3_v3(ebo_parent->tail, ebo->head); - if (t->mode == TFM_BONE_ENVELOPE) ebo_parent->rad_tail = ebo->rad_head; + + /* on extrude bones, oldlength==0.0f, so we scale radius of points */ + ebo->length = len_v3v3(ebo->head, ebo->tail); + if (ebo->oldlength == 0.0f) { + ebo->rad_head = 0.25f * ebo->length; + ebo->rad_tail = 0.10f * ebo->length; + ebo->dist = 0.25f * ebo->length; + if (ebo->parent) { + if (ebo->rad_head > ebo->parent->rad_tail) + ebo->rad_head = ebo->parent->rad_tail; + } } - } - - /* on extrude bones, oldlength==0.0f, so we scale radius of points */ - ebo->length = len_v3v3(ebo->head, ebo->tail); - if (ebo->oldlength == 0.0f) { - ebo->rad_head = 0.25f * ebo->length; - ebo->rad_tail = 0.10f * ebo->length; - ebo->dist = 0.25f * ebo->length; - if (ebo->parent) { - if (ebo->rad_head > ebo->parent->rad_tail) - ebo->rad_head = ebo->parent->rad_tail; + else if (t->mode != TFM_BONE_ENVELOPE) { + /* if bones change length, lets do that for the deform distance as well */ + ebo->dist *= ebo->length / ebo->oldlength; + ebo->rad_head *= ebo->length / ebo->oldlength; + ebo->rad_tail *= ebo->length / ebo->oldlength; + ebo->oldlength = ebo->length; + + if (ebo_parent) { + ebo_parent->rad_tail = ebo->rad_head; + } } } - else if (t->mode != TFM_BONE_ENVELOPE) { - /* if bones change length, lets do that for the deform distance as well */ - ebo->dist *= ebo->length / ebo->oldlength; - ebo->rad_head *= ebo->length / ebo->oldlength; - ebo->rad_tail *= ebo->length / ebo->oldlength; - ebo->oldlength = ebo->length; - if (ebo_parent) { - ebo_parent->rad_tail = ebo->rad_head; - } - } - } - - if (!ELEM(t->mode, TFM_BONE_ROLL, TFM_BONE_ENVELOPE, TFM_BONE_ENVELOPE_DIST, TFM_BONESIZE)) { - /* fix roll */ - for (i = 0; i < t->total; i++, td++) { - if (td->extra) { - float vec[3], up_axis[3]; - float qrot[4]; - float roll; - - ebo = td->extra; + if (!ELEM(t->mode, TFM_BONE_ROLL, TFM_BONE_ENVELOPE, TFM_BONE_ENVELOPE_DIST, TFM_BONESIZE)) { + /* fix roll */ + for (i = 0; i < tc->data_len; i++, td++) { + if (td->extra) { + float vec[3], up_axis[3]; + float qrot[4]; + float roll; - if (t->state == TRANS_CANCEL) { - /* restore roll */ - ebo->roll = td->ival; - } - else { - copy_v3_v3(up_axis, td->axismtx[2]); + ebo = td->extra; - sub_v3_v3v3(vec, ebo->tail, ebo->head); - normalize_v3(vec); - rotation_between_vecs_to_quat(qrot, td->axismtx[1], vec); - mul_qt_v3(qrot, up_axis); + if (t->state == TRANS_CANCEL) { + /* restore roll */ + ebo->roll = td->ival; + } + else { + copy_v3_v3(up_axis, td->axismtx[2]); - /* roll has a tendency to flip in certain orientations - [#34283], [#33974] */ - roll = ED_armature_ebone_roll_to_vector(ebo, up_axis, false); - ebo->roll = angle_compat_rad(roll, td->ival); + sub_v3_v3v3(vec, ebo->tail, ebo->head); + normalize_v3(vec); + rotation_between_vecs_to_quat(qrot, td->axismtx[1], vec); + mul_qt_v3(qrot, up_axis); + + /* roll has a tendency to flip in certain orientations - [#34283], [#33974] */ + roll = ED_armature_ebone_roll_to_vector(ebo, up_axis, false); + ebo->roll = angle_compat_rad(roll, td->ival); + } } } } - } - - if (arm->flag & ARM_MIRROR_EDIT) { - if (t->state != TRANS_CANCEL) - ED_armature_edit_transform_mirror_update(t->obedit); - else - restoreBones(t); + + if (arm->flag & ARM_MIRROR_EDIT) { + if (t->state != TRANS_CANCEL) { + ED_armature_edit_transform_mirror_update(tc->obedit); + } + else { + restoreBones(tc); + } + } } } else { if (t->state != TRANS_CANCEL) { applyProject(t); } - DEG_id_tag_update(t->obedit->data, 0); /* sets recalc flags */ + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + if (tc->data_len) { + DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */ + } + } } + } - else if ((t->flag & T_POSE) && t->poseobj) { - Object *ob = t->poseobj; - bArmature *arm = ob->data; - - /* if animtimer is running, and the object already has animation data, - * check if the auto-record feature means that we should record 'samples' - * (i.e. uneditable animation values) - * - * context is needed for keying set poll() functions. - */ - // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes? - if ((t->animtimer) && (t->context) && IS_AUTOKEY_ON(t->scene)) { - int targetless_ik = (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet! - - animrecord_check_state(t->scene, &ob->id, t->animtimer); - autokeyframe_pose_cb_func(t->context, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik); - } - - /* old optimize trick... this enforces to bypass the depgraph */ - if (!(arm->flag & ARM_DELAYDEFORM)) { - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */ - /* transformation of pose may affect IK tree, make sure it is rebuilt */ - BIK_clear_data(ob->pose); + else if (t->flag & T_POSE) { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Object *ob = tc->poseobj; + bArmature *arm = ob->data; + + /* if animtimer is running, and the object already has animation data, + * check if the auto-record feature means that we should record 'samples' + * (i.e. uneditable animation values) + * + * context is needed for keying set poll() functions. + */ + // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes? + if ((t->animtimer) && (t->context) && IS_AUTOKEY_ON(t->scene)) { + int targetless_ik = (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet! + + animrecord_check_state(t->scene, &ob->id, t->animtimer); + autokeyframe_pose_cb_func(t->context, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik); + } + + /* old optimize trick... this enforces to bypass the depgraph */ + if (!(arm->flag & ARM_DELAYDEFORM)) { + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */ + /* transformation of pose may affect IK tree, make sure it is rebuilt */ + BIK_clear_data(ob->pose); + } + else { + BKE_pose_where_is(t->depsgraph, t->scene, ob); + } } - else - BKE_pose_where_is(&t->eval_ctx, t->scene, ob); } else if (base && (base->object->mode & OB_MODE_PARTICLE_EDIT) && PE_get_current(t->scene, base->object)) @@ -915,34 +947,37 @@ static void recalcData_objects(TransInfo *t) if (t->state != TRANS_CANCEL) { applyProject(t); } - - for (i = 0; i < t->total; i++) { - TransData *td = t->data + i; - Object *ob = td->ob; - - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - - /* if animtimer is running, and the object already has animation data, - * check if the auto-record feature means that we should record 'samples' - * (i.e. uneditable animation values) - */ - // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes? - if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) { - animrecord_check_state(t->scene, &ob->id, t->animtimer); - autokeyframe_ob_cb_func(t->context, t->scene, t->view_layer, (View3D *)t->view, ob, t->mode); - } - - /* sets recalc flags fully, instead of flushing existing ones - * otherwise proxies don't function correctly - */ - DEG_id_tag_update(&ob->id, OB_RECALC_OB); - if (t->flag & T_TEXTURE) - DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + + for (i = 0; i < tc->data_len; i++, td++) { + Object *ob = td->ob; + + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + /* if animtimer is running, and the object already has animation data, + * check if the auto-record feature means that we should record 'samples' + * (i.e. uneditable animation values) + */ + // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes? + if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) { + animrecord_check_state(t->scene, &ob->id, t->animtimer); + autokeyframe_ob_cb_func(t->context, t->scene, t->view_layer, (View3D *)t->view, ob, t->mode); + } + + /* sets recalc flags fully, instead of flushing existing ones + * otherwise proxies don't function correctly + */ + DEG_id_tag_update(&ob->id, OB_RECALC_OB); + + if (t->flag & T_TEXTURE) + DEG_id_tag_update(&ob->id, OB_RECALC_DATA); + } } } } @@ -954,7 +989,9 @@ static void recalcData_sequencer(TransInfo *t) int a; Sequence *seq_prev = NULL; - for (a = 0, td = t->data; a < t->total; a++, td++) { + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + + for (a = 0, td = tc->data; a < tc->data_len; a++, td++) { TransDataSeq *tdsq = (TransDataSeq *) td->extra; Sequence *seq = tdsq->seq; @@ -979,8 +1016,10 @@ static void recalcData_sequencer(TransInfo *t) /* force recalculation of triangles during transformation */ static void recalcData_gpencil_strokes(TransInfo *t) { - TransData *td = t->data; - for (int i = 0; i < t->total; i++, td++) { + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + + TransData *td = tc->data; + for (int i = 0; i < tc->data_len; i++, td++) { bGPDstroke *gps = td->extra; if (gps != NULL) { gps->flag |= GP_STROKE_RECALC_CACHES; @@ -1078,11 +1117,17 @@ void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis */ void resetTransModal(TransInfo *t) { - if (t->mode == TFM_EDGE_SLIDE) { - freeEdgeSlideVerts(t, &t->custom.mode); - } - else if (t->mode == TFM_VERT_SLIDE) { - freeVertSlideVerts(t, &t->custom.mode); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + if (t->mode == TFM_EDGE_SLIDE) { + freeEdgeSlideVerts(t, tc, &tc->custom.mode); + } + else if (t->mode == TFM_VERT_SLIDE) { + freeVertSlideVerts(t, tc, &tc->custom.mode); + } + else { + /* no need to keep looping... */ + break; + } } } @@ -1105,6 +1150,40 @@ static int initTransInfo_edit_pet_to_flag(const int proportional) } } +void initTransDataContainers_FromObjectData(TransInfo *t) +{ + const eObjectMode object_mode = OBACT(t->view_layer) ? OBACT(t->view_layer)->mode : OB_MODE_OBJECT; + const short object_type = OBACT(t->view_layer) ? OBACT(t->view_layer)->type : -1; + + if ((object_mode & OB_MODE_EDIT) || + ((object_mode & OB_MODE_POSE) && (object_type == OB_ARMATURE))) + { + if (t->data_container) { + MEM_freeN(t->data_container); + } + uint objects_len; + Object **objects = BKE_view_layer_array_from_objects_in_mode( + t->view_layer, &objects_len, { + .object_mode = object_mode, + .no_dup_data = true}); + t->data_container = MEM_callocN(sizeof(*t->data_container) * objects_len, __func__); + t->data_container_len = objects_len; + + for (int i = 0; i < objects_len; i++) { + TransDataContainer *tc = &t->data_container[i]; + if (object_mode & OB_MODE_EDIT) { + tc->obedit = objects[i]; + copy_m3_m4(tc->obedit_mat, tc->obedit->obmat); + normalize_m3(tc->obedit_mat); + } + else if (object_mode & OB_MODE_POSE) { + tc->poseobj = objects[i]; + } + } + MEM_freeN(objects); + } +} + /** * Setup internal data, mouse, vectors * @@ -1114,15 +1193,15 @@ static int initTransInfo_edit_pet_to_flag(const int proportional) */ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event) { - CTX_data_eval_ctx(C, &t->eval_ctx); Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *sce = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + const eObjectMode object_mode = OBACT(view_layer) ? OBACT(view_layer)->mode : OB_MODE_OBJECT; + const short object_type = OBACT(view_layer) ? OBACT(view_layer)->type : -1; ToolSettings *ts = CTX_data_tool_settings(C); ARegion *ar = CTX_wm_region(C); ScrArea *sa = CTX_wm_area(C); - Object *obedit = CTX_data_edit_object(C); - Object *ob = CTX_data_active_object(C); + bGPdata *gpd = CTX_data_gpencil_data(C); RenderEngineType *engine_type = CTX_data_engine_type(C); PropertyRNA *prop; @@ -1133,22 +1212,21 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve t->engine_type = engine_type; t->sa = sa; t->ar = ar; - t->obedit = obedit; t->settings = ts; t->reports = op ? op->reports : NULL; - if (obedit) { - copy_m3_m4(t->obedit_mat, obedit->obmat); - normalize_m3(t->obedit_mat); - } - - t->data = NULL; - t->ext = NULL; - t->helpline = HLP_NONE; t->flag = 0; - + + t->obedit_type = (object_mode == OB_MODE_EDIT) ? object_type : -1; + + /* Many kinds of transform only use a single handle. */ + if (t->data_container == NULL) { + t->data_container = MEM_callocN(sizeof(*t->data_container), __func__); + t->data_container_len = 1; + } + t->redraw = TREDRAW_HARD; /* redraw first time */ if (event) { @@ -1169,12 +1247,11 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve t->transform = NULL; t->handleEvent = NULL; - t->total = 0; + t->data_len_all = 0; t->val = 0.0f; zero_v3(t->vec); - zero_v3(t->center); zero_v3(t->center_global); unit_m3(t->mat); @@ -1260,13 +1337,13 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL)) { const bool use_island = transdata_check_local_islands(t, t->around); - if (obedit && !use_island) { + if ((t->obedit_type != -1) && !use_island) { t->options |= CTX_NO_PET; } } } - if (ob && ob->mode & OB_MODE_ALL_PAINT) { + if (object_mode & OB_MODE_ALL_PAINT) { Paint *p = BKE_paint_get_active_from_context(C); if (p && p->brush && (p->brush->flag & BRUSH_CURVE)) { t->options |= CTX_PAINT_CURVE; @@ -1295,7 +1372,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve t->view = &ar->v2d; t->around = sima->around; - if (ED_space_image_show_uvedit(sima, t->obedit)) { + if (ED_space_image_show_uvedit(sima, OBACT(t->view_layer))) { /* UV transform */ } else if (sima->mode == SI_MODE_MASK) { @@ -1385,7 +1462,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } // Need stuff to take it from edit mesh or whatnot here else if (t->spacetype == SPACE_VIEW3D) { - if (t->obedit && t->obedit->type == OB_MESH && (((Mesh *)t->obedit->data)->editflag & ME_EDIT_MIRROR_X)) { + /* TODO(campbell): xform, get mirror from each object. */ + if (t->obedit_type == OB_MESH && (((Mesh *)OBACT(t->view_layer)->data)->editflag & ME_EDIT_MIRROR_X)) { t->flag |= T_MIRROR; t->mirror = 1; } @@ -1406,7 +1484,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve else if (t->spacetype == SPACE_ACTION) { t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional_action); } - else if (t->obedit) { + else if (t->obedit_type != -1) { t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional); } else if (t->options & CTX_GPENCIL_STROKES) { @@ -1421,7 +1499,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } } } - else if (t->obedit == NULL && ts->proportional_objects) { + else if ((t->obedit_type == -1) && ts->proportional_objects) { t->flag |= T_PROP_EDIT; } } @@ -1467,8 +1545,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve setTransformViewAspect(t, t->aspect); if (op && (prop = RNA_struct_find_property(op->ptr, "center_override")) && RNA_property_is_set(op->ptr, prop)) { - RNA_property_float_get_array(op->ptr, prop, t->center); - mul_v3_v3(t->center, t->aspect); + RNA_property_float_get_array(op->ptr, prop, t->center_global); + mul_v3_v3(t->center_global, t->aspect); t->flag |= T_OVERRIDE_CENTER; } @@ -1476,11 +1554,25 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve initNumInput(&t->num); } +static void freeTransCustomDataContainer(TransInfo *t, TransDataContainer *tc, TransCustomDataContainer *tcdc) +{ + TransCustomData *custom_data = &tcdc->first_elem; + for (int i = 0; i < TRANS_CUSTOM_DATA_ELEM_MAX; i++, custom_data++) { + if (custom_data->free_cb) { + /* Can take over freeing t->data and data_2d etc... */ + custom_data->free_cb(t, tc, custom_data); + BLI_assert(custom_data->data == NULL); + } + else if ((custom_data->data != NULL) && custom_data->use_free) { + MEM_freeN(custom_data->data); + custom_data->data = NULL; + } + } +} + /* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */ void postTrans(bContext *C, TransInfo *t) { - TransData *td; - if (t->draw_handle_view) ED_region_draw_cb_exit(t->ar->type, t->draw_handle_view); if (t->draw_handle_apply) @@ -1491,46 +1583,37 @@ void postTrans(bContext *C, TransInfo *t) WM_paint_cursor_end(CTX_wm_manager(C), t->draw_handle_cursor); /* Free all custom-data */ - { - TransCustomData *custom_data = &t->custom.first_elem; - for (int i = 0; i < TRANS_CUSTOM_DATA_ELEM_MAX; i++, custom_data++) { - if (custom_data->free_cb) { - /* Can take over freeing t->data and data2d etc... */ - custom_data->free_cb(t, custom_data); - BLI_assert(custom_data->data == NULL); - } - else if ((custom_data->data != NULL) && custom_data->use_free) { - MEM_freeN(custom_data->data); - custom_data->data = NULL; - } - } + freeTransCustomDataContainer(t, NULL, &t->custom); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + freeTransCustomDataContainer(t, tc, &tc->custom); } /* postTrans can be called when nothing is selected, so data is NULL already */ - if (t->data) { - - /* free data malloced per trans-data */ - if ((t->obedit && ELEM(t->obedit->type, OB_CURVE, OB_SURF)) || - (t->spacetype == SPACE_IPO)) - { - int a; - for (a = 0, td = t->data; a < t->total; a++, td++) { - if (td->flag & TD_BEZTRIPLE) { - MEM_freeN(td->hdata); + if (t->data_len_all != 0) { + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + /* free data malloced per trans-data */ + if (ELEM(t->obedit_type, OB_CURVE, OB_SURF) || + (t->spacetype == SPACE_IPO)) + { + TransData *td = tc->data; + for (int a = 0; a < tc->data_len; a++, td++) { + if (td->flag & TD_BEZTRIPLE) { + MEM_freeN(td->hdata); + } } } + MEM_freeN(tc->data); + + MEM_SAFE_FREE(tc->data_ext); + MEM_SAFE_FREE(tc->data_2d); } - MEM_freeN(t->data); } + MEM_SAFE_FREE(t->data_container); + t->data_container = NULL; + BLI_freelistN(&t->tsnap.points); - if (t->ext) MEM_freeN(t->ext); - if (t->data2d) { - MEM_freeN(t->data2d); - t->data2d = NULL; - } - if (t->spacetype == SPACE_IMAGE) { if (t->options & (CTX_MASK | CTX_PAINT_CURVE)) { /* pass */ @@ -1558,9 +1641,11 @@ void postTrans(bContext *C, TransInfo *t) void applyTransObjects(TransInfo *t) { + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); + TransData *td; - - for (td = t->data; td < t->data + t->total; td++) { + + for (td = tc->data; td < tc->data + tc->data_len; td++) { copy_v3_v3(td->iloc, td->loc); if (td->ext->rot) { copy_v3_v3(td->ext->irot, td->ext->rot); @@ -1609,25 +1694,29 @@ static void restoreElement(TransData *td) void restoreTransObjects(TransInfo *t) { - TransData *td; - TransData2D *td2d; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { - for (td = t->data; td < t->data + t->total; td++) { - restoreElement(td); - } - - for (td2d = t->data2d; t->data2d && td2d < t->data2d + t->total; td2d++) { - if (td2d->h1) { - td2d->h1[0] = td2d->ih1[0]; - td2d->h1[1] = td2d->ih1[1]; + TransData *td; + TransData2D *td2d; + + for (td = tc->data; td < tc->data + tc->data_len; td++) { + restoreElement(td); } - if (td2d->h2) { - td2d->h2[0] = td2d->ih2[0]; - td2d->h2[1] = td2d->ih2[1]; + + for (td2d = tc->data_2d; tc->data_2d && td2d < tc->data_2d + tc->data_len; td2d++) { + if (td2d->h1) { + td2d->h1[0] = td2d->ih1[0]; + td2d->h1[1] = td2d->ih1[1]; + } + if (td2d->h2) { + td2d->h2[0] = td2d->ih2[0]; + td2d->h2[1] = td2d->ih2[1]; + } } - } - unit_m3(t->mat); + unit_m3(t->mat); + + } recalcData(t); } @@ -1635,32 +1724,26 @@ void restoreTransObjects(TransInfo *t) void calculateCenter2D(TransInfo *t) { BLI_assert(!is_zero_v3(t->aspect)); - - if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - float vec[3]; - - copy_v3_v3(vec, t->center); - mul_m4_v3(ob->obmat, vec); - projectFloatView(t, vec, t->center2d); - } - else { - projectFloatView(t, t->center, t->center2d); - } + projectFloatView(t, t->center_global, t->center2d); } -void calculateCenterGlobal( - TransInfo *t, const float center_local[3], - float r_center_global[3]) +void calculateCenterLocal( + TransInfo *t, const float center_global[3]) { /* setting constraint center */ /* note, init functions may over-ride t->center */ if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - mul_v3_m4v3(r_center_global, ob->obmat, center_local); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + float obinv[4][4]; + Object *ob = tc->obedit ? tc->obedit : tc->poseobj; + invert_m4_m4(obinv, ob->obmat); + mul_v3_m4v3(tc->center_local, obinv, center_global); + } } else { - copy_v3_v3(r_center_global, center_local); + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + copy_v3_v3(tc->center_local, center_global); + } } } @@ -1672,16 +1755,7 @@ void calculateCenterCursor(TransInfo *t, float r_center[3]) copy_v3_v3(r_center, cursor); /* If edit or pose mode, move cursor in local space */ - if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - float mat[3][3], imat[3][3]; - - sub_v3_v3v3(r_center, r_center, ob->obmat[3]); - copy_m3_m4(mat, ob->obmat); - invert_m3_m3(imat, mat); - mul_m3_v3(imat, r_center); - } - else if (t->options & CTX_PAINT_CURVE) { + if (t->options & CTX_PAINT_CURVE) { if (ED_view3d_project_float_global(t->ar, cursor, r_center, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) { r_center[0] = t->ar->winx / 2.0f; r_center[1] = t->ar->winy / 2.0f; @@ -1755,13 +1829,23 @@ void calculateCenterMedian(TransInfo *t, float r_center[3]) { float partial[3] = {0.0f, 0.0f, 0.0f}; int total = 0; - int i; - - for (i = 0; i < t->total; i++) { - if (t->data[i].flag & TD_SELECTED) { - if (!(t->data[i].flag & TD_NOCENTER)) { - add_v3_v3(partial, t->data[i].center); - total++; + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Object *ob_xform = tc->obedit ? tc->obedit : tc->poseobj; + int i; + for (i = 0; i < tc->data_len; i++) { + if (tc->data[i].flag & TD_SELECTED) { + if (!(tc->data[i].flag & TD_NOCENTER)) { + if (ob_xform) { + float v[3]; + mul_v3_m4v3(v, ob_xform->obmat, tc->data[i].center); + add_v3_v3(partial, v); + } + else { + add_v3_v3(partial, tc->data[i].center); + } + total++; + } } } } @@ -1776,16 +1860,29 @@ void calculateCenterBound(TransInfo *t, float r_center[3]) float max[3]; float min[3]; int i; - for (i = 0; i < t->total; i++) { - if (i) { - if (t->data[i].flag & TD_SELECTED) { - if (!(t->data[i].flag & TD_NOCENTER)) - minmax_v3v3_v3(min, max, t->data[i].center); + bool is_first = true; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Object *ob_xform = tc->obedit ? tc->obedit : tc->poseobj; + for (i = 0; i < tc->data_len; i++) { + if (is_first == false) { + if (tc->data[i].flag & TD_SELECTED) { + if (!(tc->data[i].flag & TD_NOCENTER)) { + if (ob_xform) { + float v[3]; + mul_v3_m4v3(v, ob_xform->obmat, tc->data[i].center); + minmax_v3v3_v3(min, max, v); + } + else { + minmax_v3v3_v3(min, max, tc->data[i].center); + } + } + } + is_first = false; + } + else { + copy_v3_v3(max, tc->data[i].center); + copy_v3_v3(min, tc->data[i].center); } - } - else { - copy_v3_v3(max, t->data[i].center); - copy_v3_v3(min, t->data[i].center); } } mid_v3_v3v3(r_center, min, max); @@ -1796,10 +1893,13 @@ void calculateCenterBound(TransInfo *t, float r_center[3]) */ bool calculateCenterActive(TransInfo *t, bool select_only, float r_center[3]) { + TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_OK(t); + bool ok = false; - if (t->obedit) { - if (ED_object_editmode_calc_active_center(t->obedit, select_only, r_center)) { + if (tc->obedit) { + if (ED_object_editmode_calc_active_center(tc->obedit, select_only, r_center)) { + mul_m4_v3(tc->obedit->obmat, r_center); ok = true; } } @@ -1810,6 +1910,7 @@ bool calculateCenterActive(TransInfo *t, bool select_only, float r_center[3]) bPoseChannel *pchan = BKE_pose_channel_active(ob); if (pchan && (!select_only || (pchan->bone->flag & BONE_SELECTED))) { copy_v3_v3(r_center, pchan->pose_head); + mul_m4_v3(tc->obedit->obmat, r_center); ok = true; } } @@ -1874,14 +1975,13 @@ static void calculateCenter_FromAround(TransInfo *t, int around, float r_center[ void calculateCenter(TransInfo *t) { if ((t->flag & T_OVERRIDE_CENTER) == 0) { - calculateCenter_FromAround(t, t->around, t->center); + calculateCenter_FromAround(t, t->around, t->center_global); } - calculateCenterGlobal(t, t->center, t->center_global); + calculateCenterLocal(t, t->center_global); /* avoid calculating again */ { TransCenterData *cd = &t->center_cache[t->around]; - copy_v3_v3(cd->local, t->center); copy_v3_v3(cd->global, t->center_global); cd->is_set = true; } @@ -1899,16 +1999,15 @@ void calculateCenter(TransInfo *t) normalize_v3(axis); /* 6.0 = 6 grid units */ - axis[0] = t->center[0] - 6.0f * axis[0]; - axis[1] = t->center[1] - 6.0f * axis[1]; - axis[2] = t->center[2] - 6.0f * axis[2]; + axis[0] = t->center_global[0] - 6.0f * axis[0]; + axis[1] = t->center_global[1] - 6.0f * axis[1]; + axis[2] = t->center_global[2] - 6.0f * axis[2]; projectFloatView(t, axis, t->center2d); /* rotate only needs correct 2d center, grab needs ED_view3d_calc_zfac() value */ if (t->mode == TFM_TRANSLATION) { - copy_v3_v3(t->center, axis); - copy_v3_v3(t->center_global, t->center); + copy_v3_v3(t->center_global, axis); } } } @@ -1942,8 +2041,7 @@ const TransCenterData *transformCenter_from_type(TransInfo *t, int around) BLI_assert(around <= V3D_AROUND_ACTIVE); TransCenterData *cd = &t->center_cache[around]; if (cd->is_set == false) { - calculateCenter_FromAround(t, around, cd->local); - calculateCenterGlobal(t, cd->local, cd->global); + calculateCenter_FromAround(t, around, cd->global); cd->is_set = true; } return cd; @@ -1951,7 +2049,6 @@ const TransCenterData *transformCenter_from_type(TransInfo *t, int around) void calculatePropRatio(TransInfo *t) { - TransData *td = t->data; int i; float dist; const bool connected = (t->flag & T_PROP_CONNECTED) != 0; @@ -1960,75 +2057,79 @@ void calculatePropRatio(TransInfo *t) if (t->flag & T_PROP_EDIT) { const char *pet_id = NULL; - for (i = 0; i < t->total; i++, td++) { - if (td->flag & TD_SELECTED) { - td->factor = 1.0f; - } - else if (t->flag & T_MIRROR && td->loc[0] * t->mirror < -0.00001f) { - td->flag |= TD_SKIP; - td->factor = 0.0f; - restoreElement(td); - } - else if ((connected && (td->flag & TD_NOTCONNECTED || td->dist > t->prop_size)) || - (connected == 0 && td->rdist > t->prop_size)) - { - /* - * The elements are sorted according to their dist member in the array, - * that means we can stop when it finds one element outside of the propsize. - * do not set 'td->flag |= TD_NOACTION', the prop circle is being changed. - */ - - td->factor = 0.0f; - restoreElement(td); - } - else { - /* Use rdist for falloff calculations, it is the real distance */ - td->flag &= ~TD_NOACTION; - - if (connected) - dist = (t->prop_size - td->dist) / t->prop_size; - else - dist = (t->prop_size - td->rdist) / t->prop_size; - - /* - * Clamp to positive numbers. - * Certain corner cases with connectivity and individual centers - * can give values of rdist larger than propsize. - */ - if (dist < 0.0f) - dist = 0.0f; - - switch (t->prop_mode) { - case PROP_SHARP: - td->factor = dist * dist; - break; - case PROP_SMOOTH: - td->factor = 3.0f * dist * dist - 2.0f * dist * dist * dist; - break; - case PROP_ROOT: - td->factor = sqrtf(dist); - break; - case PROP_LIN: - td->factor = dist; - break; - case PROP_CONST: - td->factor = 1.0f; - break; - case PROP_SPHERE: - td->factor = sqrtf(2 * dist - dist * dist); - break; - case PROP_RANDOM: - td->factor = BLI_frand() * dist; - break; - case PROP_INVSQUARE: - td->factor = dist * (2.0f - dist); - break; - default: - td->factor = 1; - break; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + if (td->flag & TD_SELECTED) { + td->factor = 1.0f; + } + else if (t->flag & T_MIRROR && td->loc[0] * t->mirror < -0.00001f) { + td->flag |= TD_SKIP; + td->factor = 0.0f; + restoreElement(td); + } + else if ((connected && (td->flag & TD_NOTCONNECTED || td->dist > t->prop_size)) || + (connected == 0 && td->rdist > t->prop_size)) + { + /* + * The elements are sorted according to their dist member in the array, + * that means we can stop when it finds one element outside of the propsize. + * do not set 'td->flag |= TD_NOACTION', the prop circle is being changed. + */ + + td->factor = 0.0f; + restoreElement(td); + } + else { + /* Use rdist for falloff calculations, it is the real distance */ + td->flag &= ~TD_NOACTION; + + if (connected) + dist = (t->prop_size - td->dist) / t->prop_size; + else + dist = (t->prop_size - td->rdist) / t->prop_size; + + /* + * Clamp to positive numbers. + * Certain corner cases with connectivity and individual centers + * can give values of rdist larger than propsize. + */ + if (dist < 0.0f) + dist = 0.0f; + + switch (t->prop_mode) { + case PROP_SHARP: + td->factor = dist * dist; + break; + case PROP_SMOOTH: + td->factor = 3.0f * dist * dist - 2.0f * dist * dist * dist; + break; + case PROP_ROOT: + td->factor = sqrtf(dist); + break; + case PROP_LIN: + td->factor = dist; + break; + case PROP_CONST: + td->factor = 1.0f; + break; + case PROP_SPHERE: + td->factor = sqrtf(2 * dist - dist * dist); + break; + case PROP_RANDOM: + td->factor = BLI_frand() * dist; + break; + case PROP_INVSQUARE: + td->factor = dist * (2.0f - dist); + break; + default: + td->factor = 1; + break; + } } } } + switch (t->prop_mode) { case PROP_SHARP: pet_id = N_("(Sharp)"); @@ -2063,8 +2164,11 @@ void calculatePropRatio(TransInfo *t) } } else { - for (i = 0; i < t->total; i++, td++) { - td->factor = 1.0; + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + TransData *td = tc->data; + for (i = 0; i < tc->data_len; i++, td++) { + td->factor = 1.0; + } } } } diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 5cb3f262ced..410564a8daa 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -272,73 +272,78 @@ void applyProject(TransInfo *t) { /* XXX FLICKER IN OBJECT MODE */ if ((t->tsnap.project) && activeSnap(t) && (t->flag & T_NO_PROJECT) == 0) { - TransData *td = t->data; float tvec[3]; - float imat[4][4]; int i; - - if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - invert_m4_m4(imat, ob->obmat); - } - for (i = 0; i < t->total; i++, td++) { - float iloc[3], loc[3], no[3]; - float mval_fl[2]; - float dist_px = TRANSFORM_DIST_MAX_PX; - - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; + FOREACH_TRANS_DATA_CONTAINER(t, tc) { + TransData *td = tc->data; - if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) - continue; - - copy_v3_v3(iloc, td->loc); + float imat[4][4]; if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - mul_m4_v3(ob->obmat, iloc); - } - else if (t->flag & T_OBJECT) { - BKE_object_eval_transform_all(G.main->eval_ctx, t->scene, td->ob); - copy_v3_v3(iloc, td->ob->obmat[3]); + Object *ob = tc->obedit ? tc->obedit : tc->poseobj; + invert_m4_m4(imat, ob->obmat); } - - if (ED_view3d_project_float_global(t->ar, iloc, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { - if (snapObjectsTransform( - t, mval_fl, &dist_px, - loc, no)) - { -// if (t->flag & (T_EDIT|T_POSE)) { -// mul_m4_v3(imat, loc); -// } - sub_v3_v3v3(tvec, loc, iloc); + for (i = 0; i < tc->data_len; i++, td++) { + float iloc[3], loc[3], no[3]; + float mval_fl[2]; + float dist_px = TRANSFORM_DIST_MAX_PX; + + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) + continue; + + copy_v3_v3(iloc, td->loc); + if (t->flag & (T_EDIT | T_POSE)) { + Object *ob = tc->obedit ? tc->obedit : tc->poseobj; + mul_m4_v3(ob->obmat, iloc); + } + else if (t->flag & T_OBJECT) { + BKE_object_eval_transform_all(t->depsgraph, t->scene, td->ob); + copy_v3_v3(iloc, td->ob->obmat[3]); + } + + if (ED_view3d_project_float_global(t->ar, iloc, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) { + if (snapObjectsTransform( + t, mval_fl, &dist_px, + loc, no)) + { +#if 0 + if (t->flag & (T_EDIT | T_POSE)) { + mul_m4_v3(imat, loc); + } +#endif - mul_m3_v3(td->smtx, tvec); + sub_v3_v3v3(tvec, loc, iloc); - add_v3_v3(td->loc, tvec); + mul_m3_v3(td->smtx, tvec); - if (t->tsnap.align && (t->flag & T_OBJECT)) { - /* handle alignment as well */ - const float *original_normal; - float mat[3][3]; + add_v3_v3(td->loc, tvec); - /* In pose mode, we want to align normals with Y axis of bones... */ - original_normal = td->axismtx[2]; + if (t->tsnap.align && (t->flag & T_OBJECT)) { + /* handle alignment as well */ + const float *original_normal; + float mat[3][3]; - rotation_between_vecs_to_mat3(mat, original_normal, no); + /* In pose mode, we want to align normals with Y axis of bones... */ + original_normal = td->axismtx[2]; - transform_data_ext_rotate(td, mat, true); + rotation_between_vecs_to_mat3(mat, original_normal, no); - /* TODO support constraints for rotation too? see ElementRotation */ + transform_data_ext_rotate(td, mat, true); + + /* TODO support constraints for rotation too? see ElementRotation */ + } } } + + //XXX constraintTransLim(t, td); } - - //XXX constraintTransLim(t, td); } } } @@ -347,7 +352,6 @@ void applyGridAbsolute(TransInfo *t) { float grid_size = 0.0f; GearsType grid_action; - TransData *td; float (*obmat)[4] = NULL; bool use_obmat = false; int i; @@ -368,42 +372,46 @@ void applyGridAbsolute(TransInfo *t) if (grid_size == 0.0f) return; - if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - obmat = ob->obmat; - use_obmat = true; - } - - for (i = 0, td = t->data; i < t->total; i++, td++) { - float iloc[3], loc[3], tvec[3]; - - if (td->flag & TD_NOACTION) - break; - - if (td->flag & TD_SKIP) - continue; - - if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) - continue; - - copy_v3_v3(iloc, td->loc); - if (use_obmat) { - mul_m4_v3(obmat, iloc); + FOREACH_TRANS_DATA_CONTAINER(t, tc) { + TransData *td; + + if (t->flag & (T_EDIT | T_POSE)) { + Object *ob = tc->obedit ? tc->obedit : tc->poseobj; + obmat = ob->obmat; + use_obmat = true; } - else if (t->flag & T_OBJECT) { - BKE_object_eval_transform_all(G.main->eval_ctx, t->scene, td->ob); - copy_v3_v3(iloc, td->ob->obmat[3]); + + for (i = 0, td = tc->data; i < tc->data_len; i++, td++) { + float iloc[3], loc[3], tvec[3]; + + if (td->flag & TD_NOACTION) + break; + + if (td->flag & TD_SKIP) + continue; + + if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) + continue; + + copy_v3_v3(iloc, td->loc); + if (use_obmat) { + mul_m4_v3(obmat, iloc); + } + else if (t->flag & T_OBJECT) { + BKE_object_eval_transform_all(t->depsgraph, t->scene, td->ob); + copy_v3_v3(iloc, td->ob->obmat[3]); + } + + mul_v3_v3fl(loc, iloc, 1.0f / grid_size); + loc[0] = roundf(loc[0]); + loc[1] = roundf(loc[1]); + loc[2] = roundf(loc[2]); + mul_v3_fl(loc, grid_size); + + sub_v3_v3v3(tvec, loc, iloc); + mul_m3_v3(td->smtx, tvec); + add_v3_v3(td->loc, tvec); } - - mul_v3_v3fl(loc, iloc, 1.0f / grid_size); - loc[0] = roundf(loc[0]); - loc[1] = roundf(loc[1]); - loc[2] = roundf(loc[2]); - mul_v3_fl(loc, grid_size); - - sub_v3_v3v3(tvec, loc, iloc); - mul_m3_v3(td->smtx, tvec); - add_v3_v3(td->loc, tvec); } } @@ -501,7 +509,8 @@ static bool bm_face_is_snap_target(BMFace *f, void *UNUSED(user_data)) static void initSnappingMode(TransInfo *t) { ToolSettings *ts = t->settings; - Object *obedit = t->obedit; + /* All obedit types will match. */ + const int obedit_type = t->data_container->obedit ? t->data_container->obedit->type : -1; ViewLayer *view_layer = t->view_layer; Base *base_act = view_layer->basact; @@ -532,10 +541,10 @@ static void initSnappingMode(TransInfo *t) /* Edit mode */ if (t->tsnap.applySnap != NULL && // A snapping function actually exist - (obedit != NULL && ELEM(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE, OB_MBALL)) ) // Temporary limited to edit mode meshes, armature, curves, mballs + ((obedit_type != -1) && ELEM(obedit_type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE, OB_MBALL)) ) // Temporary limited to edit mode meshes, armature, curves, mballs { /* Exclude editmesh if using proportional edit */ - if ((obedit->type == OB_MESH) && (t->flag & T_PROP_EDIT)) { + if ((obedit_type == OB_MESH) && (t->flag & T_PROP_EDIT)) { t->tsnap.modeSelect = SNAP_NOT_ACTIVE; } else { @@ -544,13 +553,13 @@ static void initSnappingMode(TransInfo *t) } /* Particles edit mode*/ else if (t->tsnap.applySnap != NULL && // A snapping function actually exist - (obedit == NULL && base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT)) + ((obedit_type == -1) && base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT)) { t->tsnap.modeSelect = SNAP_ALL; } /* Object mode */ else if (t->tsnap.applySnap != NULL && // A snapping function actually exist - (obedit == NULL) ) // Object Mode + (obedit_type == -1) ) // Object Mode { /* In "Edit Strokes" mode, Snap tool can perform snap to selected or active objects (see T49632) * TODO: perform self snap in gpencil_strokes */ @@ -584,7 +593,7 @@ static void initSnappingMode(TransInfo *t) if (t->spacetype == SPACE_VIEW3D) { if (t->tsnap.object_context == NULL) { t->tsnap.object_context = ED_transform_snap_object_context_create_view3d( - G.main, t->scene, t->view_layer, 0, t->ar, t->view); + G.main, t->scene, 0, t->ar, t->view); ED_transform_snap_object_context_set_editmesh_callbacks( t->tsnap.object_context, @@ -863,7 +872,8 @@ static float TranslationBetween(TransInfo *UNUSED(t), const float p1[3], const f return len_squared_v3v3(p1, p2); } -static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3]) +static float RotationBetween( + TransInfo *t, const float p1[3], const float p2[3]) { float angle, start[3], end[3]; @@ -874,7 +884,7 @@ static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3]) if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) { float axis[3], tmp[3]; - t->con.applyRot(t, NULL, axis, NULL); + t->con.applyRot(t, NULL, NULL, axis, NULL); project_v3_v3v3(tmp, end, axis); sub_v3_v3v3(end, end, tmp); @@ -977,14 +987,14 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) t->tsnap.status &= ~POINT_INIT; } } - else if (t->spacetype == SPACE_IMAGE && t->obedit != NULL && t->obedit->type == OB_MESH) { + else if (t->spacetype == SPACE_IMAGE && t->obedit_type == OB_MESH) { /* same as above but for UV's */ Image *ima = ED_space_image(t->sa->spacedata.first); float co[2]; UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], &co[0], &co[1]); - if (ED_uvedit_nearest_uv(t->scene, t->obedit, ima, co, t->tsnap.snapPoint)) { + if (ED_uvedit_nearest_uv(t->scene, TRANS_DATA_CONTAINER_FIRST_EVIL(t)->obedit, ima, co, t->tsnap.snapPoint)) { t->tsnap.snapPoint[0] *= t->aspect[0]; t->tsnap.snapPoint[1] *= t->aspect[1]; @@ -1059,11 +1069,6 @@ static void TargetSnapActive(TransInfo *t) /* Only need to calculate once */ if ((t->tsnap.status & TARGET_INIT) == 0) { if (calculateCenterActive(t, true, t->tsnap.snapTarget)) { - if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - mul_m4_v3(ob->obmat, t->tsnap.snapTarget); - } - TargetSnapOffset(t, NULL); t->tsnap.status |= TARGET_INIT; @@ -1081,23 +1086,34 @@ static void TargetSnapMedian(TransInfo *t) { // Only need to calculate once if ((t->tsnap.status & TARGET_INIT) == 0) { - TransData *td = NULL; - int i; + int i_accum = 0; t->tsnap.snapTarget[0] = 0; t->tsnap.snapTarget[1] = 0; t->tsnap.snapTarget[2] = 0; - - for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) { - add_v3_v3(t->tsnap.snapTarget, td->center); - } - - mul_v3_fl(t->tsnap.snapTarget, 1.0 / i); - - if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - mul_m4_v3(ob->obmat, t->tsnap.snapTarget); + + FOREACH_TRANS_DATA_CONTAINER (t, tc) { + Object *ob_xform = NULL; + if (t->flag & (T_EDIT | T_POSE)) { + ob_xform = tc->obedit ? tc->obedit : tc->poseobj; + } + TransData *td = tc->data; + int i; + for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) { + /* TODO(campbell): perform the global transformation once per TransDataContainer */ + if (ob_xform) { + float v[3]; + mul_v3_m4v3(v, ob_xform->obmat, td->center); + add_v3_v3(t->tsnap.snapTarget, v); + } + else { + add_v3_v3(t->tsnap.snapTarget, td->center); + } + } + i_accum += i; } + + mul_v3_fl(t->tsnap.snapTarget, 1.0 / i_accum); TargetSnapOffset(t, NULL); @@ -1110,25 +1126,45 @@ static void TargetSnapClosest(TransInfo *t) // Only valid if a snap point has been selected if (t->tsnap.status & POINT_INIT) { float dist_closest = 0.0f; - TransData *closest = NULL, *td = NULL; + TransData *closest = NULL; /* Object mode */ if (t->flag & T_OBJECT) { int i; - for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) { - struct BoundBox *bb = BKE_object_boundbox_get(td->ob); - - /* use boundbox if possible */ - if (bb) { - int j; - - for (j = 0; j < 8; j++) { + FOREACH_TRANS_DATA_CONTAINER(t, tc) { + TransData *td = tc->data; + for (td = tc->data, i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) { + struct BoundBox *bb = BKE_object_boundbox_get(td->ob); + + /* use boundbox if possible */ + if (bb) { + int j; + + for (j = 0; j < 8; j++) { + float loc[3]; + float dist; + + copy_v3_v3(loc, bb->vec[j]); + mul_m4_v3(td->ext->obmat, loc); + + dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); + + if ((dist != TRANSFORM_DIST_INVALID) && + (closest == NULL || fabsf(dist) < fabsf(dist_closest))) + { + copy_v3_v3(t->tsnap.snapTarget, loc); + closest = td; + dist_closest = dist; + } + } + } + /* use element center otherwise */ + else { float loc[3]; float dist; - - copy_v3_v3(loc, bb->vec[j]); - mul_m4_v3(td->ext->obmat, loc); - + + copy_v3_v3(loc, td->center); + dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); if ((dist != TRANSFORM_DIST_INVALID) && @@ -1136,17 +1172,26 @@ static void TargetSnapClosest(TransInfo *t) { copy_v3_v3(t->tsnap.snapTarget, loc); closest = td; - dist_closest = dist; } } } - /* use element center otherwise */ - else { + } + } + else { + FOREACH_TRANS_DATA_CONTAINER(t, tc) { + TransData *td = tc->data; + int i; + for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) { float loc[3]; float dist; - + copy_v3_v3(loc, td->center); - + + if (t->flag & (T_EDIT | T_POSE)) { + Object *ob = tc->obedit ? tc->obedit : tc->poseobj; + mul_m4_v3(ob->obmat, loc); + } + dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); if ((dist != TRANSFORM_DIST_INVALID) && @@ -1154,34 +1199,11 @@ static void TargetSnapClosest(TransInfo *t) { copy_v3_v3(t->tsnap.snapTarget, loc); closest = td; + dist_closest = dist; } } } } - else { - int i; - for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) { - float loc[3]; - float dist; - - copy_v3_v3(loc, td->center); - - if (t->flag & (T_EDIT | T_POSE)) { - Object *ob = t->obedit ? t->obedit : t->poseobj; - mul_m4_v3(ob->obmat, loc); - } - - dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); - - if ((dist != TRANSFORM_DIST_INVALID) && - (closest == NULL || fabsf(dist) < fabsf(dist_closest))) - { - copy_v3_v3(t->tsnap.snapTarget, loc); - closest = td; - dist_closest = dist; - } - } - } TargetSnapOffset(t, closest); diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 2a9b4790eaf..5c46d1d0e59 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -54,6 +54,7 @@ #include "BKE_context.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "ED_transform.h" #include "ED_transform_snap_object_context.h" @@ -108,7 +109,7 @@ typedef struct SnapObjectData_EditMesh { struct SnapObjectContext { Main *bmain; Scene *scene; - EvaluationContext eval_ctx; + Depsgraph *depsgraph; int flag; @@ -162,8 +163,9 @@ static void iter_snap_objects( IterSnapObjsCallback sob_callback, void *data) { - Base *base_act = sctx->eval_ctx.view_layer->basact; - for (Base *base = sctx->eval_ctx.view_layer->object_bases.first; base != NULL; base = base->next) { + ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph); + Base *base_act = view_layer->basact; + for (Base *base = view_layer->object_bases.first; base != NULL; base = base->next) { if ((BASE_VISIBLE(base)) && (base->flag_legacy & BA_SNAP_FIX_DEPS_FIASCO) == 0 && !((snap_select == SNAP_NOT_SELECTED && ((base->flag & BASE_SELECTED) || (base->flag_legacy & BA_WAS_SEL))) || (snap_select == SNAP_NOT_ACTIVE && base == base_act))) @@ -172,7 +174,7 @@ static void iter_snap_objects( Object *obj = base->object; if (obj->transflag & OB_DUPLI) { DupliObject *dupli_ob; - ListBase *lb = object_duplilist(&sctx->eval_ctx, sctx->scene, obj); + ListBase *lb = object_duplilist(sctx->depsgraph, sctx->scene, obj); for (dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) { use_obedit = obedit && dupli_ob->ob->data == obedit->data; sob_callback(sctx, use_obedit, use_obedit ? obedit : dupli_ob->ob, dupli_ob->mat, data); @@ -729,10 +731,10 @@ static bool raycastObj( DerivedMesh *dm; em = BKE_editmesh_from_object(ob); if (em) { - editbmesh_get_derived_cage_and_final(&sctx->eval_ctx, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm); + editbmesh_get_derived_cage_and_final(sctx->depsgraph, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm); } else { - dm = mesh_get_derived_final(&sctx->eval_ctx, sctx->scene, ob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(sctx->depsgraph, sctx->scene, ob, CD_MASK_BAREMESH); } retval = raycastDerivedMesh( sctx, @@ -821,7 +823,8 @@ static bool raycastObjects( Object **r_ob, float r_obmat[4][4], ListBase *r_hit_list) { - Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(sctx->eval_ctx.view_layer) : NULL; + ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph); + Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL; struct RaycastObjUserData data = { .ray_start = ray_start, @@ -1936,10 +1939,10 @@ static bool snapObject( DerivedMesh *dm; em = BKE_editmesh_from_object(ob); if (em) { - editbmesh_get_derived_cage_and_final(&sctx->eval_ctx, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm); + editbmesh_get_derived_cage_and_final(sctx->depsgraph, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm); } else { - dm = mesh_get_derived_final(&sctx->eval_ctx, sctx->scene, ob, CD_MASK_BAREMESH); + dm = mesh_get_derived_final(sctx->depsgraph, sctx->scene, ob, CD_MASK_BAREMESH); } retval = snapDerivedMesh( sctx, snapdata, ob, dm, obmat, @@ -2054,7 +2057,8 @@ static bool snapObjectsRay( float r_loc[3], float r_no[3], Object **r_ob, float r_obmat[4][4]) { - Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(sctx->eval_ctx.view_layer) : NULL; + ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph); + Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL; struct SnapObjUserData data = { .snapdata = snapdata, @@ -2079,7 +2083,7 @@ static bool snapObjectsRay( * \{ */ SnapObjectContext *ED_transform_snap_object_context_create( - Main *bmain, Scene *scene, ViewLayer *view_layer, int flag) + Main *bmain, Scene *scene, int flag) { SnapObjectContext *sctx = MEM_callocN(sizeof(*sctx), __func__); @@ -2088,9 +2092,6 @@ SnapObjectContext *ED_transform_snap_object_context_create( sctx->bmain = bmain; sctx->scene = scene; - DEG_evaluation_context_init_from_scene( - &sctx->eval_ctx, scene, view_layer, DAG_EVAL_VIEWPORT); - sctx->cache.object_map = BLI_ghash_ptr_new(__func__); sctx->cache.mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__); @@ -2098,11 +2099,11 @@ SnapObjectContext *ED_transform_snap_object_context_create( } SnapObjectContext *ED_transform_snap_object_context_create_view3d( - Main *bmain, Scene *scene, ViewLayer *view_layer, int flag, + Main *bmain, Scene *scene, int flag, /* extra args for view3d */ const ARegion *ar, const View3D *v3d) { - SnapObjectContext *sctx = ED_transform_snap_object_context_create(bmain, scene, view_layer, flag); + SnapObjectContext *sctx = ED_transform_snap_object_context_create(bmain, scene, flag); sctx->use_v3d = true; sctx->v3d_data.ar = ar; @@ -2365,7 +2366,7 @@ bool ED_transform_snap_object_project_view3d_ex( ED_view3d_win_to_vector(ar, mval, ray_normal); ED_view3d_clip_range_get( - sctx->eval_ctx.depsgraph, + sctx->depsgraph, sctx->v3d_data.v3d, sctx->v3d_data.ar->regiondata, &depth_range[0], &depth_range[1], false); @@ -2432,7 +2433,7 @@ bool ED_transform_snap_object_project_all_view3d_ex( float ray_start[3], ray_normal[3]; if (!ED_view3d_win_to_ray_ex( - sctx->eval_ctx.depsgraph, + sctx->depsgraph, sctx->v3d_data.ar, sctx->v3d_data.v3d, mval, NULL, ray_normal, ray_start, true)) { diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c index d8b194e3336..0b77006afb7 100644 --- a/source/blender/editors/undo/ed_undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -36,6 +36,7 @@ #include "CLG_log.h" #include "DNA_scene_types.h" +#include "DNA_object_types.h" #include "BLI_utildefines.h" @@ -46,6 +47,7 @@ #include "BKE_global.h" #include "BKE_main.h" #include "BKE_screen.h" +#include "BKE_layer.h" #include "BKE_undo_system.h" #include "ED_gpencil.h" @@ -495,3 +497,24 @@ void ED_OT_undo_history(wmOperatorType *ot) } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Undo Helper Functions + * \{ */ + +void ED_undo_object_set_active_or_warn(ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log) +{ + Object *ob_prev = OBACT(view_layer); + if (ob_prev != ob) { + Base *base = BKE_view_layer_base_find(view_layer, ob); + if (base != NULL) { + view_layer->basact = base; + } + else { + /* Should never fail, may not crash but can give odd behavior. */ + CLOG_WARN(log, "'%s' failed to restore active object: '%s'", info, ob->id.name + 2); + } + } +} + +/** \} */ diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 3fcc89d0973..328ab3f1a8d 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -51,6 +51,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_editmesh.h" #include "BKE_material.h" +#include "BKE_layer.h" #include "BKE_scene.h" @@ -1100,12 +1101,21 @@ void ED_uvedit_draw_main( draw_uv_shadows_get(sima, obact, obedit, &show_uvshadow, &show_texpaint_uvshadow); if (show_uvedit || show_uvshadow || show_texpaint_uvshadow) { - if (show_uvshadow) + if (show_uvshadow) { draw_uvs_shadow(obedit); - else if (show_uvedit) - draw_uvs(sima, scene, view_layer, obedit, depsgraph); - else + } + else if (show_uvedit) { + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *ob_iter = objects[ob_index]; + draw_uvs(sima, scene, view_layer, ob_iter, depsgraph); + } + MEM_SAFE_FREE(objects); + } + else { draw_uvs_texpaint(sima, scene, view_layer, obact); + } if (show_uvedit && !(toolsettings->use_uv_sculpt)) ED_image_draw_cursor(ar, sima->cursor); diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h index c5f16d6fb14..e3db0162f10 100644 --- a/source/blender/editors/uvedit/uvedit_intern.h +++ b/source/blender/editors/uvedit/uvedit_intern.h @@ -51,6 +51,8 @@ void uv_poly_center(struct BMFace *f, float r_cent[2], const int cd_loop_uv_off /* find nearest */ typedef struct UvNearestHit { + /** Only for `*_multi(..)` versions of functions. */ + struct Object *ob; /** Always set if we have a hit. */ struct BMFace *efa; struct BMLoop *l; @@ -66,14 +68,23 @@ typedef struct UvNearestHit { bool uv_find_nearest_vert( struct Scene *scene, struct Image *ima, struct Object *obedit, const float co[2], const float penalty_dist, struct UvNearestHit *hit_final); +bool uv_find_nearest_vert_multi( + struct Scene *scene, struct Image *ima, struct Object **objects, const uint objects_len, + const float co[2], const float penalty_dist, struct UvNearestHit *hit_final); bool uv_find_nearest_edge( struct Scene *scene, struct Image *ima, struct Object *obedit, const float co[2], struct UvNearestHit *hit_final); +bool uv_find_nearest_edge_multi( + struct Scene *scene, struct Image *ima, struct Object **objects, const uint objects_len, + const float co[2], struct UvNearestHit *hit_final); bool uv_find_nearest_face( struct Scene *scene, struct Image *ima, struct Object *obedit, const float co[2], struct UvNearestHit *hit_final); +bool uv_find_nearest_face_multi( + struct Scene *scene, struct Image *ima, struct Object **objects, const uint objects_len, + const float co[2], struct UvNearestHit *hit_final); /* utility tool functions */ diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 9df0c7c89ed..e8e20c1cad5 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -66,6 +66,7 @@ #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_editmesh.h" +#include "BKE_layer.h" #include "DEG_depsgraph.h" @@ -89,7 +90,10 @@ #include "uvedit_intern.h" -static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, int action); +static bool uv_select_is_any_selected(Scene *scene, Image *ima, Object *obedit); +static bool uv_select_is_any_selected_multi(Scene *scene, Image *ima, Object **objects, const uint objects_len); +static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, int action); +static void uv_select_all_perform_multi(Scene *scene, Image *ima, Object **objects, const uint objects_len, int action); static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object *obedit, const bool select); static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object *obedit, const bool select); @@ -794,6 +798,21 @@ bool uv_find_nearest_edge( return found; } +bool uv_find_nearest_edge_multi( + Scene *scene, Image *ima, Object **objects, const uint objects_len, + const float co[2], UvNearestHit *hit_final) +{ + bool found = false; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + if (uv_find_nearest_edge(scene, ima, obedit, co, hit_final)) { + hit_final->ob = obedit; + found = true; + } + } + return found; +} + bool uv_find_nearest_face( Scene *scene, Image *ima, Object *obedit, const float co[2], UvNearestHit *hit_final) @@ -837,6 +856,21 @@ bool uv_find_nearest_face( return found; } +bool uv_find_nearest_face_multi( + Scene *scene, Image *ima, Object **objects, const uint objects_len, + const float co[2], UvNearestHit *hit_final) +{ + bool found = false; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + if (uv_find_nearest_face(scene, ima, obedit, co, hit_final)) { + hit_final->ob = obedit; + found = true; + } + } + return found; +} + static bool uv_nearest_between( const BMLoop *l, const float co[2], const int cd_loop_uv_offset) @@ -918,6 +952,21 @@ bool uv_find_nearest_vert( return found; } +bool uv_find_nearest_vert_multi( + Scene *scene, Image *ima, Object **objects, const uint objects_len, + float const co[2], const float penalty_dist, UvNearestHit *hit_final) +{ + bool found = false; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + if (uv_find_nearest_vert(scene, ima, obedit, co, penalty_dist, hit_final)) { + hit_final->ob = obedit; + found = true; + } + } + return found; +} + bool ED_uvedit_nearest_uv(Scene *scene, Object *obedit, Image *ima, const float co[2], float r_uv[2]) { BMEditMesh *em = BKE_editmesh_from_object(obedit); @@ -1043,9 +1092,10 @@ static bool uv_select_edgeloop_edge_tag_faces(BMEditMesh *em, UvMapVert *first1, } static int uv_select_edgeloop( - Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, UvNearestHit *hit, + Scene *scene, Image *ima, Object *obedit, UvNearestHit *hit, const float limit[2], const bool extend) { + BMEditMesh *em = BKE_editmesh_from_object(obedit); BMFace *efa; BMIter iter, liter; BMLoop *l; @@ -1064,7 +1114,7 @@ static int uv_select_edgeloop( BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE); if (!extend) { - uv_select_all_perform(scene, ima, obedit, em, SEL_DESELECT); + uv_select_all_perform(scene, ima, obedit, SEL_DESELECT); } BM_mesh_elem_hflag_disable_all(em->bm, BM_FACE, BM_ELEM_TAG, false); @@ -1147,168 +1197,133 @@ static int uv_select_edgeloop( /** \name Select Linked * \{ */ -static void uv_select_linked( - Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, const float limit[2], +static void uv_select_linked_multi( + Scene *scene, Image *ima, Object **objects, const uint objects_len, const float limit[2], UvNearestHit *hit_final, bool extend, bool select_faces) { - BMFace *efa; - BMLoop *l; - BMIter iter, liter; - MLoopUV *luv; - UvVertMap *vmap; - UvMapVert *vlist, *iterv, *startv; - int i, stacksize = 0, *stack; - unsigned int a; - char *flag; + /* loop over objects, or just use hit_final->ob */ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + if (hit_final && ob_index != 0) { + break; + } + Object *obedit = hit_final ? hit_final->ob : objects[ob_index]; - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + BMFace *efa; + BMLoop *l; + BMIter iter, liter; + MLoopUV *luv; + UvVertMap *vmap; + UvMapVert *vlist, *iterv, *startv; + int i, stacksize = 0, *stack; + unsigned int a; + char *flag; - BM_mesh_elem_table_ensure(em->bm, BM_FACE); /* we can use this too */ + BMEditMesh *em = BKE_editmesh_from_object(obedit); + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - /* Note, we had 'use winding' so we don't consider overlapping islands as connected, see T44320 - * this made *every* projection split the island into front/back islands. - * Keep 'use_winding' to false, see: T50970. - * - * Better solve this by having a delimit option for select-linked operator, - * keeping island-select working as is. */ - vmap = BM_uv_vert_map_create(em->bm, limit, !select_faces, false); + BM_mesh_elem_table_ensure(em->bm, BM_FACE); /* we can use this too */ - if (vmap == NULL) - return; + /* Note, we had 'use winding' so we don't consider overlapping islands as connected, see T44320 + * this made *every* projection split the island into front/back islands. + * Keep 'use_winding' to false, see: T50970. + * + * Better solve this by having a delimit option for select-linked operator, + * keeping island-select working as is. */ + vmap = BM_uv_vert_map_create(em->bm, limit, !select_faces, false); - stack = MEM_mallocN(sizeof(*stack) * (em->bm->totface + 1), "UvLinkStack"); - flag = MEM_callocN(sizeof(*flag) * em->bm->totface, "UvLinkFlag"); + if (vmap == NULL) + return; - if (hit_final == NULL) { - /* Use existing selection */ - BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { - if (uvedit_face_visible_test(scene, obedit, ima, efa)) { - if (select_faces) { - if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { - stack[stacksize] = a; - stacksize++; - flag[a] = 1; - } - } - else { - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + stack = MEM_mallocN(sizeof(*stack) * (em->bm->totface + 1), "UvLinkStack"); + flag = MEM_callocN(sizeof(*flag) * em->bm->totface, "UvLinkFlag"); - if (luv->flag & MLOOPUV_VERTSEL) { + if (hit_final == NULL) { + /* Use existing selection */ + BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { + if (uvedit_face_visible_test(scene, obedit, ima, efa)) { + if (select_faces) { + if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { stack[stacksize] = a; stacksize++; flag[a] = 1; + } + } + else { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - break; + if (luv->flag & MLOOPUV_VERTSEL) { + stack[stacksize] = a; + stacksize++; + flag[a] = 1; + + break; + } } } } } } - } - else { - BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { - if (efa == hit_final->efa) { - stack[stacksize] = a; - stacksize++; - flag[a] = 1; - break; + else { + BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { + if (efa == hit_final->efa) { + stack[stacksize] = a; + stacksize++; + flag[a] = 1; + break; + } } } - } - while (stacksize > 0) { + while (stacksize > 0) { - stacksize--; - a = stack[stacksize]; + stacksize--; + a = stack[stacksize]; - efa = BM_face_at_index(em->bm, a); + efa = BM_face_at_index(em->bm, a); - BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { + BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) { - /* make_uv_vert_map_EM sets verts tmp.l to the indices */ - vlist = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); - - startv = vlist; + /* make_uv_vert_map_EM sets verts tmp.l to the indices */ + vlist = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v)); - for (iterv = vlist; iterv; iterv = iterv->next) { - if (iterv->separate) - startv = iterv; - if (iterv->f == a) - break; - } + startv = vlist; - for (iterv = startv; iterv; iterv = iterv->next) { - if ((startv != iterv) && (iterv->separate)) - break; - else if (!flag[iterv->f]) { - flag[iterv->f] = 1; - stack[stacksize] = iterv->f; - stacksize++; + for (iterv = vlist; iterv; iterv = iterv->next) { + if (iterv->separate) + startv = iterv; + if (iterv->f == a) + break; } - } - } - } - if (!extend) { - BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { - if (select_faces) { - if (flag[a]) - BM_face_select_set(em->bm, efa, true); - else - BM_face_select_set(em->bm, efa, false); - } - else { - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - - if (flag[a]) - luv->flag |= MLOOPUV_VERTSEL; - else - luv->flag &= ~MLOOPUV_VERTSEL; - } - } - } - } - else { - BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { - if (!flag[a]) { - continue; - } - - if (select_faces) { - if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) - break; - } - else { - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - - if (luv->flag & MLOOPUV_VERTSEL) { + for (iterv = startv; iterv; iterv = iterv->next) { + if ((startv != iterv) && (iterv->separate)) break; + else if (!flag[iterv->f]) { + flag[iterv->f] = 1; + stack[stacksize] = iterv->f; + stacksize++; } } - - if (l) { - break; - } } } - if (efa) { + if (!extend) { BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { - if (!flag[a]) { - continue; - } - if (select_faces) { - BM_face_select_set(em->bm, efa, false); + if (flag[a]) + BM_face_select_set(em->bm, efa, true); + else + BM_face_select_set(em->bm, efa, false); } else { BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - luv->flag &= ~MLOOPUV_VERTSEL; + if (flag[a]) + luv->flag |= MLOOPUV_VERTSEL; + else + luv->flag &= ~MLOOPUV_VERTSEL; } } } @@ -1320,22 +1335,66 @@ static void uv_select_linked( } if (select_faces) { - BM_face_select_set(em->bm, efa, true); + if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) + break; } else { BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - luv->flag |= MLOOPUV_VERTSEL; + if (luv->flag & MLOOPUV_VERTSEL) { + break; + } + } + + if (l) { + break; + } + } + } + + if (efa) { + BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { + if (!flag[a]) { + continue; + } + + if (select_faces) { + BM_face_select_set(em->bm, efa, false); + } + else { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + + luv->flag &= ~MLOOPUV_VERTSEL; + } + } + } + } + else { + BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) { + if (!flag[a]) { + continue; + } + + if (select_faces) { + BM_face_select_set(em->bm, efa, true); + } + else { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + + luv->flag |= MLOOPUV_VERTSEL; + } } } } } + + MEM_freeN(stack); + MEM_freeN(flag); + BM_uv_vert_map_free(vmap); } - - MEM_freeN(stack); - MEM_freeN(flag); - BM_uv_vert_map_free(vmap); } /* WATCH IT: this returns first selected UV, @@ -1957,9 +2016,53 @@ static void UV_OT_weld(wmOperatorType *ot) /** \name (De)Select All Operator * \{ */ -static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, BMEditMesh *em, int action) + +static bool uv_select_is_any_selected(Scene *scene, Image *ima, Object *obedit) +{ + ToolSettings *ts = scene->toolsettings; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMFace *efa; + BMLoop *l; + BMIter iter, liter; + MLoopUV *luv; + + if (ts->uv_flag & UV_SYNC_SELECTION) { + return (em->bm->totvertsel || em->bm->totedgesel || em->bm->totfacesel); + } + else { + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) { + continue; + } + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + if (luv->flag & MLOOPUV_VERTSEL) { + return true; + } + } + } + } + return false; +} + +static bool uv_select_is_any_selected_multi(Scene *scene, Image *ima, Object **objects, const uint objects_len) +{ + bool found = false; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + if (uv_select_is_any_selected(scene, ima, obedit)) { + found = true; + break; + } + } + return found; +} + +static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, int action) { ToolSettings *ts = scene->toolsettings; + BMEditMesh *em = BKE_editmesh_from_object(obedit); BMFace *efa; BMLoop *l; BMIter iter, liter; @@ -1967,8 +2070,11 @@ static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, BMEd const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - if (ts->uv_flag & UV_SYNC_SELECTION) { + if (action == SEL_TOGGLE) { + action = uv_select_is_any_selected(scene, ima, obedit) ? SEL_DESELECT : SEL_SELECT; + } + if (ts->uv_flag & UV_SYNC_SELECTION) { switch (action) { case SEL_TOGGLE: EDBM_select_toggle_all(em); @@ -1986,24 +2092,6 @@ static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, BMEd } } else { - if (action == SEL_TOGGLE) { - action = SEL_SELECT; - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) - continue; - - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - - if (luv->flag & MLOOPUV_VERTSEL) { - action = SEL_DESELECT; - break; - } - } - } - } - - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (!uvedit_face_visible_test(scene, obedit, ima, efa)) continue; @@ -2027,18 +2115,38 @@ static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, BMEd } } +static void uv_select_all_perform_multi( + Scene *scene, Image *ima, Object **objects, const uint objects_len, int action) +{ + if (action == SEL_TOGGLE) { + action = uv_select_is_any_selected_multi(scene, ima, objects, objects_len) ? SEL_DESELECT : SEL_SELECT; + } + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + uv_select_all_perform(scene, ima, obedit, action); + } +} + static int uv_select_all_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); - Object *obedit = CTX_data_edit_object(C); Image *ima = CTX_data_edit_image(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); + ViewLayer *view_layer = CTX_data_view_layer(C); int action = RNA_enum_get(op->ptr, "action"); - uv_select_all_perform(scene, ima, obedit, em, action); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + uv_select_all_perform_multi(scene, ima, objects, objects_len, action); + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + } + + MEM_SAFE_FREE(objects); return OPERATOR_FINISHED; } @@ -2087,14 +2195,14 @@ static bool uv_sticky_select(float *limit, int hitv[], int v, float *hituv[], fl return false; } -static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loop) +static int uv_mouse_select_multi( + bContext *C, Object **objects, uint objects_len, + const float co[2], bool extend, bool loop) { SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; - Object *obedit = CTX_data_edit_object(C); Image *ima = CTX_data_edit_image(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); BMFace *efa; BMLoop *l; BMIter iter, liter; @@ -2105,8 +2213,6 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo int flush = 0, hitlen = 0; /* 0 == don't flush, 1 == sel, -1 == desel; only use when selection sync is enabled */ float limit[2], **hituv = NULL; - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - /* notice 'limit' is the same no matter the zoom level, since this is like * remove doubles and could annoying if it joined points when zoomed out. * 'penalty' is in screen pixel space otherwise zooming in on a uv-vert and @@ -2143,7 +2249,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo /* find nearest element */ if (loop) { /* find edge */ - if (!uv_find_nearest_edge(scene, ima, obedit, co, &hit)) { + if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) { return OPERATOR_CANCELLED; } @@ -2151,7 +2257,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo } else if (selectmode == UV_SELECT_VERTEX) { /* find vertex */ - if (!uv_find_nearest_vert(scene, ima, obedit, co, penalty_dist, &hit)) { + if (!uv_find_nearest_vert_multi(scene, ima, objects, objects_len, co, penalty_dist, &hit)) { return OPERATOR_CANCELLED; } @@ -2167,7 +2273,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo } else if (selectmode == UV_SELECT_EDGE) { /* find edge */ - if (!uv_find_nearest_edge(scene, ima, obedit, co, &hit)) { + if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) { return OPERATOR_CANCELLED; } @@ -2185,10 +2291,13 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo } else if (selectmode == UV_SELECT_FACE) { /* find face */ - if (!uv_find_nearest_face(scene, ima, obedit, co, &hit)) { + if (!uv_find_nearest_face_multi(scene, ima, objects, objects_len, co, &hit)) { return OPERATOR_CANCELLED; } + BMEditMesh *em = BKE_editmesh_from_object(hit.ob); + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + /* make active */ BM_mesh_active_face_set(em->bm, hit.efa); @@ -2205,7 +2314,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo hitlen = hit.efa->len; } else if (selectmode == UV_SELECT_ISLAND) { - if (!uv_find_nearest_edge(scene, ima, obedit, co, &hit)) { + if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) { return OPERATOR_CANCELLED; } @@ -2216,12 +2325,24 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo return OPERATOR_CANCELLED; } + Object *obedit = hit.ob; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + /* do selection */ if (loop) { - flush = uv_select_edgeloop(scene, ima, obedit, em, &hit, limit, extend); + if (!extend) { + /* TODO(MULTI_EDIT): We only need to de-select non-active */ + uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT); + } + flush = uv_select_edgeloop(scene, ima, obedit, &hit, limit, extend); } else if (selectmode == UV_SELECT_ISLAND) { - uv_select_linked(scene, ima, obedit, em, limit, &hit, extend, false); + if (!extend) { + /* TODO(MULTI_EDIT): We only need to de-select non-active */ + uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT); + } + uv_select_linked_multi(scene, ima, objects, objects_len, limit, &hit, extend, false); } else if (extend) { if (selectmode == UV_SELECT_VERTEX) { @@ -2271,7 +2392,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo } else { /* deselect all */ - uv_select_all_perform(scene, ima, obedit, em, SEL_DESELECT); + uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT); if (selectmode == UV_SELECT_VERTEX) { /* select vertex */ @@ -2339,6 +2460,15 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED; } +static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loop) +{ + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len); + int ret = uv_mouse_select_multi(C, objects, objects_len, co, extend, loop); + MEM_freeN(objects); + return ret; +} static int uv_select_exec(bContext *C, wmOperator *op) { @@ -2443,9 +2573,8 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; - Object *obedit = CTX_data_edit_object(C); + ViewLayer *view_layer = CTX_data_view_layer(C); Image *ima = CTX_data_edit_image(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); float limit[2]; int extend; bool select_faces = (ts->uv_flag & UV_SYNC_SELECTION) && (ts->selectmode & SCE_SELECT_FACE); @@ -2460,6 +2589,9 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent extend = RNA_boolean_get(op->ptr, "extend"); uvedit_pixel_to_float(sima, limit, 0.05f); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len); + if (pick) { float co[2]; @@ -2475,15 +2607,32 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent RNA_float_get_array(op->ptr, "location", co); } - if (!uv_find_nearest_edge(scene, ima, obedit, co, &hit)) { + if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) { + MEM_SAFE_FREE(objects); return OPERATOR_CANCELLED; } } - uv_select_linked(scene, ima, obedit, em, limit, pick ? &hit : NULL, extend, select_faces); + if (!extend) { + uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT); + } - DEG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + uv_select_linked_multi(scene, ima, objects, objects_len, limit, pick ? &hit : NULL, extend, select_faces); + + /* weak!, but works */ + Object **objects_free = objects; + if (pick) { + objects = &hit.ob; + objects_len = 1; + } + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + DEG_id_tag_update(obedit->data, 0); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + } + + MEM_SAFE_FREE(objects_free); return OPERATOR_FINISHED; } @@ -2879,23 +3028,20 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; - Object *obedit = CTX_data_edit_object(C); + ViewLayer *view_layer = CTX_data_view_layer(C); Image *ima = CTX_data_edit_image(C); ARegion *ar = CTX_wm_region(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); BMFace *efa; BMLoop *l; BMIter iter, liter; MLoopUV *luv; rctf rectf; - bool changed, pinned, select, extend; + bool pinned, select, extend; const bool use_face_center = ( (ts->uv_flag & UV_SYNC_SELECTION) ? (ts->selectmode == SCE_SELECT_FACE) : (ts->uv_selectmode == UV_SELECT_FACE)); - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - /* get rectangle from operator */ WM_operator_properties_border_to_rctf(op, &rectf); UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf); @@ -2905,79 +3051,98 @@ static int uv_border_select_exec(bContext *C, wmOperator *op) extend = RNA_boolean_get(op->ptr, "extend"); pinned = RNA_boolean_get(op->ptr, "pinned"); - if (!extend) - uv_select_all_perform(scene, ima, obedit, em, SEL_DESELECT); + bool changed_multi = false; - /* do actual selection */ - if (use_face_center && !pinned) { - /* handle face selection mode */ - float cent[2]; + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len); - changed = false; + /* don't indent to avoid diff noise! */ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - /* assume not touched */ - BM_elem_flag_disable(efa, BM_ELEM_TAG); + bool changed = false; - if (uvedit_face_visible_test(scene, obedit, ima, efa)) { - uv_poly_center(efa, cent, cd_loop_uv_offset); - if (BLI_rctf_isect_pt_v(&rectf, cent)) { - BM_elem_flag_enable(efa, BM_ELEM_TAG); - changed = true; + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + + if (!extend) + uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT); + + /* do actual selection */ + if (use_face_center && !pinned) { + /* handle face selection mode */ + float cent[2]; + + changed = false; + + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + /* assume not touched */ + BM_elem_flag_disable(efa, BM_ELEM_TAG); + + if (uvedit_face_visible_test(scene, obedit, ima, efa)) { + uv_poly_center(efa, cent, cd_loop_uv_offset); + if (BLI_rctf_isect_pt_v(&rectf, cent)) { + BM_elem_flag_enable(efa, BM_ELEM_TAG); + changed = true; + } } } - } - /* (de)selects all tagged faces and deals with sticky modes */ - if (changed) { - uv_select_flush_from_tag_face(sima, scene, obedit, select); + /* (de)selects all tagged faces and deals with sticky modes */ + if (changed) { + uv_select_flush_from_tag_face(sima, scene, obedit, select); + } } - } - else { - /* other selection modes */ - changed = true; - BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false); + else { + /* other selection modes */ + changed = true; + BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false); - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, efa)) - continue; - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + if (!uvedit_face_visible_test(scene, obedit, ima, efa)) + continue; + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (!pinned || (ts->uv_flag & UV_SYNC_SELECTION)) { + if (!pinned || (ts->uv_flag & UV_SYNC_SELECTION)) { - /* UV_SYNC_SELECTION - can't do pinned selection */ - if (BLI_rctf_isect_pt_v(&rectf, luv->uv)) { - uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); - BM_elem_flag_enable(l->v, BM_ELEM_TAG); + /* UV_SYNC_SELECTION - can't do pinned selection */ + if (BLI_rctf_isect_pt_v(&rectf, luv->uv)) { + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); + BM_elem_flag_enable(l->v, BM_ELEM_TAG); + } } - } - else if (pinned) { - if ((luv->flag & MLOOPUV_PINNED) && BLI_rctf_isect_pt_v(&rectf, luv->uv)) { - uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); - BM_elem_flag_enable(l->v, BM_ELEM_TAG); + else if (pinned) { + if ((luv->flag & MLOOPUV_PINNED) && BLI_rctf_isect_pt_v(&rectf, luv->uv)) { + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); + BM_elem_flag_enable(l->v, BM_ELEM_TAG); + } } } } + + if (sima->sticky == SI_STICKY_VERTEX) { + uvedit_vertex_select_tagged(em, scene, select, cd_loop_uv_offset); + } } - if (sima->sticky == SI_STICKY_VERTEX) { - uvedit_vertex_select_tagged(em, scene, select, cd_loop_uv_offset); + if (changed) { + uv_select_sync_flush(ts, em, select); + + if (ts->uv_flag & UV_SYNC_SELECTION) { + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + } } + changed_multi |= changed; } - if (changed) { - uv_select_sync_flush(ts, em, select); + MEM_SAFE_FREE(objects); - if (ts->uv_flag & UV_SYNC_SELECTION) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); - } - + if (changed_multi) { return OPERATOR_FINISHED; } - return OPERATOR_CANCELLED; -} +} static void UV_OT_select_border(wmOperatorType *ot) { @@ -3131,99 +3296,112 @@ static void UV_OT_circle_select(wmOperatorType *ot) /** \name Lasso Select Operator * \{ */ -static bool do_lasso_select_mesh_uv( - bContext *C, const int mcords[][2], short moves, - const bool select, const bool extend) +static bool do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short moves, + const bool select, const bool extend) { SpaceImage *sima = CTX_wm_space_image(C); Image *ima = CTX_data_edit_image(C); ARegion *ar = CTX_wm_region(C); - Object *obedit = CTX_data_edit_object(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; - BMEditMesh *em = BKE_editmesh_from_object(obedit); + ViewLayer *view_layer = CTX_data_view_layer(C); const bool use_face_center = ( (ts->uv_flag & UV_SYNC_SELECTION) ? (ts->selectmode == SCE_SELECT_FACE) : (ts->uv_selectmode == UV_SELECT_FACE)); - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); BMIter iter, liter; BMFace *efa; BMLoop *l; int screen_uv[2]; - bool changed = false; + bool changed_multi = false; rcti rect; BLI_lasso_boundbox(&rect, mcords, moves); - if (!extend && select) { - uv_select_all_perform(scene, ima, obedit, em, SEL_DESELECT); - } + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len); - if (use_face_center) { /* Face Center Sel */ - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - BM_elem_flag_disable(efa, BM_ELEM_TAG); - /* assume not touched */ - if (select != uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) { - float cent[2]; - uv_poly_center(efa, cent, cd_loop_uv_offset); + /* don't indent to avoid diff noise! */ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; - if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_uv[0], &screen_uv[1]) && - BLI_rcti_isect_pt_v(&rect, screen_uv) && - BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) - { - BM_elem_flag_enable(efa, BM_ELEM_TAG); - changed = true; + bool changed = false; + + BMEditMesh *em = BKE_editmesh_from_object(obedit); + + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + + if (!extend && select) { + uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT); + } + + if (use_face_center) { /* Face Center Sel */ + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + BM_elem_flag_disable(efa, BM_ELEM_TAG); + /* assume not touched */ + if (select != uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) { + float cent[2]; + uv_poly_center(efa, cent, cd_loop_uv_offset); + + if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_uv[0], &screen_uv[1]) && + BLI_rcti_isect_pt_v(&rect, screen_uv) && + BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) + { + BM_elem_flag_enable(efa, BM_ELEM_TAG); + changed = true; + } } } - } - /* (de)selects all tagged faces and deals with sticky modes */ - if (changed) { - uv_select_flush_from_tag_face(sima, scene, obedit, select); + /* (de)selects all tagged faces and deals with sticky modes */ + if (changed) { + uv_select_flush_from_tag_face(sima, scene, obedit, select); + } } - } - else { /* Vert Sel */ - BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false); + else { /* Vert Sel */ + BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false); - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (uvedit_face_visible_test(scene, obedit, ima, efa)) { - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - if ((select) != (uvedit_uv_select_test(scene, l, cd_loop_uv_offset))) { - MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - if (UI_view2d_view_to_region_clip( - &ar->v2d, - luv->uv[0], luv->uv[1], - &screen_uv[0], &screen_uv[1]) && - BLI_rcti_isect_pt_v(&rect, screen_uv) && - BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) - { - uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); - changed = true; - BM_elem_flag_enable(l->v, BM_ELEM_TAG); + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + if (uvedit_face_visible_test(scene, obedit, ima, efa)) { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + if ((select) != (uvedit_uv_select_test(scene, l, cd_loop_uv_offset))) { + MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + if (UI_view2d_view_to_region_clip( + &ar->v2d, + luv->uv[0], luv->uv[1], + &screen_uv[0], &screen_uv[1]) && + BLI_rcti_isect_pt_v(&rect, screen_uv) && + BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) + { + uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset); + changed = true; + BM_elem_flag_enable(l->v, BM_ELEM_TAG); + } } } } } - } - if (sima->sticky == SI_STICKY_VERTEX) { - uvedit_vertex_select_tagged(em, scene, select, cd_loop_uv_offset); + if (sima->sticky == SI_STICKY_VERTEX) { + uvedit_vertex_select_tagged(em, scene, select, cd_loop_uv_offset); + } } - } - if (changed) { - uv_select_sync_flush(scene->toolsettings, em, select); + if (changed) { + uv_select_sync_flush(scene->toolsettings, em, select); - if (ts->uv_flag & UV_SYNC_SELECTION) { - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + if (ts->uv_flag & UV_SYNC_SELECTION) { + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); + } } + + changed_multi |= changed; } - return changed; + return changed_multi; } static int uv_lasso_select_exec(bContext *C, wmOperator *op) @@ -4175,7 +4353,7 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *op) me->drawflag |= ME_DRAWSEAMS; if (scene->toolsettings->edge_mode_live_unwrap) - ED_unwrap_lscm(scene, ob, false); + ED_unwrap_lscm(scene, ob, false, false); DEG_id_tag_update(&me->id, 0); WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 4f28d1f9eea..828f84855ce 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -61,6 +61,7 @@ #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_editmesh.h" +#include "BKE_layer.h" #include "DEG_depsgraph.h" @@ -202,6 +203,21 @@ static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, bool implicit) return false; } +static bool uvedit_have_selection_multi( + Scene *scene, Object **objects, const uint objects_len, bool implicit) +{ + bool have_select = false; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + if (uvedit_have_selection(scene, em, implicit)) { + have_select = true; + break; + } + } + return have_select; +} + void ED_uvedit_get_aspect(Scene *scene, Object *ob, BMesh *bm, float *aspx, float *aspy) { bool sloppy = true; @@ -258,9 +274,11 @@ static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene, param_face_add(handle, key, i, vkeys, co, uv, pin, select, efa->no); } -static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMesh *bm, - const bool implicit, const bool fill, const bool sel, - const bool correct_aspect) +/* See: construct_param_handle_multi to handle multiple objects at once. */ +static ParamHandle *construct_param_handle( + Scene *scene, Object *ob, BMesh *bm, + const bool implicit, const bool fill, const bool sel, + const bool correct_aspect) { ParamHandle *handle; BMFace *efa; @@ -324,6 +342,89 @@ static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMesh *bm, return handle; } +/** + * Version of #construct_param_handle_single that handles multiple objects. + */ +static ParamHandle *construct_param_handle_multi( + Scene *scene, Object **objects, const uint objects_len, + const bool implicit, const bool fill, const bool sel, + const bool correct_aspect) +{ + ParamHandle *handle; + BMFace *efa; + BMLoop *l; + BMEdge *eed; + BMIter iter, liter; + int i; + + + handle = param_construct_begin(); + + if (correct_aspect) { + Object *ob = objects[0]; + BMEditMesh *em = BKE_editmesh_from_object(ob); + BMesh *bm = em->bm; + float aspx, aspy; + + ED_uvedit_get_aspect(scene, ob, bm, &aspx, &aspy); + if (aspx != aspy) { + param_aspect_ratio(handle, aspx, aspy); + } + } + + /* we need the vert indices */ + EDBM_mesh_elem_index_ensure_multi(objects, objects_len, BM_VERT); + + int offset = 0; + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + BMesh *bm = em->bm; + + const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); + + BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) { + + if ((BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) || (sel && BM_elem_flag_test(efa, BM_ELEM_SELECT) == 0)) { + continue; + } + + if (implicit) { + bool is_loopsel = false; + + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { + is_loopsel = true; + break; + } + } + if (is_loopsel == false) { + continue; + } + } + + construct_param_handle_face_add(handle, scene, efa, i + offset, cd_loop_uv_offset); + } + + if (!implicit) { + BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) { + if (BM_elem_flag_test(eed, BM_ELEM_SEAM)) { + ParamKey vkeys[2]; + vkeys[0] = (ParamKey)BM_elem_index_get(eed->v1); + vkeys[1] = (ParamKey)BM_elem_index_get(eed->v2); + param_edge_set_seam(handle, vkeys); + } + } + } + offset += bm->totface; + } + + param_construct_end(handle, fill, implicit); + + return handle; +} + static void texface_from_original_index(BMFace *efa, int index, float **uv, ParamBool *pin, ParamBool *select, Scene *scene, const int cd_loop_uv_offset) @@ -715,6 +816,7 @@ void UV_OT_minimize_stretch(wmOperatorType *ot) /* ******************** Pack Islands operator **************** */ + void ED_uvedit_pack_islands(Scene *scene, Object *ob, BMesh *bm, bool selected, bool correct_aspect, bool do_rotate) { ParamHandle *handle; @@ -724,14 +826,29 @@ void ED_uvedit_pack_islands(Scene *scene, Object *ob, BMesh *bm, bool selected, param_delete(handle); } +void ED_uvedit_pack_islands_multi( + Scene *scene, Object **objects, const uint objects_len, + bool selected, bool correct_aspect, bool do_rotate) +{ + ParamHandle *handle; + handle = construct_param_handle_multi( + scene, objects, objects_len, true, false, selected, correct_aspect); + param_pack(handle, scene->toolsettings->uvcalc_margin, do_rotate); + param_flush(handle); + param_delete(handle); +} + static int pack_islands_exec(bContext *C, wmOperator *op) { + ViewLayer *view_layer = CTX_data_view_layer(C); Scene *scene = CTX_data_scene(C); - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); bool do_rotate = RNA_boolean_get(op->ptr, "rotate"); - if (!uvedit_have_selection(scene, em, true)) { + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len); + + if (!uvedit_have_selection_multi(scene, objects, objects_len, true)) { + MEM_SAFE_FREE(objects); return OPERATOR_CANCELLED; } @@ -740,10 +857,15 @@ static int pack_islands_exec(bContext *C, wmOperator *op) else RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin); - ED_uvedit_pack_islands(scene, obedit, em->bm, true, true, do_rotate); - - DEG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + ED_uvedit_pack_islands_multi(scene, objects, objects_len, true, true, do_rotate); + + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + DEG_id_tag_update(obedit->data, 0); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + } + + MEM_SAFE_FREE(objects); return OPERATOR_FINISHED; } @@ -856,7 +978,7 @@ void ED_uvedit_live_unwrap(Scene *scene, Object *obedit) if (scene->toolsettings->edge_mode_live_unwrap && CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)) { - ED_unwrap_lscm(scene, obedit, false); /* unwrap all not just sel */ + ED_unwrap_lscm(scene, obedit, false, false); /* unwrap all not just sel */ } } @@ -1178,7 +1300,7 @@ static void uv_map_clip_correct(Scene *scene, Object *ob, BMEditMesh *em, wmOper /* ******************** Unwrap operator **************** */ /* assumes UV Map is checked, doesn't run update funcs */ -void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel) +void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel, const bool pack) { BMEditMesh *em = BKE_editmesh_from_object(obedit); ParamHandle *handle; @@ -1199,7 +1321,10 @@ void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel) param_lscm_end(handle); param_average(handle); - param_pack(handle, scene->toolsettings->uvcalc_margin, false); + + if (pack) { + param_pack(handle, scene->toolsettings->uvcalc_margin, false); + } param_flush(handle); @@ -1208,33 +1333,48 @@ void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel) static int unwrap_exec(bContext *C, wmOperator *op) { + ViewLayer *view_layer = CTX_data_view_layer(C); Scene *scene = CTX_data_scene(C); - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); int method = RNA_enum_get(op->ptr, "method"); const bool fill_holes = RNA_boolean_get(op->ptr, "fill_holes"); const bool correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect"); const bool use_subsurf = RNA_boolean_get(op->ptr, "use_subsurf_data"); - bool use_subsurf_final; float obsize[3]; bool implicit = false; - if (!uvedit_have_selection(scene, em, implicit)) { + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + if (!uvedit_have_selection_multi(scene, objects, objects_len, implicit)) { + MEM_SAFE_FREE(objects); return OPERATOR_CANCELLED; } - + /* add uvs if they don't exist yet */ - if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { - return OPERATOR_CANCELLED; - } + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + bool use_subsurf_final; + + if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { + continue; + } + + mat4_to_size(obsize, obedit->obmat); + if (!(fabsf(obsize[0] - obsize[1]) < 1e-4f && fabsf(obsize[1] - obsize[2]) < 1e-4f)) + BKE_report(op->reports, RPT_INFO, + "Object has non-uniform scale, unwrap will operate on a non-scaled version of the mesh"); + else if (is_negative_m4(obedit->obmat)) + BKE_report(op->reports, RPT_INFO, + "Object has negative scale, unwrap will operate on a non-flipped version of the mesh"); - mat4_to_size(obsize, obedit->obmat); - if (!(fabsf(obsize[0] - obsize[1]) < 1e-4f && fabsf(obsize[1] - obsize[2]) < 1e-4f)) - BKE_report(op->reports, RPT_INFO, - "Object has non-uniform scale, unwrap will operate on a non-scaled version of the mesh"); - else if (is_negative_m4(obedit->obmat)) - BKE_report(op->reports, RPT_INFO, - "Object has negative scale, unwrap will operate on a non-flipped version of the mesh"); + + /* double up the check here but better keep ED_unwrap_lscm interface simple and not + * pass operator for warning append */ + modifier_unwrap_state(obedit, scene, &use_subsurf_final); + if (use_subsurf != use_subsurf_final) { + BKE_report(op->reports, RPT_INFO, "Subdivision Surface modifier needs to be first to work with unwrap"); + } + } /* remember last method for live unwrap */ if (RNA_struct_property_is_set(op->ptr, "method")) @@ -1257,17 +1397,17 @@ static int unwrap_exec(bContext *C, wmOperator *op) if (use_subsurf) scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF; else scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF; - /* double up the check here but better keep ED_unwrap_lscm interface simple and not - * pass operator for warning append */ - modifier_unwrap_state(obedit, scene, &use_subsurf_final); - if (use_subsurf != use_subsurf_final) - BKE_report(op->reports, RPT_INFO, "Subdivision Surface modifier needs to be first to work with unwrap"); - /* execute unwrap */ - ED_unwrap_lscm(scene, obedit, true); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + ED_unwrap_lscm(scene, obedit, true, false); + DEG_id_tag_update(obedit->data, 0); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + } - DEG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + ED_uvedit_pack_islands_multi(scene, objects, objects_len, true, true, true); + + MEM_SAFE_FREE(objects); return OPERATOR_FINISHED; } @@ -1322,9 +1462,8 @@ static int uv_from_view_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE static int uv_from_view_exec(bContext *C, wmOperator *op) { + ViewLayer *view_layer = CTX_data_view_layer(C); Scene *scene = CTX_data_scene(C); - Object *obedit = CTX_data_edit_object(C); - BMEditMesh *em = BKE_editmesh_from_object(obedit); ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); @@ -1334,69 +1473,90 @@ static int uv_from_view_exec(bContext *C, wmOperator *op) BMIter iter, liter; MLoopUV *luv; float rotmat[4][4]; + bool changed_multi = false; - int cd_loop_uv_offset; + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); - /* add uvs if they don't exist yet */ - if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { - return OPERATOR_CANCELLED; - } + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + bool changed = false; - cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + /* add uvs if they don't exist yet */ + if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { + continue; + } - if (RNA_boolean_get(op->ptr, "orthographic")) { - uv_map_rotation_matrix(rotmat, rv3d, obedit, 90.0f, 0.0f, 1.0f); - - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) - continue; + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - BLI_uvproject_from_view_ortho(luv->uv, l->v->co, rotmat); - } - } - } - else if (camera) { - const bool camera_bounds = RNA_boolean_get(op->ptr, "camera_bounds"); - struct ProjCameraInfo *uci = BLI_uvproject_camera_info(v3d->camera, obedit->obmat, - camera_bounds ? (scene->r.xsch * scene->r.xasp) : 1.0f, - camera_bounds ? (scene->r.ysch * scene->r.yasp) : 1.0f); + if (RNA_boolean_get(op->ptr, "orthographic")) { + uv_map_rotation_matrix(rotmat, rv3d, obedit, 90.0f, 0.0f, 1.0f); - if (uci) { BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) continue; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - BLI_uvproject_from_camera(luv->uv, l->v->co, uci); + BLI_uvproject_from_view_ortho(luv->uv, l->v->co, rotmat); } + changed = true; } - - MEM_freeN(uci); } - } - else { - copy_m4_m4(rotmat, obedit->obmat); + else if (camera) { + const bool camera_bounds = RNA_boolean_get(op->ptr, "camera_bounds"); + struct ProjCameraInfo *uci = BLI_uvproject_camera_info( + v3d->camera, obedit->obmat, + camera_bounds ? (scene->r.xsch * scene->r.xasp) : 1.0f, + camera_bounds ? (scene->r.ysch * scene->r.yasp) : 1.0f); + + if (uci) { + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + continue; + + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + BLI_uvproject_from_camera(luv->uv, l->v->co, uci); + } + changed = true; + } - BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) - continue; + MEM_freeN(uci); + } + } + else { + copy_m4_m4(rotmat, obedit->obmat); - BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - BLI_uvproject_from_view(luv->uv, l->v->co, rv3d->persmat, rotmat, ar->winx, ar->winy); + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) + continue; + + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + BLI_uvproject_from_view(luv->uv, l->v->co, rv3d->persmat, rotmat, ar->winx, ar->winy); + } + changed = true; } } - } - uv_map_clip_correct(scene, obedit, em, op); + if (changed) { + uv_map_clip_correct(scene, obedit, em, op); - DEG_id_tag_update(obedit->data, 0); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + DEG_id_tag_update(obedit->data, 0); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + changed_multi = true; + } + } + MEM_SAFE_FREE(objects); - return OPERATOR_FINISHED; + if (changed_multi) { + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } } static int uv_from_view_poll(bContext *C) diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index c1fa86d4653..29d14442a47 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -80,16 +80,8 @@ NodeGroup *BlenderFileLoader::Load() } ViewLayer *view_layer = (ViewLayer*)BLI_findstring(&_re->scene->view_layers, _view_layer->name, offsetof(ViewLayer, name)); - - EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); Depsgraph *depsgraph = DEG_graph_new(_re->scene, view_layer, DAG_EVAL_RENDER); - DEG_evaluation_context_init_from_view_layer_for_render( - eval_ctx, - depsgraph, - _re->scene, - view_layer); - BKE_scene_graph_update_tagged(depsgraph, _re->main); #if 0 @@ -116,7 +108,7 @@ NodeGroup *BlenderFileLoader::Load() bool apply_modifiers = true; bool calc_undeformed = false; bool calc_tessface = false; - Mesh *mesh = BKE_mesh_new_from_object(eval_ctx, + Mesh *mesh = BKE_mesh_new_from_object(depsgraph, _re->main, _re->scene, ob, @@ -132,7 +124,6 @@ NodeGroup *BlenderFileLoader::Load() DEG_OBJECT_ITER_END; DEG_graph_free(depsgraph); - DEG_evaluation_context_free(eval_ctx); // Return the built scene. return _Scene; diff --git a/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h b/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h index 956842580c5..4142117c361 100644 --- a/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h +++ b/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h @@ -275,7 +275,7 @@ protected: { if (_Point != 0) { delete _Point; - _Point = 0; + _Point = 0; } if ((_currentn == _n - 1) && (_t == 1.0f)) { // we're setting the iterator to end diff --git a/source/blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h b/source/blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h index 8e98cabd75b..a3a0b5cbaeb 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h +++ b/source/blender/freestyle/intern/view_map/ViewMapAdvancedIterators.h @@ -555,9 +555,9 @@ public: // operators // operator corresponding to ++i. inline Self& operator++() - { - increment(); - return *this; + { + increment(); + return *this; } // operator corresponding to i++, i.e. which returns the value *and then* increments it. diff --git a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h index 5683b39fd28..601c208b137 100644 --- a/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h +++ b/source/blender/freestyle/intern/winged_edge/WingedEdgeBuilder.h @@ -113,7 +113,7 @@ public: #endif inline void setRenderMonitor(RenderMonitor *iRenderMonitor) { - _pRenderMonitor = iRenderMonitor; + _pRenderMonitor = iRenderMonitor; } protected: diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h index 57185d2f39e..92dc512e27d 100644 --- a/source/blender/gpu/GPU_texture.h +++ b/source/blender/gpu/GPU_texture.h @@ -71,6 +71,7 @@ typedef enum GPUTextureFormat { GPU_R32F, GPU_R16F, GPU_R16I, + GPU_R16UI, GPU_RG8, GPU_R8, #if 0 @@ -89,7 +90,6 @@ typedef enum GPUTextureFormat { GPU_RG8UI, GPU_R32I, GPU_R32UI, - GPU_R16UI, GPU_R16, GPU_R8I, GPU_R8UI, diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c index 8d8fb50d9b9..d31ba79d9ed 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.c +++ b/source/blender/gpu/intern/gpu_framebuffer.c @@ -87,7 +87,7 @@ static GLenum convert_attachment_type_to_gl(GPUAttachmentType type) [GPU_FB_COLOR_ATTACHMENT2] = GL_COLOR_ATTACHMENT2, [GPU_FB_COLOR_ATTACHMENT3] = GL_COLOR_ATTACHMENT3, [GPU_FB_COLOR_ATTACHMENT4] = GL_COLOR_ATTACHMENT4 - }; + }; return table[type]; } diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index a408a41513a..98d8eea6036 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1384,8 +1384,10 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr) shade_one_light(shi, shr, lamp); } + /* TODO: won't fix because will be removed. */ +#if 0 if (ob->transflag & OB_DUPLI) { - ListBase *lb = object_duplilist(G.main->eval_ctx, shi->gpumat->scene, ob); + ListBase *lb = object_duplilist(G.main->depsgraph, shi->gpumat->scene, ob); for (DupliObject *dob = lb->first; dob; dob = dob->next) { Object *ob_iter = dob->ob; @@ -1405,6 +1407,7 @@ static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr) free_object_duplilist(lb); } +#endif } /* prevent only shadow lamps from producing negative colors.*/ diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index 75830f60f03..cfc229166ed 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -147,8 +147,14 @@ static GLenum gpu_texture_get_format( } else { /* Integer formats */ - if (ELEM(data_type, GPU_RG16I, GPU_R16I)) { - *data_format = GL_INT; + if (ELEM(data_type, GPU_RG16I, GPU_R16I, GPU_R16UI)) { + if (ELEM(data_type, GPU_R16UI)) { + *data_format = GL_UNSIGNED_INT; + } + else { + *data_format = GL_INT; + } + *format_flag |= GPU_FORMAT_INTEGER; switch (components) { @@ -224,6 +230,7 @@ static GLenum gpu_texture_get_format( case GPU_R32F: return GL_R32F; case GPU_R16F: return GL_R16F; case GPU_R16I: return GL_R16I; + case GPU_R16UI: return GL_R16UI; case GPU_RG8: return GL_RG8; case GPU_R8: return GL_R8; /* Special formats texture & renderbuffer */ diff --git a/source/blender/ikplugin/BIK_api.h b/source/blender/ikplugin/BIK_api.h index ad842029941..2a7a473db51 100644 --- a/source/blender/ikplugin/BIK_api.h +++ b/source/blender/ikplugin/BIK_api.h @@ -43,7 +43,7 @@ struct bPoseChannel; struct bPose; struct Scene; struct bConstraint; -struct EvaluationContext; +struct Depsgraph; enum BIK_ParamType { BIK_PARAM_TYPE_FLOAT = 0, @@ -62,8 +62,8 @@ struct BIK_ParamValue { }; typedef struct BIK_ParamValue BIK_ParamValue; -void BIK_initialize_tree(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, float ctime); -void BIK_execute_tree(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime); +void BIK_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); +void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime); void BIK_release_tree(struct Scene *scene, struct Object *ob, float ctime); void BIK_clear_data(struct bPose *pose); void BIK_clear_cache(struct bPose *pose); diff --git a/source/blender/ikplugin/intern/ikplugin_api.c b/source/blender/ikplugin/intern/ikplugin_api.c index 0ee26ff45f1..9330f969ae7 100644 --- a/source/blender/ikplugin/intern/ikplugin_api.c +++ b/source/blender/ikplugin/intern/ikplugin_api.c @@ -89,20 +89,20 @@ static IKPlugin *get_plugin(bPose *pose) /*----------------------------------------*/ /* Plugin API */ -void BIK_initialize_tree(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float ctime) +void BIK_initialize_tree(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime) { IKPlugin *plugin = get_plugin(ob->pose); if (plugin && plugin->initialize_tree_func) - plugin->initialize_tree_func(eval_ctx, scene, ob, ctime); + plugin->initialize_tree_func(depsgraph, scene, ob, ctime); } -void BIK_execute_tree(const struct EvaluationContext *eval_ctx, struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) +void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime) { IKPlugin *plugin = get_plugin(ob->pose); if (plugin && plugin->execute_tree_func) - plugin->execute_tree_func(eval_ctx, scene, ob, pchan, ctime); + plugin->execute_tree_func(depsgraph, scene, ob, pchan, ctime); } void BIK_release_tree(struct Scene *scene, Object *ob, float ctime) diff --git a/source/blender/ikplugin/intern/ikplugin_api.h b/source/blender/ikplugin/intern/ikplugin_api.h index 9a71463ede4..1c55639c33b 100644 --- a/source/blender/ikplugin/intern/ikplugin_api.h +++ b/source/blender/ikplugin/intern/ikplugin_api.h @@ -38,15 +38,15 @@ extern "C" { #endif +struct Depsgraph; struct Object; -struct bPoseChannel; struct Scene; -struct EvaluationContext; +struct bPoseChannel; struct IKPlugin { - void (*initialize_tree_func)(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, float ctime); - void (*execute_tree_func)(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime); + void (*initialize_tree_func)(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); + void (*execute_tree_func)(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime); void (*release_tree_func)(struct Scene *scene, struct Object *ob, float ctime); void (*remove_armature_func)(struct bPose *pose); void (*clear_cache)(struct bPose *pose); diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c index 5169b72590c..8ad07d85639 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.c +++ b/source/blender/ikplugin/intern/iksolver_plugin.c @@ -252,7 +252,7 @@ static void where_is_ik_bone(bPoseChannel *pchan, float ik_mat[3][3]) // nr = /* called from within the core BKE_pose_where_is loop, all animsystems and constraints * were executed & assigned. Now as last we do an IK pass */ -static void execute_posetree(const struct EvaluationContext *eval_ctx, struct Scene *scene, Object *ob, PoseTree *tree) +static void execute_posetree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, PoseTree *tree) { float R_parmat[3][3], identity[3][3]; float iR_parmat[3][3]; @@ -394,7 +394,7 @@ static void execute_posetree(const struct EvaluationContext *eval_ctx, struct Sc /* 1.0=ctime, we pass on object for auto-ik (owner-type here is object, even though * strictly speaking, it is a posechannel) */ - BKE_constraint_target_matrix_get(eval_ctx, scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); + BKE_constraint_target_matrix_get(depsgraph, scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); /* and set and transform goal */ mul_m4_m4m4(goal, goalinv, rootmat); @@ -405,7 +405,7 @@ static void execute_posetree(const struct EvaluationContext *eval_ctx, struct Sc /* same for pole vector target */ if (data->poletar) { - BKE_constraint_target_matrix_get(eval_ctx, scene, target->con, 1, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); + BKE_constraint_target_matrix_get(depsgraph, scene, target->con, 1, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0); if (data->flag & CONSTRAINT_IK_SETANGLE) { /* don't solve IK when we are setting the pole angle */ @@ -534,7 +534,7 @@ static void free_posetree(PoseTree *tree) ///---------------------------------------- /// Plugin API for legacy iksolver -void iksolver_initialize_tree(const struct EvaluationContext *UNUSED(eval_ctx), struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime)) +void iksolver_initialize_tree(struct Depsgraph *UNUSED(depsgraph), struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime)) { bPoseChannel *pchan; @@ -545,7 +545,7 @@ void iksolver_initialize_tree(const struct EvaluationContext *UNUSED(eval_ctx), ob->pose->flag &= ~POSE_WAS_REBUILT; } -void iksolver_execute_tree(const struct EvaluationContext *eval_ctx, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) +void iksolver_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) { while (pchan_root->iktree.first) { PoseTree *tree = pchan_root->iktree.first; @@ -558,13 +558,13 @@ void iksolver_execute_tree(const struct EvaluationContext *eval_ctx, struct Scen /* 4. walk over the tree for regular solving */ for (a = 0; a < tree->totchannel; a++) { if (!(tree->pchan[a]->flag & POSE_DONE)) // successive trees can set the flag - BKE_pose_where_is_bone(eval_ctx, scene, ob, tree->pchan[a], ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob, tree->pchan[a], ctime, 1); /* tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is() */ tree->pchan[a]->flag |= POSE_CHAIN; } /* 5. execute the IK solver */ - execute_posetree(eval_ctx, scene, ob, tree); + execute_posetree(depsgraph, scene, ob, tree); /* 6. apply the differences to the channels, * we need to calculate the original differences first */ diff --git a/source/blender/ikplugin/intern/iksolver_plugin.h b/source/blender/ikplugin/intern/iksolver_plugin.h index f1ca91ebb49..9925d3c45d4 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.h +++ b/source/blender/ikplugin/intern/iksolver_plugin.h @@ -41,9 +41,9 @@ extern "C" { #endif void iksolver_initialize_tree( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, float ctime); + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); void iksolver_execute_tree( - const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, + struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime); #ifdef __cplusplus diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index c74cbb252ff..dc2d081f835 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -90,7 +90,7 @@ typedef void (*ErrorCallback)(const iTaSC::ConstraintValues *values, unsigned in // one structure for each target in the scene struct IK_Target { - const struct EvaluationContext *eval_ctx; + struct Depsgraph *bldepsgraph; struct Scene *blscene; iTaSC::MovingFrame* target; iTaSC::ConstraintSet* constraint; @@ -108,7 +108,7 @@ struct IK_Target { float eeRest[4][4]; //end effector initial pose relative to armature IK_Target() { - eval_ctx = NULL; + bldepsgraph = NULL; blscene = NULL; target = NULL; constraint = NULL; @@ -159,7 +159,7 @@ struct IK_Channel { }; struct IK_Scene { - const struct EvaluationContext *eval_ctx; + struct Depsgraph *bldepsgraph; struct Scene *blscene; IK_Scene* next; int numchan; // number of channel in pchan @@ -180,7 +180,7 @@ struct IK_Scene { std::vector<IK_Target*> targets; IK_Scene() { - eval_ctx = NULL; + bldepsgraph = NULL; blscene = NULL; next = NULL; channels = NULL; @@ -554,7 +554,7 @@ static bool target_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Fram bConstraint *constraint = (bConstraint *)target->blenderConstraint; float tarmat[4][4]; - BKE_constraint_target_matrix_get(target->eval_ctx, target->blscene, constraint, 0, CONSTRAINT_OBTYPE_OBJECT, target->owner, tarmat, 1.0); + BKE_constraint_target_matrix_get(target->bldepsgraph, target->blscene, constraint, 0, CONSTRAINT_OBTYPE_OBJECT, target->owner, tarmat, 1.0); // rootmat contains the target pose in world coordinate // if enforce is != 1.0, blend the target position with the end effector position @@ -623,7 +623,7 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame& IK_Channel &rootchan = ikscene->channels[0]; // get polar target matrix in world space - BKE_constraint_target_matrix_get(ikscene->eval_ctx, ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0); + BKE_constraint_target_matrix_get(ikscene->bldepsgraph, ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0); // convert to armature space mul_m4_m4m4(polemat, imat, mat); // get the target in world space (was computed before as target object are defined before base object) @@ -867,7 +867,7 @@ static bool joint_callback(const iTaSC::Timestamp& timestamp, iTaSC::ConstraintV } // build array of joint corresponding to IK chain -static int convert_channels(const struct EvaluationContext *eval_ctx, IK_Scene *ikscene, PoseTree *tree, float ctime) +static int convert_channels(struct Depsgraph *depsgraph, IK_Scene *ikscene, PoseTree *tree, float ctime) { IK_Channel *ikchan; bPoseChannel *pchan; @@ -884,7 +884,7 @@ static int convert_channels(const struct EvaluationContext *eval_ctx, IK_Scene * // this is because some of the pose data (e.g. pose head) don't have corresponding // joint angles and can't be applied to the iTaSC armature dynamically if (!(pchan->flag & POSE_DONE)) - BKE_pose_where_is_bone(eval_ctx, ikscene->blscene, ikscene->blArmature, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, ikscene->blscene, ikscene->blArmature, pchan, ctime, 1); // tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is() pchan->flag |= (POSE_DONE | POSE_CHAIN); @@ -1060,7 +1060,7 @@ static void BKE_pose_rest(IK_Scene *ikscene) } } -static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *blscene, Object *ob, bPoseChannel *pchan, float ctime) +static IK_Scene *convert_tree(struct Depsgraph *depsgraph, Scene *blscene, Object *ob, bPoseChannel *pchan, float ctime) { PoseTree *tree = (PoseTree *)pchan->iktree.first; PoseTarget *target; @@ -1086,7 +1086,7 @@ static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *b ikscene = new IK_Scene; ikscene->blscene = blscene; - ikscene->eval_ctx = eval_ctx; + ikscene->bldepsgraph = depsgraph; arm = new iTaSC::Armature(); scene = new iTaSC::Scene(); ikscene->channels = new IK_Channel[tree->totchannel]; @@ -1139,7 +1139,7 @@ static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *b std::vector<double> weights; double weight[3]; // build the array of joints corresponding to the IK chain - convert_channels(eval_ctx, ikscene, tree, ctime); + convert_channels(depsgraph, ikscene, tree, ctime); if (ingame) { // in the GE, set the initial joint angle to match the current pose // this will update the jointArray in ikscene @@ -1444,7 +1444,7 @@ static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *b for (t = 0; t < ikscene->targets.size(); t++) { IK_Target *iktarget = ikscene->targets[t]; iktarget->blscene = blscene; - iktarget->eval_ctx = eval_ctx; + iktarget->bldepsgraph = depsgraph; condata = (bKinematicConstraint *)iktarget->blenderConstraint->data; pchan = tree->pchan[iktarget->channel]; unsigned int controltype, bonecnt; @@ -1532,7 +1532,7 @@ static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *b return ikscene; } -static void create_scene(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, float ctime) +static void create_scene(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime) { bPoseChannel *pchan; @@ -1543,7 +1543,7 @@ static void create_scene(const struct EvaluationContext *eval_ctx, Scene *scene, if (tree) { IK_Data *ikdata = get_ikdata(ob->pose); // convert tree in iTaSC::Scene - IK_Scene *ikscene = convert_tree(eval_ctx, scene, ob, pchan, ctime); + IK_Scene *ikscene = convert_tree(depsgraph, scene, ob, pchan, ctime); if (ikscene) { ikscene->next = ikdata->first; ikdata->first = ikscene; @@ -1582,7 +1582,7 @@ static int init_scene(Object *ob) return 0; } -static void execute_scene(const struct EvaluationContext *eval_ctx, Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, float ctime, float frtime) +static void execute_scene(struct Depsgraph *depsgraph, Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, float ctime, float frtime) { int i; IK_Channel *ikchan; @@ -1598,7 +1598,7 @@ static void execute_scene(const struct EvaluationContext *eval_ctx, Scene *blsce // in animation mode, we must get the bone position from action and constraints for (i = 0, ikchan = ikscene->channels; i < ikscene->numchan; i++, ++ikchan) { if (!(ikchan->pchan->flag & POSE_DONE)) - BKE_pose_where_is_bone(eval_ctx, blscene, ikscene->blArmature, ikchan->pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, blscene, ikscene->blArmature, ikchan->pchan, ctime, 1); // tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is() ikchan->pchan->flag |= (POSE_DONE | POSE_CHAIN); ikchan->jointValid = 0; @@ -1750,7 +1750,7 @@ static void execute_scene(const struct EvaluationContext *eval_ctx, Scene *blsce //--------------------------------------------------- // plugin interface // -void itasc_initialize_tree(const struct EvaluationContext *eval_ctx, struct Scene *scene, Object *ob, float ctime) +void itasc_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, float ctime) { bPoseChannel *pchan; int count = 0; @@ -1770,13 +1770,13 @@ void itasc_initialize_tree(const struct EvaluationContext *eval_ctx, struct Scen // if at least one tree, create the scenes from the PoseTree stored in the channels // postpone until execute_tree: this way the pose constraint are included if (count) - create_scene(eval_ctx, scene, ob, ctime); + create_scene(depsgraph, scene, ob, ctime); itasc_update_param(ob->pose); // make sure we don't rebuilt until the user changes something important ob->pose->flag &= ~POSE_WAS_REBUILT; } -void itasc_execute_tree(const struct EvaluationContext *eval_ctx, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) +void itasc_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) { if (ob->pose->ikdata) { IK_Data *ikdata = (IK_Data *)ob->pose->ikdata; @@ -1793,7 +1793,7 @@ void itasc_execute_tree(const struct EvaluationContext *eval_ctx, struct Scene * if (timestep > 0.2f) timestep = 0.2f; } - execute_scene(eval_ctx, scene, ikscene, ikparam, ctime, timestep); + execute_scene(depsgraph, scene, ikscene, ikparam, ctime, timestep); break; } } diff --git a/source/blender/ikplugin/intern/itasc_plugin.h b/source/blender/ikplugin/intern/itasc_plugin.h index 2f4e4036d76..0ab9a67dce4 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.h +++ b/source/blender/ikplugin/intern/itasc_plugin.h @@ -40,8 +40,8 @@ extern "C" { #endif -void itasc_initialize_tree(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, float ctime); -void itasc_execute_tree(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime); +void itasc_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime); +void itasc_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime); void itasc_release_tree(struct Scene *scene, struct Object *ob, float ctime); void itasc_clear_data(struct bPose *pose); void itasc_clear_cache(struct bPose *pose); diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp index a4281514e39..7c11fca3c34 100644 --- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp +++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp @@ -704,11 +704,12 @@ void DDSHeader::setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask { // Make sure the masks are correct. if ((rmask & gmask) || - (rmask & bmask) || - (rmask & amask) || - (gmask & bmask) || - (gmask & amask) || - (bmask & amask)) { + (rmask & bmask) || + (rmask & amask) || + (gmask & bmask) || + (gmask & amask) || + (bmask & amask)) + { printf("DDS: bad RGBA masks, pixel format not set\n"); return; } @@ -1068,7 +1069,7 @@ bool DirectDrawSurface::isTexture3D() const } else { - return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0; + return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0; } } diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index 388c2734fe9..30a0fdf4e55 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -119,7 +119,7 @@ static void info_callback(const char *msg, void *client_data) # define PIXEL_LOOPER_END \ } \ - } (void)0 \ +} (void)0 \ struct ImBuf *imb_jp2_decode(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]) { diff --git a/source/blender/makesrna/intern/rna_key.c b/source/blender/makesrna/intern/rna_key.c index a47a5c604b4..472298a3053 100644 --- a/source/blender/makesrna/intern/rna_key.c +++ b/source/blender/makesrna/intern/rna_key.c @@ -713,7 +713,7 @@ static void rna_def_keyblock(BlenderRNA *brna) prop = RNA_def_property(srna, "relative_key", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "ShapeKey"); - RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL | PROP_PTR_NO_OWNERSHIP); RNA_def_property_pointer_funcs(prop, "rna_ShapeKey_relative_key_get", "rna_ShapeKey_relative_key_set", NULL, NULL); RNA_def_property_ui_text(prop, "Relative Key", "Shape used as a relative key"); diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 077dac262b6..41970a69c6c 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -302,14 +302,8 @@ Mesh *rna_Main_meshes_new_from_object( Main *bmain, ReportList *reports, Depsgraph *depsgraph, Object *ob, int apply_modifiers, int calc_tessface, int calc_undeformed) { - EvaluationContext eval_ctx; Scene *sce = DEG_get_evaluated_scene(depsgraph); - DEG_evaluation_context_init(&eval_ctx, DEG_get_mode(depsgraph)); - eval_ctx.ctime = DEG_get_ctime(depsgraph); - eval_ctx.view_layer = DEG_get_evaluated_view_layer(depsgraph); - eval_ctx.depsgraph = depsgraph; - switch (ob->type) { case OB_FONT: case OB_CURVE: @@ -322,7 +316,7 @@ Mesh *rna_Main_meshes_new_from_object( return NULL; } - return BKE_mesh_new_from_object(&eval_ctx, bmain, sce, ob, apply_modifiers, calc_tessface, calc_undeformed); + return BKE_mesh_new_from_object(depsgraph, bmain, sce, ob, apply_modifiers, calc_tessface, calc_undeformed); } static Lamp *rna_Main_lamps_new(Main *bmain, const char *name, int type) diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index bf6e13e587c..8bc818d2658 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -376,7 +376,7 @@ static const EnumPropertyItem *rna_Material_texture_coordinates_itemf(bContext * RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_ORCO); if (ma->material_type == MA_TYPE_VOLUME) { - + /* pass */ } else if (ELEM(ma->material_type, MA_TYPE_SURFACE, MA_TYPE_HALO, MA_TYPE_WIRE)) { RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_UV); diff --git a/source/blender/makesrna/intern/rna_mesh_utils.h b/source/blender/makesrna/intern/rna_mesh_utils.h index 05274e13e1e..a85e2095121 100644 --- a/source/blender/makesrna/intern/rna_mesh_utils.h +++ b/source/blender/makesrna/intern/rna_mesh_utils.h @@ -85,7 +85,7 @@ } \ else { \ layer = NULL; \ - } \ + } \ return rna_pointer_inherit_refine(ptr, &RNA_##layer_rna_type, layer); \ } \ \ diff --git a/source/blender/makesrna/intern/rna_meta.c b/source/blender/makesrna/intern/rna_meta.c index 8589d819360..124f3a2fbe2 100644 --- a/source/blender/makesrna/intern/rna_meta.c +++ b/source/blender/makesrna/intern/rna_meta.c @@ -48,6 +48,7 @@ #include "BKE_mball.h" #include "BKE_main.h" +#include "BKE_scene.h" #include "DEG_depsgraph.h" diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 012545cb5d2..0caffb4867c 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -3144,11 +3144,6 @@ void rna_ShaderNodePointDensity_density_cache(bNode *self, return; } - EvaluationContext eval_ctx; - DEG_evaluation_context_init_from_depsgraph(&eval_ctx, - depsgraph, - DEG_get_mode(depsgraph)); - /* Make sure there's no cached data. */ BKE_texture_pointdensity_free_data(pd); RE_point_density_free(pd); @@ -3177,8 +3172,7 @@ void rna_ShaderNodePointDensity_density_cache(bNode *self, shader_point_density->cached_resolution = shader_point_density->resolution; /* Single-threaded sampling of the voxel domain. */ - RE_point_density_cache(&eval_ctx, - pd); + RE_point_density_cache(depsgraph, pd); } void rna_ShaderNodePointDensity_density_calc(bNode *self, @@ -3195,11 +3189,6 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self, return; } - EvaluationContext eval_ctx; - DEG_evaluation_context_init_from_depsgraph(&eval_ctx, - depsgraph, - DEG_get_mode(depsgraph)); - /* TODO(sergey): Will likely overflow, but how to pass size_t via RNA? */ *length = 4 * resolution * resolution * resolution; @@ -3208,10 +3197,7 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self, } /* Single-threaded sampling of the voxel domain. */ - RE_point_density_sample(&eval_ctx, - pd, - resolution, - *values); + RE_point_density_sample(depsgraph, pd, resolution, *values); /* We're done, time to clean up. */ BKE_texture_pointdensity_free_data(pd); @@ -3233,12 +3219,7 @@ void rna_ShaderNodePointDensity_density_minmax(bNode *self, return; } - EvaluationContext eval_ctx; - DEG_evaluation_context_init_from_depsgraph(&eval_ctx, - depsgraph, - DEG_get_mode(depsgraph)); - - RE_point_density_minmax(&eval_ctx, pd, r_min, r_max); + RE_point_density_minmax(depsgraph, pd, r_min, r_max); } #else diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index f50be85c446..84f3738d15d 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -908,7 +908,7 @@ static void rna_def_pose_channel(BlenderRNA *brna) prop = RNA_def_property(srna, "bbone_custom_handle_start", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "bbone_prev"); RNA_def_property_struct_type(prop, "PoseBone"); - RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_PTR_NO_OWNERSHIP); RNA_def_property_ui_text(prop, "B-Bone Start Handle", "Bone that serves as the start handle for the B-Bone curve"); RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable"); @@ -924,7 +924,7 @@ static void rna_def_pose_channel(BlenderRNA *brna) prop = RNA_def_property(srna, "bbone_custom_handle_end", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "bbone_next"); RNA_def_property_struct_type(prop, "PoseBone"); - RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_PTR_NO_OWNERSHIP); RNA_def_property_ui_text(prop, "B-Bone End Handle", "Bone that serves as the end handle for the B-Bone curve"); RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable"); diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c index d2afb43d65e..7887ea49f19 100644 --- a/source/blender/makesrna/intern/rna_scene_api.c +++ b/source/blender/makesrna/intern/rna_scene_api.c @@ -163,7 +163,7 @@ static void rna_SceneRender_get_frame_path(RenderData *rd, int frame, int previe } static void rna_Scene_ray_cast( - Scene *scene, ViewLayer *view_layer, + Scene *scene, ViewLayer *UNUSED(view_layer), float origin[3], float direction[3], float ray_dist, int *r_success, float r_location[3], float r_normal[3], int *r_index, Object **r_ob, float r_obmat[16]) @@ -171,7 +171,7 @@ static void rna_Scene_ray_cast( normalize_v3(direction); SnapObjectContext *sctx = ED_transform_snap_object_context_create( - G.main, scene, view_layer, 0); + G.main, scene, 0); bool ret = ED_transform_snap_object_project_ray_ex( sctx, diff --git a/source/blender/makesrna/intern/rna_space_api.c b/source/blender/makesrna/intern/rna_space_api.c index 822f5cbb4b6..f1206b7130f 100644 --- a/source/blender/makesrna/intern/rna_space_api.c +++ b/source/blender/makesrna/intern/rna_space_api.c @@ -39,20 +39,27 @@ static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d, bContext *C) { bScreen *sc = (bScreen *)id; - EvaluationContext eval_ctx; ScrArea *sa; ARegion *ar; - CTX_data_eval_ctx(C, &eval_ctx); - area_region_from_regiondata(sc, rv3d, &sa, &ar); if (sa && ar && sa->spacetype == SPACE_VIEW3D) { View3D *v3d = sa->spacedata.first; - Scene *scene = ED_screen_scene_find(sc, G.main->wm.first); - - ED_view3d_update_viewmat(&eval_ctx, scene, v3d, ar, NULL, NULL, NULL); + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win; + + for (win = wm->windows.first; win; win = win->next) { + if (WM_window_get_active_screen(win) == sc) { + Scene *scene = WM_window_get_active_scene(win); + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true); + + ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL); + break; + } + } } } diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index f6640704a83..37578664c4e 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -106,7 +106,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -127,7 +127,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *em, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *em, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { ArmatureModifierData *amd = (ArmatureModifierData *) md; @@ -150,7 +150,7 @@ static void deformVertsEM( } static void deformMatricesEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *em, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *em, DerivedMesh *derivedData, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts) { @@ -165,7 +165,7 @@ static void deformMatricesEM( if (!derivedData) dm->release(dm); } -static void deformMatrices(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, DerivedMesh *derivedData, +static void deformMatrices(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts) { ArmatureModifierData *amd = (ArmatureModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index f598667f96d..42e3cf94d00 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -754,7 +754,7 @@ static DerivedMesh *arrayModifier_doArray( } -static DerivedMesh *applyModifier(ModifierData *md, const EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag flag) { diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 35b8a3fd9cb..48de3507cfd 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -86,7 +86,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) /* * This calls the new bevel code (added since 2.64) */ -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), struct Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index c9d762a7fbe..16d456d1314 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -166,7 +166,7 @@ static int bm_face_isect_pair(BMFace *f, void *UNUSED(user_data)) } static DerivedMesh *applyModifier( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag flag) { diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c index 2e0b13b0603..f99fef130f8 100644 --- a/source/blender/modifiers/intern/MOD_build.c +++ b/source/blender/modifiers/intern/MOD_build.c @@ -75,7 +75,7 @@ static bool dependsOnTime(ModifierData *UNUSED(md)) return true; } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c index bf86377960a..9037e5b6d54 100644 --- a/source/blender/modifiers/intern/MOD_cast.c +++ b/source/blender/modifiers/intern/MOD_cast.c @@ -429,7 +429,7 @@ static void cuboid_do( } } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -452,7 +452,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c index 0c55d8f8beb..fd5bf1af312 100644 --- a/source/blender/modifiers/intern/MOD_cloth.c +++ b/source/blender/modifiers/intern/MOD_cloth.c @@ -69,7 +69,7 @@ static void initData(ModifierData *md) cloth_init(clmd); } -static void deformVerts(ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], +static void deformVerts(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) { DerivedMesh *dm; @@ -109,7 +109,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *eval_c CDDM_apply_vert_coords(dm, vertexCos); - clothModifier_do(clmd, eval_ctx, md->scene, ob, dm, vertexCos); + clothModifier_do(clmd, depsgraph, md->scene, ob, dm, vertexCos); dm->release(dm); } diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index d2ecbaeaafe..cc14e6a0528 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -98,7 +98,7 @@ static bool dependsOnTime(ModifierData *UNUSED(md)) return true; } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int UNUSED(numVerts), diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c index d95f0ae9286..23a78312871 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.c +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c @@ -713,7 +713,7 @@ error: static void deformVerts( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, DerivedMesh *derivedData, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) { DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false); @@ -727,7 +727,7 @@ static void deformVerts( static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *editData, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { DerivedMesh *dm = get_dm(ob, editData, derivedData, NULL, false, false); diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index acb69de1e85..2152717319f 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -111,7 +111,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Curve Modifier"); } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -126,14 +126,14 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, struct BMEditMesh *em, + ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct BMEditMesh *em, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { DerivedMesh *dm = derivedData; if (!derivedData) dm = CDDM_from_editbmesh(em, false, false); - deformVerts(md, eval_ctx, ob, dm, vertexCos, numVerts, 0); + deformVerts(md, depsgraph, ob, dm, vertexCos, numVerts, 0); if (!derivedData) dm->release(dm); } diff --git a/source/blender/modifiers/intern/MOD_datatransfer.c b/source/blender/modifiers/intern/MOD_datatransfer.c index a804a35954c..5b98c84422b 100644 --- a/source/blender/modifiers/intern/MOD_datatransfer.c +++ b/source/blender/modifiers/intern/MOD_datatransfer.c @@ -148,7 +148,7 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams)) DT_TYPE_SHARP_FACE \ ) -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, DerivedMesh *derivedData, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { DataTransferModifierData *dtmd = (DataTransferModifierData *) md; @@ -180,7 +180,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte BKE_reports_init(&reports, RPT_STORE); /* Note: no islands precision for now here. */ - BKE_object_data_transfer_dm(eval_ctx, md->scene, dtmd->ob_source, ob, dm, dtmd->data_types, false, + BKE_object_data_transfer_dm(depsgraph, md->scene, dtmd->ob_source, ob, dm, dtmd->data_types, false, dtmd->vmap_mode, dtmd->emap_mode, dtmd->lmap_mode, dtmd->pmap_mode, space_transform, false, max_dist, dtmd->map_ray_radius, 0.0f, dtmd->layers_select_src, dtmd->layers_select_dst, diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index 83dcd7b9b89..ff124ef607d 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -86,7 +86,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index 7ec89b23f25..a28c0fb8379 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -368,7 +368,7 @@ static void displaceModifier_do( } } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -384,7 +384,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *editData, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { DerivedMesh *dm = get_cddm(ob, editData, derivedData, vertexCos, dependsOnNormals(md)); diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c index 914b4101760..4335d488656 100644 --- a/source/blender/modifiers/intern/MOD_dynamicpaint.c +++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c @@ -114,7 +114,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *eval_ctx, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *dm, ModifierApplyFlag flag) { @@ -122,7 +122,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte /* dont apply dynamic paint on orco dm stack */ if (!(flag & MOD_APPLY_ORCO)) { - return dynamicPaint_Modifier_do(pmd, eval_ctx, md->scene, ob, dm); + return dynamicPaint_Modifier_do(pmd, depsgraph, md->scene, ob, dm); } return dm; } diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c b/source/blender/modifiers/intern/MOD_edgesplit.c index 0e344a851f2..655284930b7 100644 --- a/source/blender/modifiers/intern/MOD_edgesplit.c +++ b/source/blender/modifiers/intern/MOD_edgesplit.c @@ -121,7 +121,7 @@ static void copyData(ModifierData *md, ModifierData *target) modifier_copyData_generic(md, target); } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index 8483da60576..041289bf70a 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -787,7 +787,7 @@ static DerivedMesh *cutEdges(ExplodeModifierData *emd, DerivedMesh *dm) } static DerivedMesh *explodeMesh( ExplodeModifierData *emd, - ParticleSystemModifierData *psmd, const struct EvaluationContext *eval_ctx, Scene *scene, + ParticleSystemModifierData *psmd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *to_explode) { DerivedMesh *explode, *dm = to_explode; @@ -813,7 +813,7 @@ static DerivedMesh *explodeMesh( mface = dm->getTessFaceArray(dm); totpart = psmd->psys->totpart; - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = ob; sim.psys = psmd->psys; @@ -995,7 +995,7 @@ static ParticleSystemModifierData *findPrecedingParticlesystem(Object *ob, Modif } return psmd; } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *eval_ctx, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { @@ -1030,7 +1030,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte if (emd->flag & eExplodeFlag_EdgeCut) { int *facepa = emd->facepa; DerivedMesh *splitdm = cutEdges(emd, dm); - DerivedMesh *explode = explodeMesh(emd, psmd, eval_ctx, md->scene, ob, splitdm); + DerivedMesh *explode = explodeMesh(emd, psmd, depsgraph, md->scene, ob, splitdm); MEM_freeN(emd->facepa); emd->facepa = facepa; @@ -1038,7 +1038,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte return explode; } else - return explodeMesh(emd, psmd, eval_ctx, md->scene, ob, derivedData); + return explodeMesh(emd, psmd, depsgraph, md->scene, ob, derivedData); } return derivedData; } diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c index 403a8706295..4b84fa00415 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim.c +++ b/source/blender/modifiers/intern/MOD_fluidsim.c @@ -82,7 +82,7 @@ static void copyData(ModifierData *md, ModifierData *target) -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag flag) { diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index 00abcc1c65c..c7c1f92edb1 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -352,7 +352,7 @@ static void deformVerts_do(HookModifierData *hmd, Object *ob, DerivedMesh *dm, } } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, DerivedMesh *derivedData, +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) { @@ -368,7 +368,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED dm->release(dm); } -static void deformVertsEM(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *editData, +static void deformVertsEM(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { HookModifierData *hmd = (HookModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c index 72db3f1c132..c3a7e63173c 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c @@ -724,7 +724,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, DerivedMesh *derivedData, +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) { DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false); @@ -736,7 +736,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *editData, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { DerivedMesh *dm = get_dm(ob, editData, derivedData, NULL, false, false); diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c index 977b8b41cc3..5d3cfd830a0 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c @@ -506,7 +506,7 @@ static CustomDataMask required_data_mask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, DerivedMesh *derivedData, +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) { DerivedMesh *dm; @@ -524,7 +524,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *editData, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { DerivedMesh *dm; diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c index 4bf52f552ce..cff07dd1584 100644 --- a/source/blender/modifiers/intern/MOD_lattice.c +++ b/source/blender/modifiers/intern/MOD_lattice.c @@ -99,7 +99,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Lattice Modifier"); } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -115,14 +115,14 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, struct BMEditMesh *em, + ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct BMEditMesh *em, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { DerivedMesh *dm = derivedData; if (!derivedData) dm = CDDM_from_editbmesh(em, false, false); - deformVerts(md, eval_ctx, ob, dm, vertexCos, numVerts, 0); + deformVerts(md, depsgraph, ob, dm, vertexCos, numVerts, 0); if (!derivedData) dm->release(dm); } diff --git a/source/blender/modifiers/intern/MOD_mask.c b/source/blender/modifiers/intern/MOD_mask.c index 080dc371508..eb9f1f39f56 100644 --- a/source/blender/modifiers/intern/MOD_mask.c +++ b/source/blender/modifiers/intern/MOD_mask.c @@ -90,7 +90,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c index 5dfa1d874b2..43c7a044434 100644 --- a/source/blender/modifiers/intern/MOD_meshcache.c +++ b/source/blender/modifiers/intern/MOD_meshcache.c @@ -272,7 +272,7 @@ static void meshcache_do( } } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -284,7 +284,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *UNUSED(editData), + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *UNUSED(editData), DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md; diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index d7f4af8df63..27a2f94255b 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -273,7 +273,7 @@ static void meshdeform_vert_task( } static void meshdeformModifier_do( - ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, DerivedMesh *dm, + ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *dm, float (*vertexCos)[3], int numVerts) { MeshDeformModifierData *mmd = (MeshDeformModifierData *) md; @@ -300,7 +300,7 @@ static void meshdeformModifier_do( */ if (mmd->object->mode & OB_MODE_EDIT) { BMEditMesh *em = BKE_editmesh_from_object(mmd->object); - tmpdm = editbmesh_get_derived_cage_and_final(eval_ctx, md->scene, mmd->object, em, 0, &cagedm); + tmpdm = editbmesh_get_derived_cage_and_final(depsgraph, md->scene, mmd->object, em, 0, &cagedm); if (tmpdm) tmpdm->release(tmpdm); } @@ -409,7 +409,7 @@ static void meshdeformModifier_do( cagedm->release(cagedm); } -static void deformVerts(ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, +static void deformVerts(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -419,13 +419,13 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *eval_c modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */ - meshdeformModifier_do(md, eval_ctx, ob, dm, vertexCos, numVerts); + meshdeformModifier_do(md, depsgraph, ob, dm, vertexCos, numVerts); if (dm && dm != derivedData) dm->release(dm); } -static void deformVertsEM(ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, +static void deformVertsEM(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct BMEditMesh *UNUSED(editData), DerivedMesh *derivedData, float (*vertexCos)[3], @@ -433,7 +433,7 @@ static void deformVertsEM(ModifierData *md, const struct EvaluationContext *eval { DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false); - meshdeformModifier_do(md, eval_ctx, ob, dm, vertexCos, numVerts); + meshdeformModifier_do(md, depsgraph, ob, dm, vertexCos, numVerts); if (dm && dm != derivedData) dm->release(dm); diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c index 10e1cdea4ca..a1ab20a6612 100644 --- a/source/blender/modifiers/intern/MOD_meshsequencecache.c +++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c @@ -90,7 +90,7 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams)) return (mcmd->cache_file == NULL) || (mcmd->object_path[0] == '\0'); } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c index 62de2711b3d..1f51d5dba11 100644 --- a/source/blender/modifiers/intern/MOD_mirror.c +++ b/source/blender/modifiers/intern/MOD_mirror.c @@ -319,7 +319,7 @@ static DerivedMesh *mirrorModifier__doMirror(MirrorModifierData *mmd, return result; } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c index 2b675d36140..3145bef5ac0 100644 --- a/source/blender/modifiers/intern/MOD_multires.c +++ b/source/blender/modifiers/intern/MOD_multires.c @@ -67,7 +67,7 @@ static void copyData(ModifierData *md, ModifierData *target) modifier_copyData_generic(md, target); } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag flag) { MultiresModifierData *mmd = (MultiresModifierData *)md; diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c index 4fc49234468..9be23dbade6 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.c +++ b/source/blender/modifiers/intern/MOD_normal_edit.c @@ -517,7 +517,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) { return normalEditModifier_do((NormalEditModifierData *)md, ob, dm); diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index b3a7ecaa138..f495e96f635 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -555,7 +555,7 @@ static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob), } #endif /* WITH_OCEANSIM */ -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c index 7979751395a..e38c7ea715f 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.c +++ b/source/blender/modifiers/intern/MOD_particleinstance.c @@ -161,7 +161,7 @@ static int particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *psy return 0; } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *eval_ctx, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { @@ -207,7 +207,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte if (totpart == 0) return derivedData; - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = md->scene; sim.ob = pimd->ob; sim.psys = psys; diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c index 9cc6e5f56b5..4dbd7ef7849 100644 --- a/source/blender/modifiers/intern/MOD_particlesystem.c +++ b/source/blender/modifiers/intern/MOD_particlesystem.c @@ -97,7 +97,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) } /* saves the current emitter state for a particle system and calculates particles */ -static void deformVerts(ModifierData *md, const struct EvaluationContext *eval_ctx, +static void deformVerts(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int UNUSED(numVerts), @@ -186,7 +186,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *eval_c if (!(ob->transflag & OB_NO_PSYS_UPDATE)) { psmd->flag &= ~eParticleSystemFlag_psys_updated; - particle_system_update(eval_ctx, md->scene, ob, psys, (flag & MOD_APPLY_RENDER) != 0); + particle_system_update(depsgraph, md->scene, ob, psys, (flag & MOD_APPLY_RENDER) != 0); psmd->flag |= eParticleSystemFlag_psys_updated; } } diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c index c9070cced7e..67a4865f9db 100644 --- a/source/blender/modifiers/intern/MOD_remesh.c +++ b/source/blender/modifiers/intern/MOD_remesh.c @@ -143,7 +143,7 @@ static void dualcon_add_quad(void *output_v, const int vert_indices[4]) } static DerivedMesh *applyModifier(ModifierData *md, - const struct EvaluationContext *UNUSED(eval_ctx), + struct Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) @@ -205,7 +205,7 @@ static DerivedMesh *applyModifier(ModifierData *md, #else /* !WITH_MOD_REMESH */ static DerivedMesh *applyModifier(ModifierData *UNUSED(md), - const struct EvaluationContext *UNUSED(eval_ctx), + struct Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index 5f30b762275..69ac3dbfefd 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -184,7 +184,7 @@ static void copyData(ModifierData *md, ModifierData *target) modifier_copyData_generic(md, target); } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, ModifierApplyFlag flag) { diff --git a/source/blender/modifiers/intern/MOD_shapekey.c b/source/blender/modifiers/intern/MOD_shapekey.c index 822decea423..dc93474a420 100644 --- a/source/blender/modifiers/intern/MOD_shapekey.c +++ b/source/blender/modifiers/intern/MOD_shapekey.c @@ -44,7 +44,7 @@ #include "MOD_modifiertypes.h" -static void deformVerts(ModifierData *UNUSED(md), const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *UNUSED(md), struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *UNUSED(derivedData), float (*vertexCos)[3], int numVerts, @@ -61,7 +61,7 @@ static void deformVerts(ModifierData *UNUSED(md), const struct EvaluationContext } } -static void deformMatrices(ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, DerivedMesh *derivedData, +static void deformMatrices(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts) { Key *key = BKE_key_from_object(ob); @@ -80,10 +80,10 @@ static void deformMatrices(ModifierData *md, const struct EvaluationContext *eva copy_m3_m3(defMats[a], scale); } - deformVerts(md, eval_ctx, ob, derivedData, vertexCos, numVerts, 0); + deformVerts(md, depsgraph, ob, derivedData, vertexCos, numVerts, 0); } -static void deformVertsEM(ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, +static void deformVertsEM(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct BMEditMesh *UNUSED(editData), DerivedMesh *derivedData, float (*vertexCos)[3], @@ -92,10 +92,10 @@ static void deformVertsEM(ModifierData *md, const struct EvaluationContext *eval Key *key = BKE_key_from_object(ob); if (key && key->type == KEY_RELATIVE) - deformVerts(md, eval_ctx, ob, derivedData, vertexCos, numVerts, 0); + deformVerts(md, depsgraph, ob, derivedData, vertexCos, numVerts, 0); } -static void deformMatricesEM(ModifierData *UNUSED(md), const struct EvaluationContext *UNUSED(eval_ctx), +static void deformMatricesEM(ModifierData *UNUSED(md), struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *UNUSED(editData), DerivedMesh *UNUSED(derivedData), float (*vertexCos)[3], diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index cbb96b31db1..877429c4a0b 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -103,7 +103,7 @@ static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, walk(userData, ob, &smd->auxTarget, IDWALK_CB_NOP); } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -124,7 +124,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED dm->release(dm); } -static void deformVertsEM(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, +static void deformVertsEM(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c b/source/blender/modifiers/intern/MOD_simpledeform.c index 8590deb508a..5cbb602113a 100644 --- a/source/blender/modifiers/intern/MOD_simpledeform.c +++ b/source/blender/modifiers/intern/MOD_simpledeform.c @@ -383,7 +383,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -403,7 +403,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED dm->release(dm); } -static void deformVertsEM(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVertsEM(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index 4afe6ca33e2..ebf7fe9f640 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -1917,7 +1917,7 @@ static void copyData(ModifierData *md, ModifierData *target) } static DerivedMesh *applyModifier(ModifierData *md, - const struct EvaluationContext *UNUSED(eval_ctx), + struct Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) diff --git a/source/blender/modifiers/intern/MOD_smoke.c b/source/blender/modifiers/intern/MOD_smoke.c index e610ef5f78d..330e0b05cdb 100644 --- a/source/blender/modifiers/intern/MOD_smoke.c +++ b/source/blender/modifiers/intern/MOD_smoke.c @@ -102,7 +102,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static DerivedMesh *applyModifier(ModifierData *md, const EvaluationContext *eval_ctx, +static DerivedMesh *applyModifier(ModifierData *md, Depsgraph *depsgraph, Object *ob, DerivedMesh *dm, ModifierApplyFlag flag) { @@ -111,7 +111,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const EvaluationContext *eva if (flag & MOD_APPLY_ORCO) return dm; - return smokeModifier_do(smd, eval_ctx, md->scene, ob, dm); + return smokeModifier_do(smd, depsgraph, md->scene, ob, dm); } static bool dependsOnTime(ModifierData *UNUSED(md)) diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index 91c724cd1c9..346a973fa77 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -215,7 +215,7 @@ static void smoothModifier_do( MEM_freeN(uctmp); } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, DerivedMesh *derivedData, +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) { DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false); @@ -228,7 +228,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, struct BMEditMesh *editData, + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { DerivedMesh *dm = get_dm(ob, editData, derivedData, NULL, false, false); diff --git a/source/blender/modifiers/intern/MOD_softbody.c b/source/blender/modifiers/intern/MOD_softbody.c index 8d5217391af..876f56f4192 100644 --- a/source/blender/modifiers/intern/MOD_softbody.c +++ b/source/blender/modifiers/intern/MOD_softbody.c @@ -49,13 +49,13 @@ #include "MOD_modifiertypes.h" -static void deformVerts(ModifierData *md, const EvaluationContext *eval_ctx, Object *ob, +static void deformVerts(ModifierData *md, Depsgraph *depsgraph, Object *ob, DerivedMesh *UNUSED(derivedData), float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) { - sbObjectStep(eval_ctx, md->scene, ob, (float)md->scene->r.cfra, vertexCos, numVerts); + sbObjectStep(depsgraph, md->scene, ob, (float)md->scene->r.cfra, vertexCos, numVerts); } static bool dependsOnTime(ModifierData *UNUSED(md)) diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c index 5635d37f100..68cd34b348c 100644 --- a/source/blender/modifiers/intern/MOD_solidify.c +++ b/source/blender/modifiers/intern/MOD_solidify.c @@ -205,7 +205,7 @@ BLI_INLINE void madd_v3v3short_fl(float r[3], const short a[3], const float f) } static DerivedMesh *applyModifier( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index a09923d6dfe..d620fec8ede 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -98,7 +98,7 @@ static bool isDisabled(ModifierData *md, int useRenderParams) return get_render_subsurf_level(&md->scene->r, levels, useRenderParams != 0) == 0; } -static DerivedMesh *applyModifier(ModifierData *md, const EvaluationContext *eval_ctx, +static DerivedMesh *applyModifier(ModifierData *md, Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, ModifierApplyFlag flag) { @@ -135,7 +135,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const EvaluationContext *eva else if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) { modifier_setError(md, "OpenSubdiv is not supported in paint modes"); } - else if ((DEG_get_eval_flags_for_id(eval_ctx->depsgraph, &ob->id) & DAG_EVAL_NEED_CPU) == 0) { + else if ((DEG_get_eval_flags_for_id(depsgraph, &ob->id) & DAG_EVAL_NEED_CPU) == 0) { subsurf_flags |= SUBSURF_USE_GPU_BACKEND; do_cddm_convert = false; } @@ -156,14 +156,14 @@ static DerivedMesh *applyModifier(ModifierData *md, const EvaluationContext *eva #ifndef WITH_OPESUBDIV (void) do_cddm_convert; - UNUSED_VARS(eval_ctx); + UNUSED_VARS(depsgraph); #endif return result; } static DerivedMesh *applyModifierEM( - ModifierData *md, const EvaluationContext *UNUSED(eval_ctx), + ModifierData *md, Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), struct BMEditMesh *UNUSED(editData), DerivedMesh *derivedData, ModifierApplyFlag flag) diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c index bef35ccf1fe..5115572168b 100644 --- a/source/blender/modifiers/intern/MOD_surface.c +++ b/source/blender/modifiers/intern/MOD_surface.c @@ -85,7 +85,7 @@ static bool dependsOnTime(ModifierData *UNUSED(md)) return true; } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int UNUSED(numVerts), diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index 30b569207db..0d50cb40937 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -1181,7 +1181,7 @@ static void surfacedeformModifier_do( } static void deformVerts( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *UNUSED(derivedData), float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) @@ -1190,7 +1190,7 @@ static void deformVerts( } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), + ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, struct BMEditMesh *UNUSED(editData), DerivedMesh *UNUSED(derivedData), float (*vertexCos)[3], int numVerts) diff --git a/source/blender/modifiers/intern/MOD_triangulate.c b/source/blender/modifiers/intern/MOD_triangulate.c index 5dd7e3dfda4..69e6578a280 100644 --- a/source/blender/modifiers/intern/MOD_triangulate.c +++ b/source/blender/modifiers/intern/MOD_triangulate.c @@ -85,7 +85,7 @@ static void copyData(ModifierData *md, ModifierData *target) } static DerivedMesh *applyModifier(ModifierData *md, - const struct EvaluationContext *UNUSED(eval_ctx), + struct Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index 02f799fecb9..386417e092a 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -331,7 +331,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, return dm; } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_uvwarp.c b/source/blender/modifiers/intern/MOD_uvwarp.c index 8af9fd6cde4..53e7d9f8e17 100644 --- a/source/blender/modifiers/intern/MOD_uvwarp.c +++ b/source/blender/modifiers/intern/MOD_uvwarp.c @@ -146,7 +146,7 @@ static void uv_warp_compute( } } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) { diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index 204e344b8e1..06167bea3ab 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -309,7 +309,7 @@ static int warp_needs_dm(WarpModifierData *wmd) return wmd->texture || wmd->defgrp_name[0]; } -static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, DerivedMesh *derivedData, +static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag)) { DerivedMesh *dm = NULL; @@ -326,7 +326,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED } } -static void deformVertsEM(ModifierData *md, const struct EvaluationContext *eval_ctx, Object *ob, struct BMEditMesh *em, +static void deformVertsEM(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct BMEditMesh *em, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { DerivedMesh *dm = derivedData; @@ -337,7 +337,7 @@ static void deformVertsEM(ModifierData *md, const struct EvaluationContext *eval dm = CDDM_from_editbmesh(em, false, false); } - deformVerts(md, eval_ctx, ob, dm, vertexCos, numVerts, 0); + deformVerts(md, depsgraph, ob, dm, vertexCos, numVerts, 0); if (use_dm) { if (!derivedData) dm->release(dm); diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index 7921ea662a7..3126ea0139e 100644 --- a/source/blender/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -56,6 +56,7 @@ #include "MOD_util.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" static void initData(ModifierData *md) { @@ -148,7 +149,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) } static void waveModifier_do(WaveModifierData *md, - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Object *ob, DerivedMesh *dm, float (*vertexCos)[3], int numVerts) { @@ -156,7 +157,7 @@ static void waveModifier_do(WaveModifierData *md, MVert *mvert = NULL; MDeformVert *dvert; int defgrp_index; - float ctime = eval_ctx->ctime; + float ctime = DEG_get_ctime(depsgraph); float minfac = (float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow)); float lifefac = wmd->height; float (*tex_co)[3] = NULL; @@ -301,7 +302,7 @@ static void waveModifier_do(WaveModifierData *md, if (wmd->texture) MEM_freeN(tex_co); } -static void deformVerts(ModifierData *md, const struct EvaluationContext *eval_ctx, +static void deformVerts(ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts, @@ -315,14 +316,14 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *eval_c else if (wmd->texture || wmd->defgrp_name[0]) dm = get_dm(ob, NULL, dm, NULL, false, false); - waveModifier_do(wmd, eval_ctx, ob, dm, vertexCos, numVerts); + waveModifier_do(wmd, depsgraph, ob, dm, vertexCos, numVerts); if (dm != derivedData) dm->release(dm); } static void deformVertsEM( - ModifierData *md, const struct EvaluationContext *eval_ctx, + ModifierData *md, struct Depsgraph *depsgraph, Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) { @@ -334,7 +335,7 @@ static void deformVertsEM( else if (wmd->texture || wmd->defgrp_name[0]) dm = get_dm(ob, editData, dm, NULL, false, false); - waveModifier_do(wmd, eval_ctx, ob, dm, vertexCos, numVerts); + waveModifier_do(wmd, depsgraph, ob, dm, vertexCos, numVerts); if (dm != derivedData) dm->release(dm); diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index 6fdfe215c37..ba5422b929d 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -155,7 +155,7 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams)) } static DerivedMesh *applyModifier(ModifierData *md, - const struct EvaluationContext *UNUSED(eval_ctx), + struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c index 45c41498792..28f6be5d588 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.c +++ b/source/blender/modifiers/intern/MOD_weightvgmix.c @@ -201,7 +201,7 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams)) return (wmd->defgrp_name_a[0] == '\0'); } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { WeightVGMixModifierData *wmd = (WeightVGMixModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 84c5207830e..f0641365d3e 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -368,7 +368,7 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams)) return (wmd->proximity_ob_target == NULL); } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) { WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md; diff --git a/source/blender/modifiers/intern/MOD_wireframe.c b/source/blender/modifiers/intern/MOD_wireframe.c index 3cb35286114..e9b9a66cd73 100644 --- a/source/blender/modifiers/intern/MOD_wireframe.c +++ b/source/blender/modifiers/intern/MOD_wireframe.c @@ -102,7 +102,7 @@ static DerivedMesh *WireframeModifier_do(WireframeModifierData *wmd, Object *ob, } -static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx), Object *ob, +static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph), Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag)) { return WireframeModifier_do((WireframeModifierData *)md, ob, dm); diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index ec787768a57..a6ed92d139c 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -933,7 +933,7 @@ PyDoc_STRVAR(bpy_bmesh_from_object_doc, ); static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject *kw) { - /* TODO: This doesn't work currently because of eval_ctx. */ + /* TODO: This doesn't work currently because of missing depsgraph. */ #if 0 static const char *kwlist[] = {"object", "scene", "deform", "render", "cage", "face_normals", NULL}; PyObject *py_object; diff --git a/source/blender/python/intern/gpu_offscreen.c b/source/blender/python/intern/gpu_offscreen.c index 72d338bd5db..cbfc712b331 100644 --- a/source/blender/python/intern/gpu_offscreen.c +++ b/source/blender/python/intern/gpu_offscreen.c @@ -163,7 +163,7 @@ PyDoc_STRVAR(pygpu_offscreen_draw_view3d_doc, ); static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *args, PyObject *kwds) { - /* TODO: This doesn't work currently because of eval_ctx. */ + /* TODO: This doesn't work currently because of missing depsgraph. */ #if 0 static const char *kwlist[] = {"scene", "view_layer", "view3d", "region", "projection_matrix", "modelview_matrix", NULL}; diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c index 88195700a50..4119917a33f 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.c +++ b/source/blender/python/mathutils/mathutils_bvhtree.c @@ -1049,7 +1049,7 @@ static DerivedMesh *bvh_get_derived_mesh( const char *funcname, struct Scene *scene, Object *ob, bool use_deform, bool use_render, bool use_cage) { - /* TODO: This doesn't work currently because of eval_ctx. */ + /* TODO: This doesn't work currently because of missing depsgraph. */ #if 0 /* we only need minimum mesh data for topology and vertex locations */ CustomDataMask mask = CD_MASK_BAREMESH; diff --git a/source/blender/render/extern/include/RE_engine.h b/source/blender/render/extern/include/RE_engine.h index d5230f74316..8e9d005df9c 100644 --- a/source/blender/render/extern/include/RE_engine.h +++ b/source/blender/render/extern/include/RE_engine.h @@ -42,7 +42,7 @@ struct bNodeTree; struct BakePixel; struct Depsgraph; struct Depsgraph; -struct EvaluationContext; +struct Depsgraph; struct IDProperty; struct Main; struct Object; diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index c5e8443374a..802413f3580 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -39,7 +39,6 @@ struct bMovieHandle; struct bNodeTree; struct Depsgraph; -struct EvaluationContext; struct Image; struct ImageFormatData; struct Main; @@ -123,8 +122,6 @@ typedef struct RenderLayer { /* optional saved endresult on disk */ void *exrhandle; - struct EvaluationContext eval_ctx; - ListBase passes; } RenderLayer; @@ -274,7 +271,7 @@ void RE_Database_FromScene( void RE_Database_CameraOnly( struct Render *re, struct Main *bmain, struct Scene *scene, unsigned int lay, int use_camera_view); -void RE_Database_Preprocess(struct EvaluationContext *eavl_ctx, struct Render *re); +void RE_Database_Preprocess(struct Depsgraph *depsgraph, struct Render *re); void RE_Database_Free(struct Render *re); /* project dbase again, when viewplane/perspective changed */ diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index 0021687efbd..cf0ff009190 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -38,7 +38,7 @@ /* called by meshtools */ struct DerivedMesh; -struct EvaluationContext; +struct Depsgraph; struct ImagePool; struct MTex; struct Scene; @@ -56,7 +56,7 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen void RE_texture_rng_init(void); void RE_texture_rng_exit(void); -struct Material *RE_sample_material_init(const struct EvaluationContext *eval_ctx, struct Material *orig_mat, struct Scene *scene); +struct Material *RE_sample_material_init(struct Depsgraph *depsgraph, struct Material *orig_mat, struct Scene *scene); void RE_sample_material_free(struct Material *mat); void RE_sample_material_color( struct Material *mat, float color[3], float *alpha, const float volume_co[3], const float surface_co[3], @@ -69,16 +69,16 @@ void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, flo struct PointDensity; void RE_point_density_cache( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct PointDensity *pd); void RE_point_density_minmax( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct PointDensity *pd, float r_min[3], float r_max[3]); void RE_point_density_sample( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct PointDensity *pd, const int resolution, float *values); diff --git a/source/blender/render/intern/include/pointdensity.h b/source/blender/render/intern/include/pointdensity.h index f122b3dc4c1..263fa44f9c4 100644 --- a/source/blender/render/intern/include/pointdensity.h +++ b/source/blender/render/intern/include/pointdensity.h @@ -37,14 +37,14 @@ * Make point density kd-trees for all point density textures in the scene */ -struct EvaluationContext; +struct Depsgraph; struct PointDensity; struct Render; struct TexResult; void free_pointdensity(struct PointDensity *pd); -void cache_pointdensity(const struct EvaluationContext *eval_ctx, struct Render *re, struct PointDensity *pd); -void make_pointdensities(const struct EvaluationContext *eval_ctx, struct Render *re); +void cache_pointdensity(struct Depsgraph *depsgraph, struct Render *re, struct PointDensity *pd); +void make_pointdensities(struct Depsgraph *depsgraph, struct Render *re); void free_pointdensities(struct Render *re); int pointdensitytex(struct Tex *tex, const float texvec[3], struct TexResult *texres); diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h index 2c46138c7ea..9b0206fd05d 100644 --- a/source/blender/render/intern/include/render_types.h +++ b/source/blender/render/intern/include/render_types.h @@ -52,7 +52,7 @@ #include "BLI_sys_types.h" // for intptr_t support -struct EvaluationContext; +struct Depsgraph; struct Object; struct MemArena; struct VertTableNode; diff --git a/source/blender/render/intern/include/renderdatabase.h b/source/blender/render/intern/include/renderdatabase.h index 1d1af7092c8..6b2deea57d8 100644 --- a/source/blender/render/intern/include/renderdatabase.h +++ b/source/blender/render/intern/include/renderdatabase.h @@ -40,7 +40,7 @@ extern "C" { struct Object; struct VlakRen; struct VertRen; -struct EvaluationContext; +struct Depsgraph; struct HaloRen; struct Main; struct Material; @@ -165,7 +165,7 @@ void area_lamp_vectors(struct LampRen *lar); /* convertblender.c */ void init_render_world(Render *re); -void RE_Database_FromScene_Vectors(struct EvaluationContext *eval_ctx, Render *re, struct Main *bmain, struct Scene *sce, unsigned int lay); +void RE_Database_FromScene_Vectors(struct Depsgraph *depsgraph, Render *re, struct Main *bmain, struct Scene *sce, unsigned int lay); #ifdef __cplusplus } diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index c358f0388a4..67869ec541d 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -1292,7 +1292,7 @@ static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int } } } -static int render_new_particle_system(const EvaluationContext *eval_ctx, Render *re, +static int render_new_particle_system(Depsgraph *depsgraph, Render *re, ObjectRen *obr, ParticleSystem *psys, int timeoffset) { Object *ob= obr->ob; @@ -1354,7 +1354,7 @@ static int render_new_particle_system(const EvaluationContext *eval_ctx, Render if (!(psmd->modifier.mode & eModifierMode_Render)) return 0; - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = re->scene; sim.ob = ob; sim.psys = psys; @@ -2171,7 +2171,7 @@ static void displace(Render *re, ObjectRen *obr) /* Metaball */ /* ------------------------------------------------------------------------- */ -static void init_render_mball(const EvaluationContext *eval_ctx, Render *re, ObjectRen *obr) +static void init_render_mball(Depsgraph *depsgraph, Render *re, ObjectRen *obr) { Object *ob= obr->ob; DispList *dl; @@ -2197,7 +2197,7 @@ static void init_render_mball(const EvaluationContext *eval_ctx, Render *re, Obj need_orco= 1; } - BKE_displist_make_mball_forRender(eval_ctx, re->scene, ob, &dispbase); + BKE_displist_make_mball_forRender(depsgraph, re->scene, ob, &dispbase); dl= dispbase.first; if (dl == NULL) return; @@ -2564,7 +2564,7 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr, } -static void init_render_surf(const EvaluationContext *eval_ctx, Render *re, ObjectRen *obr, int timeoffset) +static void init_render_surf(Depsgraph *depsgraph, Render *re, ObjectRen *obr, int timeoffset) { Object *ob= obr->ob; Nurb *nu = NULL; @@ -2597,13 +2597,13 @@ static void init_render_surf(const EvaluationContext *eval_ctx, Render *re, Obje if (ob->parent && (ob->parent->type==OB_LATTICE)) need_orco= 1; - BKE_displist_make_surf(eval_ctx, re->scene, ob, &displist, &dm, 1, 0, 1); + BKE_displist_make_surf(depsgraph, re->scene, ob, &displist, &dm, 1, 0, 1); if (dm) { if (need_orco) { orco = get_object_orco(re, ob); if (!orco) { - orco= BKE_displist_make_orco(eval_ctx, re->scene, ob, dm, true, true); + orco= BKE_displist_make_orco(depsgraph, re->scene, ob, dm, true, true); if (orco) { set_object_orco(re, ob, orco); } @@ -2635,7 +2635,7 @@ static void init_render_surf(const EvaluationContext *eval_ctx, Render *re, Obje MEM_freeN(matar); } -static void init_render_curve(const EvaluationContext *eval_ctx, Render *re, ObjectRen *obr, int timeoffset) +static void init_render_curve(Depsgraph *depsgraph, Render *re, ObjectRen *obr, int timeoffset) { Object *ob= obr->ob; Curve *cu; @@ -2655,7 +2655,7 @@ static void init_render_curve(const EvaluationContext *eval_ctx, Render *re, Obj if (ob->type==OB_FONT && cu->str==NULL) return; else if (ob->type==OB_CURVE && cu->nurb.first==NULL) return; - BKE_displist_make_curveTypes_forRender(eval_ctx, re->scene, ob, &disp, &dm, false, true); + BKE_displist_make_curveTypes_forRender(depsgraph, re->scene, ob, &disp, &dm, false, true); dl= disp.first; if (dl==NULL) return; @@ -2682,7 +2682,7 @@ static void init_render_curve(const EvaluationContext *eval_ctx, Render *re, Obj if (need_orco) { orco = get_object_orco(re, ob); if (!orco) { - orco = BKE_displist_make_orco(eval_ctx, re->scene, ob, dm, true, true); + orco = BKE_displist_make_orco(depsgraph, re->scene, ob, dm, true, true); if (orco) { set_object_orco(re, ob, orco); } @@ -2696,7 +2696,7 @@ static void init_render_curve(const EvaluationContext *eval_ctx, Render *re, Obj if (need_orco) { orco = get_object_orco(re, ob); if (!orco) { - orco = BKE_curve_make_orco(eval_ctx, re->scene, ob, NULL); + orco = BKE_curve_make_orco(depsgraph, re->scene, ob, NULL); set_object_orco(re, ob, orco); } } @@ -3107,7 +3107,7 @@ static bool has_freestyle_edge_mark(EdgeHash *edge_hash, int v1, int v2) } #endif -static void init_render_mesh(const EvaluationContext *eval_ctx, Render *re, ObjectRen *obr, int timeoffset) +static void init_render_mesh(Depsgraph *depsgraph, Render *re, ObjectRen *obr, int timeoffset) { Object *ob= obr->ob; Mesh *me; @@ -3196,9 +3196,9 @@ static void init_render_mesh(const EvaluationContext *eval_ctx, Render *re, Obje #endif if (re->r.scemode & R_VIEWPORT_PREVIEW) - dm= mesh_create_derived_view(eval_ctx, re->scene, ob, mask); + dm= mesh_create_derived_view(depsgraph, re->scene, ob, mask); else - dm= mesh_create_derived_render(eval_ctx, re->scene, ob, mask); + dm= mesh_create_derived_render(depsgraph, re->scene, ob, mask); if (dm==NULL) return; /* in case duplicated object fails? */ mvert= dm->getVertArray(dm); @@ -4601,7 +4601,7 @@ static void set_dupli_tex_mat(Render *re, ObjectInstanceRen *obi, DupliObject *d copy_v2_v2(obi->dupliuv, dob->uv); } -static void init_render_object_data(const EvaluationContext *eval_ctx, Render *re, ObjectRen *obr, int timeoffset) +static void init_render_object_data(Depsgraph *depsgraph, Render *re, ObjectRen *obr, int timeoffset) { Object *ob= obr->ob; ParticleSystem *psys; @@ -4615,26 +4615,26 @@ static void init_render_object_data(const EvaluationContext *eval_ctx, Render *r const CustomDataMask mask = CD_MASK_RENDER_INTERNAL; if (re->r.scemode & R_VIEWPORT_PREVIEW) - dm = mesh_create_derived_view(eval_ctx, re->scene, ob, mask); + dm = mesh_create_derived_view(depsgraph, re->scene, ob, mask); else - dm = mesh_create_derived_render(eval_ctx, re->scene, ob, mask); + dm = mesh_create_derived_render(depsgraph, re->scene, ob, mask); dm->release(dm); } for (psys=ob->particlesystem.first, i=0; i<obr->psysindex-1; i++) psys= psys->next; - render_new_particle_system(eval_ctx, re, obr, psys, timeoffset); + render_new_particle_system(depsgraph, re, obr, psys, timeoffset); } else { if (ELEM(ob->type, OB_FONT, OB_CURVE)) - init_render_curve(eval_ctx, re, obr, timeoffset); + init_render_curve(depsgraph, re, obr, timeoffset); else if (ob->type==OB_SURF) - init_render_surf(eval_ctx, re, obr, timeoffset); + init_render_surf(depsgraph, re, obr, timeoffset); else if (ob->type==OB_MESH) - init_render_mesh(eval_ctx, re, obr, timeoffset); + init_render_mesh(depsgraph, re, obr, timeoffset); else if (ob->type==OB_MBALL) - init_render_mball(eval_ctx, re, obr); + init_render_mball(depsgraph, re, obr); } finalize_render_object(re, obr, timeoffset); @@ -4645,7 +4645,7 @@ static void init_render_object_data(const EvaluationContext *eval_ctx, Render *r re->totstrand += obr->totstrand; } -static void add_render_object(const EvaluationContext *eval_ctx, Render *re, Object *ob, Object *par, DupliObject *dob, +static void add_render_object(Depsgraph *depsgraph, Render *re, Object *ob, Object *par, DupliObject *dob, float omat[4][4], int timeoffset) { ObjectRen *obr; @@ -4672,7 +4672,7 @@ static void add_render_object(const EvaluationContext *eval_ctx, Render *re, Obj obr->flag |= R_INSTANCEABLE; copy_m4_m4(obr->obmat, ob->obmat); } - init_render_object_data(eval_ctx, re, obr, timeoffset); + init_render_object_data(depsgraph, re, obr, timeoffset); /* only add instance for objects that have not been used for dupli */ if (!(ob->transflag & OB_RENDER_DUPLI)) { @@ -4703,7 +4703,7 @@ static void add_render_object(const EvaluationContext *eval_ctx, Render *re, Obj } if (dob) psys->flag |= PSYS_USE_IMAT; - init_render_object_data(eval_ctx, re, obr, timeoffset); + init_render_object_data(depsgraph, re, obr, timeoffset); psys->flag &= ~PSYS_USE_IMAT; /* only add instance for objects that have not been used for dupli */ @@ -4719,7 +4719,7 @@ static void add_render_object(const EvaluationContext *eval_ctx, Render *re, Obj /* par = pointer to duplicator parent, needed for object lookup table */ /* index = when duplicater copies same object (particle), the counter */ -static void init_render_object(const EvaluationContext *eval_ctx, Render *re, Object *ob, Object *par, DupliObject *dob, +static void init_render_object(Depsgraph *depsgraph, Render *re, Object *ob, Object *par, DupliObject *dob, float omat[4][4], int timeoffset) { static double lasttime= 0.0; @@ -4729,7 +4729,7 @@ static void init_render_object(const EvaluationContext *eval_ctx, Render *re, Ob if (ob->type==OB_LAMP) add_render_lamp(re, ob); else if (render_object_type(ob->type)) - add_render_object(eval_ctx, re, ob, par, dob, omat, timeoffset); + add_render_object(depsgraph, re, ob, par, dob, omat, timeoffset); else { mul_m4_m4m4(mat, re->viewmat, ob->obmat); invert_m4_m4(ob->imat, mat); @@ -4890,7 +4890,7 @@ static int get_vector_viewlayers(Scene *UNUSED(sce)) return 0; } -static void add_group_render_dupli_obs(const EvaluationContext *eval_ctx, Render *re, Group *group, int nolamps, +static void add_group_render_dupli_obs(Depsgraph *depsgraph, Render *re, Group *group, int nolamps, int onlyselected, Object *actob, int timeoffset, int level) { /* Simple preventing of too deep nested groups. */ @@ -4903,11 +4903,11 @@ static void add_group_render_dupli_obs(const EvaluationContext *eval_ctx, Render if (ob->flag & OB_DONE) { if (ob->transflag & OB_RENDER_DUPLI) { if (allow_render_object(re, ob, nolamps, onlyselected, actob)) { - init_render_object(eval_ctx, re, ob, NULL, NULL, NULL, timeoffset); + init_render_object(depsgraph, re, ob, NULL, NULL, NULL, timeoffset); ob->transflag &= ~OB_RENDER_DUPLI; if (ob->dup_group) { - add_group_render_dupli_obs(eval_ctx, re, ob->dup_group, nolamps, onlyselected, actob, timeoffset, level+1); + add_group_render_dupli_obs(depsgraph, re, ob->dup_group, nolamps, onlyselected, actob, timeoffset, level+1); } } } @@ -4916,7 +4916,7 @@ static void add_group_render_dupli_obs(const EvaluationContext *eval_ctx, Render FOREACH_GROUP_OBJECT_END; } -static void database_init_objects(const EvaluationContext *eval_ctx, Render *re, unsigned int UNUSED(renderlay), +static void database_init_objects(Depsgraph *depsgraph, Render *re, unsigned int UNUSED(renderlay), int nolamps, int onlyselected, Object *actob, int timeoffset) { Base *base; @@ -4970,7 +4970,7 @@ static void database_init_objects(const EvaluationContext *eval_ctx, Render *re, * it still needs to create the ObjectRen containing the data */ if (ob->transflag & OB_RENDER_DUPLI) { if (allow_render_object(re, ob, nolamps, onlyselected, actob)) { - init_render_object(eval_ctx, re, ob, NULL, NULL, NULL, timeoffset); + init_render_object(depsgraph, re, ob, NULL, NULL, NULL, timeoffset); ob->transflag &= ~OB_RENDER_DUPLI; } } @@ -4984,8 +4984,8 @@ static void database_init_objects(const EvaluationContext *eval_ctx, Render *re, /* create list of duplis generated by this object, particle * system need to have render settings set for dupli particles */ - duplilist = object_duplilist(eval_ctx, re->scene, ob); - duplilist_apply_data = duplilist_apply(eval_ctx, ob, NULL, duplilist); + duplilist = object_duplilist(depsgraph, re->scene, ob); + duplilist_apply_data = duplilist_apply(depsgraph, ob, NULL, duplilist); for (dob= duplilist->first, i = 0; dob; dob= dob->next, ++i) { DupliExtraData *dob_extra = &duplilist_apply_data->extra[i]; @@ -5065,7 +5065,7 @@ static void database_init_objects(const EvaluationContext *eval_ctx, Render *re, if (obi==NULL) /* can't instance, just create the object */ - init_render_object(eval_ctx, re, obd, ob, dob, dob_extra->obmat, timeoffset); + init_render_object(depsgraph, re, obd, ob, dob, dob_extra->obmat, timeoffset); if (dob->type != OB_DUPLIGROUP) { obd->flag |= OB_DONE; @@ -5073,7 +5073,7 @@ static void database_init_objects(const EvaluationContext *eval_ctx, Render *re, } } else - init_render_object(eval_ctx, re, obd, ob, dob, dob_extra->obmat, timeoffset); + init_render_object(depsgraph, re, obd, ob, dob, dob_extra->obmat, timeoffset); if (re->test_break(re->tbh)) break; } @@ -5085,10 +5085,10 @@ static void database_init_objects(const EvaluationContext *eval_ctx, Render *re, free_object_duplilist(duplilist); if (allow_render_object(re, ob, nolamps, onlyselected, actob)) - init_render_object(eval_ctx, re, ob, NULL, NULL, NULL, timeoffset); + init_render_object(depsgraph, re, ob, NULL, NULL, NULL, timeoffset); } else if (allow_render_object(re, ob, nolamps, onlyselected, actob)) - init_render_object(eval_ctx, re, ob, NULL, NULL, NULL, timeoffset); + init_render_object(depsgraph, re, ob, NULL, NULL, NULL, timeoffset); } if (re->test_break(re->tbh)) break; @@ -5097,7 +5097,7 @@ static void database_init_objects(const EvaluationContext *eval_ctx, Render *re, /* objects in groups with OB_RENDER_DUPLI set still need to be created, * since they may not be part of the scene */ for (group= re->main->group.first; group; group=group->id.next) - add_group_render_dupli_obs(eval_ctx, re, group, nolamps, onlyselected, actob, timeoffset, 0); + add_group_render_dupli_obs(depsgraph, re, group, nolamps, onlyselected, actob, timeoffset, 0); if (!re->test_break(re->tbh)) RE_makeRenderInstances(re); @@ -5204,12 +5204,12 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l set_node_shader_lamp_loop(shade_material_loop); /* MAKE RENDER DATA */ - EvaluationContext *eval_ctx = NULL; - BLI_assert(eval_ctx); + Depsgraph *depsgraph = NULL; + BLI_assert(depsgraph); /* This will break things, and it should because honestly this function is deprecated and no one uses it. * maybe freestyle? But even so, this need to change. Even freestyle need to get data from depsgraph * so we can't create the database only once. */ - database_init_objects(eval_ctx, re, lay, 0, 0, NULL, 0); + database_init_objects(depsgraph, re, lay, 0, 0, NULL, 0); if (!re->test_break(re->tbh)) { set_material_lightgroups(re); @@ -5224,7 +5224,7 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l } } -void RE_Database_Preprocess(EvaluationContext *eval_ctx, Render *re) +void RE_Database_Preprocess(Depsgraph *depsgraph, Render *re) { if (!re->test_break(re->tbh)) { int tothalo; @@ -5254,7 +5254,7 @@ void RE_Database_Preprocess(EvaluationContext *eval_ctx, Render *re) /* point density texture */ if (!re->test_break(re->tbh)) - make_pointdensities(eval_ctx, re); + make_pointdensities(depsgraph, re); /* voxel data texture */ if (!re->test_break(re->tbh)) make_voxeldata(re); @@ -5325,7 +5325,7 @@ void RE_DataBase_GetView(Render *re, float mat[4][4]) /* Speed Vectors */ /* ------------------------------------------------------------------------- */ -static void database_fromscene_vectors(EvaluationContext *eval_ctx, +static void database_fromscene_vectors(Depsgraph *depsgraph, Render *re, Scene *scene, unsigned int lay, @@ -5346,7 +5346,7 @@ static void database_fromscene_vectors(EvaluationContext *eval_ctx, /* applies changes fully */ scene->r.cfra += timeoffset; - BKE_scene_graph_update_for_newframe(eval_ctx->depsgraph, re->main); + BKE_scene_graph_update_for_newframe(depsgraph, re->main); /* if no camera, viewmat should have been set! */ if (camera) { @@ -5357,7 +5357,7 @@ static void database_fromscene_vectors(EvaluationContext *eval_ctx, } /* MAKE RENDER DATA */ - database_init_objects(eval_ctx, re, lay, 0, 0, NULL, timeoffset); + database_init_objects(depsgraph, re, lay, 0, 0, NULL, timeoffset); if (!re->test_break(re->tbh)) project_renderdata(re, projectverto, (re->r.mode & R_PANORAMA) != 0, 0, 1); @@ -5714,7 +5714,7 @@ static void free_dbase_object_vectors(ListBase *lb) BLI_freelistN(lb); } -void RE_Database_FromScene_Vectors(EvaluationContext *eval_ctx, Render *re, Main *bmain, Scene *sce, unsigned int lay) +void RE_Database_FromScene_Vectors(Depsgraph *depsgraph, Render *re, Main *bmain, Scene *sce, unsigned int lay) { ObjectInstanceRen *obi, *oldobi; StrandSurface *mesh; @@ -5729,7 +5729,7 @@ void RE_Database_FromScene_Vectors(EvaluationContext *eval_ctx, Render *re, Main speedvector_project(re, NULL, NULL, NULL); /* initializes projection code */ /* creates entire dbase */ - database_fromscene_vectors(eval_ctx, re, sce, lay, -1); + database_fromscene_vectors(depsgraph, re, sce, lay, -1); /* copy away vertex info */ copy_dbase_object_vectors(re, &oldtable); @@ -5745,7 +5745,7 @@ void RE_Database_FromScene_Vectors(EvaluationContext *eval_ctx, Render *re, Main /* creates entire dbase */ re->i.infostr = IFACE_("Calculating next frame vectors"); - database_fromscene_vectors(eval_ctx, re, sce, lay, +1); + database_fromscene_vectors(depsgraph, re, sce, lay, +1); } /* copy away vertex info */ copy_dbase_object_vectors(re, &newtable); @@ -5759,7 +5759,7 @@ void RE_Database_FromScene_Vectors(EvaluationContext *eval_ctx, Render *re, Main if (!re->test_break(re->tbh)) { RE_Database_FromScene(re, bmain, sce, lay, 1); - RE_Database_Preprocess(eval_ctx, re); + RE_Database_Preprocess(depsgraph, re); } if (!re->test_break(re->tbh)) { @@ -5872,9 +5872,7 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, ViewLayer *view_l RE_init_threadcount(re); - EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); Depsgraph *depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER); - DEG_evaluation_context_init_from_view_layer_for_render(eval_ctx, depsgraph, scene, view_layer); DEG_graph_build_from_view_layer(depsgraph, bmain, scene, view_layer); BKE_scene_graph_update_tagged(depsgraph, bmain); @@ -5948,7 +5946,7 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, ViewLayer *view_l set_node_shader_lamp_loop(shade_material_loop); /* MAKE RENDER DATA */ - database_init_objects(eval_ctx, re, lay, nolamps, onlyselected, actob, 0); + database_init_objects(depsgraph, re, lay, nolamps, onlyselected, actob, 0); set_material_lightgroups(re); @@ -5964,7 +5962,7 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, ViewLayer *view_l /* point density texture */ if (!re->test_break(re->tbh)) - make_pointdensities(eval_ctx, re); + make_pointdensities(depsgraph, re); /* voxel data texture */ if (!re->test_break(re->tbh)) diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 9ad9c653e54..c42f85ef017 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -867,7 +867,7 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, } eEvaluationMode mode = (re->r.scemode & R_VIEWPORT_PREVIEW) ? DAG_EVAL_PREVIEW : DAG_EVAL_RENDER; - /* If we had a consistent EvaluationContext now would be the time to update it. */ + /* This mode should have been set in the Depsgraph immediately when it was created. */ (void)mode; /* ensure renderdatabase can use part settings correct */ @@ -2733,11 +2733,10 @@ static void do_render_seq(Render *re) tot_views = BKE_scene_multiview_num_views_get(&re->r); ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * tot_views, "Sequencer Views ImBufs"); - EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER); BKE_sequencer_new_render_data( - eval_ctx, re->main, re->scene, - re_x, re_y, 100, + re->main, re->scene, + re_x, re_y, 100, true, &context); /* the renderresult gets destroyed during the rendering, so we first collect all ibufs @@ -2758,8 +2757,6 @@ static void do_render_seq(Render *re) } } - DEG_evaluation_context_free(eval_ctx); - rr = re->result; BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE); diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index bba422345e0..6d0cd52544b 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -170,7 +170,7 @@ static void alloc_point_data(PointDensity *pd) } } -static void pointdensity_cache_psys(const EvaluationContext *eval_ctx, Scene *scene, +static void pointdensity_cache_psys(Depsgraph *depsgraph, Scene *scene, PointDensity *pd, Object *ob, ParticleSystem *psys, @@ -196,12 +196,12 @@ static void pointdensity_cache_psys(const EvaluationContext *eval_ctx, Scene *sc data_used = point_data_used(pd); if (use_render_params) { - dm = mesh_create_derived_render(eval_ctx, scene, + dm = mesh_create_derived_render(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL); } else { - dm = mesh_get_derived_final(eval_ctx, scene, + dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL); } @@ -210,7 +210,7 @@ static void pointdensity_cache_psys(const EvaluationContext *eval_ctx, Scene *sc return; } - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = ob; sim.psys = psys; @@ -391,7 +391,7 @@ static void pointdensity_cache_vertex_normal(PointDensity *pd, Object *UNUSED(ob } } -static void pointdensity_cache_object(const EvaluationContext *eval_ctx, Scene *scene, +static void pointdensity_cache_object(Depsgraph *depsgraph, Scene *scene, PointDensity *pd, Object *ob, const bool use_render_params) @@ -412,10 +412,10 @@ static void pointdensity_cache_object(const EvaluationContext *eval_ctx, Scene * } if (use_render_params) { - dm = mesh_create_derived_render(eval_ctx, scene, ob, mask); + dm = mesh_create_derived_render(depsgraph, scene, ob, mask); } else { - dm = mesh_get_derived_final(eval_ctx, scene, ob, mask); + dm = mesh_get_derived_final(depsgraph, scene, ob, mask); } mvert = dm->getVertArray(dm); /* local object space */ @@ -466,7 +466,7 @@ static void pointdensity_cache_object(const EvaluationContext *eval_ctx, Scene * } -static void cache_pointdensity_ex(const EvaluationContext *eval_ctx, +static void cache_pointdensity_ex(Depsgraph *depsgraph, Scene *scene, PointDensity *pd, const bool use_render_params) @@ -493,7 +493,7 @@ static void cache_pointdensity_ex(const EvaluationContext *eval_ctx, return; } - pointdensity_cache_psys(eval_ctx, + pointdensity_cache_psys(depsgraph, scene, pd, ob, @@ -503,13 +503,13 @@ static void cache_pointdensity_ex(const EvaluationContext *eval_ctx, else if (pd->source == TEX_PD_OBJECT) { Object *ob = pd->object; if (ob && ob->type == OB_MESH) - pointdensity_cache_object(eval_ctx, scene, pd, ob, use_render_params); + pointdensity_cache_object(depsgraph, scene, pd, ob, use_render_params); } } -void cache_pointdensity(const EvaluationContext *eval_ctx, Render *re, PointDensity *pd) +void cache_pointdensity(Depsgraph *depsgraph, Render *re, PointDensity *pd) { - cache_pointdensity_ex(eval_ctx, + cache_pointdensity_ex(depsgraph, re->scene, pd, true); @@ -533,7 +533,7 @@ void free_pointdensity(PointDensity *pd) pd->totpoints = 0; } -void make_pointdensities(const EvaluationContext *eval_ctx, Render *re) +void make_pointdensities(Depsgraph *depsgraph, Render *re) { Tex *tex; @@ -546,7 +546,7 @@ void make_pointdensities(const EvaluationContext *eval_ctx, Render *re) for (tex = re->main->tex.first; tex != NULL; tex = tex->id.next) { if (tex->id.us && tex->type == TEX_POINTDENSITY) { - cache_pointdensity(eval_ctx, re, tex->pd); + cache_pointdensity(depsgraph, re, tex->pd); } } @@ -863,7 +863,7 @@ static void sample_dummy_point_density(int resolution, float *values) memset(values, 0, sizeof(float) * 4 * resolution * resolution * resolution); } -static void particle_system_minmax(const EvaluationContext *eval_ctx, +static void particle_system_minmax(Depsgraph *depsgraph, Scene *scene, Object *object, ParticleSystem *psys, @@ -887,7 +887,7 @@ static void particle_system_minmax(const EvaluationContext *eval_ctx, unit_m4(mat); - sim.eval_ctx = eval_ctx; + sim.depsgraph = depsgraph; sim.scene = scene; sim.ob = object; sim.psys = psys; @@ -918,26 +918,24 @@ static void particle_system_minmax(const EvaluationContext *eval_ctx, } void RE_point_density_cache( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, PointDensity *pd) { - const bool use_render_params = (eval_ctx->mode == DAG_EVAL_RENDER); + const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); - Depsgraph *depsgraph = eval_ctx->depsgraph; Scene *scene = DEG_get_evaluated_scene(depsgraph); /* Same matricies/resolution as dupli_render_particle_set(). */ BLI_mutex_lock(&sample_mutex); - cache_pointdensity_ex(eval_ctx, scene, pd, use_render_params); + cache_pointdensity_ex(depsgraph, scene, pd, use_render_params); BLI_mutex_unlock(&sample_mutex); } void RE_point_density_minmax( - const struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct PointDensity *pd, float r_min[3], float r_max[3]) { - Depsgraph *depsgraph = eval_ctx->depsgraph; Scene *scene = DEG_get_evaluated_scene(depsgraph); Object *object = pd->object; if (object == NULL) { @@ -960,7 +958,7 @@ void RE_point_density_minmax( return; } - particle_system_minmax(eval_ctx, + particle_system_minmax(depsgraph, scene, object, psys, @@ -1032,7 +1030,7 @@ static void point_density_sample_func( * NOTE 2: Frees point density structure after sampling. */ void RE_point_density_sample( - const EvaluationContext *eval_ctx, + Depsgraph *depsgraph, PointDensity *pd, const int resolution, float *values) @@ -1050,7 +1048,7 @@ void RE_point_density_sample( } BLI_mutex_lock(&sample_mutex); - RE_point_density_minmax(eval_ctx, + RE_point_density_minmax(depsgraph, pd, min, max); diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index cefa739a796..929fc3cc9c3 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -3745,7 +3745,7 @@ static void textured_face_generate_uv( } /* Generate an updated copy of material to use for color sampling. */ -Material *RE_sample_material_init(const EvaluationContext *eval_ctx, Material *orig_mat, Scene *scene) +Material *RE_sample_material_init(Depsgraph *depsgraph, Material *orig_mat, Scene *scene) { Tex *tex = NULL; Material *mat; @@ -3821,7 +3821,7 @@ Material *RE_sample_material_init(const EvaluationContext *eval_ctx, Material *o unit_m4(dummy_re.viewmat); unit_m4(dummy_re.winmat); dummy_re.winx = dummy_re.winy = 128; - cache_pointdensity(eval_ctx, &dummy_re, tex->pd); + cache_pointdensity(depsgraph, &dummy_re, tex->pd); } /* update image sequences and movies */ diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index c2d5c060530..f3e391672a9 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -970,18 +970,18 @@ static void add_to_diffuse(float diff[3], const ShadeInput *shi, const float is, /* input */ switch (ma->rampin_col) { - case MA_RAMP_IN_ENERGY: - fac = IMB_colormanagement_get_luminance(rgb); - break; - case MA_RAMP_IN_SHADER: - fac = is; - break; - case MA_RAMP_IN_NOR: - fac = dot_v3v3(shi->view, shi->vn); - break; - default: - fac = 0.0f; - break; + case MA_RAMP_IN_ENERGY: + fac = IMB_colormanagement_get_luminance(rgb); + break; + case MA_RAMP_IN_SHADER: + fac = is; + break; + case MA_RAMP_IN_NOR: + fac = dot_v3v3(shi->view, shi->vn); + break; + default: + fac = 0.0f; + break; } BKE_colorband_evaluate(ma->ramp_col, fac, col); diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index ed276aa690d..c650bfe08c9 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -135,7 +135,7 @@ static bool wm_area_test_invalid_backbuf(ScrArea *sa) return true; } -static void wm_region_test_render_do_draw(const Scene *scene, const struct Depsgraph *depsgraph, +static void wm_region_test_render_do_draw(const Scene *scene, struct Depsgraph *depsgraph, ScrArea *sa, ARegion *ar) { /* tag region for redraw from render engine preview running inside of it */ diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 6591a8c9f59..9dcb83244ca 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1025,10 +1025,6 @@ static ImBuf *blend_file_thumb(const bContext *C, Scene *scene, ViewLayer *view_ ARegion *ar = NULL; View3D *v3d = NULL; - EvaluationContext eval_ctx; - - CTX_data_eval_ctx(C, &eval_ctx); - /* In case we are given a valid thumbnail data, just generate image from it. */ if (*thumb_pt) { thumb = *thumb_pt; @@ -1052,18 +1048,19 @@ static ImBuf *blend_file_thumb(const bContext *C, Scene *scene, ViewLayer *view_ } /* gets scaled to BLEN_THUMB_SIZE */ + Depsgraph *depsgraph = CTX_data_depsgraph(C); RenderEngineType *engine_type = CTX_data_engine_type(C); if (scene->camera) { ibuf = ED_view3d_draw_offscreen_imbuf_simple( - &eval_ctx, scene, view_layer, engine_type, scene->camera, + depsgraph, scene, view_layer, engine_type, scene->camera, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, IB_rect, V3D_OFSDRAW_NONE, OB_SOLID, R_ALPHAPREMUL, 0, NULL, NULL, err_out); } else { ibuf = ED_view3d_draw_offscreen_imbuf( - &eval_ctx, scene, view_layer, engine_type, v3d, ar, + depsgraph, scene, view_layer, engine_type, v3d, ar, BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2, IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL, NULL, err_out); diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c index d774c4e4a2e..d032cb79edc 100644 --- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c +++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c @@ -487,7 +487,6 @@ static int manipulator_find_intersected_3d_intern( ListBase *visible_manipulators, const bContext *C, const int co[2], const int hotspot) { - EvaluationContext eval_ctx; ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); View3D *v3d = sa->spacedata.first; @@ -499,9 +498,7 @@ static int manipulator_find_intersected_3d_intern( BLI_rcti_init_pt_radius(&rect, co, hotspot); - CTX_data_eval_ctx(C, &eval_ctx); - - ED_view3d_draw_setup_view(CTX_wm_window(C), &eval_ctx, CTX_data_scene(C), ar, v3d, NULL, NULL, &rect); + ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, &rect); if (do_passes) GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, GPU_SELECT_NEAREST_FIRST_PASS, 0); @@ -518,7 +515,7 @@ static int manipulator_find_intersected_3d_intern( GPU_select_end(); } - ED_view3d_draw_setup_view(CTX_wm_window(C), &eval_ctx, CTX_data_scene(C), ar, v3d, NULL, NULL, NULL); + ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, NULL); const GLuint *hit_near = GPU_select_buffer_near(buffer, hits); diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c index 78d895e3779..b35fb30af66 100644 --- a/source/blenderplayer/bad_level_call_stubs/stubs.c +++ b/source/blenderplayer/bad_level_call_stubs/stubs.c @@ -278,7 +278,7 @@ int multitex_ext(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], i int multitex_ext_safe(struct Tex *tex, float texvec[3], struct TexResult *texres, struct ImagePool *pool, bool scene_color_manage, const bool skip_load_image) RET_ZERO int multitex_nodes(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, const short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex, struct ImagePool *pool) RET_ZERO -struct Material *RE_sample_material_init(const struct EvaluationContext *eval_ctx, struct Material *orig_mat, struct Scene *scene) RET_NULL +struct Material *RE_sample_material_init(struct Depsgraph *depsgraph, struct Material *orig_mat, struct Scene *scene) RET_NULL void RE_sample_material_free(struct Material *mat) RET_NONE void RE_sample_material_color( struct Material *mat, float color[3], float *alpha, const float volume_co[3], const float surface_co[3], @@ -483,7 +483,7 @@ char *ED_fsmenu_entry_get_name(struct FSMenuEntry *fsentry) RET_NULL void ED_fsmenu_entry_set_name(struct FSMenuEntry *fsentry, const char *name) RET_NONE struct PTCacheEdit *PE_get_current(struct Scene *scene, struct Object *ob) RET_NULL -void PE_current_changed(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob) RET_NONE +void PE_current_changed(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob) RET_NONE /* rna keymap */ struct wmKeyMap *WM_keymap_active(struct wmWindowManager *wm, struct wmKeyMap *keymap) RET_NULL @@ -547,7 +547,7 @@ void ED_node_tree_pop(struct SpaceNode *snode) RET_NONE int ED_view3d_view_layer_set(int lay, const int *values, int *active) RET_ZERO void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip) RET_NONE void ED_view3d_from_m4(float mat[4][4], float ofs[3], float quat[4], float *dist) RET_NONE -void ED_view3d_update_viewmat(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct View3D *v3d, struct ARegion *ar, float viewmat[4][4], float winmat[4][4], const struct rcti *rect) RET_NONE +void ED_view3d_update_viewmat(struct Depsgraph *depsgraph, struct Scene *scene, struct View3D *v3d, struct ARegion *ar, float viewmat[4][4], float winmat[4][4], const struct rcti *rect) RET_NONE float ED_view3d_grid_scale(struct Scene *scene, struct View3D *v3d, const char **grid_unit) RET_ZERO void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrArea *sa) RET_NONE void ED_node_shader_default(const struct bContext *C, struct ID *id) RET_NONE @@ -617,9 +617,9 @@ bool ED_texture_context_check_others(const struct bContext *C) RET_ZERO bool ED_text_region_location_from_cursor(SpaceText *st, ARegion *ar, const int cursor_co[2], int r_pixel_co[2]) RET_ZERO SnapObjectContext *ED_transform_snap_object_context_create( - struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, int flag) RET_NULL + struct Main *bmain, struct Scene *scene, int flag) RET_NULL SnapObjectContext *ED_transform_snap_object_context_create_view3d( - struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, int flag, + struct Main *bmain, struct Scene *scene, int flag, const struct ARegion *ar, const struct View3D *v3d) RET_NULL void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx) RET_NONE bool ED_transform_snap_object_project_ray_ex( @@ -765,9 +765,9 @@ void RE_engine_update_memory_stats(struct RenderEngine *engine, float mem_used, struct RenderEngine *RE_engine_create(struct RenderEngineType *type) RET_NULL void RE_engine_frame_set(struct RenderEngine *engine, int frame, float subframe) RET_NONE void RE_FreePersistentData(void) RET_NONE -void RE_point_density_cache(const struct EvaluationContext *eval_ctx, struct PointDensity *pd) RET_NONE -void RE_point_density_minmax(const struct EvaluationContext *eval_ctx, struct PointDensity *pd, float r_min[3], float r_max[3]) RET_NONE -void RE_point_density_sample(const struct EvaluationContext *eval_ctx, struct PointDensity *pd, const int resolution, float *values) RET_NONE +void RE_point_density_cache(struct Depsgraph *depsgraph, struct PointDensity *pd) RET_NONE +void RE_point_density_minmax(struct Depsgraph *depsgraph, struct PointDensity *pd, float r_min[3], float r_max[3]) RET_NONE +void RE_point_density_sample(struct Depsgraph *depsgraph, struct PointDensity *pd, const int resolution, float *values) RET_NONE void RE_point_density_free(struct PointDensity *pd) RET_NONE void RE_instance_get_particle_info(struct ObjectInstanceRen *obi, float *index, float *random, float *age, float *lifetime, float co[3], float *size, float vel[3], float angvel[3]) RET_NONE void RE_FreeAllPersistentData(void) RET_NONE diff --git a/source/tools b/source/tools -Subproject 7695e14cfc5820ac66546e0e515914d85ab81af +Subproject f35d8e55afffb9da50cc13b14615ed280f9e558 |