00001 // 00002 // Copyright (c) 2000 by Tech Soft 3D, LLC. 00003 // The information contained herein is confidential and proprietary to 00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under 00005 // civil and criminal statutes. Tech Soft 3D shall pursue its civil 00006 // and criminal remedies in the event of unauthorized use or misappropriation 00007 // of its trade secrets. Use of this information by anyone other than 00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a 00009 // written non-disclosure agreement, expressly prescribing the scope and 00010 // manner of such use. 00011 // 00012 //"Parts of HQuat Copyright (C) Jason Shankel, 2000" 00013 // 00014 // $Id: 8a555c15d24af72688e1fed9bd2e526d504938f6 $ 00015 // 00016 00021 #ifndef _H_HBhvUtility_H 00022 #define _H_HBhvUtility_H 00023 00024 #ifdef H_PACK_8 00025 #pragma pack(push) 00026 #pragma pack(8) 00027 #endif 00028 00029 #include "HTools.h" 00030 00031 #ifndef SWIG 00032 #include "BStream.h" 00033 #endif 00034 00035 class HUtilityXMLTag; 00036 class HUtilityTextParser; 00037 class HBhvTimeline; 00038 class HBaseModel; 00039 class HStreamFileToolkit; 00040 class HBaseView; 00041 class HBaseModel; 00042 class HBhvAnimation; 00043 00044 #define BHV_MAX_NAME_LENGTH 256 //!< Maximum Length of "Names" in animations 00045 #define BHV_MAX_VERSION_LENGTH 256 //!< Maximum Length of "Version" string 00046 #define BHV_MAX_VENDOR_LENGTH 4096 //!< Maximum Length of "Vendor" string 00047 #define BHV_MAX_TYPE_LENGTH 4096 //!< Maximum Length of Animation Type string 00048 00049 00051 enum HANIKeyframeType { 00052 HANIChannel, 00053 HANIRotation, 00054 HANIString, 00055 HANI3String 00056 }; 00057 00058 00060 enum HANIChannelType { 00061 HANILinear, 00062 HANIHermiteSpline, 00063 HANIBezierSpline, 00064 HANIFollowPath, 00065 HANIDiscrete 00066 }; 00067 00068 00070 enum HANIRotationType { 00071 HANIAxisRotation, 00072 HANIQuatSlerpRotation, 00073 HANIQuatSquadRotation, 00074 HANIEulerRotation 00075 }; 00076 00077 00078 00079 00081 00086 class MVO_API HQuat 00087 { 00088 public: 00089 float x; 00090 float y; 00091 float z; 00092 float w; 00093 const HQuat &Normalize(); 00095 HQuat() { x=0.0f;y=0.0f;z=0.0f; w=0;}; 00097 HQuat(float X,float Y,float Z, float W) { x=X;y=Y;z=Z; w=W;}; 00099 HQuat(HQuat const *p) { x=p->x;y=p->y;z=p->z; w=p->w;}; 00101 HQuat(const HQuat &p) { x=p.x;y=p.y;z=p.z; w=p.w;}; 00102 00104 void Set(float X,float Y,float Z, float W) { x=X;y=Y;z=Z; w=W; }; 00105 00111 HQuat operator *(const HQuat &q2) const 00112 { 00113 00114 return HQuat(y*q2.z - z*q2.y + w*q2.x + x*q2.w, 00115 z*q2.x - x*q2.z + w*q2.y + y*q2.w, 00116 x*q2.y - y*q2.x + w*q2.z + z*q2.w, 00117 w*q2.w - x*q2.x - y*q2.y - z*q2.z); 00118 } 00119 00125 HQuat operator *(float v) const 00126 { 00127 return HQuat(x*v, y*v, z*v, w*v); 00128 } 00129 00136 friend HQuat operator* (float v, const HQuat& q) 00137 { 00138 return HQuat(v*q.x,v*q.y,v*q.z, v*q.w); 00139 } 00140 00146 HQuat operator /(float v) const 00147 { 00148 return HQuat(x/v, y/v, z/v, w/v); 00149 } 00150 HQuat operator -(const HQuat &q2) const 00156 { 00157 return HQuat(x-q2.x, y-q2.y, z-q2.z, w-q2.w); 00158 } 00159 00165 HQuat operator +(const HQuat &q2) const 00166 { 00167 return HQuat(x+q2.x, y+q2.y, z+q2.z, w+q2.w); 00168 } 00169 00176 static HQuat Qlog(const HQuat &q); 00177 00182 void ToMatrix(float matrix[16]); 00183 00184 00190 static HQuat Qexp(const HQuat &q); 00198 static HQuat Qlerp(const HQuat &q1,const HQuat &q2,float fraction); 00206 static HQuat Qslerp(const HQuat &q1,const HQuat &q2,float fraction); 00215 static HQuat QslerpNoInvert(const HQuat &q1,const HQuat &q2,float fraction); 00224 static HQuat QslerpNoInvertExtraSpins(const HQuat &q1,const HQuat &q2,float fraction, int ExtraSpins); 00234 static HQuat Qsquad(const HQuat &q1,const HQuat &q2,const HQuat &a,const HQuat &b,float fraction); 00242 static HQuat Qspline(const HQuat &qnm1,const HQuat &qn,const HQuat &qnp1); 00247 static HQuat MatrixToQuaternion(float *matrix); 00248 00249 }; 00250 00251 00252 00254 00260 class MVO_API HKeyframe 00261 { 00262 public: 00266 HKeyframe() 00267 { 00268 m_bConstant = false; 00269 m_bEaseInOut = false; 00270 } 00271 virtual ~HKeyframe() {}; 00272 00278 virtual HKeyframe *Clone() { 00279 HKeyframe *p = new HKeyframe; 00280 *p = *this; 00281 return p; 00282 } 00283 00287 virtual void Serialize(HUtilityXMLTag *xmlgen) { } 00288 00294 virtual void SetConstant(bool constant) { m_bConstant = constant; } 00300 virtual void SetEaseInOut(bool easeinout) { m_bEaseInOut = easeinout; } 00302 virtual void SetRelative(bool relative) { m_bRelative = relative; } 00303 00304 HANIKeyframeType m_type; 00305 bool m_bConstant; 00306 bool m_bRelative; 00307 bool m_bEaseInOut; 00308 }; 00309 00310 00312 00315 class MVO_API HKeyframeChannel : public HKeyframe 00316 { 00317 public: 00318 00322 HKeyframeChannel() 00323 { 00324 m_cp.Set(0.0f,0.0f,0.0f); 00325 m_type = HANIChannel; 00326 } 00327 virtual ~HKeyframeChannel() {}; 00328 00334 virtual HKeyframe *Clone () 00335 { 00336 HKeyframeChannel *p= new HKeyframeChannel; 00337 *p = *this; 00338 return p; 00339 } 00340 00349 virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res) { } 00350 00351 HPoint m_cp; 00352 HANIChannelType m_channeltype; 00353 }; 00354 00355 00356 00357 00359 class MVO_API HKeyframeChannelLinear : public HKeyframeChannel 00360 { 00361 public: 00362 00366 HKeyframeChannelLinear(float x=0, float y=0, float z=0) : HKeyframeChannel() 00367 { 00368 m_channeltype = HANILinear; 00369 m_cp.Set(x,y,z); 00370 } 00371 virtual ~HKeyframeChannelLinear() {}; 00372 00378 virtual HKeyframe *Clone () 00379 { 00380 HKeyframeChannelLinear *p= new HKeyframeChannelLinear; 00381 *p = *this; 00382 return p; 00383 } 00384 00393 virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res); 00394 00398 virtual void Serialize(HUtilityXMLTag *xmlgen); 00399 00400 }; 00401 00403 00406 class MVO_API HKeyframeChannelDiscrete : public HKeyframeChannel 00407 { 00408 public: 00409 00413 HKeyframeChannelDiscrete(float x=0, float y=0, float z = 0) : HKeyframeChannel() 00414 { 00415 m_channeltype = HANIDiscrete; 00416 m_cp.Set(x,y,z); 00417 00418 } 00419 virtual ~HKeyframeChannelDiscrete() {}; 00420 00426 virtual HKeyframe *Clone () 00427 { 00428 HKeyframeChannelDiscrete *p= new HKeyframeChannelDiscrete; 00429 *p = *this; 00430 return p; 00431 } 00432 00443 virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res); 00444 00448 virtual void Serialize(HUtilityXMLTag *xmlgen); 00449 00450 }; 00451 00452 00453 00455 00457 class MVO_API HKeyframeChannelCurve : public HKeyframeChannel 00458 { 00459 public: 00460 00464 HKeyframeChannelCurve(float x = 0, float y = 0, float z = 0) : HKeyframeChannel() 00465 { 00466 m_channeltype = HANIHermiteSpline; 00467 m_cp.Set(x,y,z); 00468 00469 } 00470 virtual ~HKeyframeChannelCurve() {}; 00471 00477 virtual HKeyframe *Clone () 00478 { 00479 HKeyframeChannelCurve *p= new HKeyframeChannelCurve; 00480 *p = *this; 00481 return p; 00482 } 00483 00490 void CalculateCurveFactor(HBhvTimeline *timeline, int keyframe); 00491 00500 void CalculateHermiteTangents(HPoint p0, HPoint p2, HPoint p3, float a = 0.5f); 00501 00509 HPoint InterpolateHermiteSpline(float fraction, HPoint p1, HPoint p2); 00510 00511 // HPoint InterpolateBezierSpline(float fraction, HPoint p2); 00512 00513 00518 void CalculateCurveLength(HPoint p2); 00519 00525 void DrawTangents(HPoint p2); 00526 00535 virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res); 00536 00540 virtual void Serialize(HUtilityXMLTag *xmlgen); 00541 00542 HPoint m_tangent1; 00543 HPoint m_tangent2; 00544 float m_factor1; 00545 float m_factor2; 00546 HPoint* control_polygon; 00547 float ItemType; 00548 float c; 00549 float b; 00550 float m_curvelength; 00552 }; 00553 00555 00559 class MVO_API HKeyframeChannelFollowPath : public HKeyframeChannelCurve 00560 { 00561 00562 public: 00563 00567 HKeyframeChannelFollowPath() 00568 { 00569 m_channeltype = HANIFollowPath; 00570 m_bLinear = false; 00571 } 00572 virtual ~HKeyframeChannelFollowPath() {}; 00573 00579 virtual HKeyframe *Clone () 00580 { 00581 HKeyframeChannelFollowPath *p= new HKeyframeChannelFollowPath; 00582 *p = *this; 00583 return p; 00584 } 00585 00594 virtual void Interpolate(HKeyframeChannel **posarray, int keyframe, float fraction, int length, HPoint &res); 00595 virtual void Serialize(HUtilityXMLTag *xmlgen); 00596 00597 // virtual void Serialize(HUtilityXMLTag *xmlgen); 00598 float tmatrix[16]; 00599 float tmatrix2[16]; 00600 bool m_bLinear; 00601 bool m_bNoRotate; 00602 }; 00603 00604 00605 00606 00608 class MVO_API HKeyframeRotation : public HKeyframe 00609 { 00610 public: 00611 00615 HKeyframeRotation() 00616 { 00617 m_type = HANIRotation; 00618 m_bLinear = false; 00619 } 00620 virtual ~HKeyframeRotation() {}; 00621 00627 virtual HKeyframe *Clone () 00628 { 00629 HKeyframeRotation *p= new HKeyframeRotation; 00630 *p = *this; 00631 return p; 00632 } 00633 00634 HANIRotationType m_rotationtype; 00635 bool m_bLinear; 00637 }; 00638 00639 00640 00642 class MVO_API HKeyframeAxisRotation : public HKeyframeRotation 00643 { 00644 public: 00645 00646 00651 HKeyframeAxisRotation(float angle = 0) 00652 { 00653 m_rotationtype = HANIAxisRotation; 00654 m_angle = angle; 00655 00656 } 00657 virtual ~HKeyframeAxisRotation() {}; 00658 00664 virtual HKeyframe *Clone () 00665 { 00666 HKeyframeAxisRotation *p= new HKeyframeAxisRotation; 00667 *p = *this; 00668 return p; 00669 00670 } 00671 00675 virtual void Serialize(HUtilityXMLTag *xmlgen); 00676 00677 float m_angle; 00678 }; 00679 00680 00682 class MVO_API HKeyframeQuatSlerp : public HKeyframeRotation 00683 { 00684 public: 00685 00689 HKeyframeQuatSlerp(float x = 0, float y = 0, float z = 0, float w = 0) 00690 { 00691 m_rotationtype = HANIQuatSlerpRotation; 00692 m_quat.Set(x,y,z,w); 00693 } 00694 00695 virtual ~HKeyframeQuatSlerp() {}; 00696 00702 virtual HKeyframe *Clone () 00703 { 00704 HKeyframeQuatSlerp *p= new HKeyframeQuatSlerp; 00705 *p = *this; 00706 return p; 00707 } 00708 00709 HQuat m_quat; 00710 }; 00711 00712 00713 00714 00716 class MVO_API HKeyframeQuatSquad : public HKeyframeRotation 00717 { 00718 public: 00719 00720 00724 HKeyframeQuatSquad(float x = 0, float y = 0, float z = 0, float w = 0) 00725 { 00726 m_rotationtype = HANIQuatSquadRotation; 00727 m_quat.Set(x,y,z,w); 00728 m_ExtraSpins = 0; 00729 00730 } 00731 virtual ~HKeyframeQuatSquad() {}; 00732 00738 virtual HKeyframe *Clone () 00739 { 00740 HKeyframeQuatSquad *p= new HKeyframeQuatSquad; 00741 *p = *this; 00742 return p; 00743 } 00744 00748 virtual void Serialize(HUtilityXMLTag *xmlgen); 00749 00750 HQuat m_quat; 00751 int m_ExtraSpins; 00752 00753 }; 00754 00755 00757 class MVO_API HKeyframeMatrix : public HKeyframeRotation 00758 { 00759 public: 00760 00761 00765 HKeyframeMatrix(float * matrix = 0) 00766 { 00767 m_rotationtype = HANIQuatSquadRotation; 00768 00769 if (matrix) 00770 { 00771 for (int i=0;i<16;i++) 00772 m_matrix[i] = matrix[i]; 00773 } 00774 00775 } 00776 virtual ~HKeyframeMatrix() {}; 00777 00783 virtual HKeyframe *Clone () 00784 { 00785 HKeyframeMatrix *p= new HKeyframeMatrix; 00786 *p = *this; 00787 return p; 00788 } 00789 00793 virtual void Serialize(HUtilityXMLTag *xmlgen); 00794 00795 float m_matrix[16]; 00796 int m_ExtraSpins; 00797 00798 }; 00799 00800 00801 00802 00803 00805 00809 class MVO_API HKeyframeString : public HKeyframe 00810 { 00811 public: 00812 00816 HKeyframeString(); 00817 virtual ~HKeyframeString() {}; 00818 00824 virtual HKeyframe *Clone () 00825 { 00826 HKeyframeString *p= new HKeyframeString; 00827 *p = *this; 00828 return p; 00829 } 00830 00834 virtual void Serialize(HUtilityXMLTag *xmlgen); 00835 00836 00841 void SetTarget(const char *target); 00842 00845 char * GetTarget() { return m_target; } 00846 00847 char m_target[MVO_BUFFER_SIZE]; 00848 bool m_bDiscrete; 00849 00850 }; 00851 00852 00854 00858 class MVO_API HKeyframe3String : public HKeyframe 00859 { 00860 public: 00861 00865 HKeyframe3String(); 00866 virtual ~HKeyframe3String() {}; 00867 00873 virtual HKeyframe *Clone () 00874 { 00875 HKeyframe3String *p= new HKeyframe3String; 00876 *p = *this; 00877 return p; 00878 } 00879 00883 virtual void Serialize(HUtilityXMLTag *xmlgen); 00884 00885 00890 void SetTarget(const char *t1, const char *t2, const char *t3); 00891 00894 char * GetTarget1() { return m_t1; } 00895 char * GetTarget2() { return m_t2; } 00896 char * GetTarget3() { return m_t3; } 00897 00898 char m_t1[255]; 00899 char m_t2[255]; 00900 char m_t3[255]; 00902 }; 00903 00904 00905 00906 00907 00909 00913 class MVO_API ShellMorphInfo { 00914 public: 00915 00919 ShellMorphInfo(); 00920 struct vlist_s* arrays_list; 00921 HC_KEY original_key; 00922 HC_KEY temp_key; 00924 }; 00925 00926 00927 00928 #ifndef SWIG 00929 00930 class MVO_API TK_Bhv_XML : public TK_XML 00931 { 00932 00933 00934 public: 00935 00940 TK_Bhv_XML(HBaseModel * model) : TK_XML() 00941 { 00942 m_pModel = model; 00943 } 00944 00946 TK_Status Interpret(BStreamFileToolkit &tk, ID_Key key, int variant) alter; 00948 TK_Status Execute (BStreamFileToolkit & tk) alter; 00949 00950 private: 00951 HBaseModel * m_pModel; 00952 }; 00953 #endif 00954 00955 00956 00958 class MVO_API HBhvUtility 00959 { 00960 public: 00961 00967 static void GetQuatPoint(HUtilityTextParser *tp, HQuat &quat); 00968 static void GetMatrix(HUtilityTextParser *tp, float *matrix); 00969 00970 00976 static void GetQuatPoint(const char *text, HQuat &quat); 00977 00978 static void GetMatrix(const char *text, float *matrix); 00979 00980 00986 static void ConvertHSFtoMorph(const char *filename, HBaseModel *model); 00987 00993 static void ConvertHSFtoSegSwitch(const char *filename, HBaseModel *model); 00994 01000 static void SetupAnimationReadFromHSF(HStreamFileToolkit *mytool, HBaseModel *model); 01001 01007 static void SetupAnimationWriteFromHSF(HStreamFileToolkit *mytool, HBaseModel *model); 01008 01013 static void ShowModellingMatrix(float *segment_modelling_matrix); 01014 01015 static void MakeCameraKeyframe(HBaseView *view, float timediff, bool targetmode = false); 01016 01017 static HBhvAnimation* AddAnimation(HBaseModel *model, char *name, char *targetpath, HPoint *pivot); 01018 static void AddPosKeyframe(HBaseModel *model, char *animname, int tick, HPoint pos, bool linear); 01019 static void AddRotKeyframe(HBaseModel *model, char *animname, int tick, HQuat pos, bool linear); 01020 static void AddPosRotKeyframe(HBaseModel *model, const char *animname, int tick, HPoint pivot, float *matrix); 01021 static void AddMatrixKeyframe(HBaseModel *model, HBhvAnimation *ani, int tick, float *matrix); 01022 01023 static void AddPosRotKeyframe(HBaseModel *model, char *animname, int tick, HPoint pos, bool linear, HQuat quat, bool linear2); 01024 static void AddInstanceCreateKeyframe(HBaseModel *model, char *animname, int tick, char *path, char *include_path, char *color); 01025 static void AddSegmentMoveKeyframe(HBaseModel *model, HBhvAnimation *anim, int tick, char *path); 01026 01027 01028 01029 01030 01031 private: 01032 static void Move_Segments_To_Segment(HC_KEY target, HC_KEY destination); 01033 static void AddShellToMorphList(HC_KEY key, struct vlist_s *morph_data_list); 01034 static bool KeyExists(HC_KEY key, struct vlist_s *morp_data_list); 01035 static void ResetMorphData(struct vlist_s *morp_data_list); 01036 static void CollectShellMorphData(HC_KEY key, struct vlist_s *morp_data_list); 01037 static void ClearAllAttributes(HC_KEY key); 01038 static int searchcounter; 01039 }; 01040 01041 typedef struct 01042 { 01043 HC_KEY segkey; 01044 float *matrix; 01045 HBhvAnimation *anim; 01046 HBhvAnimation *anim2; 01047 int tick; 01048 int tick2; 01049 char *path; 01050 }segmentanimation; 01051 01052 01053 class MVO_API HBhvSegmentTracker 01054 { 01055 public: 01056 HBhvSegmentTracker(HBaseModel *model); 01057 void MakeTreeSnapshotRecursive(HC_KEY segkey, HC_KEY newsegkey, MVO_POINTER_SIZED_INT &uid); 01058 void MakeTreeSnapshot(); 01059 01060 HC_KEY m_TrackerKey; 01061 HBaseModel *m_pModel; 01062 struct vhash_s * m_NewIncludesHash; 01063 }; 01064 01065 class MVO_API HBhvKeyframeGenerator 01066 { 01067 public: 01068 HBhvKeyframeGenerator(HBaseModel * model); 01069 01070 void NewFrame(); 01071 void StartFrames(); 01072 01073 bool CompareMatrices(float *m1, float *m2); 01074 01075 private: 01076 HBaseModel *m_pModel; 01077 struct vlist_s * m_Anims; 01078 struct vhash_s * m_Segments; 01079 int m_AnimCounter; 01080 int m_Tick; 01081 bool m_bFirstFrame; 01082 HBhvSegmentTracker *m_pSegmentTracker; 01083 }; 01084 01085 01086 01087 01088 01089 #ifdef H_PACK_8 01090 #pragma pack(pop) 01091 #endif 01092 01093 #endif 01094 01095 01096