From a9f6d03ce928e338d2f2b3a614489179f6695627 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 10 Jan 2001 17:38:55 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/chan/Sources.pp | 3 ++- panda/src/chan/config_chan.cxx | 27 ++++++++++++++++++++++++++ panda/src/mathutil/fftCompressor.cxx | 19 +++++++++++++----- pandatool/src/bam/eggToBam.cxx | 29 ++++++++++++++++++++++++++++ pandatool/src/bam/eggToBam.h | 3 +++ 5 files changed, 75 insertions(+), 6 deletions(-) diff --git a/panda/src/chan/Sources.pp b/panda/src/chan/Sources.pp index 14b8ca9f71..5f1f9405ce 100644 --- a/panda/src/chan/Sources.pp +++ b/panda/src/chan/Sources.pp @@ -31,7 +31,8 @@ animChannelMatrixXfmTable.h animChannelScalarTable.I \ animChannelScalarTable.h animControl.I animControl.h \ animControlCollection.I animControlCollection.h animGroup.I \ - animGroup.h auto_bind.h movingPart.I movingPart.h movingPartBase.I \ + animGroup.h auto_bind.h config_chan.h \ + movingPart.I movingPart.h movingPartBase.I \ movingPartBase.h movingPartMatrix.I movingPartMatrix.h \ movingPartScalar.I movingPartScalar.h partBundle.I partBundle.h \ partBundleNode.I partBundleNode.h partGroup.I partGroup.h \ diff --git a/panda/src/chan/config_chan.cxx b/panda/src/chan/config_chan.cxx index 2583645348..71adcccf3b 100644 --- a/panda/src/chan/config_chan.cxx +++ b/panda/src/chan/config_chan.cxx @@ -27,6 +27,33 @@ NotifyCategoryDef(chan, ""); // Set this true to enable compress of animation channels when writing to // the bam file. This is an experimental lossy compression. bool compress_channels = config_chan.GetBool("compress-channels", false); + +// The quality level is an integer number that generally ranges +// between 0 and 100, where smaller numbers indicate greater +// compression at the cost of quality, and larger numbers indicate +// higher quality but less compression. Generally, 95 is the highest +// useful value; values between 95 and 100 produce substantially +// larger, but not substantially better, output files. This is akin +// to the JPEG compression level. +// +// There are some special values above 100 which are generally only +// useful for debugging (specifically, to research at what point a +// particular animation artifact is being introduced): +// +// 101 Output numerically lossless data. The output is not run +// through the FFTCompressor. This can be used to check +// whether a particular artifact is due to the FFT conversion +// or not. However, joint angles (HPR) are still converted to +// quaternions and normalized, discarding the fourth +// (redundant) component. +// +// 102 As above, but the fourth quaternion component is preserved. +// +// 103 Quaternions are not used; instead, the HPR values are written +// directly. All output is now completely lossless; if some +// artifacts are being introduced at this point, check your +// sanity. +// int compress_chan_quality = config_chan.GetInt("compress-chan-quality", 95); ConfigureFn(config_chan) { diff --git a/panda/src/mathutil/fftCompressor.cxx b/panda/src/mathutil/fftCompressor.cxx index bfe09aff49..dfeb7e4b55 100644 --- a/panda/src/mathutil/fftCompressor.cxx +++ b/panda/src/mathutil/fftCompressor.cxx @@ -323,18 +323,26 @@ write_hprs(Datagram &datagram, const LVecBase3f *array, int length) { rot.set(-rot.get_r(), -rot.get_i(), -rot.get_j(), -rot.get_k()); } - /* - { + // This is a debug severity, and not a warning or error, because + // (a) some small errors in hpr are usually acceptable, and (b) + // sometimes two different hpr trios actually represent the same + // rotation, e.g. (180, 0, -180) vs. (0, 0, 0). + if (mathutil_cat.is_debug()) { LMatrix3f mat2; rot.extract_to_matrix(mat2); LVecBase3f scale, hpr; bool success = decompose_matrix(mat2, scale, hpr); nassertv(success); - if (!array[i].almost_equal(hpr, 0.001)) { - cerr << "array " << array[i] << " hpr " << hpr << "\n"; + if (!array[i].almost_equal(hpr, 0.001) || + !scale.almost_equal(LVecBase3f(1.0, 1.0, 1.0), 0.001)) { + mathutil_cat.debug() + << "Converted hpr to quaternion incorrectly!\n" + << " Source hpr: " << array[i] << "\n" + << " Quaternion: " << rot << "\n" + << " Which represents: hpr " << hpr << " scale " + << scale << "\n"; } } - */ qr.push_back(rot.get_r()); qi.push_back(rot.get_i()); @@ -529,6 +537,7 @@ read_hprs(DatagramIterator &di, vector_LVecBase3f &array) { LVecBase3f scale, hpr; bool success = decompose_matrix(mat, scale, hpr); nassertr(success, false); + array.push_back(hpr); } } diff --git a/pandatool/src/bam/eggToBam.cxx b/pandatool/src/bam/eggToBam.cxx index f4354ea126..4f7bc535fa 100644 --- a/pandatool/src/bam/eggToBam.cxx +++ b/pandatool/src/bam/eggToBam.cxx @@ -10,6 +10,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////////////// // Function: EggToBam::Constructor @@ -37,6 +38,23 @@ EggToBam() : "whatever is specified by the bam-texture-mode Configrc variable.", &EggToBam::dispatch_none, &_keep_paths); + add_option + ("C", "quality", 0, + "Specify the quality level for lossy channel compression. If this " + "is specified, the animation channels will be compressed at this " + "quality level, which is normally an integer value between 0 and 100, " + "inclusive, where higher numbers produce larger files with greater " + "quality. Generally, 95 is the highest useful quality level. Use " + "-NC (described below) to disable channel compression. If neither " + "option is specified, the default comes from the Configrc file.", + &EggToBam::dispatch_int, &_has_compression_quality, &_compression_quality); + + add_option + ("NC", "", 0, + "Turn off lossy compression of animation channels. Channels will be " + "written exactly as they are, losslessly.", + &EggToBam::dispatch_none, &_compression_off); + redescribe_option ("cs", "Specify the coordinate system of the resulting " + _format_name + @@ -59,6 +77,17 @@ run() { bam_texture_mode = BTM_fullpath; } + if (_compression_off) { + // If the user specified -NC, turn off channel compression. + compress_channels = false; + + } else if (_has_compression_quality) { + // Otherwise, if the user specified a compression quality with -C, + // use that quality level. + compress_channels = true; + compress_chan_quality = _compression_quality; + } + if (!_got_coordinate_system) { // If the user didn't specify otherwise, ensure the coordinate // system is Z-up. diff --git a/pandatool/src/bam/eggToBam.h b/pandatool/src/bam/eggToBam.h index 788b212492..61784f8dc4 100644 --- a/pandatool/src/bam/eggToBam.h +++ b/pandatool/src/bam/eggToBam.h @@ -21,6 +21,9 @@ public: void run(); bool _keep_paths; + bool _has_compression_quality; + int _compression_quality; + bool _compression_off; }; #endif