21#include "cal3d/global.h"
22#include "cal3d/datasource.h"
23#include "cal3d/coreanimation.h"
24#include "cal3d/corematerial.h"
25#include "cal3d/coremesh.h"
26#include "cal3d/coreskeleton.h"
27#include "cal3d/tinyxml.h"
54 LOADER_ROTATE_X_AXIS = 1,
55 LOADER_INVERT_V_COORD = 2,
56 LOADER_FLIP_WINDING = 4
71 static unsigned int const keyframeBitsPerOriComponent;
72 static unsigned int const keyframeBitsPerTime;
74 static unsigned int const keyframeBitsPerUnsignedPosComponent;
75 static unsigned int const keyframeBitsPerPosPadding;
76 static float const keyframePosRange;
77 static unsigned int const keyframePosBytes;
79 static unsigned int const keyframeBitsPerUnsignedPosComponentSmall;
80 static unsigned int const keyframeBitsPerPosPaddingSmall;
81 static float const keyframePosRangeSmall;
82 static unsigned int const keyframePosBytesSmall;
85 static CalCoreMeshPtr loadCoreMesh(
const std::string& strFilename);
97 static CalCoreAnimatedMorph *loadCoreAnimatedMorphFromBuffer(
void* inputBuffer,
unsigned int len);
108 static void setLoadingMode(
int flags);
109 static void setAnimationCollapseSequencesOn(
bool p );
110 static void setAnimationLoadingCompressionOn(
bool p );
111 static void setAnimationTranslationTolerance(
double p );
112 static void setAnimationRotationToleranceDegrees(
double p );
114 static bool getAnimationLoadingCompressionOn() {
return loadingCompressionOn; }
117 static double getAnimationTranslationTolerance() {
return translationTolerance; }
118 static double getAnimationRotationToleranceDegrees() {
return rotationToleranceDegrees; }
119 static int getAnimationNumEliminatedKeyframes() {
return numEliminatedKeyframes; }
120 static int getAnimationNumKeptKeyframes() {
return numKeptKeyframes; }
121 static int getAnimationNumRoundedKeyframes() {
return numRoundedKeyframes; }
122 static int getAnimationNumCompressedAnimations() {
return numCompressedAnimations; }
123 static void addAnimationCompressionStatistic(
int totalKeyframes,
int eliminatedKeyframes,
int numRounded ) {
124 numEliminatedKeyframes += eliminatedKeyframes;
125 numKeptKeyframes += totalKeyframes - eliminatedKeyframes;
126 numRoundedKeyframes += numRounded;
127 numCompressedAnimations++;
129 static void resetCompressionStatistics() {
130 numEliminatedKeyframes = 0;
131 numKeptKeyframes = 0;
132 numCompressedAnimations = 0;
134 static bool usesAnimationCompression(
int version );
135 static unsigned int compressedKeyframeRequiredBytes(
CalCoreKeyframe * lastCoreKeyframe,
bool translationRequired,
bool highRangeRequired,
bool translationIsDynamic );
136 static unsigned int readCompressedKeyframe(
unsigned char * buf,
unsigned int bytes,
CalCoreBone * coreboneOrNull,
139 bool translationRequired,
bool highRangeRequired,
bool translationIsDynamic,
140 bool useAnimationCompression);
141 static unsigned int writeCompressedKeyframe(
unsigned char * buf,
unsigned int bufLen,
const std::string& strFilename,
144 bool needTranslation,
bool highRangeRequired );
152 static CalCoreMeshPtr loadXmlCoreMesh(
const std::string& strFilename);
158 static CalCoreSkeletonPtr loadXmlCoreSkeletonFromFile(
const std::string& strFilename);
168 bool translationRequired,
bool highRangeRequired,
bool translationIsDynamic,
169 bool useAnimationCompression);
180 static int loadingMode;
181 static double translationTolerance;
182 static double rotationToleranceDegrees;
183 static bool loadingCompressionOn;
184 static bool collapseSequencesOn;
186 static int numEliminatedKeyframes;
187 static int numKeptKeyframes;
188 static int numCompressedAnimations;
189 static int numRoundedKeyframes;
201 void write(
unsigned int data,
unsigned int numBits );
203 inline unsigned int bytesWritten() {
return bytesWritten_; }
206 unsigned int bitsInBuf_;
207 unsigned int bytesWritten_;
208 unsigned char * dest_;
214 BitReader(
unsigned char const * source ) {
220 inline void read(
unsigned int * data,
unsigned int numBits );
221 inline unsigned int bytesRead() {
return bytesRead_; }
224 unsigned int bitsInBuf_;
225 unsigned int bytesRead_;
226 unsigned char const * source_;
230BitReader::read(
unsigned int * data,
unsigned int numBits )
235 assert( bitsInBuf_ < 8 );
236 while( bitsInBuf_ < numBits ) {
237 buf_ |= ( source_[ bytesRead_ ] << bitsInBuf_ );
243 * data = buf_ & ( ( 1 << numBits ) - 1 );
245 bitsInBuf_ -= numBits;
249FloatZeroToOneToFixedPoint(
float zeroToOne,
unsigned int numBits )
274 unsigned int maxVal = ( 1 << numBits ) - 1;
275 return (
unsigned int ) ( maxVal * zeroToOne + 0.5f );
279FixedPointToFloatZeroToOne(
unsigned int fixedPoint,
unsigned int numBits )
281 unsigned int maxVal = ( 1 << numBits ) - 1;
282 return (
float ) fixedPoint / maxVal;
289WriteQuatAndExtra(
unsigned char * dest,
float const * vals,
unsigned int extra,
290 unsigned int bitsPerComponent,
unsigned int bitsPerExtra )
292 float absVals[] = { fabsf( vals[ 0 ] ), fabsf( vals[ 1 ] ), fabsf( vals[ 2 ] ), fabsf( vals[ 3 ] ) };
296 unsigned int bigi = 0;
297 float biggest = absVals[ bigi ];
298 for( i = 1; i < 4; i++ ) {
299 if( absVals[ i ] > biggest ) {
300 biggest = absVals[ i ];
307 unsigned int signOne = ( vals[ bigi ] < 0 ) ? 0 : 1;
308 unsigned int signZero = 1 - signOne;
318 for( i = 0; i < 4; i++ ) {
322 if( vals[ i ] < 0 ) {
323 bw.write( signOne, 1 );
325 bw.write( signZero, 1 );
329 bw.write( FloatZeroToOneToFixedPoint( absVals[ i ], bitsPerComponent ), bitsPerComponent );
332 bw.write( extra, bitsPerExtra );
334 return bw.bytesWritten();
341ReadQuatAndExtra(
unsigned char const * data,
float * valsResult,
unsigned int * extraResult,
342 unsigned int bitsPerComponent,
unsigned int bitsPerExtra )
346 br.read( & bigi, 2 );
349 for( i = 0; i < 4; i++ ) {
352 br.read( & sign, 1 );
354 br.read( & val, bitsPerComponent );
355 float fval = FixedPointToFloatZeroToOne( val, bitsPerComponent );
356 valsResult[ i ] = sign ? - fval : fval;
357 sum += valsResult[ i ] * valsResult[ i ];
360 if( sum > 1.0f ) sum = 1.0f;
361 valsResult[ bigi ] = sqrtf( 1.0f - sum );
362 br.read( extraResult, bitsPerExtra );
363 return br.bytesRead();
367SetTranslationInvalid(
float * xResult,
float * yResult,
float * zResult );
369SetTranslationInvalid(
CalVector * result );
371TranslationInvalid(
CalVector const & result );
The core animatedMorph class.
Definition: coreanimatedmorph.h:37
Definition: coreanimation.h:24
Definition: corebone.h:35
The core keyframe class.
Definition: corekeyframe.h:32
Definition: corematerial.h:23
Definition: coremesh.h:24
Definition: coremodel.h:26
The core keyframe class.
Definition: coremorphkeyframe.h:32
Definition: coremorphtrack.h:39
Definition: coreskeleton.h:25
Definition: coresubmesh.h:32
Definition: coretrack.h:27
CalDataSource abstract interface class.
Definition: datasource.h:31
The loader class.
Definition: loader.h:68
The quaternion class.
Definition: quaternion.h:36
The vector class.
Definition: vector.h:37
A container-safe smart pointer used for refcounted classes.
Definition: refptr.h:11
Always the top level node.
Definition: tinyxml.h:991