diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index 828179f603..20a2f90ab4 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -6191,20 +6191,32 @@ write_bounds(ostream &out) const { // than the bounding volume returned by get_bounds() // (but it is more expensive to compute). // +// The bounding box is computed relative to the parent +// node's coordinate system by default. You can +// optionally specify a different NodePath to compute +// the bounds relative to. Note that the box is always +// axis-aligned against the given NodePath's coordinate +// system, so you might get a differently sized box +// depending on which node you pass. +// // The return value is true if any points are within the // bounding volume, or false if none are. //////////////////////////////////////////////////////////////////// bool NodePath:: calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, - Thread *current_thread) const { + const NodePath &other, Thread *current_thread) const { min_point.set(0.0f, 0.0f, 0.0f); max_point.set(0.0f, 0.0f, 0.0f); nassertr_always(!is_empty(), false); + CPT(TransformState) transform = TransformState::make_identity(); + if (!other.is_empty()) { + transform = get_transform(other)->compose(get_transform()->get_inverse()); + } + bool found_any = false; node()->calc_tight_bounds(min_point, max_point, found_any, - TransformState::make_identity(), - current_thread); + MOVE(transform), current_thread); return found_any; } diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index 68a5196550..4e7a098601 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -876,9 +876,10 @@ PUBLISHED: void force_recompute_bounds(); void write_bounds(ostream &out) const; bool calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, + const NodePath &other = NodePath(), Thread *current_thread = Thread::get_current_thread()) const; - EXTENSION(PyObject *get_tight_bounds() const); + EXTENSION(PyObject *get_tight_bounds(const NodePath &other = NodePath()) const); // void analyze() const; diff --git a/panda/src/pgraph/nodePath_ext.cxx b/panda/src/pgraph/nodePath_ext.cxx index b5cc7dbd51..d38164d3ba 100644 --- a/panda/src/pgraph/nodePath_ext.cxx +++ b/panda/src/pgraph/nodePath_ext.cxx @@ -240,14 +240,15 @@ py_decode_NodePath_from_bam_stream_persist(PyObject *unpickler, const string &da // objects. This is a convenience function for Python // users, among which the use of calc_tight_bounds // may be confusing. +// // Returns None if calc_tight_bounds returned false. //////////////////////////////////////////////////////////////////// PyObject *Extension:: -get_tight_bounds() const { +get_tight_bounds(const NodePath &other) const { LPoint3 *min_point = new LPoint3; LPoint3 *max_point = new LPoint3; - if (_this->calc_tight_bounds(*min_point, *max_point)) { + if (_this->calc_tight_bounds(*min_point, *max_point, other)) { #ifdef STDFLOAT_DOUBLE PyObject *min_inst = DTool_CreatePyInstance((void*) min_point, Dtool_LPoint3d, true, false); PyObject *max_inst = DTool_CreatePyInstance((void*) max_point, Dtool_LPoint3d, true, false); diff --git a/panda/src/pgraph/nodePath_ext.h b/panda/src/pgraph/nodePath_ext.h index 00983a9de1..67afe2a383 100644 --- a/panda/src/pgraph/nodePath_ext.h +++ b/panda/src/pgraph/nodePath_ext.h @@ -48,7 +48,7 @@ public: INLINE bool has_net_python_tag(const string &key) const; NodePath find_net_python_tag(const string &key) const; - PyObject *get_tight_bounds() const; + PyObject *get_tight_bounds(const NodePath &other = NodePath()) const; }; BEGIN_PUBLISH