159 lines
4.6 KiB
C++
159 lines
4.6 KiB
C++
/*************************************************************************/
|
|
/* File : XLoader.h */
|
|
/* */
|
|
/* DirectX .X files loader */
|
|
/* */
|
|
/* Virtools SDK */
|
|
/* Copyright (c) Virtools 2000, All Rights Reserved. */
|
|
/*************************************************************************/
|
|
|
|
#ifndef _XLOADER_H
|
|
#define _XLOADER_H
|
|
|
|
#include "Windows.h"
|
|
#include "stdio.h"
|
|
#include "DxFile.h"
|
|
#include "rmxfguid.h"
|
|
#include "rmxftmpl.h"
|
|
#include "Ge2Virtools.h"
|
|
|
|
|
|
// Hash Tables (objects name <-> objects)
|
|
// used for meshes , materials and frames
|
|
typedef XHashTable<CKObject*,XString> XCKObjectsHashTable;
|
|
typedef XHashTable<CKObject*,XString>::Iterator XCKObjectsHashTableIt;
|
|
typedef XHashTable<CKObject*,XString>::Pair XCKObjectsHashTablePair;
|
|
|
|
|
|
|
|
// X File rotate key structure
|
|
struct XFileRotateKey
|
|
{
|
|
DWORD Time;
|
|
DWORD FCount; // Normally always 4
|
|
float w;
|
|
float x;
|
|
float y;
|
|
float z;
|
|
};
|
|
|
|
// X File position and scale key structure
|
|
struct XFileVectorKey
|
|
{
|
|
DWORD Time;
|
|
DWORD FCount; // Normally always 3
|
|
VxVector Key;
|
|
};
|
|
|
|
|
|
// X File Matrix key structure
|
|
struct XFileMatrixKey
|
|
{
|
|
DWORD Time;
|
|
DWORD FCount; // Normally always 16
|
|
VxMatrix Key;
|
|
};
|
|
|
|
XString GetFileObjectName(LPDIRECTXFILEOBJECT obj);
|
|
|
|
|
|
#define SAFERELEASE(x) { if (x) x->Release(); x = NULL; }
|
|
|
|
/**************************************************
|
|
+ Overload of a model reade
|
|
+
|
|
***************************************************/
|
|
class CKXReader: public CKModelReader {
|
|
public:
|
|
void Release() {delete this; };
|
|
|
|
// Reader Info
|
|
virtual CKPluginInfo* GetReaderInfo();
|
|
|
|
// No specific Options
|
|
virtual int GetOptionsCount() { return 0; }
|
|
virtual CKSTRING GetOptionDescription(int i) { return NULL; }
|
|
|
|
// This reader can only load .X files
|
|
virtual CK_DATAREADER_FLAGS GetFlags() {return (CK_DATAREADER_FLAGS)CK_DATAREADER_FILELOAD;}
|
|
|
|
// Load Method
|
|
virtual CKERROR Load(CKContext* context,CKSTRING FileName,CKObjectArray *liste,CKDWORD LoadFlags,CKCharacter *carac=NULL);
|
|
|
|
CKXReader() {
|
|
m_XFile = NULL;
|
|
m_Context = NULL;
|
|
m_VirtoolsExport = NULL;
|
|
m_XFileEnumerator = NULL;
|
|
m_Unnamed = 0;
|
|
}
|
|
~CKXReader() {
|
|
CleanUp();
|
|
}
|
|
|
|
protected:
|
|
void CleanUp() {
|
|
SAFERELEASE(m_XFileEnumerator);
|
|
SAFERELEASE(m_XFile);
|
|
delete m_VirtoolsExport;
|
|
m_VirtoolsExport = NULL;
|
|
}
|
|
//-- High level
|
|
HRESULT LoadFileData(LPDIRECTXFILEDATA CurData,CK3dEntity* Parent);
|
|
//-- Medium level
|
|
HRESULT LoadAnimationSet(LPDIRECTXFILEDATA CurData);
|
|
HRESULT LoadAnimation(LPDIRECTXFILEDATA CurData);
|
|
HRESULT LoadMesh(LPDIRECTXFILEOBJECT CurData,CK3dEntity* Parent);
|
|
CKMaterial* LoadMaterial(LPDIRECTXFILEOBJECT CurData);
|
|
//-- low level ....
|
|
|
|
//--- Per Anim
|
|
void LoadAnimationPositionKey(CKObjectAnimation* anim,DWORD KeyCount,DWORD* keys);
|
|
void LoadAnimationRotationKey(CKObjectAnimation* anim,DWORD KeyCount,DWORD* keys);
|
|
void LoadAnimationScaleKey(CKObjectAnimation* anim,DWORD KeyCount,DWORD* keys);
|
|
void LoadAnimationMatrixKey(CKObjectAnimation* anim,DWORD KeyCount,DWORD* keys);
|
|
|
|
//--- Per Mesh
|
|
HRESULT LoadMeshVertexColors(LPDIRECTXFILEDATA CurData,VirtoolsTransitionMesh* m);
|
|
HRESULT LoadMeshTextureCoords(LPDIRECTXFILEDATA CurData,VirtoolsTransitionMesh* m);
|
|
HRESULT LoadMeshMaterials(LPDIRECTXFILEDATA CurData,VirtoolsTransitionMesh* m);
|
|
HRESULT LoadMeshNormals(LPDIRECTXFILEDATA CurData,VirtoolsTransitionMesh* m);
|
|
HRESULT LoadSkinBone(LPDIRECTXFILEDATA CurData,VirtoolsTransitionMesh* m,CK3dEntity* Parent);
|
|
//--- Per Frame
|
|
HRESULT LoadTransformationMatrix(LPDIRECTXFILEDATA CurData,CK3dEntity* Parent);
|
|
|
|
//--- Return TRUEif we are in character mode (in which case
|
|
//--- we have to create bodyparts instead of CK3dobjects...
|
|
BOOL CharacterMode() { return m_Character ? TRUE : ((m_LoadFlags & CK_LOAD_ASCHARACTER)!=0); }
|
|
|
|
//-- For unnamed objects return a generic string "Unnamed_XX"
|
|
XString GetUnnamed() { XString Temp = "Unnamed_"; Temp << m_Unnamed++; return Temp; }
|
|
|
|
public:
|
|
CKContext* m_Context;
|
|
CK_OBJECTCREATION_OPTIONS m_CreationOptions;
|
|
CKCharacter* m_Character;
|
|
DWORD m_LoadFlags;
|
|
CK_CLASSID m_3dObjectsClass;
|
|
XString m_FileName;
|
|
|
|
Export2Virtools* m_VirtoolsExport;
|
|
XCKObjectsHashTable m_MeshHashTable;
|
|
XCKObjectsHashTable m_FrameHashTable;
|
|
XCKObjectsHashTable m_MaterialHashTable;
|
|
int m_Unnamed;
|
|
float m_AnimationLength;
|
|
|
|
//--- X file objects
|
|
LPDIRECTXFILE m_XFile;
|
|
LPDIRECTXFILEENUMOBJECT m_XFileEnumerator;
|
|
|
|
//--- Bone arrays when skinning information is read before actual bones
|
|
XClassArray<XString> m_BonesName;
|
|
XArray<int> m_BonesIndex;
|
|
XArray<CKSkin*> m_Skins;
|
|
};
|
|
|
|
|
|
#endif
|