Add optional "other" NodePath argument for get_tight_bounds()

This commit is contained in:
rdb 2015-07-06 14:52:08 +02:00
parent d43482ec9b
commit 214d799d82
4 changed files with 21 additions and 7 deletions

View File

@ -6191,20 +6191,32 @@ write_bounds(ostream &out) const {
// than the bounding volume returned by get_bounds() // than the bounding volume returned by get_bounds()
// (but it is more expensive to compute). // (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 // The return value is true if any points are within the
// bounding volume, or false if none are. // bounding volume, or false if none are.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool NodePath:: bool NodePath::
calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, 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); min_point.set(0.0f, 0.0f, 0.0f);
max_point.set(0.0f, 0.0f, 0.0f); max_point.set(0.0f, 0.0f, 0.0f);
nassertr_always(!is_empty(), false); 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; bool found_any = false;
node()->calc_tight_bounds(min_point, max_point, found_any, node()->calc_tight_bounds(min_point, max_point, found_any,
TransformState::make_identity(), MOVE(transform), current_thread);
current_thread);
return found_any; return found_any;
} }

View File

@ -876,9 +876,10 @@ PUBLISHED:
void force_recompute_bounds(); void force_recompute_bounds();
void write_bounds(ostream &out) const; void write_bounds(ostream &out) const;
bool calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, bool calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
const NodePath &other = NodePath(),
Thread *current_thread = Thread::get_current_thread()) const; 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; // void analyze() const;

View File

@ -240,14 +240,15 @@ py_decode_NodePath_from_bam_stream_persist(PyObject *unpickler, const string &da
// objects. This is a convenience function for Python // objects. This is a convenience function for Python
// users, among which the use of calc_tight_bounds // users, among which the use of calc_tight_bounds
// may be confusing. // may be confusing.
//
// Returns None if calc_tight_bounds returned false. // Returns None if calc_tight_bounds returned false.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PyObject *Extension<NodePath>:: PyObject *Extension<NodePath>::
get_tight_bounds() const { get_tight_bounds(const NodePath &other) const {
LPoint3 *min_point = new LPoint3; LPoint3 *min_point = new LPoint3;
LPoint3 *max_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 #ifdef STDFLOAT_DOUBLE
PyObject *min_inst = DTool_CreatePyInstance((void*) min_point, Dtool_LPoint3d, true, false); PyObject *min_inst = DTool_CreatePyInstance((void*) min_point, Dtool_LPoint3d, true, false);
PyObject *max_inst = DTool_CreatePyInstance((void*) max_point, Dtool_LPoint3d, true, false); PyObject *max_inst = DTool_CreatePyInstance((void*) max_point, Dtool_LPoint3d, true, false);

View File

@ -48,7 +48,7 @@ public:
INLINE bool has_net_python_tag(const string &key) const; INLINE bool has_net_python_tag(const string &key) const;
NodePath find_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 BEGIN_PUBLISH