57#define FILTER_TABLE_SIZE (256)
58#define FILTER_TABLE_GEN_START (16)
59#define FILTER_TABLE_GEN_SIZE (FILTER_TABLE_SIZE - FILTER_TABLE_GEN_START)
80static bool table_valid =
false;
101 CompressedData(
NULL),
136void MotionChannelClass::Free(
void)
138 if (CompressedData) {
139 delete[] CompressedData;
176 PivotIdx = chan.
Pivot;
178 unsigned int num_floats = LastFrame-FirstFrame+1;
179 num_floats*=VectorLen;
180 unsigned int datasize=(num_floats-1)*
sizeof(
float);
183 Data[0] = chan.
Data[0];
185 if (cload.
Read(&(Data[1]),datasize) != datasize) {
190 if (saved_datasize-datasize>0) {
191 cload.
Seek(saved_datasize-datasize);
252void BitChannelClass::Free(
void)
287 PivotIdx = chan.
Pivot;
290 uint32 numbits = LastFrame - FirstFrame + 1;
291 uint32 numbytes = (numbits + 7) / 8;
292 uint32 bytesleft = numbytes - 1;
299 Bits[0] = chan.
Data[0];
302 if (cload.
Read(&(Bits[1]),bytesleft) != bytesleft) {
365void TimeCodedMotionChannelClass::Free(
void)
390 unsigned int numInts = (datasize /
sizeof(
uint32)) + 1;
400 PivotIdx = chan.
Pivot;
401 PacketSize = VectorLen+1;
403 LastTimeCodeIdx = (NumTimeCodes-1) * PacketSize;
406 Data[0] = chan.
Data[0];
408 if (cload.
Read(&(Data[1]), datasize) != datasize) {
435 uint32 pidx = get_index( tc0 );
438 if (pidx == ((NumTimeCodes - 1) * PacketSize)) {
442 for (
int i=0; i < VectorLen; i++) {
452 p2idx = pidx + PacketSize;
455 uint32 time = Data[p2idx];
459 for (
int i=0; i < VectorLen; i++) {
468 float32 ratio = (frame - time1) / (time2 - time1);
473 for (
int i=0; i < VectorLen; i++) {
485 assert(VectorLen == 4);
493 uint32 pidx = get_index( tc0 );
496 if (pidx == ((NumTimeCodes - 1) * PacketSize)) {
500 q.Set(vec[0], vec[1], vec[2], vec[3]);
506 p2idx = pidx + PacketSize;
509 uint32 time = Data[p2idx];
515 q.Set(vec[0], vec[1], vec[2], vec[3]);
523 float32 ratio = (frame - time1) / (time2 - time1);
531 q1.
Set(frame1[0], frame1[1], frame1[2], frame1[3]);
532 q2.
Set(frame2[0], frame2[1], frame2[2], frame2[3]);
555uint32 TimeCodedMotionChannelClass::binary_search_index(
uint32 timecode)
558 int rightIdx = NumTimeCodes - 2;
563 int idx = LastTimeCodeIdx;
570 if (timecode >= time)
return(idx);
574 dx = rightIdx - leftIdx;
580 idx = dx * PacketSize;
584 if (timecode < time) {
589 time = Data[idx + PacketSize] & ~W3D_TIMECODED_BINARY_MOVEMENT_FLAG;
591 if (timecode < time)
return(idx);
624uint32 TimeCodedMotionChannelClass::get_index(
uint32 timecode)
626 assert(CachedIdx <= LastTimeCodeIdx);
630 time = Data[CachedIdx] & ~W3D_TIMECODED_BINARY_MOVEMENT_FLAG;
632 if (timecode >= time) {
636 if (CachedIdx == LastTimeCodeIdx)
return(CachedIdx);
637 time = Data[CachedIdx + PacketSize] & ~W3D_TIMECODED_BINARY_MOVEMENT_FLAG;
638 if (timecode < time)
return(CachedIdx);
641 CachedIdx+=PacketSize;
642 if (CachedIdx == LastTimeCodeIdx)
return(CachedIdx);
643 time = Data[CachedIdx + PacketSize] & ~W3D_TIMECODED_BINARY_MOVEMENT_FLAG;
644 if (timecode < time)
return(CachedIdx);
647 CachedIdx = binary_search_index( timecode );
665void TimeCodedMotionChannelClass::set_identity(
float * setvec)
733void TimeCodedBitChannelClass::Free(
void)
767 PivotIdx = chan.
Pivot;
778 Bits[0] = chan.
Data[0];
781 if (cload.
Read(&(Bits[1]),bytesleft) != bytesleft) {
806 assert(CachedIdx < NumTimeCodes);
821 for (;idx < (int) NumTimeCodes ; idx++) {
825 if (frame < time)
break;
831 if (idx < 0) idx = 0;
865 if (
false == table_valid) {
913void AdaptiveDeltaMotionChannelClass::Free(
void)
944 unsigned int numInts = (datasize /
sizeof(
uint32)) + 1;
953 PivotIdx = chan.
Pivot;
956 CacheFrame = 0x7FFFFFFF;
957 CacheData =
MSGW3DNEWARRAY(
"AdaptiveDeltaMotionChannelClass::CacheData")
float[VectorLen * 2];
960 Data[0] = chan.
Data[0];
962 if (cload.
Read(&(Data[1]), datasize) != datasize) {
983#define PACKET_SIZE (9)
984void AdaptiveDeltaMotionChannelClass::decompress(
uint32 frame_idx,
float *outdata)
987 float *base = (
float *) &Data[0];
991 for(
int vi=0; vi<VectorLen; vi++) {
993 unsigned char *pPacket = (
unsigned char *) Data;
994 pPacket+= (
sizeof(float) * VectorLen);
997 float last_value = base[vi];
999 for (
uint32 frame=1; frame<=frame_idx;) {
1001 uint32 filter_index = *pPacket;
1005 float filter = filtertable[filter_index] * Scale;
1008 for (
int fi=0; fi < 16; fi++) {
1015 factor = pPacket[pi];
1019 factor = pPacket[pi];
1025 factor |= 0xFFFFFFF0;
1030 float ffactor = factor;
1032 float delta = ffactor *
filter;
1036 if (frame == frame_idx) {
1050 outdata[vi] = last_value;
1056void AdaptiveDeltaMotionChannelClass::decompress(
uint32 src_idx,
float *srcdata,
uint32 frame_idx,
float *outdata)
1060 assert(src_idx < frame_idx);
1063 float *base = (
float *) &Data[0];
1068 for(
int vi=0; vi<VectorLen; vi++) {
1070 unsigned char *pPacket = (
unsigned char *) base;
1072 pPacket+= (
PACKET_SIZE * VectorLen) * ((src_idx-1)>>4);
1075 int fi = (src_idx-1) & 0xF;
1077 float last_value = srcdata[vi];
1079 for (
uint32 frame=src_idx; frame<=frame_idx;) {
1081 uint32 filter_index = *pPacket;
1085 float filter = filtertable[filter_index] * Scale;
1088 for (fi; fi < 16; fi++) {
1095 factor = pPacket[pi];
1099 factor = pPacket[pi];
1105 factor |= 0xFFFFFFF0;
1110 float ffactor = factor;
1112 float delta = ffactor *
filter;
1116 if (frame == frame_idx) {
1131 outdata[vi] = last_value;
1150float AdaptiveDeltaMotionChannelClass::getframe(
uint32 frame_idx,
uint32 vector_idx)
1154 if (frame_idx >= NumFrames) frame_idx = NumFrames - 1;
1158 if (CacheFrame == frame_idx) {
1159 return(CacheData[vector_idx]);
1162 if ((CacheFrame+1) == frame_idx) {
1163 return(CacheData[vector_idx + VectorLen]);
1166 if (frame_idx < CacheFrame) {
1170 decompress(frame_idx, &CacheData[0]);
1172 if (frame_idx != (NumFrames - 1)) {
1173 decompress(frame_idx, &CacheData[0], frame_idx+1, &CacheData[VectorLen]);
1176 CacheFrame = frame_idx;
1178 return(CacheData[vector_idx]);
1183 if (frame_idx == (CacheFrame + 2)) {
1186 memcpy(&CacheData[0], &CacheData[VectorLen], VectorLen *
sizeof(
float));
1190 decompress(CacheFrame, &CacheData[0], frame_idx, &CacheData[VectorLen]);
1192 return(CacheData[VectorLen + vector_idx]);
1197 assert(VectorLen <= 4);
1201 memcpy(&temp[0], &CacheData[VectorLen], VectorLen *
sizeof(
float));
1203 decompress(CacheFrame, &temp[0], frame_idx, &CacheData[0]);
1204 CacheFrame = frame_idx;
1206 if (frame_idx != (NumFrames - 1)) {
1207 decompress(CacheFrame, &CacheData[0], frame_idx+1, &CacheData[VectorLen]);
1210 return(CacheData[vector_idx]);
1231 float ratio = frame - frame1;
1233 float value1 = getframe(frame1);
1234 float value2 = getframe(frame1 + 1);
1249 uint32 frame2 = frame1+1;
1250 float ratio = frame - frame1;
1253 q1.
Set( getframe(frame1, 0),
1254 getframe(frame1, 1),
1255 getframe(frame1, 2),
1256 getframe(frame1, 3) );
1260 q2.
Set( getframe(frame2, 0),
1261 getframe(frame2, 1),
1262 getframe(frame2, 2),
1263 getframe(frame2, 3) );
1280 float value_min=FLT_MAX;
1281 float value_max=-FLT_MAX;
1282 int count=datasize/
sizeof(float);
1283 for (
int i=0;i<count;i++) {
1284 float value=Data[i];
1293 ValueOffset=value_min;
1294 ValueScale=value_max-value_min;
1296 if (ValueScale>2000.0f)
return;
1300 CompressedData=
new unsigned short[count];
1301 float inv_scale=0.0f;
1302 if (ValueScale!=0.0f) {
1303 inv_scale=1.0f/ValueScale;
1305 inv_scale*=65535.0f;
1306 for (i=0;i<count;++i) {
1307 float value=Data[i];
1311 CompressedData[i]=
unsigned short(ivalue);
1313 float new_scale=ValueScale/65535.0f;
1314 float new_value=int(CompressedData[i]);
1315 float new_float = new_value*new_scale+ValueOffset;
#define W3D_TIMECODED_BIT_MASK
#define W3D_TIMECODED_BINARY_MOVEMENT_FLAG
#define MSGW3DNEWARRAY(MSG)
void Get_Vector(float32 frame, float *setvec)
~AdaptiveDeltaMotionChannelClass(void)
bool Load_W3D(ChunkLoadClass &cload)
AdaptiveDeltaMotionChannelClass(void)
Quaternion Get_QuatVector(float32 frame)
bool Load_W3D(ChunkLoadClass &cload)
uint32 Cur_Chunk_Length()
uint32 Seek(uint32 nbytes)
uint32 Read(void *buf, uint32 nbytes)
bool Load_W3D(ChunkLoadClass &cload)
~MotionChannelClass(void)
void Do_Data_Compression(int datasize)
WWINLINE void Set(float a=0.0, float b=0.0, float c=0.0, float d=1.0)
~TimeCodedBitChannelClass(void)
bool Load_W3D(ChunkLoadClass &cload)
TimeCodedBitChannelClass(void)
TimeCodedMotionChannelClass(void)
~TimeCodedMotionChannelClass(void)
Quaternion Get_QuatVector(float32 frame)
void Get_Vector(float32 frame, float *setvec)
bool Load_W3D(ChunkLoadClass &cload)
static float Lerp(float a, float b, float lerp)
static WWINLINE int Float_To_Int_Floor(const float &f)
static float Sin(float val)
#define FILTER_TABLE_SIZE
#define FILTER_TABLE_GEN_START
#define FILTER_TABLE_GEN_SIZE
void __cdecl Fast_Slerp(Quaternion &res, const Quaternion &p, const Quaternion &q, float alpha)