From 7b6d2864597e63853c8229f6ccfae1a79f2bd48a Mon Sep 17 00:00:00 2001 From: Almaz Shinbay Date: Tue, 30 May 2023 22:32:04 +0500 Subject: [PATCH 1/2] Outliner: Port mesh elements to new tree-element code design Adds new tree-element class for the mesh-ID. Signed-off-by: Almaz Shinbay --- .../editors/space_outliner/CMakeLists.txt | 2 + .../editors/space_outliner/outliner_tree.cc | 16 +------ .../space_outliner/tree/tree_element_id.cc | 4 +- .../tree/tree_element_id_mesh.cc | 48 +++++++++++++++++++ .../tree/tree_element_id_mesh.hh | 27 +++++++++++ 5 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 source/blender/editors/space_outliner/tree/tree_element_id_mesh.cc create mode 100644 source/blender/editors/space_outliner/tree/tree_element_id_mesh.hh diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt index 78163b13fcb..7ab9582775c 100644 --- a/source/blender/editors/space_outliner/CMakeLists.txt +++ b/source/blender/editors/space_outliner/CMakeLists.txt @@ -56,6 +56,7 @@ set(SRC tree/tree_element_gpencil_layer.cc tree/tree_element_id.cc tree/tree_element_id_library.cc + tree/tree_element_id_mesh.cc tree/tree_element_id_scene.cc tree/tree_element_label.cc tree/tree_element_nla.cc @@ -76,6 +77,7 @@ set(SRC tree/tree_element_gpencil_layer.hh tree/tree_element_id.hh tree/tree_element_id_library.hh + tree/tree_element_id_mesh.hh tree/tree_element_id_scene.hh tree/tree_element_label.hh tree/tree_element_nla.hh diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc index c98fdfdfe92..66db3ad5d63 100644 --- a/source/blender/editors/space_outliner/outliner_tree.cc +++ b/source/blender/editors/space_outliner/outliner_tree.cc @@ -550,27 +550,13 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner, switch (GS(id->name)) { case ID_LI: case ID_SCE: + case ID_ME: BLI_assert_msg(0, "ID type expected to be expanded through new tree-element design"); break; case ID_OB: { outliner_add_object_contents(space_outliner, te, tselem, (Object *)id); break; } - case ID_ME: { - Mesh *me = (Mesh *)id; - - if (outliner_animdata_test(me->adt)) { - outliner_add_element(space_outliner, &te->subtree, me, te, TSE_ANIM_DATA, 0); - } - - outliner_add_element(space_outliner, &te->subtree, me->key, te, TSE_SOME_ID, 0); - for (int a = 0; a < me->totcol; a++) { - outliner_add_element(space_outliner, &te->subtree, me->mat[a], te, TSE_SOME_ID, a); - } - /* could do tfaces with image links, but the images are not grouped nicely. - * would require going over all tfaces, sort images in use. etc... */ - break; - } case ID_CU_LEGACY: { Curve *cu = (Curve *)id; diff --git a/source/blender/editors/space_outliner/tree/tree_element_id.cc b/source/blender/editors/space_outliner/tree/tree_element_id.cc index d4f6865fb75..f5cff0cb9aa 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_id.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_id.cc @@ -19,6 +19,7 @@ #include "../outliner_intern.hh" #include "common.hh" #include "tree_element_id_library.hh" +#include "tree_element_id_mesh.hh" #include "tree_element_id_scene.hh" #include "tree_element_id.hh" @@ -37,8 +38,9 @@ std::unique_ptr TreeElementID::createFromID(TreeElement &legacy_t return std::make_unique(legacy_te, (Library &)id); case ID_SCE: return std::make_unique(legacy_te, (Scene &)id); - case ID_OB: case ID_ME: + return std::make_unique(legacy_te, (Mesh &)id); + case ID_OB: case ID_CU_LEGACY: case ID_MB: case ID_MA: diff --git a/source/blender/editors/space_outliner/tree/tree_element_id_mesh.cc b/source/blender/editors/space_outliner/tree/tree_element_id_mesh.cc new file mode 100644 index 00000000000..fb21b72dacd --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_id_mesh.cc @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#include "DNA_listBase.h" +#include "DNA_mesh_types.h" +#include "DNA_outliner_types.h" + +#include "../outliner_intern.hh" + +#include "tree_element_id_mesh.hh" + +namespace blender::ed::outliner { + +TreeElementIDMesh::TreeElementIDMesh(TreeElement &legacy_te_, Mesh &mesh) +: TreeElementID(legacy_te_, mesh.id), mesh_(mesh) +{ +} + +bool TreeElementIDMesh::isExpandValid() const +{ + return true; +} + +void TreeElementIDMesh::expand(SpaceOutliner &space_outliner) const +{ + expand_animation_data(space_outliner, mesh_.adt); + + expandKey(space_outliner); + expandMaterials(space_outliner); +} + +void TreeElementIDMesh::expandKey(SpaceOutliner &space_outliner) const +{ + outliner_add_element(&space_outliner, &legacy_te_.subtree, mesh_.key, &legacy_te_, TSE_SOME_ID, 0); +} + +void TreeElementIDMesh::expandMaterials(SpaceOutliner &space_outliner) const +{ + for (int a = 0; a < mesh_.totcol; a++) + { + outliner_add_element(&space_outliner, &legacy_te_.subtree, mesh_.mat[a], &legacy_te_, TSE_SOME_ID, a); + } +} + +} // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_id_mesh.hh b/source/blender/editors/space_outliner/tree/tree_element_id_mesh.hh new file mode 100644 index 00000000000..a0342bd25db --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_id_mesh.hh @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#pragma once + +#include "tree_element_id.hh" + +namespace blender::ed::outliner { + +class TreeElementIDMesh final : public TreeElementID { + Mesh &mesh_; + + public: + TreeElementIDMesh(TreeElement &legacy_te_, Mesh &mesh); + + void expand(SpaceOutliner &) const override; + bool isExpandValid() const override; + + private: + void expandKey(SpaceOutliner &) const; + void expandMaterials(SpaceOutliner &) const; +}; + +} // namespace blender::ed::outliner -- 2.30.2 From 83b1d399c45d99b483011c006c1cbe0bb4815278 Mon Sep 17 00:00:00 2001 From: Almaz Shinbay Date: Wed, 31 May 2023 20:56:34 +0500 Subject: [PATCH 2/2] Run clang-format to remove formatting errors --- .../space_outliner/tree/tree_element_id_mesh.cc | 15 ++++++++------- .../space_outliner/tree/tree_element_id_mesh.hh | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/space_outliner/tree/tree_element_id_mesh.cc b/source/blender/editors/space_outliner/tree/tree_element_id_mesh.cc index fb21b72dacd..a0d1e40d757 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_id_mesh.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_id_mesh.cc @@ -15,7 +15,7 @@ namespace blender::ed::outliner { TreeElementIDMesh::TreeElementIDMesh(TreeElement &legacy_te_, Mesh &mesh) -: TreeElementID(legacy_te_, mesh.id), mesh_(mesh) + : TreeElementID(legacy_te_, mesh.id), mesh_(mesh) { } @@ -27,22 +27,23 @@ bool TreeElementIDMesh::isExpandValid() const void TreeElementIDMesh::expand(SpaceOutliner &space_outliner) const { expand_animation_data(space_outliner, mesh_.adt); - + expandKey(space_outliner); expandMaterials(space_outliner); } void TreeElementIDMesh::expandKey(SpaceOutliner &space_outliner) const { - outliner_add_element(&space_outliner, &legacy_te_.subtree, mesh_.key, &legacy_te_, TSE_SOME_ID, 0); + outliner_add_element( + &space_outliner, &legacy_te_.subtree, mesh_.key, &legacy_te_, TSE_SOME_ID, 0); } void TreeElementIDMesh::expandMaterials(SpaceOutliner &space_outliner) const { - for (int a = 0; a < mesh_.totcol; a++) - { - outliner_add_element(&space_outliner, &legacy_te_.subtree, mesh_.mat[a], &legacy_te_, TSE_SOME_ID, a); + for (int a = 0; a < mesh_.totcol; a++) { + outliner_add_element( + &space_outliner, &legacy_te_.subtree, mesh_.mat[a], &legacy_te_, TSE_SOME_ID, a); } } -} // namespace blender::ed::outliner +} // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_id_mesh.hh b/source/blender/editors/space_outliner/tree/tree_element_id_mesh.hh index a0342bd25db..d3f99982db0 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_id_mesh.hh +++ b/source/blender/editors/space_outliner/tree/tree_element_id_mesh.hh @@ -12,16 +12,16 @@ namespace blender::ed::outliner { class TreeElementIDMesh final : public TreeElementID { Mesh &mesh_; - + public: TreeElementIDMesh(TreeElement &legacy_te_, Mesh &mesh); - + void expand(SpaceOutliner &) const override; bool isExpandValid() const override; - + private: void expandKey(SpaceOutliner &) const; void expandMaterials(SpaceOutliner &) const; }; -} // namespace blender::ed::outliner +} // namespace blender::ed::outliner -- 2.30.2