Panda3D
jointVertexTransform.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file jointVertexTransform.cxx
10  * @author drose
11  * @date 2005-03-24
12  */
13 
14 #include "jointVertexTransform.h"
15 #include "datagram.h"
16 #include "datagramIterator.h"
17 #include "bamReader.h"
18 #include "bamWriter.h"
19 #include "lightMutexHolder.h"
20 
21 TypeHandle JointVertexTransform::_type_handle;
22 
23 /**
24  * Constructs an invalid object; used only by the bam loader.
25  */
26 JointVertexTransform::
27 JointVertexTransform()
28 {
29 }
30 
31 /**
32  * Constructs a new object that converts vertices from the indicated joint's
33  * coordinate space, into the other indicated joint's space.
34  */
35 JointVertexTransform::
36 JointVertexTransform(CharacterJoint *joint) :
37  _joint(joint)
38 {
39  // Tell the joint that we need to be informed when it moves.
40  _joint->_vertex_transforms.insert(this);
41  mark_modified(Thread::get_current_thread());
42 }
43 
44 /**
45  *
46  */
47 JointVertexTransform::
48 ~JointVertexTransform() {
49  // Tell the joint to stop informing us about its motion.
50  _joint->_vertex_transforms.erase(this);
51 }
52 
53 /**
54  * Stores the transform's matrix in the indicated object.
55  */
57 get_matrix(LMatrix4 &matrix) const {
58  matrix = _joint->_skinning_matrix;
59 }
60 
61 /**
62  * Premultiplies this transform's matrix with the indicated previous matrix,
63  * so that the result is the net composition of the given transform with this
64  * transform. The result is stored in the parameter "result", which should
65  * not be the same matrix as previous.
66  */
68 mult_matrix(LMatrix4 &result, const LMatrix4 &previous) const {
69  result.multiply(_joint->_skinning_matrix, previous);
70 }
71 
72 /**
73  * Adds the value of this transform's matrix, modified by the indicated
74  * weight, into the indicated accumulation matrix. This is used to compute
75  * the result of several blended transforms.
76  */
78 accumulate_matrix(LMatrix4 &accum, PN_stdfloat weight) const {
79  accum.accumulate(_joint->_skinning_matrix, weight);
80 }
81 
82 /**
83  *
84  */
85 void JointVertexTransform::
86 output(std::ostream &out) const {
87  out << _joint->get_name();
88 }
89 
90 /**
91  * Tells the BamReader how to create objects of type JointVertexTransform.
92  */
95  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
96 }
97 
98 /**
99  * Writes the contents of this object to the datagram for shipping out to a
100  * Bam file.
101  */
104  VertexTransform::write_datagram(manager, dg);
105 
106  manager->write_pointer(dg, _joint);
107 }
108 
109 /**
110  * Receives an array of pointers, one for each time manager->read_pointer()
111  * was called in fillin(). Returns the number of pointers processed.
112  */
115  int pi = VertexTransform::complete_pointers(p_list, manager);
116 
117  _joint = DCAST(CharacterJoint, p_list[pi++]);
118  _joint->_vertex_transforms.insert(this);
119 
120  return pi;
121 }
122 
123 /**
124  * This function is called by the BamReader's factory when a new object of
125  * type JointVertexTransform is encountered in the Bam file. It should create
126  * the JointVertexTransform and extract its information from the file.
127  */
128 TypedWritable *JointVertexTransform::
129 make_from_bam(const FactoryParams &params) {
131  DatagramIterator scan;
132  BamReader *manager;
133 
134  parse_params(params, scan, manager);
135  object->fillin(scan, manager);
136 
137  return object;
138 }
139 
140 /**
141  * This internal function is called by make_from_bam to read in all of the
142  * relevant data from the BamFile for the new JointVertexTransform.
143  */
144 void JointVertexTransform::
145 fillin(DatagramIterator &scan, BamReader *manager) {
146  VertexTransform::fillin(scan, manager);
147 
148  manager->read_pointer(scan);
149  mark_modified(Thread::get_current_thread());
150 }
virtual void get_matrix(LMatrix4 &matrix) const
Stores the transform's matrix in the indicated object.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
virtual void accumulate_matrix(LMatrix4 &accum, PN_stdfloat weight) const
Adds the value of this transform's matrix, modified by the indicated weight, into the indicated accum...
virtual void mult_matrix(LMatrix4 &result, const LMatrix4 &previous) const
Premultiplies this transform's matrix with the indicated previous matrix, so that the result is the n...
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
This is a specialization on VertexTransform that returns the transform necessary to move vertices as ...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
This represents one joint of the character's animation, containing an animating transform matrix.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
static void register_with_read_factory()
Tells the BamReader how to create objects of type JointVertexTransform.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A class to retrieve the individual data elements previously stored in a Datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:317