deargui-vpl/ref/virtools/Samples/ExportPlugins/3dsMax Export/Max2Nmo.h

415 lines
17 KiB
C++

//**************************************************************************
//* Max2Nmo.h - Virtools File Exporter
//*
//* Romain Sididris - Copyright (c) Virtools 2000
//*
//* (Based on Ascii File Exporter source code
//* By Christer Janson
//* Kinetix Development
//* Copyright (c) Kinetix 1997, All Rights Reserved. )
//*
//* Class Definition
//*
//***************************************************************************
//#define _USESCRIPTS_
extern ClassDesc* GetAsciiExpDesc();
extern ClassDesc* GetVirtoolsToolDesc();
extern TCHAR *GetString(int id);
extern HINSTANCE hInstance;
#define VERSION 150 // Version number * 100
#define CFGFILENAME _T("Max2NmoV.CFG") // Configuration file
#define MR3_CLASS_ID Class_ID(0x17bb6854, 0xa5cba2a3) // Morpher modifier
struct TextureUVGen {
BOOL TileU,TileV;
BOOL MirrorU,MirrorV;
BOOL Cropping;
float UOffset,VOffset;
float UScale,VScale;
float AngleMap;
float UCropOffset,VCropOffset;
float UCropScale,VCropScale;
TextureUVGen() {
TileU = TileV = MirrorU = MirrorV = Cropping = FALSE;
UOffset = VOffset = AngleMap = UCropOffset =VCropOffset = 0.0f;
UScale = VScale = UCropScale = VCropScale = 0.0f;
}
};
struct NodeMeshMtl {
void* mesh;
Mtl* mtl;
CKMesh* CKMesh;
};
class MtlKeeper {
public:
BOOL AddMtl(Mtl* mtl);
int GetMtlID(Mtl* mtl);
int Count();
Mtl* GetMtl(int id);
Tab<Mtl*> mtlTab;
};
// This is the main class for the exporter.
class Max2Nmo : public SceneExport {
public:
Max2Nmo();
~Max2Nmo();
void InitDefaultValues(); //set default values for exporter
void UpdateInterface(HWND hWnd); //update interface from exporter values
// SceneExport methods
int ExtCount(); // Number of extensions supported
const TCHAR * Ext(int n); // Extension #n (i.e. "Nmo")
const TCHAR * LongDesc(); // Long ASCII description (i.e. "Virtools Export")
const TCHAR * ShortDesc(); // Short ASCII description (i.e. "Virtools")
const TCHAR * AuthorName(); // ASCII Author name
const TCHAR * CopyrightMessage(); // ASCII Copyright message
const TCHAR * OtherMessage1(); // Other message #1
const TCHAR * OtherMessage2(); // Other message #2
unsigned int Version(); // Version number * 100 (i.e. v3.01 = 301)
void ShowAbout(HWND hWnd); // Show DLL's "About..." box
int DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts=FALSE, DWORD options=0); // Export file
BOOL SupportsOptions(int ext, DWORD options);
//-------------------------------------------------------------
// Other methods
// Register All Special Parameters
BOOL RegisterAllSpecialParameters();
// Really Export
int ReallyDoExport(const TCHAR *name, Interface *inf, BOOL sel );
#ifdef _USESCRIPTS_
// Evaluate User Defined Properties
BOOL evaluateNodeUserDefinedProperties( INode* node );
#endif
// Node enumeration
BOOL nodeEnum(INode* node);
void PreProcess(INode* node, int& nodeCount);
void PostProcess(INode* node);
// High level export
void ExportMaterialList();
void ExportGeomObject(INode* node);
void ExportLightObject(INode* node);
void ExportCameraObject(INode* node);
void ExportShapeObject(INode* node);
void ExportHelperObject(INode* node);
void ExportLevelSettings();
// Mid level export
void ExportMesh(INode* node,CK3dEntity* ent);
void ExportPatchMesh(INode* node,CK3dEntity* ent);
void ExportAnimKeys(INode* node,CK3dEntity* ent);
void ExportAnimMesh(INode* node);
BOOL ExportSkinnedMesh(INode* node,CK3dEntity* ent);
BOOL ExportPhysiqueMesh(INode* node,CK3dEntity* ent);
void ExportBlendShapes(INode* node, Mesh* refMesh, VirtoolsTransitionMesh& vMesh);
#ifndef MAX42
BOOL ExportPhysiqueMeshCS312(INode* node,CK3dEntity* ent);
#endif
BOOL ExportPhysiqueMeshCS300(INode* node,CK3dEntity* ent);
void ExportIKJoints(INode* node);
void ExportNodeBase(INode* node,CK3dEntity* entity);
BOOL ExportStartingCamera( CKCamera* startCam, float fogNear, float fogFar );
// Material export
CKMaterial* DumpMaterial(Mtl* mtl);
void DumpMaterialStandard(Mtl* mtl, VirtoolsMaterial &NMat, BOOL &OpacityValid);
void DumpMaterialTextures(StdMat* stdM, VirtoolsMaterial &NMat, BOOL &OpacityValid);
CKTexture* ConvertTextureMap(StdMat* stdM, int MapToRetrieve, float &MixAmount, void* &oKey);
void DumpMaterialBakedShell(Mtl* mtl, VirtoolsMaterial &NMat, BOOL &OpacityValid);
BOOL DumpMaterialLM(Mtl* mtl, VirtoolsMaterial &NMat);
//Low Level
void DumpUVGen(StdUVGen* uvGen);
// Animation
//returns false if not supported
BOOL DumpIndePos(INode* node,Control* cont,CKObjectAnimation* anim); // In case of supported PositionController
BOOL DumpIndeRot(INode* node,Control* cont,CKObjectAnimation* anim); // In case of supported PositionController
void DumpSampledAnim(INode* node,CKObjectAnimation* anim); // In case of sampling
void DumpPosKeys(Control* cont,CKObjectAnimation* anim); // In case of supported PositionController
void DumpRotKeys(Control* cont,CKObjectAnimation* anim); // In case of supported RotationController
void DumpScaleKeys(Control* cont,CKObjectAnimation* anim); // In case of supported ScaleController
void DumpMeshMorphKey(CKMorphController* ctrl,INode* node,TimeValue t);
void DumpPatchMeshMorphKey(CKMorphController* ctrl,INode* node,TimeValue t);
void DumpSampledFloatAnim(Control* cont, CKObjectAnimation* anim, float scale, const char* targetBlendShapeName);
void DumpFloatKeys(Control* cont, CKObjectAnimation* anim, float scale, const char* targetBlendShapeName);
//UI
void UIToolTips(HWND hWnd);
void UICreateToolTip(HWND hWnd, LPTSTR lptstr);
void UIUpdate(HWND hWnd);
void UIEnableCharacter(HWND hWnd, BOOL v);
void UIEnableLevel(HWND hWnd, BOOL v);
void UIEnableTextureOptions(HWND hWnd, BOOL v);
void UIEnableAnimation(HWND hWnd, BOOL v);
void UIAnimationOnly(HWND hWnd);
void UIEnableGeometryOptions(HWND hWnd, BOOL v );
void UIEnableResizeTexture(HWND hWnd, BOOL v );
void UIEnableReadChannels(HWND hWnd, BOOL v );
void UIEnableReport(HWND hWnd, BOOL v );
const char* UIGetFilename(HWND hWnd, TCHAR oFileName[], DWORD iMaxLength, TCHAR* szFilter=NULL, BOOL iSave=FALSE);
// Misc utility methods
Point3 GetVertexNormal(Mesh* mesh, int faceNo, RVertex* rv);
void make_face_uv(Face *f, VxUV *tv);
BOOL TMNegParity(Matrix3 &m);
BOOL CheckForAnimation(INode* node, BOOL& pos, BOOL& rot, BOOL& scale,BOOL& scaleAxis);
BOOL IsKnownController(Control* cont);
void ConvertMaxMatrix2Virtools(Matrix3 &m, VxMatrix& WM);
void ConvertMaxLightMatrix2Virtools(Matrix3 &m, VxMatrix& WM);
Modifier* FindSkinModifier (INode* node);
Modifier* FindModifier(INode* node, Class_ID classID, int* modifierIndex = NULL, IDerivedObject** derivedObj = NULL);
CKDWORD GetModifierCount(INode* node, Class_ID classID);
void DeleteNodes(const INodeTab& nodes);
#ifndef MAX42
Modifier* FindSkinModifierCS312 (INode* node);
#endif
Modifier* FindSkinModifierCS300 (INode* node);
Modifier* FindPhysiqueModifier (INode* node);
#ifndef MAX42
Modifier* FindPhysiqueModifierCS312 (INode* node);
#endif
Modifier* FindPhysiqueModifierCS300 (INode* node);
TriObject* GetTriObjectFromNode(INode *node, TimeValue t, int &deleteIt);
PatchObject* GetPatchObjectFromNode(INode *node,TimeValue t,int &deleteIt);
SplineShape* GetSplineShapeFromNode(INode *node,TimeValue t,int &deleteIt);
Matrix3 GetNodeOffsetTM(INode* node);
Mtl* GetMaterialByIndex(Mtl *pMtl,DWORD MatId,int MapChannel, void*& returnedKey, BOOL iSearchingForChannel = false );
BOOL GetTextureUvGen(Mtl* pMtl,TextureUVGen& uvgen);
void ApplyUvGen(VxUV& uv,TextureUVGen& uvgen,BOOL useUVGen);
// Configuration file IO methods
TSTR GetCfgFilename();
BOOL ReadConfig();
void WriteConfig();
// Interface to member variables
inline BOOL GetShowProgressionBar() { return bShowProgressionBar; }
inline BOOL GetExportAsObjects() { return bExportAsObjects; }
inline BOOL GetExportAsCharacter() { return bExportAsCharacter; }
inline BOOL GetExportAsAnimationOnly() { return bExportAsAnimationOnly; }
inline BOOL GetExportAsLevel() { return bExportAsLevel; }
inline BOOL GetConvertPhysiqueToSkin() { return bConvertPhysiqueToSkin; }
inline BOOL GetForceSkinToMorph() { return bForceSkinToMorph; }
inline BOOL GetStoreOnlyFilenames() { return bStoreOnlyTextureFilenames; }
inline BOOL GetRescaleScene() { return bRescaleScene; }
inline BOOL GetSaveBipedGeom() { return bSaveBipedGeom; }
inline BOOL GetGroupAsPlace() { return bGroupAsPlace; }
inline BOOL GetSelectionAsGroup() { return bSelectionAsGroup; }
inline TSTR GetCharacterName() { return szCharacterName.Str(); }
inline TSTR GetAnimationName() { return szAnimationName.Str(); }
inline int GetMeshFrameStep() { return nMeshFrameStep; }
inline int GetKeyFrameStep() { return nKeyFrameStep; }
inline int GetStaticFrame() { return 0; }
inline int GetCompressionLevel() { return nCompressionLevel; }
inline int GetReportLevel() { return nReportLevel; }
inline Interface* GetInterface() { return ip; }
inline BOOL GetAlignAnimOnZ() { return bAlignAnimOnZ; }
inline BOOL ReduceRedondantKeys() { return bReduceRedondantKeys; }
inline BOOL GetShellMaterialExportBoth() {return bShellMaterialExportBoth; }
inline BOOL GetIgnore1KeyAnimation() {return bIgnore1KeyAnimation; }
inline BOOL GetExportAnimation() {return bExportAnimation;}
inline float GetKeysThreshold() {return fKeysThreshold;}
inline BOOL GetForceAllUVs() {return bForceAllUVs;}
inline BOOL GetSplitMesh() {return bSplitMesh;}
inline BOOL GetLOD() {return bLOD;}
inline BOOL GetSplinesAsDummies() {return bSplinesAsDummies;}
inline BOOL GetExportAlphaMap() {return bExportAlphaMap;}
inline BOOL GetUsePower2() {return bUsePower2;}
inline BOOL GetForce1x1Ratio() {return bForce1x1Ratio;}
inline int GetForce1x1RatioMethod() {return nForce1x1RatioMethod;}
inline BOOL GetDeactivateMeshChannels() {return bDeactivateMeshChannels;}
inline BOOL GetHideHelpers() {return bHideHelpers;}
inline BOOL GetDASIAnimation() {return bDASIAnimation;}
inline BOOL GetDASIMesh() {return bDASIMesh;}
inline BOOL GetDASIMaterial() {return bDASIMaterial;}
inline BOOL GetDASITexture() {return bDASITexture;}
inline const char* GetStartingCamera() {return sStartingCamera.CStr();}
inline BOOL GetReadChannels() {return bReadChannels;}
inline const char* GetReadChannelsFilename(){return szReadChannelsFilename.CStr();}
inline BOOL GetReport() {return bReport;}
inline const char* GetReportFilename() {return szReportFilename.CStr();}
inline BOOL GetAlphaRef() {return bAlphaRef;}
inline int GetAlphaRefValue() {return iAlphaRefValue;}
inline BOOL GetExportBlendShapes() {return bExportBlendShapes;}
inline BOOL GetExportBlendShapeAnims() {return bExportBlendShapeAnims;}
inline BOOL GetIncludeBlendShapesInMorphController() {return bIncludeBlendShapesInMorphController;}
inline BOOL GetReduceRedondantBlendShapesKeys() { return bReduceRedondantBlendShapesKeys; }
inline float GetBlendShapesKeysThreshold() {return fBlendShapesKeysThreshold;}
inline int GetBlendShapesStep() { return nBlendShapesStep; }
inline void SetShowProgressionBar(BOOL v) { bShowProgressionBar = v; }
inline void SetExportAsObjects(BOOL v) { bExportAsObjects = v ; }
inline void SetExportAsCharacter(BOOL v) { bExportAsCharacter = v ; }
inline void SetExportAsAnimationOnly(BOOL v) { bExportAsAnimationOnly = v ; }
inline void SetExportAsLevel(BOOL v) { bExportAsLevel = v ; }
inline void SetConvertPhysiqueToSkin(BOOL v) { bConvertPhysiqueToSkin = v ; }
inline void SetForceSkinToMorph(BOOL v) { bForceSkinToMorph = v ; }
inline void SetStoreOnlyFilenames(BOOL v) { bStoreOnlyTextureFilenames = v ; }
inline void SetRescaleScene (BOOL v) { bRescaleScene = v ; }
inline void SetSaveBipedGeom(BOOL v) { bSaveBipedGeom = v ; }
inline void SetGroupAsPlace(BOOL v) { bGroupAsPlace = v ; }
inline void SetSelectionAsGroup(BOOL v) { bSelectionAsGroup = v ; }
inline void SetCharacterName(char* v) { szCharacterName = XString(v) ; }
inline void SetAnimationName(char* v) { szAnimationName = XString(v) ; }
inline void SetMeshFrameStep(int v) { nMeshFrameStep = v ; }
inline void SetKeyFrameStep(int v) { nKeyFrameStep = v ; }
inline void SetCompressionLevel(int v) { nCompressionLevel = v ; }
inline void SetReportLevel(int v) { nReportLevel = v ; }
inline void SetbAlignAnimOnZ(BOOL v) { bAlignAnimOnZ = v ; }
inline void SetReduceRedondantKeys(BOOL v) { bReduceRedondantKeys = v ; }
inline void SetShellMaterialAsSingle(BOOL v) { bShellMaterialExportBoth = v; }
inline void SetIgnore1Keyanimation(BOOL v) { bIgnore1KeyAnimation= v ; }
inline void SetExportAnimation(BOOL v) {bExportAnimation= v;}
inline void SetKeysThreshold(float f) {fKeysThreshold=f;}
inline void SetForceAllUVs(BOOL v) {bForceAllUVs= v;}
inline void SetSplitMesh(BOOL v) {bSplitMesh= v;}
inline void SetLOD(BOOL v) {bLOD= v;}
inline void SetSplinesAsDummies(BOOL v) {bSplinesAsDummies= v;}
inline void SetExportAlphaMap(BOOL v) {bExportAlphaMap= v;}
inline void SetUsePower2(BOOL v) {bUsePower2= v;}
inline void SetForce1x1Ratio(BOOL v) {bForce1x1Ratio= v;}
inline void SetForce1x1RatioMethod(int v) {nForce1x1RatioMethod= v;}
inline void SetDeactivateMeshChannels(BOOL v) {bDeactivateMeshChannels= v;}
inline void SetHideHelpers(BOOL v) {bHideHelpers= v;}
inline void SetDASIAnimation(BOOL v) {bDASIAnimation= v;}
inline void SetDASIMesh(BOOL v) {bDASIMesh= v;}
inline void SetDASIMaterial(BOOL v) {bDASIMaterial= v;}
inline void SetDASITexture(BOOL v) {bDASITexture= v;}
inline void SetStartingCamera(const char* v) {sStartingCamera= v;}
inline void SetReadChannels(BOOL v) {bReadChannels=v;}
inline void SetReadChannelsFilename(char* v) {szReadChannelsFilename=v;}
inline void SetReport(BOOL v) {bReport=v;}
inline void SetReportFilename(char* v) {szReportFilename=v;}
inline void SetAlphaRef(BOOL v) {bAlphaRef=v;}
inline void SetAlphaRefValue(int v) {iAlphaRefValue=v;}
inline void SetExportBlendShapes(BOOL v) {bExportBlendShapes=v;}
inline void SetExportBlendShapeAnims(BOOL v) {bExportBlendShapeAnims=v;}
inline void SetIncludeBlendShapesInMorphController(BOOL v) {bIncludeBlendShapesInMorphController=v;}
inline void SetReduceRedondantBlendShapesKeys(BOOL v) { bReduceRedondantBlendShapesKeys = v ; }
inline void SetBlendShapesKeysThreshold(float f) {fBlendShapesKeysThreshold=f;}
inline void SetBlendShapesStep(int v) { nBlendShapesStep = v; }
inline void CopyUV(void* UVDest,void* UVSrc) {
DWORD* Dst = (DWORD*)UVDest; DWORD* Src = (DWORD*)UVSrc;
*(Dst++) = *(Src++); *Dst = *Src;
}
inline float FrameTime(TimeValue t) { return ((float )t-m_StartFrame)*m_InvFrameRate; }
CKMesh* IsMeshInstance(void* mesh,Mtl* mtl);
void InsertNewMeshInstance(void* mesh,Mtl* mtl,CKMesh* ckmesh);
XArray<char> ReportBuffer;
void RescaleScene();
XString StrGroupIndent();
inline XString GetExportFileName() {return m_ExportFileName;}
private:
BOOL bShowProgressionBar;
BOOL bExportAsObjects;
BOOL bExportAsCharacter;
BOOL bExportAsAnimationOnly;
BOOL bExportAsLevel;
BOOL bConvertPhysiqueToSkin;
BOOL bForceSkinToMorph;
BOOL bStoreOnlyTextureFilenames;
BOOL bRescaleScene;
BOOL bSaveBipedGeom;
BOOL bGroupAsPlace;
BOOL bSelectionAsGroup;
BOOL bAlignAnimOnZ;
XString szCharacterName;
XString szAnimationName;
int nMeshFrameStep;
int nKeyFrameStep;
int nCompressionLevel;
int nReportLevel;
BOOL bReduceRedondantKeys;
BOOL bShellMaterialExportBoth;
BOOL bIgnore1KeyAnimation;
BOOL bExportAnimation;
float fKeysThreshold;
BOOL bForceAllUVs;
BOOL bSplitMesh;
BOOL bLOD;
BOOL bSplinesAsDummies;
BOOL bExportAlphaMap;
BOOL bUsePower2;
BOOL bForce1x1Ratio;
int nForce1x1RatioMethod;
BOOL bDeactivateMeshChannels;
BOOL bHideHelpers;
BOOL bDASIAnimation;
BOOL bDASIMesh;
BOOL bDASIMaterial;
BOOL bDASITexture;
XString sStartingCamera;
BOOL bReadChannels;
XString szReadChannelsFilename;
BOOL bReport;
XString szReportFilename;
BOOL bAlphaRef;
int iAlphaRefValue;
BOOL bExportBlendShapes;
BOOL bExportBlendShapeAnims;
BOOL bIncludeBlendShapesInMorphController;
BOOL bReduceRedondantBlendShapesKeys;
float fBlendShapesKeysThreshold;
int nBlendShapesStep;
float m_RescaleFactor;
Interface* ip;
int nTotalNodeCount;
int nCurNode;
float m_StartFrame,m_EndFrame,m_InvFrameRate;
MtlKeeper mtlList;
Export2Virtools* VirtoolsExporter;
CKContext* VirtoolsContext;
XList<CKGroup*> CKGroups;
int GroupIndent;
XArray<NodeMeshMtl> MeshTable;
BOOL UsedChannels[8];
CKObjectArray *m_VirtoolsObjects;
int ReportBufferPos;
GeLog* m_ReportGeLog;
void Report(int InfoLevel,char *format, ...);
//--- Hash table to retrieve Base Diffuse Material of Lightmap Shaders
XHashTable< Mtl*, XString, XHashFun<XString> > m_lightmapBaseMaterials;
// Fix Thomas Bucher
// We need to access the file name into the options dialog
// in order to know which kind of file (NMO, CMO, VMO) we are
// exporting, to enable the good options
XString m_ExportFileName;
};
#define REPORT_NONE 0
#define REPORT_HLEVEL 1
#define REPORT_MLEVEL 2
#define REPORT_LLEVEL 3