diff --git a/panda/src/pgraph/billboardEffect.I b/panda/src/pgraph/billboardEffect.I index d94d8135f7..b6ee6f31b0 100644 --- a/panda/src/pgraph/billboardEffect.I +++ b/panda/src/pgraph/billboardEffect.I @@ -86,6 +86,15 @@ get_axial_rotate() const { return _axial_rotate; } +/** + * Returns true if this billboard always appears at a fixed distance from the + * camera. + */ +INLINE bool BillboardEffect:: +get_fixed_depth() const { + return _fixed_depth; +} + /** * Returns the distance toward the camera (or the look_at_point) the billboard * is moved towards, after rotating. This can be used to ensure the billboard diff --git a/panda/src/pgraph/billboardEffect.cxx b/panda/src/pgraph/billboardEffect.cxx index c5843bb667..60c6e72c97 100644 --- a/panda/src/pgraph/billboardEffect.cxx +++ b/panda/src/pgraph/billboardEffect.cxx @@ -29,7 +29,7 @@ TypeHandle BillboardEffect::_type_handle; CPT(RenderEffect) BillboardEffect:: make(const LVector3 &up_vector, bool eye_relative, bool axial_rotate, PN_stdfloat offset, const NodePath &look_at, - const LPoint3 &look_at_point) { + const LPoint3 &look_at_point, bool fixed_depth) { BillboardEffect *effect = new BillboardEffect; effect->_up_vector = up_vector; effect->_eye_relative = eye_relative; @@ -37,6 +37,7 @@ make(const LVector3 &up_vector, bool eye_relative, effect->_offset = offset; effect->_look_at = look_at; effect->_look_at_point = look_at_point; + effect->_fixed_depth = fixed_depth; effect->_off = false; return return_new(effect); } @@ -82,7 +83,9 @@ output(std::ostream &out) const { if (_eye_relative) { out << " eye"; } - if (_offset != 0.0f) { + if (_fixed_depth) { + out << " depth " << -_offset; + } else if (_offset != 0.0f) { out << " offset " << _offset; } if (!_look_at.is_empty()) { @@ -201,6 +204,9 @@ compare_to_impl(const RenderEffect *other) const { if (_eye_relative != ta->_eye_relative) { return (int)_eye_relative - (int)ta->_eye_relative; } + if (_fixed_depth != ta->_fixed_depth) { + return (int)_fixed_depth - (int)ta->_fixed_depth; + } if (_offset != ta->_offset) { return _offset < ta->_offset ? -1 : 1; } @@ -274,11 +280,17 @@ compute_billboard(CPT(TransformState) &node_transform, // Also slide the billboard geometry towards the camera according to the // offset factor. - if (_offset != 0.0f) { + if (_offset != 0.0f || _fixed_depth) { LVector3 translate(rel_mat(3, 0), rel_mat(3, 1), rel_mat(3, 2)); + LPoint3 pos; + if (_fixed_depth) { + pos = translate / rel_mat(3, 3); + } else { + pos.fill(0.0f); + } translate.normalize(); translate *= _offset; - rotate.set_row(3, translate); + rotate.set_row(3, pos + translate); } node_transform = translate->compose(TransformState::make_mat(rotate))->compose(node_transform); @@ -307,7 +319,25 @@ write_datagram(BamWriter *manager, Datagram &dg) { dg.add_stdfloat(_offset); _look_at_point.write_datagram(dg); - // *** We don't write out the _look_at NodePath right now. Maybe we should. + if (manager->get_file_minor_ver() >= 43) { + _look_at.write_datagram(manager, dg); + dg.add_bool(_fixed_depth); + } +} + +/** + * Receives an array of pointers, one for each time manager->read_pointer() + * was called in fillin(). Returns the number of pointers processed. + */ +int BillboardEffect:: +complete_pointers(TypedWritable **p_list, BamReader *manager) { + int pi = RenderEffect::complete_pointers(p_list, manager); + + if (manager->get_file_minor_ver() >= 43) { + pi += _look_at.complete_pointers(p_list + pi, manager); + } + + return pi; } /** @@ -341,4 +371,9 @@ fillin(DatagramIterator &scan, BamReader *manager) { _axial_rotate = scan.get_bool(); _offset = scan.get_stdfloat(); _look_at_point.read_datagram(scan); + + if (manager->get_file_minor_ver() >= 43) { + _look_at.fillin(scan, manager); + _fixed_depth = scan.get_stdfloat(); + } } diff --git a/panda/src/pgraph/billboardEffect.h b/panda/src/pgraph/billboardEffect.h index f83ecc5323..d080cec0d4 100644 --- a/panda/src/pgraph/billboardEffect.h +++ b/panda/src/pgraph/billboardEffect.h @@ -34,7 +34,8 @@ PUBLISHED: bool axial_rotate, PN_stdfloat offset, const NodePath &look_at, - const LPoint3 &look_at_point); + const LPoint3 &look_at_point, + bool fixed_depth = false); INLINE static CPT(RenderEffect) make_axis(); INLINE static CPT(RenderEffect) make_point_eye(); INLINE static CPT(RenderEffect) make_point_world(); @@ -43,6 +44,7 @@ PUBLISHED: INLINE const LVector3 &get_up_vector() const; INLINE bool get_eye_relative() const; INLINE bool get_axial_rotate() const; + INLINE bool get_fixed_depth() const; INLINE PN_stdfloat get_offset() const; INLINE const NodePath &get_look_at() const; INLINE const LPoint3 &get_look_at_point() const; @@ -72,9 +74,10 @@ private: private: bool _off; - LVector3 _up_vector; bool _eye_relative; bool _axial_rotate; + bool _fixed_depth; + LVector3 _up_vector; PN_stdfloat _offset; NodePath _look_at; LPoint3 _look_at_point; @@ -82,6 +85,8 @@ private: public: static void register_with_read_factory(); virtual void write_datagram(BamWriter *manager, Datagram &dg); + virtual int complete_pointers(TypedWritable **plist, + BamReader *manager); protected: static TypedWritable *make_from_bam(const FactoryParams ¶ms); diff --git a/panda/src/pgraph/compassEffect.cxx b/panda/src/pgraph/compassEffect.cxx index 41bd9af880..fe39b03bf3 100644 --- a/panda/src/pgraph/compassEffect.cxx +++ b/panda/src/pgraph/compassEffect.cxx @@ -284,8 +284,25 @@ void CompassEffect:: write_datagram(BamWriter *manager, Datagram &dg) { RenderEffect::write_datagram(manager, dg); dg.add_uint16(_properties); - // *** We don't write out the _reference NodePath right now. Maybe we - // should. + + if (manager->get_file_minor_ver() >= 43) { + _reference.write_datagram(manager, dg); + } +} + +/** + * Receives an array of pointers, one for each time manager->read_pointer() + * was called in fillin(). Returns the number of pointers processed. + */ +int CompassEffect:: +complete_pointers(TypedWritable **p_list, BamReader *manager) { + int pi = RenderEffect::complete_pointers(p_list, manager); + + if (manager->get_file_minor_ver() >= 43) { + pi += _reference.complete_pointers(p_list + pi, manager); + } + + return pi; } /** @@ -313,4 +330,8 @@ void CompassEffect:: fillin(DatagramIterator &scan, BamReader *manager) { RenderEffect::fillin(scan, manager); _properties = scan.get_uint16(); + + if (manager->get_file_minor_ver() >= 43) { + _reference.fillin(scan, manager); + } } diff --git a/panda/src/pgraph/compassEffect.h b/panda/src/pgraph/compassEffect.h index adba81f9e6..a8aada7a59 100644 --- a/panda/src/pgraph/compassEffect.h +++ b/panda/src/pgraph/compassEffect.h @@ -90,6 +90,8 @@ private: public: static void register_with_read_factory(); virtual void write_datagram(BamWriter *manager, Datagram &dg); + virtual int complete_pointers(TypedWritable **plist, + BamReader *manager); protected: static TypedWritable *make_from_bam(const FactoryParams ¶ms); diff --git a/panda/src/pgraph/nodePath.I b/panda/src/pgraph/nodePath.I index 5b7e80f7b7..8ca3153da5 100644 --- a/panda/src/pgraph/nodePath.I +++ b/panda/src/pgraph/nodePath.I @@ -1752,7 +1752,7 @@ set_billboard_axis(PN_stdfloat offset) { * the camera. */ INLINE void NodePath:: -set_billboard_point_eye(PN_stdfloat offset) { +set_billboard_point_eye(PN_stdfloat offset, bool fixed_depth) { set_billboard_point_eye(NodePath(), offset); } diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index 0f2639bccc..9d473304b6 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -4744,11 +4744,11 @@ set_billboard_axis(const NodePath &camera, PN_stdfloat offset) { * the camera, towards a specified "camera" instead of to the viewing camera. */ void NodePath:: -set_billboard_point_eye(const NodePath &camera, PN_stdfloat offset) { +set_billboard_point_eye(const NodePath &camera, PN_stdfloat offset, bool fixed_depth) { nassertv_always(!is_empty()); CPT(RenderEffect) billboard = BillboardEffect::make (LVector3::up(), true, false, - offset, camera, LPoint3(0.0f, 0.0f, 0.0f)); + offset, camera, LPoint3(0.0f, 0.0f, 0.0f), fixed_depth); node()->set_effect(billboard); } diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index cf159972c5..9c047c0728 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -815,10 +815,10 @@ PUBLISHED: void do_billboard_point_eye(const NodePath &camera, PN_stdfloat offset); void do_billboard_point_world(const NodePath &camera, PN_stdfloat offset); INLINE void set_billboard_axis(PN_stdfloat offset = 0.0); - INLINE void set_billboard_point_eye(PN_stdfloat offset = 0.0); + INLINE void set_billboard_point_eye(PN_stdfloat offset = 0.0, bool fixed_depth = false); INLINE void set_billboard_point_world(PN_stdfloat offset = 0.0); void set_billboard_axis(const NodePath &camera, PN_stdfloat offset); - void set_billboard_point_eye(const NodePath &camera, PN_stdfloat offset); + void set_billboard_point_eye(const NodePath &camera, PN_stdfloat offset, bool fixed_depth = false); void set_billboard_point_world(const NodePath &camera, PN_stdfloat offset); void clear_billboard(); bool has_billboard() const; diff --git a/panda/src/putil/bam.h b/panda/src/putil/bam.h index ad7d000fd2..96f41cbf98 100644 --- a/panda/src/putil/bam.h +++ b/panda/src/putil/bam.h @@ -32,7 +32,7 @@ static const unsigned short _bam_major_ver = 6; // Bumped to major version 6 on 2006-02-11 to factor out PandaNode::CData. static const unsigned short _bam_first_minor_ver = 14; -static const unsigned short _bam_minor_ver = 42; +static const unsigned short _bam_minor_ver = 43; // Bumped to minor version 14 on 2007-12-19 to change default ColorAttrib. // Bumped to minor version 15 on 2008-04-09 to add TextureAttrib::_implicit_sort. // Bumped to minor version 16 on 2008-05-13 to add Texture::_quality_level. @@ -62,5 +62,6 @@ static const unsigned short _bam_minor_ver = 42; // Bumped to minor version 40 on 2016-01-11 to make NodePaths writable. // Bumped to minor version 41 on 2016-03-02 to change LensNode, Lens, and Camera. // Bumped to minor version 42 on 2016-04-08 to expand ColorBlendAttrib. +// Bumped to minor version 43 on 2018-12-06 to expand BillboardEffect and CompassEffect. #endif