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_;
230 BitReader::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;
249 FloatZeroToOneToFixedPoint(
float zeroToOne,
unsigned int numBits )
274 unsigned int maxVal = ( 1 << numBits ) - 1;
275 return (
unsigned int ) ( maxVal * zeroToOne + 0.5f );
279 FixedPointToFloatZeroToOne(
unsigned int fixedPoint,
unsigned int numBits )
281 unsigned int maxVal = ( 1 << numBits ) - 1;
282 return (
float ) fixedPoint / maxVal;
289 WriteQuatAndExtra(
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();
341 ReadQuatAndExtra(
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();
367 SetTranslationInvalid(
float * xResult,
float * yResult,
float * zResult );
369 SetTranslationInvalid(
CalVector * result );
371 TranslationInvalid(
CalVector const & result );
Definition: coremodel.h:25
Definition: corematerial.h:22
CalDataSource abstract interface class.
Definition: datasource.h:30
Definition: coreanimation.h:23
A container-safe smart pointer used for refcounted classes.
Definition: refcounted.h:11
Definition: corebone.h:34
Always the top level node.
Definition: tinyxml.h:990
The core keyframe class.
Definition: coremorphkeyframe.h:31
Definition: coreskeleton.h:24
Definition: coremesh.h:23
Definition: coremorphtrack.h:38
The core animatedMorph class.
Definition: coreanimatedmorph.h:36
The vector class.
Definition: vector.h:36
Definition: coresubmesh.h:31
Definition: coretrack.h:26
The core keyframe class.
Definition: corekeyframe.h:31
The quaternion class.
Definition: quaternion.h:35
The loader class.
Definition: loader.h:67