diff --git a/panda/src/chan/auto_bind.cxx b/panda/src/chan/auto_bind.cxx index c7086cf8cb..b3312c9a79 100644 --- a/panda/src/chan/auto_bind.cxx +++ b/panda/src/chan/auto_bind.cxx @@ -14,6 +14,7 @@ #include #include #include +#include typedef set AnimNodes; typedef map Anims; @@ -78,8 +79,20 @@ bind_anims(const PartNodes &parts, const AnimNodes &anims, PT(AnimControl) control = part->bind_anim(anim, hierarchy_match_flags); + string name = anim->get_name(); if (control != (AnimControl *)NULL) { - controls.store_anim(control, anim->get_name()); + if (controls.find_anim(name) != (AnimControl *)NULL) { + // That name's already used; synthesize another one. + int index = 0; + string new_name; + do { + index++; + new_name = name + '.' + format_string(index); + } while (controls.find_anim(new_name) != (AnimControl *)NULL); + name = new_name; + } + + controls.store_anim(control, name); } if (chan_cat.is_info()) { @@ -89,7 +102,8 @@ bind_anims(const PartNodes &parts, const AnimNodes &anims, } else { chan_cat.info() << "Bind succeeded, index " - << control->get_channel_index() << "\n"; + << control->get_channel_index() << "; accessible as " + << name << "\n"; } } } @@ -132,8 +146,11 @@ void auto_bind(Node *root_node, AnimControlCollection &controls, // But here we have (at least one) match! bind_anims((*pi).second, (*ai).second, controls, hierarchy_match_flags); - ++ai; ++pi; + + // We don't increment the anim counter yet. That way, the same + // anim may bind to multiple parts, if they all share the same + // name. } } } diff --git a/panda/src/sgattrib/colorProperty.cxx b/panda/src/sgattrib/colorProperty.cxx index 76d24ae6f9..dfb4fca5ed 100644 --- a/panda/src/sgattrib/colorProperty.cxx +++ b/panda/src/sgattrib/colorProperty.cxx @@ -4,6 +4,8 @@ //////////////////////////////////////////////////////////////////// #include "colorProperty.h" +#include +#include //////////////////////////////////////////////////////////////////// // Function: ColorProperty::output @@ -18,3 +20,27 @@ output(ostream &out) const { out << "uncolor"; } } + +//////////////////////////////////////////////////////////////////// +// Function: ColorProperty::write_datagram +// Access: Public +// Description: Function to write the important information in +// this object to a Datagram +//////////////////////////////////////////////////////////////////// +void ColorProperty:: +write_datagram(Datagram &destination) { + _color.write_datagram(destination); + destination.add_bool(_real); +} + +//////////////////////////////////////////////////////////////////// +// Function: ColorProperty::read_datagram +// Access: Public +// Description: Function to write the important information into +// this object out of a Datagram +//////////////////////////////////////////////////////////////////// +void ColorProperty:: +read_datagram(DatagramIterator &source) { + _color.read_datagram(source); + _real = source.get_bool(); +} diff --git a/panda/src/sgattrib/colorProperty.h b/panda/src/sgattrib/colorProperty.h index 462949201d..a3ff17ddbe 100644 --- a/panda/src/sgattrib/colorProperty.h +++ b/panda/src/sgattrib/colorProperty.h @@ -10,6 +10,9 @@ #include +class Datagram; +class DatagramIterator; + //////////////////////////////////////////////////////////////////// // Class : ColorProperty // Description : This class defines the scene graph color property @@ -33,6 +36,10 @@ public: INLINE int compare_to(const ColorProperty &other) const; void output(ostream &out) const; +public: + void write_datagram(Datagram &destination); + void read_datagram(DatagramIterator &source); + private: Colorf _color; bool _real; diff --git a/panda/src/sgattrib/colorTransition.cxx b/panda/src/sgattrib/colorTransition.cxx index 1ba4298ffc..343e3620ec 100644 --- a/panda/src/sgattrib/colorTransition.cxx +++ b/panda/src/sgattrib/colorTransition.cxx @@ -7,6 +7,10 @@ #include "colorAttribute.h" #include +#include +#include +#include +#include TypeHandle ColorTransition::_type_handle; @@ -78,3 +82,55 @@ void ColorTransition:: write_value(ostream &out, int indent_level) const { indent(out, indent_level) << _value << "\n"; } + +//////////////////////////////////////////////////////////////////// +// Function: ColorTransition::register_with_read_factory +// Access: Public, Static +// Description: Factory method to generate a ColorTransition object +//////////////////////////////////////////////////////////////////// +void ColorTransition:: +register_with_read_factory() { + BamReader::get_factory()->register_factory(get_class_type(), make_ColorTransition); +} + +//////////////////////////////////////////////////////////////////// +// Function: ColorTransition::write_datagram +// Access: Public +// Description: Function to write the important information in +// the particular object to a Datagram +//////////////////////////////////////////////////////////////////// +void ColorTransition:: +write_datagram(BamWriter *manager, Datagram &me) { + OnOffTransition::write_datagram(manager, me); + _value.write_datagram(me); +} + +//////////////////////////////////////////////////////////////////// +// Function: ColorTransition::make_ColorTransition +// Access: Protected +// Description: Factory method to generate a ColorTransition object +//////////////////////////////////////////////////////////////////// +TypedWritable *ColorTransition:: +make_ColorTransition(const FactoryParams ¶ms) { + ColorTransition *me = new ColorTransition; + DatagramIterator scan; + BamReader *manager; + + parse_params(params, scan, manager); + me->fillin(scan, manager); + return me; +} + +//////////////////////////////////////////////////////////////////// +// Function: ColorTransition::fillin +// Access: Protected +// Description: Function that reads out of the datagram (or asks +// manager to read) all of the data that is needed to +// re-create this object and stores it in the appropiate +// place +//////////////////////////////////////////////////////////////////// +void ColorTransition:: +fillin(DatagramIterator& scan, BamReader* manager) { + OnOffTransition::fillin(scan, manager); + _value.read_datagram(scan); +} diff --git a/panda/src/sgattrib/colorTransition.h b/panda/src/sgattrib/colorTransition.h index dfb0080464..3cc8eba136 100644 --- a/panda/src/sgattrib/colorTransition.h +++ b/panda/src/sgattrib/colorTransition.h @@ -49,6 +49,14 @@ protected: ColorProperty _value; +public: + static void register_with_read_factory(); + virtual void write_datagram(BamWriter *manager, Datagram &me); + +protected: + static TypedWritable *make_ColorTransition(const FactoryParams ¶ms); + void fillin(DatagramIterator& scan, BamReader* manager); + public: virtual TypeHandle get_type() const { return get_class_type(); diff --git a/panda/src/sgattrib/config_sgattrib.cxx b/panda/src/sgattrib/config_sgattrib.cxx index ab7d15013b..50f6202199 100644 --- a/panda/src/sgattrib/config_sgattrib.cxx +++ b/panda/src/sgattrib/config_sgattrib.cxx @@ -188,6 +188,7 @@ ConfigureFn(config_sgattrib) { //functions with BamReader's factory BillboardTransition::register_with_read_factory(); ColorMatrixTransition::register_with_read_factory(); + ColorTransition::register_with_read_factory(); CullFaceTransition::register_with_read_factory(); DecalTransition::register_with_read_factory(); DepthTestTransition::register_with_read_factory();