| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- /**
- * PANDA 3D SOFTWARE
- * Copyright (c) Carnegie Mellon University. All rights reserved.
- *
- * All use of this software is subject to the terms of the revised BSD
- * license. You should have received a copy of this license along
- * with this source code in a file named "LICENSE."
- *
- * @file eggComponentData.cxx
- * @author drose
- * @date 2001-02-26
- */
- #include "eggComponentData.h"
- #include "eggBackPointer.h"
- #include "nameUniquifier.h"
- #include "indent.h"
- TypeHandle EggComponentData::_type_handle;
- /**
- *
- */
- EggComponentData::
- EggComponentData(EggCharacterCollection *collection,
- EggCharacterData *char_data) :
- _collection(collection),
- _char_data(char_data)
- {
- }
- /**
- *
- */
- EggComponentData::
- ~EggComponentData() {
- for (EggBackPointer *back : _back_pointers) {
- delete back;
- }
- }
- /**
- * Adds the indicated name to the set of names that this component can be
- * identified with. If this is the first name added, it becomes the primary
- * name of the component; later names added do not replace the primary name,
- * but do get added to the list of names that will be accepted by
- * matched_name().
- */
- void EggComponentData::
- add_name(const std::string &name, NameUniquifier &uniquifier) {
- if (_names.insert(name).second) {
- // This is a new name for this component.
- if (!has_name()) {
- set_name(uniquifier.add_name(name));
- if (get_name() != name) {
- nout << "Warning: renamed " << name << " to " << get_name()
- << " to avoid naming conflict.\n";
- }
- }
- }
- }
- /**
- * Returns true if the indicated name matches any name that was ever matched
- * with this particular joint, false otherwise.
- */
- bool EggComponentData::
- matches_name(const std::string &name) const {
- if (name == get_name()) {
- return true;
- }
- return (_names.find(name) != _names.end());
- }
- /**
- * Returns the number of frames of animation for this particular component in
- * the indicated model.
- */
- int EggComponentData::
- get_num_frames(int model_index) const {
- EggBackPointer *back = get_model(model_index);
- if (back == nullptr) {
- return 0;
- }
- return back->get_num_frames();
- }
- /**
- * Extends the number of frames in the indicated model (presumably an
- * animation table model) to the given number.
- */
- void EggComponentData::
- extend_to(int model_index, int num_frames) const {
- EggBackPointer *back = get_model(model_index);
- nassertv(back != nullptr);
- back->extend_to(num_frames);
- }
- /**
- * Returns the number of frames of animation for this particular component in
- * the indicated model.
- */
- double EggComponentData::
- get_frame_rate(int model_index) const {
- EggBackPointer *back = get_model(model_index);
- if (back == nullptr) {
- return 0.0;
- }
- return back->get_frame_rate();
- }
- /**
- * Sets the back_pointer associated with the given model_index.
- */
- void EggComponentData::
- set_model(int model_index, EggBackPointer *back) {
- while ((int)_back_pointers.size() <= model_index) {
- _back_pointers.push_back(nullptr);
- }
- if (_back_pointers[model_index] != nullptr) {
- nout << "Warning: deleting old back pointer.\n";
- delete _back_pointers[model_index];
- }
- _back_pointers[model_index] = back;
- }
|