Panda3D
|
An animated character, with skeleton-morph animation and either soft-skinned or hard-skinned vertices. More...
#include "character.h"
Public Member Functions | |
Character (const string &name) | |
void | clear_lod_animation () |
Undoes the effect of a recent call to set_lod_animation(). | |
virtual PandaNode * | combine_with (PandaNode *other) |
Collapses this node with the other node, if possible, and returns a pointer to the combined node, or NULL if the two nodes cannot safely be combined. | |
virtual int | complete_pointers (TypedWritable **plist, BamReader *manager) |
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin(). | |
virtual | CPT (TransformState) calc_tight_bounds(LPoint3 &min_point |
virtual bool | cull_callback (CullTraverser *trav, CullTraverserData &data) |
This function will be called during the cull traversal to perform any additional operations that should be performed at cull time. | |
virtual PandaNode * | dupe_for_flatten () const |
This is similar to make_copy(), but it makes a copy for the specific purpose of flatten. | |
CharacterJoint * | find_joint (const string &name) const |
Returns a pointer to the joint with the given name, if there is such a joint, or NULL if there is no such joint. | |
CharacterSlider * | find_slider (const string &name) const |
Returns a pointer to the slider with the given name, if there is such a slider, or NULL if there is no such slider. | |
virtual TypeHandle | force_init_type () |
void | force_update () |
Recalculates the character even if we think it doesn't need it. | |
CharacterJointBundle * | get_bundle (int i) const |
virtual TypeHandle | get_type () const |
virtual PandaNode * | make_copy () const |
The Character make_copy() function will make a new copy of the Character, with all of its joints copied, and with a new set of dynamic vertex arrays all ready to go, but it will not copy any of the original Character's geometry, so the new Character won't look like much. | |
void | merge_bundles (PartBundle *old_bundle, PartBundle *other_bundle) |
Merges old_bundle with new_bundle. | |
void | merge_bundles (PartBundleHandle *old_bundle_handle, PartBundleHandle *other_bundle_handle) |
Merges old_bundle_handle->get_bundle() with new_bundle. | |
void | set_lod_animation (const LPoint3 ¢er, PN_stdfloat far_distance, PN_stdfloat near_distance, PN_stdfloat delay_factor) |
Activates a special mode in which the character animates less frequently as it gets further from the camera. | |
void | update () |
Recalculates the Character's joints and vertices for the current frame. | |
void | update_to_now () |
Advances the character's frame to the current time, and then calls update(). | |
virtual void | write_datagram (BamWriter *manager, Datagram &dg) |
Writes the contents of this object to the datagram for shipping out to a Bam file. | |
void | write_part_values (ostream &out) const |
Writes a list of the Character's joints and sliders, along with each current position, in their hierchical structure, to the indicated output stream. | |
void | write_parts (ostream &out) const |
Writes a list of the Character's joints and sliders, in their hierchical structure, to the indicated output stream. | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
static void | register_with_read_factory () |
Tells the BamReader how to create objects of type Character. | |
Public Attributes | |
virtual LPoint3 bool const TransformState Thread *current_thread | const |
virtual LPoint3 bool & | found_any |
virtual LPoint3 & | max_point |
virtual LPoint3 bool const TransformState * | transform |
Protected Member Functions | |
Character (const Character ©, bool copy_bundles) | |
Use make_copy() or copy_subgraph() to copy a Character. | |
CPT (TransformState) get_rel_transform(CullTraverser *trav | |
void | fillin (DatagramIterator &scan, BamReader *manager) |
This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new Character. | |
virtual void | r_copy_children (const PandaNode *from, InstanceMap &inst_map, Thread *current_thread) |
This is called by r_copy_subgraph(); the copy has already been made of this particular node (and this is the copy); this function's job is to copy all of the children from the original. | |
virtual void | update_bundle (PartBundleHandle *old_bundle_handle, PartBundle *new_bundle) |
Replaces the contents of the indicated PartBundleHandle (presumably stored within this node) with new_bundle. | |
Static Protected Member Functions | |
static TypedWritable * | make_from_bam (const FactoryParams ¶ms) |
This function is called by the BamReader's factory when a new object of type Character is encountered in the Bam file. | |
Protected Attributes | |
CullTraverserData & | data |
An animated character, with skeleton-morph animation and either soft-skinned or hard-skinned vertices.
Definition at line 41 of file character.h.
Character::Character | ( | const Character & | copy, |
bool | copy_bundles | ||
) | [protected] |
Use make_copy() or copy_subgraph() to copy a Character.
Definition at line 42 of file character.cxx.
References PartGroup::copy_subgraph(), and PandaNode::set_cull_callback().
Referenced by dupe_for_flatten(), make_copy(), and make_from_bam().
void Character::clear_lod_animation | ( | ) |
Undoes the effect of a recent call to set_lod_animation().
Henceforth, the character will animate every frame, regardless of its distance from the camera.
Definition at line 402 of file character.cxx.
References LPoint3f::zero().
PandaNode * Character::combine_with | ( | PandaNode * | other | ) | [virtual] |
Collapses this node with the other node, if possible, and returns a pointer to the combined node, or NULL if the two nodes cannot safely be combined.
The return value may be this, other, or a new node altogether.
This function is called from GraphReducer::flatten(), and need not deal with children; its job is just to decide whether to collapse the two nodes and what the collapsed node should look like.
Reimplemented from PandaNode.
Definition at line 153 of file character.cxx.
References TypedObject::is_exact_type(), and PartBundleNode::steal_bundles().
int Character::complete_pointers | ( | TypedWritable ** | p_list, |
BamReader * | manager | ||
) | [virtual] |
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Returns the number of pointers processed.
Reimplemented from PartBundleNode.
Definition at line 1259 of file character.cxx.
bool Character::cull_callback | ( | CullTraverser * | trav, |
CullTraverserData & | data | ||
) | [virtual] |
This function will be called during the cull traversal to perform any additional operations that should be performed at cull time.
This may include additional manipulation of render state or additional visible/invisible decisions, or any other arbitrary operation.
Note that this function will *not* be called unless set_cull_callback() is called in the constructor of the derived class. It is necessary to call set_cull_callback() to indicated that we require cull_callback() to be called.
By the time this function is called, the node has already passed the bounding-volume test for the viewing frustum, and the node's transform and state have already been applied to the indicated CullTraverserData object.
The return value is true if this node should be visible, or false if it should be culled.
Reimplemented from PandaNode.
Definition at line 191 of file character.cxx.
References NodePath::any_path(), ClockObject::get_frame_count(), ClockObject::get_global_clock(), and update().
PandaNode * Character::dupe_for_flatten | ( | ) | const [virtual] |
This is similar to make_copy(), but it makes a copy for the specific purpose of flatten.
Typically, this will be a new PandaNode with a new pointer, but all of the internal data will always be shared with the original; whereas the new node returned by make_copy() might not share the internal data.
Reimplemented from PandaNode.
Definition at line 133 of file character.cxx.
References Character().
void Character::fillin | ( | DatagramIterator & | scan, |
BamReader * | manager | ||
) | [protected, virtual] |
This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new Character.
Reimplemented from PartBundleNode.
Definition at line 1293 of file character.cxx.
References DatagramIterator::get_uint16(), Namable::has_name(), and BamReader::read_pointer().
Referenced by make_from_bam().
CharacterJoint * Character::find_joint | ( | const string & | name | ) | const |
Returns a pointer to the joint with the given name, if there is such a joint, or NULL if there is no such joint.
This will not return a pointer to a slider.
Definition at line 419 of file character.cxx.
References PartGroup::find_child(), and TypedObject::is_of_type().
CharacterSlider * Character::find_slider | ( | const string & | name | ) | const |
Returns a pointer to the slider with the given name, if there is such a slider, or NULL if there is no such slider.
This will not return a pointer to a joint.
Definition at line 440 of file character.cxx.
References PartGroup::find_child(), and TypedObject::is_of_type().
void Character::force_update | ( | ) |
Recalculates the character even if we think it doesn't need it.
Definition at line 531 of file character.cxx.
References PartBundle::force_update().
PandaNode * Character::make_copy | ( | ) | const [virtual] |
The Character make_copy() function will make a new copy of the Character, with all of its joints copied, and with a new set of dynamic vertex arrays all ready to go, but it will not copy any of the original Character's geometry, so the new Character won't look like much.
Use copy_subgraph() to make a full copy of the Character.
Reimplemented from PandaNode.
Definition at line 118 of file character.cxx.
References Character().
TypedWritable * Character::make_from_bam | ( | const FactoryParams & | params | ) | [static, protected] |
This function is called by the BamReader's factory when a new object of type Character is encountered in the Bam file.
It should create the Character and extract its information from the file.
Reimplemented from PandaNode.
Definition at line 1274 of file character.cxx.
References Character(), and fillin().
Referenced by register_with_read_factory().
void Character::merge_bundles | ( | PartBundle * | old_bundle, |
PartBundle * | new_bundle | ||
) |
Merges old_bundle with new_bundle.
old_bundle must be one of the PartBundles within this node. At the end of this call, the old_bundle pointer within this node will be replaced with the new_bundle pointer, and all geometry within this node will be updated to reference new_bundle.
This method is deprecated. Use the newer version of this method, below.
Definition at line 288 of file character.cxx.
void Character::merge_bundles | ( | PartBundleHandle * | old_bundle_handle, |
PartBundleHandle * | new_bundle_handle | ||
) |
Merges old_bundle_handle->get_bundle() with new_bundle.
old_bundle_handle must be one of the PartBundleHandle within this node. At the end of this call, the bundle pointer within the old_bundle_handle will be replaced with that within the new_bundle_handle pointer, and all geometry within this node will be updated to reference new_bundle.
Normally, this is called when the two bundles have the same, or nearly the same, hierarchies. In this case, new_bundle will simply be assigned over the old_bundle position. However, if any joints are present in one bundle or the other, new_bundle will be modified to contain the union of all joints.
The geometry below this node is also updated to reference new_bundle, instead of the original old_bundle.
This method is intended to unify two different models that share a common skeleton, for instance, different LOD's of the same model.
Definition at line 337 of file character.cxx.
References PartBundleHandle::get_bundle(), PartBundle::merge_anim_preloads(), and update_bundle().
void Character::r_copy_children | ( | const PandaNode * | from, |
PandaNode::InstanceMap & | inst_map, | ||
Thread * | current_thread | ||
) | [protected, virtual] |
This is called by r_copy_subgraph(); the copy has already been made of this particular node (and this is the copy); this function's job is to copy all of the children from the original.
Note that it includes the parameter inst_map, which is a map type, and is not (and cannot be) exported from PANDA.DLL. Thus, any derivative of PandaNode that is not also a member of PANDA.DLL *cannot* access this map, and probably should not even override this function.
Reimplemented from PandaNode.
Definition at line 558 of file character.cxx.
void Character::register_with_read_factory | ( | ) | [static] |
Tells the BamReader how to create objects of type Character.
Reimplemented from PandaNode.
Definition at line 1233 of file character.cxx.
References BamReader::get_factory(), make_from_bam(), and Factory< Type >::register_factory().
void Character::set_lod_animation | ( | const LPoint3 & | center, |
PN_stdfloat | far_distance, | ||
PN_stdfloat | near_distance, | ||
PN_stdfloat | delay_factor | ||
) |
Activates a special mode in which the character animates less frequently as it gets further from the camera.
This is intended as a simple optimization to minimize the effort of computing animation for lots of characters that may not necessarily be very important to animate every frame.
If the character is closer to the camera than near_distance, then it is animated its normal rate, every frame. If the character is exactly far_distance away, it is animated only every delay_factor seconds (which should be a number greater than 0). If the character is between near_distance and far_distance, its animation rate is linearly interpolated according to its distance between the two. The interpolation function continues beyond far_distance, so that the character is animated increasingly less frequently as it gets farther away.
The distance calculations are made from center, which is a fixed point relative to the character node, to the camera's lod center or cull center node (or to the camera node itself).
If multiple cameras are viewing the character in any given frame, the closest one counts.
Definition at line 378 of file character.cxx.
void Character::update | ( | ) |
Recalculates the Character's joints and vertices for the current frame.
Normally this is performed automatically during the render and need not be called explicitly.
Definition at line 508 of file character.cxx.
References NodePath::any_path(), ClockObject::get_frame_time(), and ClockObject::get_global_clock().
Referenced by cull_callback(), and update_to_now().
void Character::update_bundle | ( | PartBundleHandle * | old_bundle_handle, |
PartBundle * | new_bundle | ||
) | [protected, virtual] |
Replaces the contents of the indicated PartBundleHandle (presumably stored within this node) with new_bundle.
Reimplemented from PartBundleNode.
Definition at line 598 of file character.cxx.
References PartBundleHandle::get_bundle().
Referenced by merge_bundles().
void Character::update_to_now | ( | ) |
Advances the character's frame to the current time, and then calls update().
This can be used by show code to force an update of the character's position to the current frame, regardless of whether the character is currently onscreen and animating.
This method is deprecated. Call update() instead.
Definition at line 495 of file character.cxx.
References update().
void Character::write_datagram | ( | BamWriter * | manager, |
Datagram & | dg | ||
) | [virtual] |
Writes the contents of this object to the datagram for shipping out to a Bam file.
Reimplemented from PartBundleNode.
Definition at line 1244 of file character.cxx.
References Datagram::add_uint16().
void Character::write_part_values | ( | ostream & | out | ) | const |
Writes a list of the Character's joints and sliders, along with each current position, in their hierchical structure, to the indicated output stream.
Definition at line 476 of file character.cxx.
References PartGroup::write_with_value().
void Character::write_parts | ( | ostream & | out | ) | const |
Writes a list of the Character's joints and sliders, in their hierchical structure, to the indicated output stream.
Definition at line 461 of file character.cxx.
References PartBundle::write().