93 Pivot[0].Parent =
NULL;
94 Pivot[0].BaseTransform.Make_Identity();
95 Pivot[0].Transform.Make_Identity();
96 Pivot[0].IsVisible =
true;
97 strcpy(Pivot[0].Name,
"RootTransform");
144 memcpy(&Name,&src.Name,
sizeof(Name));
146 NumPivots = src.NumPivots;
151 for (
int pi = 0; pi < NumPivots; pi++) {
152 Pivot[pi] = src.Pivot[pi];
155 Pivot[pi].Parent = &(Pivot[src.Pivot[pi].
Parent->
Index]);
157 Pivot[pi].Parent =
NULL;
161 ScaleFactor = src.ScaleFactor;
226 if (!read_pivots(cload,pre30)) {
276 strcpy(Pivot[0].Name,
"RootTransform");
280 for (
int pidx=first_piv; pidx < NumPivots; pidx++) {
282 if (cload.
Read(&piv,
sizeof(W3dPivotStruct)) !=
sizeof(W3dPivotStruct)) {
287 Pivot[pidx].Index = pidx;
289 Pivot[pidx].BaseTransform.Make_Identity();
292#ifdef ALLOW_TEMPORARIES
293 Pivot[pidx].BaseTransform =
294 Pivot[pidx].BaseTransform *
305 Pivot[pidx].BaseTransform.postMul(
331 Pivot[pidx].Parent =
NULL;
334 Pivot[pidx].Parent = &(Pivot[piv.
ParentIdx]);
340 Pivot[0].IsVisible =
true;
358void HTreeClass::Free(
void)
395 if ( motion !=
NULL &&
398 pivot_index < NumPivots)
404 for (
PivotClass *pivot = &Pivot[pivot_index];
405 pivot !=
NULL && pivot->Parent !=
NULL;
406 pivot = pivot->Parent)
432#ifdef ALLOW_TEMPORARIES
442#ifdef ALLOW_TEMPORARIES
479 if ( end_tm !=
NULL &&
481 pivot_index < NumPivots)
487 for (
PivotClass *pivot = &Pivot[pivot_index];
488 pivot !=
NULL && pivot->Parent !=
NULL;
489 pivot = pivot->Parent)
536 Pivot[0].IsVisible =
true;
538 for (
int piv_idx=1; piv_idx < NumPivots; piv_idx++) {
540 pivot = &Pivot[piv_idx];
567 Pivot[0].Transform = root;
568 Pivot[0].IsVisible =
true;
572 for (
int piv_idx=1; piv_idx < NumPivots; piv_idx++) {
573 pivot = &Pivot[piv_idx];
580 if (piv_idx < num_anim_pivots) {
591#ifdef ALLOW_TEMPORARIES
616 Pivot[0].IsVisible =
true;
634 endpivot=pivot+(NumPivots-1);
635 lastAnimPivot = &Pivot[num_anim_pivots];
637 for (
int piv_idx=1; pivot < endpivot; pivot++,nodeMotion++) {
644 if (pivot < lastAnimPivot)
648 trans.
Set(0.0f,0.0f,0.0f);
651 if (nodeMotion->
X !=
NULL)
653 if (nodeMotion->
Y !=
NULL)
655 if (nodeMotion->
Z !=
NULL)
658 if (ScaleFactor == 1.0f)
663 if (nodeMotion->
Q !=
NULL)
665#ifdef ALLOW_TEMPORARIES
713 Pivot[0].Transform = root;
714 Pivot[0].IsVisible =
true;
718 for (
int piv_idx=1; piv_idx < NumPivots; piv_idx++) {
720 pivot = &Pivot[piv_idx];
725 if (piv_idx < num_anim_pivots) {
731 Vector3 lerped = (1.0 - percentage) * trans0 + (percentage) * trans1;
741#ifdef ALLOW_TEMPORARIES
781 Pivot[0].Transform = root;
782 Pivot[0].IsVisible =
true;
784 int num_anim_pivots = 100000;
785 for (
int anim_num = 0; anim_num < anim->
Get_Num_Anims(); anim_num++ ) {
788 if ( num_anim_pivots == 100000 ) {
792 for (
int piv_idx=1; piv_idx < NumPivots; piv_idx++) {
794 pivot = &Pivot[piv_idx];
798 if (piv_idx < num_anim_pivots) {
800#define ASSUME_NORMALIZED_ANIM_COMBO_WEIGHTS
805#ifndef ASSUME_NORMALIZED_ANIM_COMBO_WEIGHTS
806 float last_weight = 0;
808 float weight_total = 0;
811 for (
int anim_num = 0; anim_num < anim->
Get_Num_Anims(); anim_num++ ) {
815 if ( motion !=
NULL ) {
817 float frame_num = anim->
Get_Frame( anim_num );
825 if ( pivot_map !=
NULL ) {
826 weight *= (*pivot_map)[piv_idx];
832 if ( weight != 0.0 ) {
837 trans += weight * ScaleFactor * temp_trans;
838 weight_total += weight;
840#ifdef ASSUME_NORMALIZED_ANIM_COMBO_WEIGHTS
845 Fast_Slerp(q0, q0, q1, weight / weight_total );
850 last_weight = weight;
859#ifdef ASSUME_NORMALIZED_ANIM_COMBO_WEIGHTS
861 if (weight_total != 0.0f ) {
867#ifdef ALLOW_TEMPORARIES
874 if (( weight_total != 0.0f ) && (wcount >= 2)) {
877 Quaternion q = Slerp_( q0, q1, last_weight / weight_total );
880 }
else if (weight_total != 0.0f) {
891 if ( motion !=
NULL ) {
892 float frame_num = anim->
Get_Frame( anim_num );
924 for (
int i=0; i < NumPivots; i++) {
925 if (stricmp(Pivot[i].Name,name) == 0) {
947 assert(boneidx >= 0);
948 assert(boneidx < NumPivots);
950 return Pivot[boneidx].Name;
970 assert(boneidx >= 0);
971 assert(boneidx < NumPivots);
973 if (Pivot[boneidx].Parent !=
NULL) {
974 return Pivot[boneidx].Parent->Index;
984 if (factor == 1.0f)
return;
987 for (
int i = 0; i < NumPivots; i++) {
988 Matrix3D &pivot_transform = Pivot[i].BaseTransform;
991 pivot_translation *= factor;
996 ScaleFactor *= factor;
1003 assert(boneindex >= 0);
1004 assert(boneindex < NumPivots);
1005#ifdef LAZY_CAP_MTX_ALLOC
1006 if (Pivot[boneindex].CapTransformPtr ==
NULL)
1012 Pivot[boneindex].IsCaptured =
true;
1018 assert(boneindex >= 0);
1019 assert(boneindex < NumPivots);
1020#ifdef LAZY_CAP_MTX_ALLOC
1021 if (Pivot[boneindex].CapTransformPtr)
1023 delete Pivot[boneindex].CapTransformPtr;
1024 Pivot[boneindex].CapTransformPtr =
NULL;
1027 Pivot[boneindex].IsCaptured =
false;
1033 assert(boneindex >= 0);
1034 assert(boneindex < NumPivots);
1035 return Pivot[boneindex].Is_Captured();
1040 assert(boneindex >= 0);
1041 assert(boneindex < NumPivots);
1042 assert(Pivot[boneindex].Is_Captured());
1044#ifdef LAZY_CAP_MTX_ALLOC
1045 if (Pivot[boneindex].CapTransformPtr ==
NULL)
1047 Pivot[boneindex].WorldSpaceTranslation = world_space_translation;
1048 Pivot[boneindex].CapTransformPtr->Mat = relative_tm;
1050 Pivot[boneindex].WorldSpaceTranslation = world_space_translation;
1051 Pivot[boneindex].CapTransform = relative_tm;
1057 assert(boneindex >= 0);
1058 assert(boneindex < NumPivots);
1063 if (Pivot[boneindex].IsCaptured) {
1064 relative_tm = Pivot[boneindex].CapTransform;
1080 char * flip_list[] = {
" RIGHTFOREARM",
" RIGHTHAND",
" LEFTFOREARM",
" LEFTHAND",
"RIGHTINDEX",
"RIGHTFINGERS",
"RIGHTTHUMB",
"LEFTINDEX",
"LEFTFINGERS",
"LEFTTHUMB", 0 };
1086 for(
int pi = 0; pi < new_tree->NumPivots; ++pi) {
1091 if(!piv.
Parent)
continue;
1096 if(!flip_list[index]) {
1098 }
else if(strcmp(piv.
Name, flip_list[index]) == 0) {
1099 adjusted_scale.
Y =
scale.Z;
1108 pivot_pos.
Scale(adjusted_scale);
1109 pivot_parent_pos.
Scale(adjusted_scale);
1116 Vector3 new_relative_vector = pivot_pos - pivot_parent_pos;
1119 new_relative_vector = parent_inverse_transform.
Rotate_Vector(new_relative_vector);
1130 const float morph_weights[],
1134 assert(num_morph_sources>0);
1135 for(i=0;i<num_morph_sources;i++) {
1136 assert( tree_array[i] );
1137 assert( morph_weights[i]>=0.0f && morph_weights[i]<=1.0f );
1139 for(i=0;i<num_morph_sources-1;i++) {
1140 assert( tree_array[i]->NumPivots == tree_array[i+1]->NumPivots );
1147 for (
int pi = 0; pi < new_tree->NumPivots; pi++) {
1150 for(
int nm = 0; nm < num_morph_sources; nm++) {
1167 float lerp_a,
float lerp_b )
1169 assert( tree_a0_b0->NumPivots == tree_a0_b1->NumPivots );
1170 assert( tree_a0_b0->NumPivots == tree_a1_b0->NumPivots );
1171 assert( tree_a0_b0->NumPivots == tree_a1_b1->NumPivots );
1178 for (
int pi = 0; pi < new_tree->NumPivots; pi++) {
1198 float a_scale,
float b_scale )
1201 assert( tree_base->NumPivots == tree_a->NumPivots );
1202 assert( tree_base->NumPivots == tree_b->NumPivots );
1210 if ( a_scale_abs + b_scale_abs > 0 ) {
1214 for (
int pi = 0; pi < new_tree->NumPivots; pi++) {
1223 pos = (pos_a * a_scale_abs + pos_b * b_scale_abs ) / ( a_scale_abs + b_scale_abs );
Color scale(const Color &a, const Color &b)
@ W3D_CHUNK_HIERARCHY_HEADER
#define W3D_MAKE_VERSION(major, minor)
#define MSGW3DNEWARRAY(MSG)
WWINLINE int Get_Bit(int frame) const
uint32 Read(void *buf, uint32 nbytes)
virtual void Get_Orientation(int pividx, float frame)
virtual void Get_Translation(int pividx, float frame)
virtual void Get_Transform(Matrix3D &, int pividx, float frame) const =0
virtual bool Get_Visibility(int pividx, float frame)=0
virtual int Get_Num_Pivots(void) const =0
float Get_Frame(int indx)
float Get_Weight(int indx)
HAnimClass * Get_Motion(int indx)
HAnimClass * Peek_Motion(int indx)
PivotMapClass * Get_Pivot_Weight_Map(int indx)
int Get_Num_Pivots(void) const
int Get_Parent_Index(int bone_indx) const
int Load_W3D(ChunkLoadClass &cload)
void Blend_Update(const Matrix3D &root, HAnimClass *motion0, float frame0, HAnimClass *motion1, float frame1, float percentage)
void Combo_Update(const Matrix3D &root, HAnimComboClass *anim)
void Base_Update(const Matrix3D &root)
void Capture_Bone(int boneindex)
bool Simple_Evaluate_Pivot(HAnimClass *motion, int pivot_index, float frame, const Matrix3D &obj_tm, Matrix3D *end_tm) const
void Control_Bone(int boneindex, const Matrix3D &relative_tm, bool world_space_translation=false)
bool Is_Bone_Captured(int boneindex) const
static HTreeClass * Create_Morphed(int num_morph_sources, const float morph_weights[], const HTreeClass *tree_array[])
static HTreeClass * Alter_Avatar_HTree(const HTreeClass *tree, Vector3 &scale)
int Get_Bone_Index(const char *name) const
const char * Get_Bone_Name(int boneid) const
static HTreeClass * Create_Interpolated(const HTreeClass *tree_a0_b0, const HTreeClass *tree_a0_b1, const HTreeClass *tree_a1_b0, const HTreeClass *tree_a1_b1, float lerp_a, float lerp_b)
void Anim_Update(const Matrix3D &root, HAnimClass *motion, float frame)
void Release_Bone(int boneindex)
void Get_Bone_Control(int boneindex, Matrix3D &relative_tm) const
void postMul(const Matrix3D &that)
static void Multiply(const Matrix3D &A, const Matrix3D &B, Matrix3D *set_result)
WWINLINE void Set_Translation(const Vector3 &t)
Vector3 Rotate_Vector(const Vector3 &vect) const
void Translate(float x, float y, float z)
void preMul(const Matrix3D &that)
WWINLINE Vector3 Get_Translation(void) const
WWINLINE void Make_Identity(void)
void Get_Inverse(Matrix3D &set_inverse) const
WWINLINE void Get_Vector_As_Quat(int frame, Quaternion &quat) const
void Get_Vector(int frame, float *setvec) const
WWINLINE void Release_Ref(void) const
void Scale(const Vector3 &scale)
WWINLINE void Set(float x, float y, float z)
static void Lerp(const Vector3 &a, const Vector3 &b, float alpha, Vector3 *set_result)
static WWINLINE float Fabs(float val)
static long Float_To_Long(float f)
void __cdecl Fast_Slerp(Quaternion &res, const Quaternion &p, const Quaternion &q, float alpha)
Matrix3D & Build_Matrix3D(const Quaternion &q, Matrix3D &out)
void Capture_Update(void)
W3dVectorStruct Translation
W3dQuaternionStruct Rotation
#define WWMEMLOG(category)