diff --git a/src/esp/bindings/SceneBindings.cpp b/src/esp/bindings/SceneBindings.cpp index 8869853cce..d2ed3b7467 100644 --- a/src/esp/bindings/SceneBindings.cpp +++ b/src/esp/bindings/SceneBindings.cpp @@ -54,6 +54,14 @@ void initSceneBindings(py::module& m) { .def_property("type", &SceneNode::getType, &SceneNode::setType) .def_property("semantic_id", &SceneNode::getSemanticId, &SceneNode::setSemanticId) + .def_property( + "object_semantic_id", &SceneNode::getBaseObjectId, + &SceneNode::setBaseObjectId, + R"(This node's owning object's ID, for instance-based semantics)") + .def_property( + "drawable_semantic_id", &SceneNode::getDrawableId, + &SceneNode::setDrawableId, + R"(This node's drawable's ID, for instance-based semantics)") .def( "create_child", [](SceneNode& self) { return &self.createChild(); }, R"(Creates a child node, and sets its parent to the current node.)") diff --git a/src/esp/scene/SceneNode.cpp b/src/esp/scene/SceneNode.cpp index 1e0617e412..2a0af71c71 100644 --- a/src/esp/scene/SceneNode.cpp +++ b/src/esp/scene/SceneNode.cpp @@ -2,8 +2,10 @@ // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. -#include "SceneNode.h" +#include + #include "SceneGraph.h" +#include "SceneNode.h" #include "esp/core/Check.h" #include "esp/geo/Geo.h" #include "esp/sensor/Sensor.h" @@ -239,6 +241,14 @@ const Mn::Range3D& SceneNode::getAbsoluteAABB() const { } } +void SceneNode::setSemanticIDVector(const std::vector& _semanticIDs) { + if (semanticIDs_.size() < _semanticIDs.size()) { + semanticIDs_.resize(_semanticIDs.size()); + } + std::copy(std::begin(_semanticIDs), std::end(_semanticIDs), + std::begin(semanticIDs_)); +} + void setSemanticIdForSubtree(SceneNode* node, int semanticId) { if (node->getSemanticId() == semanticId) { // We assume the entire subtree's semanticId matches the root's, so we can @@ -253,5 +263,17 @@ void setSemanticIdForSubtree(SceneNode* node, int semanticId) { preOrderTraversalWithCallback(*node, cb); } +void setSemanticInfoForSubtree(SceneNode* node, + const std::vector& _semanticIDs) { + if (node->getSemanticIDVector() == _semanticIDs) { + // We assume the entire subtree's semantic/instance ID vector matches the + // root's, so we can early out here. + return; + } + + auto cb = [&](SceneNode& node) { node.setSemanticIDVector(_semanticIDs); }; + preOrderTraversalWithCallback(*node, cb); +} + } // namespace scene } // namespace esp diff --git a/src/esp/scene/SceneNode.h b/src/esp/scene/SceneNode.h index be86d6a3bc..6623fcf1db 100644 --- a/src/esp/scene/SceneNode.h +++ b/src/esp/scene/SceneNode.h @@ -165,14 +165,24 @@ class SceneNode : public MagnumObject, semanticId; } + //! Gets node's owning objectID, for panoptic rendering. + virtual int getBaseObjectId() const { + return semanticIDs_[static_cast(SceneNodeSemanticDataIDX::OBJECT_ID)]; + } + //! Sets node's owning objectID, for panoptic rendering. - virtual void setBaseObjectId(int objectId) { + void setBaseObjectId(int objectId) { semanticIDs_[static_cast(SceneNodeSemanticDataIDX::OBJECT_ID)] = objectId; } + //! Gets node's corresponding drawable's id, for panoptic rendering. + virtual int getDrawableId() const { + return semanticIDs_[static_cast( + SceneNodeSemanticDataIDX::DRAWABLE_ID)]; + } //! Sets node's corresponding drawable's id, for panoptic rendering. - virtual void setDrawableId(int drawableId) { + void setDrawableId(int drawableId) { semanticIDs_[static_cast(SceneNodeSemanticDataIDX::DRAWABLE_ID)] = drawableId; } @@ -182,7 +192,7 @@ class SceneNode : public MagnumObject, * @param idToGetIDX The index of the ID to get * @return the semantic value corresponding to the given index */ - virtual int getShaderObjectID(int idToGetIDX) const { + int getShaderObjectID(int idToGetIDX) const { return semanticIDs_[idToGetIDX]; } @@ -191,6 +201,17 @@ class SceneNode : public MagnumObject, * scene node. */ const std::vector& getSemanticIDVector() const { return semanticIDs_; } + + /** + * @brief Set the value for the various semantic IDs to be rendered by this + * scene node. As values are added, we want to make sure we support shorter, + * older vectors. + * @param _semanticIDs The vector of semantic sensor IDs this scene node will + * use for rendering. This vector might not be the same size as the current + * vector. + */ + void setSemanticIDVector(const std::vector& _semanticIDs); + Magnum::Vector3 absoluteTranslation() const; Magnum::Vector3 absoluteTranslation(); @@ -408,6 +429,15 @@ void preOrderFeatureTraversalWithCallback(SceneNode& node, Callable&& cb) { */ void setSemanticIdForSubtree(SceneNode* node, int semanticId); +/** + * @brief Set the semantic and instance IDs of a scene graph subtree. + * + * @param node Root node of the subtree. + * @param semanticIDs Vector of semantic and instance ids to set + */ +void setSemanticInfoForSubtree(SceneNode* node, + const std::vector& _semanticIDs); + CORRADE_ENUMSET_OPERATORS(SceneNodeTags) } // namespace scene } // namespace esp