18 #include "pandaVersion.h" 20 #include "FCDocument/FCDocument.h" 21 #include "FCDocument/FCDAsset.h" 22 #include "FCDocument/FCDTransform.h" 25 #define TO_VEC3(v) (LVecBase3d(v[0], v[1], v[2])) 26 #define TO_VEC4(v) (LVecBase4d(v[0], v[1], v[2], v[3])) 27 #define TO_COLOR(v) (LColor(v[0], v[1], v[2], v[3])) 28 #define FROM_VEC3(v) (FMVector3(v[0], v[1], v[2])) 29 #define FROM_VEC4(v) (FMVector4(v[0], v[1], v[2], v[3])) 30 #define FROM_MAT4(v) (FMMatrix44(v.get_data())) 31 #define FROM_FSTRING(fs) (fs.c_str()) 42 set_binary_output(
false);
43 set_program_brief(
"convert .egg files into COLLADA asset files");
44 set_program_description
45 (
"This program converts files from the egg format to the COLLADA " 46 ".dae (Digital Asset Exchange) format.");
59 nassertv(_data != NULL);
61 FCollada::Initialize();
62 _document = FCollada::NewTopDocument();
65 FCDAssetContributor* contributor = _document->GetAsset()->AddContributor();
66 const char* user_name = getenv(
"USER");
67 if (user_name == NULL) user_name = getenv(
"USERNAME");
68 if (user_name != NULL) contributor->SetAuthor(TO_FSTRING(user_name));
70 char authoring_tool[1024];
71 snprintf(authoring_tool, 1024,
"Panda3D %s eggToDAE converter | FCollada v%d.%02d", PANDA_VERSION_STR, FCOLLADA_VERSION >> 16, FCOLLADA_VERSION & 0xFFFF);
72 authoring_tool[1023] = 0;
73 contributor->SetAuthoringTool(TO_FSTRING(authoring_tool));
76 switch (_data->get_coordinate_system()) {
78 _document->GetAsset()->SetUpAxis(FMVector3::ZAxis);
81 _document->GetAsset()->SetUpAxis(FMVector3::YAxis);
86 FCDSceneNode* visual_scene = _document->AddVisualScene();
87 for (EggGroupNode::iterator it = _data->begin(); it != _data->end(); ++it) {
88 if ((*it)->is_of_type(EggGroup::get_class_type())) {
89 process_node(visual_scene, DCAST(
EggGroup, *it));
95 SAFE_DELETE(_document);
104 void EggToDAE::process_node(FCDSceneNode* parent,
const PT(
EggGroup) node) {
105 assert(node != NULL);
106 FCDSceneNode* scene_node = parent->AddChildNode();
108 scene_node->SetDaeId(node->get_name().c_str());
109 scene_node->SetJointFlag(node->
is_joint());
111 apply_transform(scene_node, node);
113 for (EggGroupNode::iterator it = node->begin(); it != node->end(); ++it) {
114 if ((*it)->is_of_type(EggGroup::get_class_type())) {
115 process_node(scene_node, DCAST(
EggGroup, *it));
120 void EggToDAE::apply_transform(FCDSceneNode* to,
const PT(
EggGroup) from) {
122 assert(from != NULL);
125 case EggTransform::CT_translate2d:
126 cerr <<
"Warning: ignoring non-supported 2d translation\n";
128 case EggTransform::CT_rotate2d:
129 cerr <<
"Warning: ignoring non-supported 2d rotation\n";
131 case EggTransform::CT_scale2d:
132 cerr <<
"Warning: ignoring non-supported 2d scaling\n";
134 case EggTransform::CT_matrix3:
135 cerr <<
"Warning: ignoring non-supported 2d matrix\n";
137 case EggTransform::CT_translate3d: {
138 FCDTTranslation* new_transform = (FCDTTranslation*) to->AddTransform(FCDTransform::TRANSLATION);
141 case EggTransform::CT_rotate3d: {
142 FCDTRotation* new_transform = (FCDTRotation*) to->AddTransform(FCDTransform::ROTATION);
145 case EggTransform::CT_scale3d: {
146 FCDTScale* new_transform = (FCDTScale*) to->AddTransform(FCDTransform::SCALE);
149 case EggTransform::CT_matrix4: {
150 FCDTMatrix* new_transform = (FCDTMatrix*) to->AddTransform(FCDTransform::MATRIX);
153 case EggTransform::CT_rotx: {
154 FCDTRotation* new_transform = (FCDTRotation*) to->AddTransform(FCDTransform::ROTATION);
157 case EggTransform::CT_roty: {
158 FCDTRotation* new_transform = (FCDTRotation*) to->AddTransform(FCDTransform::ROTATION);
161 case EggTransform::CT_rotz: {
162 FCDTRotation* new_transform = (FCDTRotation*) to->AddTransform(FCDTransform::ROTATION);
165 case EggTransform::CT_uniform_scale: {
166 FCDTScale* new_transform = (FCDTScale*) to->AddTransform(FCDTransform::SCALE);
170 cerr <<
"Warning: ignoring invalid transform\n";
175 int main(
int argc,
char *argv[]) {
virtual bool is_joint() const
Returns true if this particular node represents a <Joint> entry or not.
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
Filename get_output_filename() const
If has_output_filename() returns true, this is the filename that the user specified.
bool has_output_filename() const
Returns true if the user specified an output filename, false otherwise (e.g.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
A program to read an egg file and write a DAE file.
This is the general base class for a file-converter program that reads some model file format and gen...