16 #include "pandaVersion.h" 18 #include <FCDocument/FCDocument.h> 19 #include <FCDocument/FCDAsset.h> 20 #include <FCDocument/FCDTransform.h> 23 #define TO_VEC3(v) (LVecBase3d(v[0], v[1], v[2])) 24 #define TO_VEC4(v) (LVecBase4d(v[0], v[1], v[2], v[3])) 25 #define TO_COLOR(v) (LColor(v[0], v[1], v[2], v[3])) 26 #define FROM_VEC3(v) (FMVector3(v[0], v[1], v[2])) 27 #define FROM_VEC4(v) (FMVector4(v[0], v[1], v[2], v[3])) 28 #define FROM_MAT4(v) (FMMatrix44(v.get_data())) 29 #define FROM_FSTRING(fs) (fs.c_str()) 40 set_binary_output(
false);
41 set_program_brief(
"convert .egg files into COLLADA asset files");
42 set_program_description
43 (
"This program converts files from the egg format to the COLLADA " 44 ".dae (Digital Asset Exchange) format.");
55 nassertv(_data !=
nullptr);
57 FCollada::Initialize();
58 _document = FCollada::NewTopDocument();
61 FCDAssetContributor* contributor = _document->GetAsset()->AddContributor();
62 const char* user_name = getenv(
"USER");
63 if (user_name ==
nullptr) user_name = getenv(
"USERNAME");
64 if (user_name !=
nullptr) contributor->SetAuthor(TO_FSTRING(user_name));
66 char authoring_tool[1024];
67 snprintf(authoring_tool, 1024,
"Panda3D %s eggToDAE converter | FCollada v%d.%02d", PANDA_VERSION_STR, FCOLLADA_VERSION >> 16, FCOLLADA_VERSION & 0xFFFF);
68 authoring_tool[1023] = 0;
69 contributor->SetAuthoringTool(TO_FSTRING(authoring_tool));
72 switch (_data->get_coordinate_system()) {
74 _document->GetAsset()->SetUpAxis(FMVector3::ZAxis);
77 _document->GetAsset()->SetUpAxis(FMVector3::YAxis);
82 FCDSceneNode* visual_scene = _document->AddVisualScene();
83 for (EggGroupNode::iterator it = _data->begin(); it != _data->end(); ++it) {
84 if ((*it)->is_of_type(EggGroup::get_class_type())) {
85 process_node(visual_scene, DCAST(
EggGroup, *it));
91 SAFE_DELETE(_document);
97 void EggToDAE::process_node(FCDSceneNode* parent,
const PT(
EggGroup) node) {
98 assert(node !=
nullptr);
99 FCDSceneNode* scene_node = parent->AddChildNode();
101 scene_node->SetDaeId(node->get_name().c_str());
102 scene_node->SetJointFlag(node->
is_joint());
104 apply_transform(scene_node, node);
106 for (EggGroupNode::iterator it = node->begin(); it != node->end(); ++it) {
107 if ((*it)->is_of_type(EggGroup::get_class_type())) {
108 process_node(scene_node, DCAST(
EggGroup, *it));
113 void EggToDAE::apply_transform(FCDSceneNode* to,
const PT(
EggGroup) from) {
114 assert(to !=
nullptr);
115 assert(from !=
nullptr);
118 case EggTransform::CT_translate2d:
119 cerr <<
"Warning: ignoring non-supported 2d translation\n";
121 case EggTransform::CT_rotate2d:
122 cerr <<
"Warning: ignoring non-supported 2d rotation\n";
124 case EggTransform::CT_scale2d:
125 cerr <<
"Warning: ignoring non-supported 2d scaling\n";
127 case EggTransform::CT_matrix3:
128 cerr <<
"Warning: ignoring non-supported 2d matrix\n";
130 case EggTransform::CT_translate3d: {
131 FCDTTranslation* new_transform = (FCDTTranslation*) to->AddTransform(FCDTransform::TRANSLATION);
134 case EggTransform::CT_rotate3d: {
135 FCDTRotation* new_transform = (FCDTRotation*) to->AddTransform(FCDTransform::ROTATION);
138 case EggTransform::CT_scale3d: {
139 FCDTScale* new_transform = (FCDTScale*) to->AddTransform(FCDTransform::SCALE);
142 case EggTransform::CT_matrix4: {
143 FCDTMatrix* new_transform = (FCDTMatrix*) to->AddTransform(FCDTransform::MATRIX);
146 case EggTransform::CT_rotx: {
147 FCDTRotation* new_transform = (FCDTRotation*) to->AddTransform(FCDTransform::ROTATION);
150 case EggTransform::CT_roty: {
151 FCDTRotation* new_transform = (FCDTRotation*) to->AddTransform(FCDTransform::ROTATION);
154 case EggTransform::CT_rotz: {
155 FCDTRotation* new_transform = (FCDTRotation*) to->AddTransform(FCDTransform::ROTATION);
158 case EggTransform::CT_uniform_scale: {
159 FCDTScale* new_transform = (FCDTScale*) to->AddTransform(FCDTransform::SCALE);
163 cerr <<
"Warning: ignoring invalid transform\n";
168 int main(
int argc,
char *argv[]) {
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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_...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...