📄 max2nmo.cpp
字号:
//**************************************************************************
//* Max2Nmo.cpp - 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. )
//*
//* This module contains the DLL startup functions
//*
//***************************************************************************
#include "Precomp.h"
#include "Max2Nmo.h"
#ifdef _USESCRIPTS_
#include "PropertiesEvaluator.h"
#include "Special Parameter Registration.h"
#include "Special Parameter Registration2.h"
#endif
#ifdef CK_LIB
#include "CKLibIncludes.h"
#endif
HINSTANCE hInstance;
int controlsInit = FALSE;
BOOL VirtoolsPluginsParsed = FALSE;
static BOOL exportSelected;
#define MAX2NMO_CLASS_ID Class_ID(0x2dee0760, 0x75462793)
//---------------------------------------
// Character Studio 3.12 headers are not
// compatible with previous version need to
// add a version check !
//
// In Version 4.2 of 3dsMax we automatically consider that we use Character studio 3.2
BOOL g_CharacterStudio312;
#ifdef _USESCRIPTS_
//----------------------------------------
//--------------- Add MAXScript Function
#undef new
#undef delete
#include "MAXScrpt.h"
#include "definsfn.h"
def_visible_primitive( Export2NMO,"export2nmo");
Value *Export2NMO_cf( Value** arg_list, int count )
{
// export2Nmo "filename"
// [BOOL onlySelected]
// [int exportAs]
// [BOOL storeOnlyTextureFileName]
// [BOOL unitIsMeter]
// [BOOL groupToPlace]
// [BOOL SelectionAsGroup]
// [BOOL convertToSkin]
// [BOOL saveBipedGeom]
// [int samplingStepForKeyFrames]
// [int samplingStepForDeformables]
// [int compressionLevel]
// [int reportLevel]
// [string characterName]
// [string animationName]
check_arg_count("export2nmo", 15, count);
int i=-1;
// "filename"
++i;
char *fileName = arg_list[i]->to_string();
ClassDesc *aed = GetAsciiExpDesc();
Max2Nmo *exp = (Max2Nmo *)aed->Create();
// [BOOL onlySelected]
++i;
BOOL exportSelected = arg_list[i]->to_bool();
// [int exportAs]
++i;
int exportAs = arg_list[i]->to_int();
exp->SetExportAsObjects( exportAs==1 );
exp->SetExportAsCharacter( exportAs==2 );
exp->SetExportAsAnimationOnly( exportAs==3 );
#define READ_BOOL_PARAM( fct ) ++i; exp->fct( arg_list[i]->to_bool() );
#define READ_INT_PARAM( fct ) ++i; exp->fct( arg_list[i]->to_int() );
#define READ_STRING_PARAM( fct ) ++i; exp->fct( arg_list[i]->to_string() );
READ_BOOL_PARAM( SetStoreOnlyFilenames ); // [BOOL storeOnlyTextureFileName]
READ_BOOL_PARAM( SetRescaleScene );// [BOOL unitIsMeter]
READ_BOOL_PARAM( SetGroupAsPlace );// [BOOL groupToPlace]
READ_BOOL_PARAM( SetSelectionAsGroup );// [BOOL SelectionAsGroup]
READ_BOOL_PARAM( SetConvertPhysiqueToSkin );// [BOOL convertToSkin]
READ_BOOL_PARAM( SetSaveBipedGeom );// [BOOL saveBipedGeom]
READ_INT_PARAM( SetKeyFrameStep );// [int samplingStepForKeyFrames]
READ_INT_PARAM( SetMeshFrameStep );// [int samplingStepForDeformables]
READ_INT_PARAM( SetCompressionLevel );// [int compressionLevel]
READ_INT_PARAM( SetReportLevel );// [int reportLevel]
READ_STRING_PARAM( SetCharacterName );// [string characterName]
READ_STRING_PARAM( SetAnimationName );// [string animationName]
//--- Really Do Export
exp->SetShowProgressionBar( FALSE );
exp->ReallyDoExport( fileName, MAXScript_interface, exportSelected );
delete exp;
return &ok;
}
//----------------------------------------
//----------------------------------------
//--------------- Add Virtools Tool Button
#include "Maxscrpt\Parser.h"
#include "utilapi.h"
#define VIRTOOLSTOOL_CLASS_ID Class_ID(0x6c7e7fe9,0x379a5550)
class VirtoolsTool : public UtilityObj {
public:
XString m_ExportFileName;
public:
VirtoolsTool();
~VirtoolsTool();
void BeginEditParams(Interface *ip,IUtil *iu);
void EndEditParams(Interface *ip,IUtil *iu);
void DeleteThis() {}
};
static VirtoolsTool theVirtoolsTool;
class VirtoolsToolClassDesc:public ClassDesc {
public:
int IsPublic() {return 1;}
void * Create(BOOL loading = FALSE) {return &theVirtoolsTool;}
const TCHAR * ClassName() {return _T("Virtools Exporter");}
SClass_ID SuperClassID() {return UTILITY_CLASS_ID;}
Class_ID ClassID() {return VIRTOOLSTOOL_CLASS_ID;}
const TCHAR* Category() {return _T("");}
};
static VirtoolsToolClassDesc VirtoolsToolDesc;
ClassDesc* GetVirtoolsToolDesc(){ return &VirtoolsToolDesc; }
VirtoolsTool::VirtoolsTool(){
m_ExportFileName = "";
}
VirtoolsTool::~VirtoolsTool(){
}
void VirtoolsTool::BeginEditParams(Interface *ip,IUtil *iu)
{
CharStream *out = thread_local(current_stdout);
Parser *parser = new Parser (out);
// First instruction to know where we came from
XString initInst("global alreadyGivenFileName = ");
StringStream *initSource = new StringStream;
if( m_ExportFileName.Length() ){
initSource->init( (initInst + "\"" + m_ExportFileName + "\"").Str() );
} else {
initSource->init( (initInst + "undefined").Str() );
}
Value *code = parser->compile( initSource );
Value *result = code->eval();
delete initSource;
XString maxScriptDir(ip->GetDir(APP_SCRIPTS_DIR));
FileStream *source = (new FileStream)->open( (maxScriptDir + "\\CKInstScripts\\VirtoolsUtility.ms").Str() , "rt");
BOOL quiet=TRUE;
if (!quiet)
source->log_to(out);
// loop through file compiling and evaluating all expressions
try
{
//source->flush_whitespace();
while (!source->at_eos())
{
code = parser->compile(source);
result = code->eval();
if (!quiet)
result->print();
//source->flush_whitespace();
}
source->close();
}
catch (...)
{
// catch any errors and tell what file we are in if any
out->printf("Error occurred in file: ");
source->sprin1(out);
out->printf("\n");
//throw;
}
/*
code = parser->compile_all(source);
result = code->eval();
source->close();
*/
delete parser;
m_ExportFileName = "";
}
void VirtoolsTool::EndEditParams(Interface *ip,IUtil *iu)
{
}
//----------------------------------------
#endif //_USESCRIPTS_
BOOL GetVersionInfo(char *file,DWORD& Version1,DWORD& Version2,DWORD& Version3,DWORD& Version4)
{
DWORD dwVerHnd;
DWORD dwVerInfoSize;
long resMOld = 327680;
int ret = -1;
dwVerInfoSize = GetFileVersionInfoSize(file, &dwVerHnd);
if (dwVerInfoSize){
// If we were able to get the information, process it:
HANDLE hMem;
LPVOID lpvMem;
BOOL fRet;
UINT cchVer = 0;
VS_FIXEDFILEINFO *vInfo;
hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
lpvMem = GlobalLock(hMem);
GetFileVersionInfo(file, dwVerHnd, dwVerInfoSize, lpvMem);
fRet = VerQueryValue(lpvMem, TEXT("\\"),
(LPVOID*)&vInfo, &cchVer);
if (fRet && cchVer && vInfo) {
vInfo->dwFileVersionMS;
vInfo->dwFileVersionLS;
Version1 = HIWORD(vInfo->dwFileVersionMS);
Version2 = LOWORD(vInfo->dwFileVersionMS);
Version3 = HIWORD(vInfo->dwFileVersionLS);
Version4 = LOWORD(vInfo->dwFileVersionLS);
}
GlobalUnlock(hMem);
GlobalFree(hMem);
return TRUE;
}
return FALSE;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved)
{
hInstance = hinstDLL;
// Initialize the custom controls. This should be done only once.
if (!controlsInit) {
controlsInit = TRUE;
InitCustomControls(hInstance);
InitCommonControls();
//#pragma NOTE(__FILE__LINE__"Initialisation CK")
DWORD fpu = VxGetFPUControlWord();
CKStartUp();
if (VxGetFPUControlWord()!=fpu)
_control87(_CW_DEFAULT, 0xfffff);
}
switch(fdwReason) {
case DLL_PROCESS_DETACH: CKShutdown();
default: return TRUE;
}
return (TRUE);
}
//-------- Presentation of functions to Max
//--------
__declspec( dllexport ) const TCHAR* LibDescription()
{
return GetString(IDS_LIBDESCRIPTION);
}
__declspec( dllexport ) int LibNumberClasses()
{
#ifdef _USESCRIPTS_
return 2;
#else
return 1;
#endif
}
__declspec( dllexport ) ClassDesc* LibClassDesc(int i)
{
switch(i) {
case 0: return GetAsciiExpDesc();
#ifdef _USESCRIPTS_
case 1: return GetVirtoolsToolDesc();
#endif
default: return 0;
}
}
__declspec( dllexport ) ULONG LibVersion()
{
return VERSION_3DSMAX;
}
// Let the plug-in register itself for deferred loading
__declspec( dllexport ) ULONG CanAutoDefer()
{
return 0;
}
static CKContext *g_VirtoolsContext = NULL;
class AsciiExpClassDesc:public ClassDesc {
public:
int IsPublic() { return 1; }
void* Create(BOOL loading = FALSE) { return new Max2Nmo; }
const TCHAR* ClassName() { return GetString(IDS_ASCIIEXP); }
SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; }
Class_ID ClassID() { return MAX2NMO_CLASS_ID; }
const TCHAR* Category() { return GetString(IDS_CATEGORY); }
~AsciiExpClassDesc(){
CKCloseContext(g_VirtoolsContext);
g_VirtoolsContext = NULL;
}
};
static AsciiExpClassDesc AsciiExpDesc;
ClassDesc* GetAsciiExpDesc()
{
return &AsciiExpDesc;
}
TCHAR *GetString(int id)
{
static TCHAR buf[256];
if (hInstance)
return LoadString(hInstance, id, buf, sizeof(buf)) ? buf : NULL;
return NULL;
}
Max2Nmo::Max2Nmo()
{
// These are the default values that will be active when
// the exporter is ran the first time.
// After the first session these options are sticky.
bShowProgressionBar = TRUE;
bExportAsObjects = TRUE;
bExportAsCharacter = FALSE;
bExportAsAnimationOnly = FALSE;
bConvertPhysiqueToSkin = TRUE;
bStoreOnlyTextureFilenames = FALSE;
bRescaleScene = FALSE;
bGroupAsPlace = FALSE;
bSelectionAsGroup = FALSE;
szCharacterName = "Character";
szAnimationName = "Animation";
nMeshFrameStep = 3;
nKeyFrameStep = 3;
nCompressionLevel = 0;
nReportLevel = 0;
GroupIndent = 0;
bSaveBipedGeom = FALSE;
bAlignAnimOnZ = FALSE;
VirtoolsExporter = NULL;
VirtoolsContext = NULL;
ReportBufferPos = 0;
}
Max2Nmo::~Max2Nmo()
{
}
int Max2Nmo::ExtCount()
{
return 2;
}
const TCHAR * Max2Nmo::Ext(int n)
{
switch(n) {
case 0:
return _T("Nmo");
case 1:
return _T("Vmo");
}
return _T("");
}
const TCHAR * Max2Nmo::LongDesc()
{
return GetString(IDS_LONGDESC);
}
const TCHAR * Max2Nmo::ShortDesc()
{
return GetString(IDS_SHORTDESC);
}
const TCHAR * Max2Nmo::AuthorName()
{
return _T("Romain Sididris and Francisco Cabrita");
}
const TCHAR * Max2Nmo::CopyrightMessage()
{
return GetString(IDS_COPYRIGHT);
}
const TCHAR * Max2Nmo::OtherMessage1()
{
return _T("");
}
const TCHAR * Max2Nmo::OtherMessage2()
{
return _T("");
}
unsigned int Max2Nmo::Version()
{
return 100;
}
static BOOL CALLBACK AboutBoxDlgProc(HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
CenterWindow(hWnd, GetParent(hWnd));
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
EndDialog(hWnd, 1);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -