mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
bring egg2maya in to ppremake system
This commit is contained in:
parent
ebd2fd2f01
commit
cb5ee1cd82
@ -155,6 +155,19 @@ as_reader() {
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggReader::pre_process_egg_file
|
||||
// Access: Public, Virtual
|
||||
// Description: Performs any processing of the egg file that is
|
||||
// appropriate after reading it in.
|
||||
//
|
||||
// Normally, you should not need to call this function
|
||||
// directly; it is called automatically at startup.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggReader::
|
||||
pre_process_egg_file() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggReader::handle_args
|
||||
// Access: Protected, Virtual
|
||||
@ -215,6 +228,8 @@ handle_args(ProgramBase::Args &args) {
|
||||
_data->merge(file_data);
|
||||
}
|
||||
|
||||
pre_process_egg_file();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
void add_delod_options(double default_delod = -1.0);
|
||||
|
||||
virtual EggReader *as_reader();
|
||||
virtual void pre_process_egg_file();
|
||||
|
||||
protected:
|
||||
virtual bool handle_args(Args &args);
|
||||
|
@ -82,6 +82,68 @@ EggToSomething(const string &format_name,
|
||||
"one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default "
|
||||
"is the same coordinate system as the input egg file. If this is "
|
||||
"different from the input egg file, a conversion will be performed.");
|
||||
|
||||
_input_units = DU_invalid;
|
||||
_output_units = DU_invalid;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggToSomething::add_units_options
|
||||
// Access: Public
|
||||
// Description: Adds -ui and -uo as valid options for this program.
|
||||
// If the user specifies -uo and -ui, or just -uo and
|
||||
// the program specifies -ui by setting _input_units,
|
||||
// the indicated units conversion will be automatically
|
||||
// applied before writing out the egg file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggToSomething::
|
||||
add_units_options() {
|
||||
add_option
|
||||
("ui", "units", 40,
|
||||
"Specify the units of the input egg file. If this is "
|
||||
"specified, the vertices in the egg file will be scaled as "
|
||||
"necessary to make the appropriate units conversion; otherwise, "
|
||||
"the vertices will be left as they are.",
|
||||
&EggToSomething::dispatch_units, NULL, &_input_units);
|
||||
|
||||
add_option
|
||||
("uo", "units", 40,
|
||||
"Specify the units of the resulting " + _format_name +
|
||||
" file. Normally, the default units for the format are used.",
|
||||
&EggToSomething::dispatch_units, NULL, &_output_units);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggToSomething::apply_units_scale
|
||||
// Access: Protected
|
||||
// Description: Applies the scale indicated by the input and output
|
||||
// units to the indicated egg file. This is normally
|
||||
// done automatically when the file is read in.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggToSomething::
|
||||
apply_units_scale(EggData *data) {
|
||||
if (_output_units != DU_invalid && _input_units != DU_invalid &&
|
||||
_input_units != _output_units) {
|
||||
nout << "Converting from " << format_long_unit(_input_units)
|
||||
<< " to " << format_long_unit(_output_units) << "\n";
|
||||
double scale = convert_units(_input_units, _output_units);
|
||||
data->transform(LMatrix4d::scale_mat(scale));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggToSomething::pre_process_egg_file
|
||||
// Access: Protected, Virtual
|
||||
// Description: Performs any processing of the egg file that is
|
||||
// appropriate after reading it in.
|
||||
//
|
||||
// Normally, you should not need to call this function
|
||||
// directly; it is called automatically at startup.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggToSomething::
|
||||
pre_process_egg_file() {
|
||||
apply_units_scale(_data);
|
||||
EggConverter::pre_process_egg_file();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "pandatoolbase.h"
|
||||
|
||||
#include "eggConverter.h"
|
||||
#include "distanceUnit.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : EggToSomething
|
||||
@ -36,8 +37,15 @@ public:
|
||||
bool allow_last_param = true,
|
||||
bool allow_stdout = true);
|
||||
|
||||
void add_units_options();
|
||||
|
||||
protected:
|
||||
void apply_units_scale(EggData *data);
|
||||
virtual void pre_process_egg_file();
|
||||
virtual bool handle_args(Args &args);
|
||||
|
||||
DistanceUnit _input_units;
|
||||
DistanceUnit _output_units;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define SOURCES \
|
||||
config_mayaegg.cxx config_mayaegg.h \
|
||||
mayaEggGroupUserData.cxx mayaEggGroupUserData.I mayaEggGroupUserData.h \
|
||||
mayaEggLoader.cxx mayaEggLoader.h \
|
||||
mayaBlendDesc.cxx mayaBlendDesc.h \
|
||||
mayaNodeDesc.cxx mayaNodeDesc.h \
|
||||
mayaNodeTree.cxx mayaNodeTree.h \
|
||||
|
@ -96,16 +96,11 @@ public:
|
||||
MeshTable _mesh_tab;
|
||||
JointTable _joint_tab;
|
||||
TexTable _tex_tab;
|
||||
CoordinateSystem _coord_sys;
|
||||
};
|
||||
|
||||
MFloatPoint ConvertCoordSys(CoordinateSystem sys, LVector3d vec)
|
||||
MFloatPoint MakeMayaPoint(const LVector3d &vec)
|
||||
{
|
||||
if (sys == CS_zup_right) {
|
||||
return MFloatPoint(vec[0], vec[2], -vec[1]);
|
||||
} else {
|
||||
return MFloatPoint(vec[0], vec[1], vec[2]);
|
||||
}
|
||||
return MFloatPoint(vec[0], vec[1], vec[2]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -219,7 +214,7 @@ public:
|
||||
LVector3d GetPos(void) { return _trans.get_row3(3); }
|
||||
MayaEggJoint *ChooseBestChild(LVector3d dir);
|
||||
void ChooseEndPos(double thickness);
|
||||
void CreateMayaBone(CoordinateSystem sys);
|
||||
void CreateMayaBone();
|
||||
void AssignNames(void);
|
||||
};
|
||||
|
||||
@ -331,16 +326,16 @@ void MayaEggJoint::ChooseEndPos(double thickness)
|
||||
_perp.normalize();
|
||||
}
|
||||
|
||||
void MayaEggJoint::CreateMayaBone(CoordinateSystem sys)
|
||||
void MayaEggJoint::CreateMayaBone()
|
||||
{
|
||||
LVector3d rxv, ryv, rzv;
|
||||
GetRotation(rxv, ryv, rzv);
|
||||
MFloatPoint xv(ConvertCoordSys(sys, rxv));
|
||||
MFloatPoint yv(ConvertCoordSys(sys, ryv));
|
||||
MFloatPoint zv(ConvertCoordSys(sys, rzv));
|
||||
MFloatPoint pos(ConvertCoordSys(sys, GetPos()));
|
||||
MFloatPoint endpos(ConvertCoordSys(sys, _endpos));
|
||||
MFloatPoint tzv(ConvertCoordSys(sys, _perp));
|
||||
MFloatPoint xv(MakeMayaPoint(rxv));
|
||||
MFloatPoint yv(MakeMayaPoint(ryv));
|
||||
MFloatPoint zv(MakeMayaPoint(rzv));
|
||||
MFloatPoint pos(MakeMayaPoint(GetPos()));
|
||||
MFloatPoint endpos(MakeMayaPoint(_endpos));
|
||||
MFloatPoint tzv(MakeMayaPoint(_perp));
|
||||
|
||||
double m[4][4];
|
||||
m[0][0]=xv.x; m[0][1]=xv.y; m[0][2]=xv.z; m[0][3]=0;
|
||||
@ -433,7 +428,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, MayaEggTex *tex);
|
||||
@ -444,7 +439,7 @@ public:
|
||||
|
||||
#define CTRLJOINT_DEFORM ((EggGroup*)((char*)(-1)))
|
||||
|
||||
int MayaEggMesh::GetVert(EggVertex *vert, EggGroup *context, CoordinateSystem sys)
|
||||
int MayaEggMesh::GetVert(EggVertex *vert, EggGroup *context)
|
||||
{
|
||||
MayaEggVertex vtx;
|
||||
vtx._pos = vert->get_pos3();
|
||||
@ -467,7 +462,7 @@ int MayaEggMesh::GetVert(EggVertex *vert, EggGroup *context, CoordinateSystem sy
|
||||
return vti->_index;
|
||||
|
||||
vtx._index = _vert_count++;
|
||||
_vertexArray.append(ConvertCoordSys(sys, vtx._pos));
|
||||
_vertexArray.append(MakeMayaPoint(vtx._pos));
|
||||
_vert_tab.insert(vtx);
|
||||
return vtx._index;
|
||||
}
|
||||
@ -712,7 +707,7 @@ void MayaEggLoader::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()));
|
||||
}
|
||||
@ -753,7 +748,11 @@ bool MayaEggLoader::ConvertEggData(EggData *data, bool merge, bool model, bool a
|
||||
JointIterator ji;
|
||||
TexIterator ti;
|
||||
|
||||
_coord_sys = data->get_coordinate_system();
|
||||
if (MGlobal::isYAxisUp()) {
|
||||
data->set_coordinate_system(CS_yup_right);
|
||||
} else {
|
||||
data->set_coordinate_system(CS_zup_right);
|
||||
}
|
||||
|
||||
TraverseEggNode(data, NULL);
|
||||
|
||||
@ -785,7 +784,7 @@ bool MayaEggLoader::ConvertEggData(EggData *data, bool merge, bool model, bool a
|
||||
for (ji = _joint_tab.begin(); ji != _joint_tab.end(); ++ji) {
|
||||
MayaEggJoint *joint = *ji;
|
||||
joint->ChooseEndPos(thickness);
|
||||
joint->CreateMayaBone(_coord_sys);
|
||||
joint->CreateMayaBone();
|
||||
}
|
||||
|
||||
for (ci = _mesh_tab.begin(); ci != _mesh_tab.end(); ++ci) {
|
@ -1,6 +1,7 @@
|
||||
#define BUILD_DIRECTORY $[HAVE_MAYA]
|
||||
|
||||
#define maya2egg maya2egg
|
||||
#define egg2maya egg2maya
|
||||
#define mayacopy mayacopy
|
||||
|
||||
#if $[UNIX_PLATFORM]
|
||||
@ -11,6 +12,7 @@
|
||||
// it in also on Unix.)
|
||||
|
||||
#set maya2egg maya2egg_bin
|
||||
#set egg2maya egg2maya_bin
|
||||
#set mayacopy mayacopy_bin
|
||||
|
||||
#begin sed_bin_target
|
||||
@ -21,6 +23,14 @@
|
||||
|
||||
#end sed_bin_target
|
||||
|
||||
#begin sed_bin_target
|
||||
#define TARGET egg2maya
|
||||
|
||||
#define SOURCE mayapath_script
|
||||
#define COMMAND s:xxx:$[MAYA_LOCATION]:g;s:yyy:$[TARGET]:g;s+zzz+$[MAYA_LICENSE_FILE]+g;
|
||||
|
||||
#end sed_bin_target
|
||||
|
||||
#begin sed_bin_target
|
||||
#define TARGET mayacopy
|
||||
|
||||
@ -51,6 +61,26 @@
|
||||
|
||||
#end bin_target
|
||||
|
||||
#begin bin_target
|
||||
#define USE_PACKAGES maya
|
||||
#define TARGET $[egg2maya]
|
||||
#define LOCAL_LIBS \
|
||||
mayaegg maya eggbase progbase
|
||||
#define OTHER_LIBS \
|
||||
egg:c pandaegg:m \
|
||||
linmath:c putil:c panda:m \
|
||||
express:c pandaexpress:m \
|
||||
interrogatedb:c dtoolutil:c dtoolbase:c prc:c dconfig:c dtoolconfig:m dtool:m pystub
|
||||
|
||||
// Irix requires this to be named explicitly.
|
||||
#define UNIX_SYS_LIBS \
|
||||
ExtensionLayer
|
||||
|
||||
#define SOURCES \
|
||||
eggToMaya.cxx eggToMaya.h
|
||||
|
||||
#end bin_target
|
||||
|
||||
|
||||
#begin bin_target
|
||||
#define USE_PACKAGES maya
|
||||
@ -112,6 +142,29 @@
|
||||
mayaSavePview.cxx mayaSavePview.h
|
||||
#end lib_target
|
||||
|
||||
#begin lib_target
|
||||
#define BUILD_TARGET $[not $[LINK_ALL_STATIC]]
|
||||
#define USE_PACKAGES maya
|
||||
#define TARGET mayaEggImport
|
||||
#define LOCAL_LIBS mayaegg maya
|
||||
#define OTHER_LIBS \
|
||||
egg:c pandaegg:m \
|
||||
framework:m \
|
||||
linmath:c putil:c panda:m \
|
||||
express:c pandaexpress:m \
|
||||
interrogatedb:c dtoolutil:c dtoolbase:c prc:c dconfig:c dtoolconfig:m dtool:m pystub
|
||||
|
||||
#define BUILDING_DLL BUILDING_MISC
|
||||
|
||||
#if $[WINDOWS_PLATFORM]
|
||||
#define dlllib mll
|
||||
#endif
|
||||
|
||||
#define SOURCES \
|
||||
mayaEggImport.cxx
|
||||
|
||||
#end lib_target
|
||||
|
||||
#begin lib_target
|
||||
#define USE_PACKAGES maya
|
||||
#define TARGET mayaloader
|
||||
|
118
pandatool/src/mayaprogs/eggToMaya.cxx
Executable file
118
pandatool/src/mayaprogs/eggToMaya.cxx
Executable file
@ -0,0 +1,118 @@
|
||||
// Filename: eggToMaya.cxx
|
||||
// Created by: drose (11Aug05)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "eggToMaya.h"
|
||||
#include "mayaEggLoader.h"
|
||||
#include "mayaApi.h"
|
||||
|
||||
// We must define this to prevent Maya from doubly-declaring its
|
||||
// MApiVersion string in this file as well as in libmayaegg.
|
||||
#define _MApiVersion
|
||||
|
||||
#include "pre_maya_include.h"
|
||||
#include <maya/MString.h>
|
||||
#include <maya/MFileIO.h>
|
||||
#include "post_maya_include.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggToMaya::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
EggToMaya::
|
||||
EggToMaya() :
|
||||
EggToSomething("Maya", ".mb", true, false)
|
||||
{
|
||||
add_units_options();
|
||||
|
||||
set_binary_output(true);
|
||||
set_program_description
|
||||
("egg2maya converts files from egg format to Maya .mb or .ma "
|
||||
"format. At the moment, it contains support for basic geometry "
|
||||
"(polygons with textures).");
|
||||
|
||||
add_option
|
||||
("a", "", 0,
|
||||
"Convert animation tables.",
|
||||
&EggToMaya::dispatch_none, &_convert_anim);
|
||||
|
||||
add_option
|
||||
("m", "", 0,
|
||||
"Convert polygon models. You may specify both -a and -m at the same "
|
||||
"time. If you specify neither, the default is -m.",
|
||||
&EggToMaya::dispatch_none, &_convert_model);
|
||||
|
||||
// Maya files always store centimeters.
|
||||
_output_units = DU_centimeters;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggToMaya::run
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggToMaya::
|
||||
run() {
|
||||
if (!_convert_anim && !_convert_model) {
|
||||
_convert_model = true;
|
||||
}
|
||||
|
||||
// Let's convert the output file to a full path before we initialize
|
||||
// Maya, since Maya now has a nasty habit of changing the current
|
||||
// directory.
|
||||
_output_filename.make_absolute();
|
||||
|
||||
nout << "Initializing Maya.\n";
|
||||
PT(MayaApi) maya = MayaApi::open_api(_program_name);
|
||||
if (!maya->is_valid()) {
|
||||
nout << "Unable to initialize Maya.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
MStatus status;
|
||||
status = MFileIO::newFile(true);
|
||||
if (!status) {
|
||||
status.perror("Could not initialize file");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Now convert the data.
|
||||
if (!MayaLoadEggData(_data, true, _convert_model, _convert_anim)) {
|
||||
nout << "Unable to convert egg file.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// And write out the resulting Maya file.
|
||||
string os_specific = _output_filename.to_os_generic();
|
||||
const char *file_type = NULL;
|
||||
if (_output_filename.get_extension() == "mb") {
|
||||
file_type = "mayaBinary";
|
||||
}
|
||||
status = MFileIO::saveAs(os_specific.c_str(), file_type);
|
||||
if (!status) {
|
||||
status.perror("Could not save file");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
EggToMaya prog;
|
||||
prog.parse_command_line(argc, argv);
|
||||
prog.run();
|
||||
return 0;
|
||||
}
|
42
pandatool/src/mayaprogs/eggToMaya.h
Executable file
42
pandatool/src/mayaprogs/eggToMaya.h
Executable file
@ -0,0 +1,42 @@
|
||||
// Filename: eggToMaya.h
|
||||
// Created by: drose (11Aug05)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef EGGTOMAYA_H
|
||||
#define EGGTOMAYA_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
|
||||
#include "eggToSomething.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : EggToMaya
|
||||
// Description : A program to read an egg file and write a maya file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EggToMaya : public EggToSomething {
|
||||
public:
|
||||
EggToMaya();
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
bool _convert_anim;
|
||||
bool _convert_model;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -31,6 +31,10 @@
|
||||
|
||||
#include "dtoolbase.h"
|
||||
|
||||
// We must define this to prevent Maya from doubly-declaring its
|
||||
// MApiVersion string in this file as well as in libmayaegg.
|
||||
#define _MApiVersion
|
||||
|
||||
#include "pre_maya_include.h"
|
||||
#include <maya/MStatus.h>
|
||||
#include <maya/MPxCommand.h>
|
Loading…
x
Reference in New Issue
Block a user