26 if (_entries.
size() != other._entries.
size()) {
27 return (
int)_entries.
size() - (int)other._entries.
size();
30 Entries::const_iterator ai, bi;
31 ai = _entries.
begin();
32 bi = other._entries.
begin();
33 while (ai != _entries.
end() && bi != other._entries.
end()) {
34 if ((*ai)._transform != (*bi)._transform) {
35 return (*ai)._transform < (*bi)._transform ? -1 : 1;
37 if (!IS_NEARLY_EQUAL((*ai)._weight, (*bi)._weight)) {
38 return (*ai)._weight < (*bi)._weight ? -1 : 1;
53 if (!IS_NEARLY_ZERO(weight)) {
55 entry._transform = transform;
56 entry._weight = weight;
57 std::pair<Entries::iterator, bool> result = _entries.insert(entry);
61 Entries::iterator ei = result.first;
62 (*ei)._weight += weight;
63 if (IS_NEARLY_ZERO((*ei)._weight)) {
68 Thread *current_thread = Thread::get_current_thread();
69 clear_result(current_thread);
79 entry._transform = transform;
81 Entries::iterator ei = _entries.find(entry);
82 if (ei != _entries.
end()) {
86 clear_result(current_thread);
96 if (max_transforms <= 0) {
101 while ((
int)_entries.
size() > max_transforms) {
103 nassertv(!_entries.
empty());
104 Entries::iterator ei_least = _entries.
begin();
105 Entries::iterator ei = ei_least;
107 while (ei != _entries.
end()) {
108 if ((*ei)._weight < (*ei_least)._weight) {
114 _entries.erase(ei_least);
125 PN_stdfloat net_weight = 0.0f;
126 Entries::iterator ei;
127 for (ei = _entries.
begin(); ei != _entries.
end(); ++ei) {
128 net_weight += (*ei)._weight;
130 if (net_weight != 0.0f) {
131 for (ei = _entries.
begin(); ei != _entries.
end(); ++ei) {
132 (*ei)._weight /= net_weight;
135 Thread *current_thread = Thread::get_current_thread();
136 clear_result(current_thread);
144 TransformEntry entry;
145 entry._transform = transform;
146 entry._weight = 0.0f;
147 Entries::const_iterator ei = _entries.find(entry);
148 return (ei != _entries.
end());
157 TransformEntry entry;
158 entry._transform = transform;
159 entry._weight = 0.0f;
160 Entries::const_iterator ei = _entries.find(entry);
161 if (ei != _entries.
end()) {
162 return (*ei)._weight;
170 void TransformBlend::
171 output(std::ostream &out)
const {
172 if (_entries.
empty()) {
175 Entries::const_iterator ei = _entries.
begin();
176 out << *(*ei)._transform <<
":" << (*ei)._weight;
178 while (ei != _entries.
end()) {
179 out <<
" " << *(*ei)._transform <<
":" << (*ei)._weight;
188 void TransformBlend::
189 write(std::ostream &out,
int indent_level)
const {
191 Entries::const_iterator ei;
192 for (ei = _entries.
begin(); ei != _entries.
end(); ++ei) {
194 << *(*ei)._transform <<
":" << (*ei)._weight <<
"\n";
196 (*ei)._transform->get_matrix(mat);
197 mat.write(out, indent_level + 4);
203 <<
"Blended result =\n";
204 blend.write(out, indent_level + 2);
211 void TransformBlend::
212 recompute_result(CData *cdata,
Thread *current_thread) {
219 Entries::const_iterator ei;
220 for (ei = _entries.
begin(); ei != _entries.
end(); ++ei) {
221 seq = std::max(seq, (*ei)._transform->get_modified(current_thread));
224 if (cdata->_modified != seq) {
226 cdata->_modified = seq;
228 cdata->_result = LMatrix4::zeros_mat();
229 for (ei = _entries.
begin(); ei != _entries.
end(); ++ei) {
230 (*ei)._transform->accumulate_matrix(cdata->_result, (*ei)._weight);
238 void TransformBlend::
239 clear_result(
Thread *current_thread) {
240 CDWriter cdata(_cycler,
true, current_thread);
244 cdata->_result = LMatrix4::ident_mat();
256 Entries::const_iterator ei;
257 for (ei = _entries.
begin(); ei != _entries.
end(); ++ei) {
271 Entries::iterator ei;
272 for (ei = _entries.
begin(); ei != _entries.
end(); ++ei) {
290 for (
size_t i = 0; i < num_entries; ++i) {
291 TransformEntry entry;
303 return new CData(*
this);
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
size_type_0 size() const
Returns the number of elements in the ordered vector.
void clear()
Removes all elements from the ordered vector.
A single page of data maintained by a PipelineCycler.
Base class for objects that can be written to and read from Bam files.
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
void reserve(size_type_0 n)
Informs the vector of a planned change in size; ensures that the capacity of the vector is greater th...
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
get_current_thread
Returns a pointer to the currently-executing Thread object.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
void sort()
Maps to sort_unique().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
A thread; that is, a lightweight process.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
This is a sequence number that increments monotonically.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.