25 TypeHandle AnimChannelScalarTable::_type_handle;
30 AnimChannelScalarTable::
31 AnimChannelScalarTable() : _table(get_class_type()) {
39 AnimChannelScalarTable::
49 AnimChannelScalarTable::
50 AnimChannelScalarTable(
AnimGroup *parent,
const std::string &name) :
52 _table(get_class_type())
63 int this_frame,
double this_frac) {
64 if (_table.size() > 1) {
65 if (last_frame != this_frame) {
66 if (_table[last_frame % _table.size()] !=
67 _table[this_frame % _table.size()]) {
71 if (last_frac != this_frac) {
74 if (_table[last_frame % _table.size()] !=
75 _table[(this_frame + 1) % _table.size()]) {
88 get_value(
int frame, PN_stdfloat &value) {
92 value = _table[frame % _table.size()];
102 int num_frames = _root->get_num_frames();
104 if (table.size() > 1 && (
int)table.size() < num_frames) {
107 nassert_raise(
"mismatched number of frames");
118 write(std::ostream &out,
int indent_level)
const {
120 << get_type() <<
" " << get_name() <<
" " << _table.size();
122 if (!_children.empty()) {
124 write_descendants(out, indent_level + 2);
125 indent(out, indent_level) <<
"}";
149 if (compress_channels) {
151 <<
"FFT compression of animations is deprecated. For compatibility "
152 "with future versions of Panda3D, set compress-channels to false.\n";
156 <<
"Compression is not available; writing uncompressed channels.\n";
157 compress_channels =
false;
162 if (!compress_channels) {
165 for(
int i = 0; i < (int)_table.size(); i++) {
177 static const int max_values = 16;
178 static const PN_stdfloat scale = 1000.0f;
183 i < (int)_table.size() && (int)index.size() <= max_values;
185 int value = (int)cfloor(_table[i] * scale + 0.5f);
188 int index_length = index.size();
189 if (index_length <= max_values) {
194 if (index_length > 0) {
197 vector_stdfloat reverse_index(index_length);
199 for (mi = index.begin(); mi != index.end(); ++mi) {
200 PN_stdfloat f = (PN_stdfloat)(*mi).first / scale;
201 int i = (*mi).second;
202 nassertv(i >= 0 && i < (
int)reverse_index.size());
203 reverse_index[i] = f;
206 for (i = 0; i < index_length; i++) {
212 int table_length = _table.size();
215 if (index_length == 1) {
220 for (i = 0; i < table_length - 1; i+= 2) {
221 int value1 = (int)cfloor(_table[i] * scale + 0.5f);
222 int value2 = (int)cfloor(_table[i + 1] * scale + 0.5f);
223 int i1 = index[value1];
224 int i2 = index[value2];
230 if (i < table_length) {
231 int value1 = (int)cfloor(_table[i] * scale + 0.5f);
232 int i1 = index[value1];
259 void AnimChannelScalarTable::
261 AnimChannelScalar::fillin(scan, manager);
263 bool wrote_compressed = scan.
get_bool();
265 PTA_stdfloat temp_table = PTA_stdfloat::empty_array(0, get_class_type());
267 if (!wrote_compressed) {
270 for(
int i = 0; i < size; i++) {
279 if (index_length < 0xff) {
281 if (index_length > 0) {
282 PN_stdfloat *index = (PN_stdfloat *)alloca(index_length *
sizeof(PN_stdfloat));
285 for (i = 0; i < index_length; i++) {
291 if (index_length == 1) {
293 for (i = 0; i < table_length; i++) {
294 temp_table.push_back(index[0]);
298 for (i = 0; i < table_length - 1; i+= 2) {
300 int i1 = (num >> 4) & 0xf;
302 temp_table.push_back(index[i1]);
303 temp_table.push_back(index[i2]);
306 if (i < table_length) {
308 int i1 = (num >> 4) & 0xf;
309 temp_table.push_back(index[i1]);
334 me->fillin(scan, manager);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
An animation channel that issues a scalar each frame, read from a table such as might have been read ...
virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac)
Returns true if the value has changed since the last call to has_changed().
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
virtual void get_value(int frame, PN_stdfloat &value)
Gets the value of the channel at the indicated frame.
set_table
Assigns the data table.
static void register_with_read_factory()
Factory method to generate a AnimChannelScalarTable object.
static TypedWritable * make_AnimChannelScalarTable(const FactoryParams ¶ms)
Factory method to generate a AnimChannelScalarTable object.
virtual void write(std::ostream &out, int indent_level) const
Writes a brief description of the table and all of its descendants.
This template class is the parent class for all kinds of AnimChannels that return different values.
This is the base class for AnimChannel and AnimBundle.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Similar to PointerToArray, except that its contents may not be modified.
A class to retrieve the individual data elements previously stored in a Datagram.
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
bool get_bool()
Extracts a boolean value.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
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_bool(bool value)
Adds a boolean value to the datagram.
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
This class manages a lossy compression and decompression of a stream of floating-point numbers to a d...
bool read_reals(DatagramIterator &di, vector_stdfloat &array)
Reads an array of floating-point numbers.
void set_use_error_threshold(bool use_error_threshold)
Enables or disables the use of the error threshold measurement to put a cap on the amount of damage d...
void set_quality(int quality)
Sets the quality factor for the compression.
bool read_header(DatagramIterator &di, int bam_minor_version)
Reads the compression header that was written previously.
static bool is_compression_available()
Returns true if the FFTW library is compiled in, so that this class is actually capable of doing usef...
void write_header(Datagram &datagram)
Writes the compression parameters to the indicated datagram.
void write_reals(Datagram &datagram, const PN_stdfloat *array, int length)
Writes an array of floating-point numbers to the indicated datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.