Updated max importer to use set_coordinate_system

This commit is contained in:
Josh Yelon 2005-08-27 02:29:33 +00:00
parent 1e81e656ab
commit 71c2a27d87
7 changed files with 458 additions and 53 deletions

View File

@ -4003,6 +4003,7 @@ for VER in ["5","6","65"]:
IPATH=['pandatool/src/mayaegg', 'pandatool/src/maya']
OPTS=['MAYA'+VER, 'NSPR']
CopyAllHeaders(IPATH[0])
CompileC(ipath=IPATH, opts=OPTS, src='mayaEggLoader.cxx', obj='mayaegg'+VER+'_loader.obj')
CompileC(ipath=IPATH, opts=OPTS, src='mayaegg_composite1.cxx', obj='mayaegg'+VER+'_composite1.obj')
CompileLIB(lib='libmayaegg'+VER+'.lib', obj=[ 'mayaegg'+VER+'_composite1.obj' ])
@ -4010,13 +4011,14 @@ for VER in ["5","6","65"]:
# DIRECTORY: pandatool/src/maxegg/
#
for VER in ["5", "6", "7"]:
for VER in ["6", "7"]:
if (OMIT.count("MAX"+VER)==0):
IPATH=['pandatool/src/maxegg']
OPTS=['MAX'+VER, 'NSPR', "WINCOMCTL", "WINCOMDLG", "WINUSER"]
CopyAllHeaders(IPATH[0], skip="ALL")
CopyFile(PREFIX+"/tmp/maxEgg.obj", "pandatool/src/maxegg/maxEgg.obj")
CompileC(ipath=IPATH, opts=OPTS, src='maxegg_composite1.cxx',obj='maxegg'+VER+'_composite1.obj')
CompileC(ipath=IPATH, opts=OPTS+["MSFORSCOPE"], src='maxEggLoader.cxx', obj='maxegg'+VER+'_loader.obj')
CompileC(ipath=IPATH, opts=OPTS, src='maxegg_composite1.cxx', obj='maxegg'+VER+'_composite1.obj')
CompileLink(opts=OPTS, dll='maxegg'+VER+'.dlo', ldef="pandatool/src/maxegg/maxEgg.def", obj=[
'maxegg'+VER+'_composite1.obj',
'maxEgg.obj',
@ -4034,19 +4036,18 @@ for VER in ["5", "6", "7"]:
#
# DIRECTORY: pandatool/src/maxeggimport/
# DIRECTORY: pandatool/src/maxprogs/
#
for VER in ["7"]:
for VER in ["6", "7"]:
if (OMIT.count("MAX"+VER)==0):
IPATH=['pandatool/src/maxeggimport']
IPATH=['pandatool/src/maxprogs']
OPTS=['MAX'+VER, 'NSPR', "WINCOMCTL", "WINCOMDLG", "WINUSER", "MSFORSCOPE"]
CopyAllHeaders(IPATH[0])
CopyFile(PREFIX+"/tmp/maxImportRes.obj", "pandatool/src/maxeggimport/maxImportRes.obj")
CompileC(ipath=IPATH, opts=OPTS, src='maxEggLoader.cxx',obj='maxeggimport'+VER+'_maxeggloader.obj')
CopyFile(PREFIX+"/tmp/maxImportRes.obj", "pandatool/src/maxprogs/maxImportRes.obj")
CompileC(ipath=IPATH, opts=OPTS, src='maxEggImport.cxx',obj='maxeggimport'+VER+'_maxeggimport.obj')
CompileLink(opts=OPTS, dll='maxeggimport'+VER+'.dle', ldef="pandatool/src/maxeggimport/maxEggImport.def", obj=[
'maxeggimport'+VER+'_maxeggloader.obj',
CompileLink(opts=OPTS, dll='maxeggimport'+VER+'.dle', ldef="pandatool/src/maxprogs/maxEggImport.def", obj=[
'maxegg'+VER+'_loader.obj',
'maxeggimport'+VER+'_maxeggimport.obj',
'maxImportRes.obj',
'libpandaegg.dll',
@ -4057,28 +4058,6 @@ for VER in ["7"]:
'libpystub.dll'
])
#
# DIRECTORY: pandatool/src/mayaeggimport/
#
for VER in ["6"]:
if (OMIT.count("MAYA"+VER)==0):
IPATH=['pandatool/src/mayaeggimport']
OPTS=['MAYA'+VER, 'NSPR', 'BUILDING_MISC']
CopyAllHeaders(IPATH[0])
CompileC(ipath=IPATH, opts=OPTS, src='mayaEggImport.cxx',obj='mayaeggimport'+VER+'_mayaeggimport.obj')
CompileC(ipath=IPATH, opts=OPTS, src='mayaEggLoader.cxx',obj='mayaeggimport'+VER+'_mayaeggloader.obj')
CompileLink(opts=OPTS, dll='mayaeggimport'+VER+'.mll', obj=[
'mayaeggimport'+VER+'_mayaeggimport.obj',
'mayaeggimport'+VER+'_mayaeggloader.obj',
'libpandaegg.dll',
'libpanda.dll',
'libpandaexpress.dll',
'libdtoolconfig.dll',
'libdtool.dll',
'libpystub.dll'
])
#
# DIRECTORY: pandatool/src/vrml/
#
@ -4191,6 +4170,17 @@ for VER in ["5","6","65"]:
IPATH=['pandatool/src/mayaprogs', 'pandatool/src/maya', 'pandatool/src/mayaegg',
'pandatool/src/cvscopy']
OPTS=['BUILDING_MISC', 'MAYA'+VER, 'NSPR']
CompileC(ipath=IPATH, opts=OPTS, src='mayaEggImport.cxx',obj='mayaprogs'+VER+'_mayaeggimport.obj')
CompileLink(opts=OPTS, dll='mayaeggimport'+VER+'.mll', obj=[
'mayaprogs'+VER+'_mayaeggimport.obj',
'mayaegg'+VER+'_loader.obj',
'libpandaegg.dll',
'libpanda.dll',
'libpandaexpress.dll',
'libdtoolconfig.dll',
'libdtool.dll',
'libpystub.dll'
])
CompileC(ipath=IPATH, opts=OPTS, src='config_mayaloader.cxx', obj='mayaloader'+VER+'_config_mayaloader.obj')
CompileLink(dll='libmayaloader'+VER+'.dll', opts=['ADVAPI', 'NSPR', 'MAYA'+VER], obj=[
'mayaloader'+VER+'_config_mayaloader.obj',

View File

@ -80,16 +80,11 @@ public:
JointTable _joint_tab;
TexTable _tex_tab;
int _next_tex;
CoordinateSystem _coord_sys;
};
Point3 ConvertCoordSys(CoordinateSystem sys, LVector3d vec)
Point3 MakeMaxPoint(LVector3d vec)
{
if (sys == CS_yup_right) {
return Point3(vec[0], -vec[2], vec[1]);
} else {
return Point3(vec[0], vec[1], vec[2]);
}
return Point3(vec[0], vec[1], vec[2]);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -156,7 +151,7 @@ public:
LVector3d GetPos(void) { return _trans.get_row3(3); }
MaxEggJoint *ChooseBestChild(LVector3d dir);
void ChooseEndPos(double thickness);
void CreateMaxBone(CoordinateSystem sys);
void CreateMaxBone(void);
};
void MaxEggJoint::GetRotation(LVector3d &xv, LVector3d &yv, LVector3d &zv)
@ -260,16 +255,16 @@ void MaxEggJoint::ChooseEndPos(double thickness)
_perp.normalize();
}
void MaxEggJoint::CreateMaxBone(CoordinateSystem sys)
void MaxEggJoint::CreateMaxBone(void)
{
LVector3d rxv,ryv,rzv;
GetRotation(rxv, ryv, rzv);
Point3 xv(ConvertCoordSys(sys, rxv));
Point3 yv(ConvertCoordSys(sys, ryv));
Point3 zv(ConvertCoordSys(sys, rzv));
Point3 pos(ConvertCoordSys(sys, GetPos()));
Point3 endpos(ConvertCoordSys(sys, _endpos));
Point3 tzv(ConvertCoordSys(sys, _perp));
Point3 xv(MakeMaxPoint(rxv));
Point3 yv(MakeMaxPoint(ryv));
Point3 zv(MakeMaxPoint(rzv));
Point3 pos(MakeMaxPoint(GetPos()));
Point3 endpos(MakeMaxPoint(_endpos));
Point3 tzv(MakeMaxPoint(_perp));
Point3 fwd = endpos - pos;
double len = fwd.Length();
@ -373,7 +368,7 @@ public:
TVertTable _tvert_tab;
CVertTable _cvert_tab;
int GetVert(EggVertex *vert, EggGroup *context, CoordinateSystem sys);
int GetVert(EggVertex *vert, EggGroup *context);
int GetTVert(TexCoordd uv);
int GetCVert(Colorf col);
int AddFace(int v0, int v1, int v2, int tv0, int tv1, int tv2, int cv0, int cv1, int cv2, int tex);
@ -382,7 +377,7 @@ public:
#define CTRLJOINT_DEFORM ((EggGroup*)((char*)(-1)))
int MaxEggMesh::GetVert(EggVertex *vert, EggGroup *context, CoordinateSystem sys)
int MaxEggMesh::GetVert(EggVertex *vert, EggGroup *context)
{
MaxEggVertex vtx;
vtx._pos = vert->get_pos3();
@ -410,7 +405,7 @@ int MaxEggMesh::GetVert(EggVertex *vert, EggGroup *context, CoordinateSystem sys
}
vtx._index = _vert_count++;
_vert_tab.insert(vtx);
_mesh->setVert(vtx._index, ConvertCoordSys(sys, vtx._pos));
_mesh->setVert(vtx._index, MakeMaxPoint(vtx._pos));
return vtx._index;
}
@ -600,7 +595,7 @@ void MaxEggLoader::TraverseEggNode(EggNode *node, EggGroup *context)
EggVertex *vtx = (*ci);
EggVertexPool *pool = poly->get_pool();
TexCoordd uv = vtx->get_uv();
vertIndices.push_back(mesh->GetVert(vtx, context, _coord_sys));
vertIndices.push_back(mesh->GetVert(vtx, context));
tvertIndices.push_back(mesh->GetTVert(uv * uvtrans));
cvertIndices.push_back(mesh->GetCVert(vtx->get_color()));
}
@ -640,12 +635,13 @@ bool MaxEggLoader::ConvertEggData(EggData *data, bool merge, bool model, bool an
MeshIterator ci;
JointIterator ji;
TexIterator ti;
data->set_coordinate_system(CS_zup_right);
SuspendAnimate();
SuspendSetKeyMode();
AnimateOff();
_next_tex = 0;
_coord_sys = data->get_coordinate_system();
TraverseEggNode(data, NULL);
@ -671,7 +667,7 @@ bool MaxEggLoader::ConvertEggData(EggData *data, bool merge, bool model, bool an
for (ji = _joint_tab.begin(); ji != _joint_tab.end(); ++ji) {
MaxEggJoint *joint = *ji;
joint->ChooseEndPos(thickness);
joint->CreateMaxBone(_coord_sys);
joint->CreateMaxBone();
}
for (ci = _mesh_tab.begin(); ci != _mesh_tab.end(); ++ci) {

View File

@ -0,0 +1,269 @@
// Filename: maxEggImport.cxx
// Created by: jyelon (15Jul05)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////
//
// This is the wrapper code for the max importer plugin.
// It includes:
//
// - user interface dialogs and popups
// - plugin initialization/registration
//
// It does not include the actual code to traverse the EggData.
//
////////////////////////////////////////////////////////////////////
// MAX includes
#include "maxEggLoader.h"
#include "Max.h"
#include "maxImportRes.h"
#include "istdplug.h"
// panda includes.
#include "notifyCategoryProxy.h"
#include <iostream>
#include <sstream>
class MaxEggImporter : public SceneImport
{
public:
// GUI-related methods
MaxEggImporter();
~MaxEggImporter();
int ExtCount(); // Number of extensions supported
const TCHAR * Ext(int n); // Extension #n (i.e. "EGG")
const TCHAR * LongDesc(); // Long ASCII description (i.e. "Egg Importer")
const TCHAR * ShortDesc(); // Short ASCII description (i.e. "Egg")
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 DoImport(const TCHAR *name,ImpInterface *ei,Interface *i, BOOL suppressPrompts);
public:
// GUI-related fields
static BOOL _merge;
static BOOL _importmodel;
static BOOL _importanim;
};
BOOL MaxEggImporter::_merge = TRUE;
BOOL MaxEggImporter::_importmodel = TRUE;
BOOL MaxEggImporter::_importanim = FALSE;
MaxEggImporter::MaxEggImporter()
{
}
MaxEggImporter::~MaxEggImporter()
{
}
int MaxEggImporter::ExtCount()
{
// Number of different extensions handled by this importer.
return 1;
}
const TCHAR * MaxEggImporter::Ext(int n)
{
// Fetch the extensions handled by this importer.
switch(n) {
case 0: return _T("egg");
default: return _T("");
}
}
const TCHAR * MaxEggImporter::LongDesc()
{
return _T("Panda3D Egg Importer");
}
const TCHAR * MaxEggImporter::ShortDesc()
{
return _T("Panda3D Egg");
}
const TCHAR * MaxEggImporter::AuthorName()
{
return _T("Joshua Yelon");
}
const TCHAR * MaxEggImporter::CopyrightMessage()
{
return _T("Copyight (c) 2005 Josh Yelon");
}
const TCHAR * MaxEggImporter::OtherMessage1()
{
return _T("");
}
const TCHAR * MaxEggImporter::OtherMessage2()
{
return _T("");
}
unsigned int MaxEggImporter::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;
}
void MaxEggImporter::ShowAbout(HWND hWnd)
{
DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX),
hWnd, AboutBoxDlgProc, 0);
}
static BOOL CALLBACK ImportDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
MaxEggImporter *imp = (MaxEggImporter*)GetWindowLong(hWnd,GWL_USERDATA);
switch (msg) {
case WM_INITDIALOG:
imp = (MaxEggImporter*)lParam;
SetWindowLong(hWnd,GWL_USERDATA,lParam);
CenterWindow(hWnd, GetParent(hWnd));
CheckDlgButton(hWnd, IDC_MERGE, imp->_merge);
CheckDlgButton(hWnd, IDC_IMPORTMODEL, imp->_importmodel);
CheckDlgButton(hWnd, IDC_IMPORTANIM, imp->_importanim);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
imp->_merge = IsDlgButtonChecked(hWnd, IDC_MERGE);
imp->_importmodel = IsDlgButtonChecked(hWnd, IDC_IMPORTMODEL);
imp->_importanim = IsDlgButtonChecked(hWnd, IDC_IMPORTANIM);
EndDialog(hWnd, 1);
break;
case IDCANCEL:
EndDialog(hWnd, 0);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
int MaxEggImporter::DoImport(const TCHAR *name,ImpInterface *ii,Interface *i, BOOL suppressPrompts)
{
// Prompt the user with our dialogbox.
if (!DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_IMPORT_DLG),
i->GetMAXHWnd(), ImportDlgProc, (LPARAM)this)) {
return 1;
}
std::ostringstream log;
Notify::ptr()->set_ostream_ptr(&log, false);
bool ok = MaxLoadEggFile(name, _merge ? true:false, _importmodel ? true:false, _importanim ? true:false);
string txt = log.str();
if (txt != "") MessageBox(NULL, txt.c_str(), "Panda3D Importer", MB_OK);
else {
if (!ok) MessageBox(NULL, "Import Failed, unknown reason\n", "Panda3D Importer", MB_OK);
}
Notify::ptr()->set_ostream_ptr(NULL, false);
return 1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Plugin Initialization
//
// The following code enables Max to load this DLL, get a list
// of the classes defined in this DLL, and provides a means for
// Max to create instances of those classes.
//
////////////////////////////////////////////////////////////////////////////////////////////////////
HINSTANCE hInstance;
BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved)
{
static int controlsInit = FALSE;
hInstance = hinstDLL;
if (!controlsInit) {
controlsInit = TRUE;
InitCustomControls(hInstance);
InitCommonControls();
}
return (TRUE);
}
#define PANDAEGGIMP_CLASS_ID1 0x377193ab
#define PANDAEGGIMP_CLASS_ID2 0x897afe12
class MaxEggImporterClassDesc: public ClassDesc
{
public:
int IsPublic() {return 1;}
void *Create(BOOL loading = FALSE) {return new MaxEggImporter;}
const TCHAR *ClassName() {return _T("MaxEggImporter");}
SClass_ID SuperClassID() {return SCENE_IMPORT_CLASS_ID;}
Class_ID ClassID() {return Class_ID(PANDAEGGIMP_CLASS_ID1,PANDAEGGIMP_CLASS_ID2);}
const TCHAR *Category() {return _T("Chrutilities");}
};
static MaxEggImporterClassDesc MaxEggImporterDesc;
__declspec( dllexport ) const TCHAR* LibDescription()
{
return _T("Panda3D Egg Importer");
}
__declspec( dllexport ) int LibNumberClasses()
{
return 1;
}
__declspec( dllexport ) ClassDesc* LibClassDesc(int i)
{
switch(i) {
case 0: return &MaxEggImporterDesc;
default: return 0;
}
}
__declspec( dllexport ) ULONG LibVersion()
{
return VERSION_3DSMAX;
}

View File

@ -0,0 +1,7 @@
EXPORTS
LibDescription @1
LibNumberClasses @2
LibClassDesc @3
LibVersion @4
SECTIONS
.data READ WRITE

View File

@ -0,0 +1,21 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by maxImportRes.rc
//
#define IDD_PANEL 101
#define IDD_ABOUTBOX 102
#define IDD_IMPORT_DLG 103
#define IDC_MERGE 1002
#define IDC_IMPORTMODEL 1003
#define IDC_IMPORTANIM 1004
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1020
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

Binary file not shown.

View File

@ -0,0 +1,122 @@
// Microsoft Visual C++ generated resource script.
//
#include "maxImportRes.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 176
TOPMARGIN, 7
BOTTOMMARGIN, 60
END
IDD_IMPORT_DLG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 187
TOPMARGIN, 7
BOTTOMMARGIN, 71
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"maxImportRes.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOGEX 0, 0, 183, 67
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Panda3D Egg Importer"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,66,45,50,14
CTEXT "Panda3D Egg Importer\n\nCarnegie Mellon\nEntertainment Technology Center",
IDC_STATIC,7,7,169,36
END
IDD_IMPORT_DLG DIALOGEX 0, 0, 194, 78
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Panda3D Egg Import"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,137,10,50,14
PUSHBUTTON "Cancel",IDCANCEL,137,30,50,14
CONTROL "Merge with Current Scene",IDC_MERGE,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,15,20,106,10
GROUPBOX "Input Options",IDC_STATIC,5,7,126,64
CONTROL "Import Model",IDC_IMPORTMODEL,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,15,41,73,10
CONTROL "Import Animation",IDC_IMPORTANIM,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,15,54,73,10
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED