15 #include "vrmlToEggConverter.h"
16 #include "vrmlAppearance.h"
17 #include "indexedFaceSet.h"
18 #include "vrmlNodeType.h"
19 #include "parse_vrml.h"
20 #include "vrmlParser.h"
21 #include "eggGroupNode.h"
24 #include "deg_2_rad.h"
32 VRMLToEggConverter() {
52 ~VRMLToEggConverter() {
116 if (_egg_data->get_coordinate_system() == CS_default) {
117 _egg_data->set_coordinate_system(CS_yup_right);
123 VrmlScene::iterator si;
124 for (si = scene->begin(); si != scene->end(); ++si) {
125 get_all_defs((*si)._node, nodes);
130 VrmlScene::const_iterator csi;
131 for (csi = scene->begin(); csi != scene->end(); ++csi) {
148 void VRMLToEggConverter::
152 switch (vrml._type) {
153 case SFNodeRef::T_def:
155 nassertv(vrml._name != NULL);
156 nassertv(vrml._p != NULL);
165 nodes[vrml._name] = vrml._p;
168 case SFNodeRef::T_use:
170 nassertv(vrml._name != NULL);
171 ni = nodes.find(vrml._name);
172 if (ni == nodes.end()) {
173 cerr <<
"Unknown node reference: " << vrml._name <<
"\n";
176 (*ni).second->_use_count++;
180 vrml._p = (*ni).second;
190 VrmlNode::Fields::iterator fi;
191 for (fi = node->_fields.begin(); fi != node->_fields.end(); ++fi) {
192 if ((*fi)._type->type == SFNODE) {
193 get_all_defs((*fi)._value._sfnode, nodes);
194 }
else if ((*fi)._type->type == MFNODE) {
195 MFArray *children = (*fi)._value._mf;
196 MFArray::iterator ci;
197 for (ci = children->begin(); ci != children->end(); ++ci) {
198 get_all_defs((*ci)._sfnode, nodes);
212 void VRMLToEggConverter::
218 if (strcmp(node->_type->getName(),
"Group") == 0) {
219 vrml_grouping_node(vrml, egg, net_transform,
220 &VRMLToEggConverter::vrml_group);
221 }
else if (strcmp(node->_type->getName(),
"Transform") == 0) {
222 vrml_grouping_node(vrml, egg, net_transform,
223 &VRMLToEggConverter::vrml_transform);
224 }
else if (strcmp(node->_type->getName(),
"Shape") == 0) {
225 vrml_grouping_node(vrml, egg, net_transform,
226 &VRMLToEggConverter::vrml_shape);
241 void VRMLToEggConverter::
248 nassertv(node != NULL);
250 if (vrml._name != NULL) {
271 egg->add_child(group);
273 LMatrix4d next_transform = net_transform;
275 if (node->_use_count > 0) {
278 group->set_group_type(EggGroup::GT_instance);
285 (this->*process_func)(node, group, next_transform);
294 void VRMLToEggConverter::
297 const MFArray *children = node->get_value(
"children")._mf;
298 MFArray::const_iterator ci;
299 for (ci = children->begin(); ci != children->end(); ++ci) {
300 vrml_node((*ci)._sfnode, group, net_transform);
310 void VRMLToEggConverter::
313 const double *scale = node->get_value(
"scale")._sfvec;
314 const double *rotation = node->get_value(
"rotation")._sfvec;
315 const double *translation = node->get_value(
"translation")._sfvec;
317 const double *center = node->get_value(
"center")._sfvec;
318 const double *o = node->get_value(
"scaleOrientation")._sfvec;
322 bool any_transform =
false;
324 if (scale[0] != 1.0 || scale[1] != 1.0 || scale[2] != 1.0) {
325 any_transform =
true;
326 if (center[0] != 0.0 || center[1] != 0.0 || center[2] != 0.0) {
361 if (rotation[3] != 0.0) {
362 any_transform =
true;
363 if (center[0] != 0.0 || center[1] != 0.0 || center[2] != 0.0) {
368 LVector3d(rotation[0], rotation[1], rotation[2]));
375 LVector3d(rotation[0], rotation[1], rotation[2]));
379 if (translation[0] != 0.0 ||
380 translation[1] != 0.0 ||
381 translation[2] != 0.0) {
382 any_transform =
true;
391 LMatrix4d next_transform = local_transform * net_transform;
393 const MFArray *children = node->get_value(
"children")._mf;
394 MFArray::const_iterator ci;
395 for (ci = children->begin(); ci != children->end(); ++ci) {
396 vrml_node((*ci)._sfnode, group, next_transform);
407 void VRMLToEggConverter::
410 const VrmlNode *geometry = node->get_value(
"geometry")._sfnode._p;
412 if (geometry != NULL) {
413 VRMLAppearance appearance(node->get_value(
"appearance")._sfnode._p);
415 if (strcmp(geometry->_type->getName(),
"IndexedFaceSet") == 0) {
417 ifs.convert_to_egg(group, net_transform);
419 cerr <<
"Ignoring " << geometry->_type->getName() <<
"\n";
This is our own Panda specialization on the default STL map.
This is a 4-by-4 transform matrix.
static LMatrix4d rotate_mat(double angle, const LVecBase3d &axis, CoordinateSystem cs=CS_default)
Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vect...
virtual string get_name() const
Returns the English name of the file type this converter supports.
A base class for nodes in the hierarchy that are not leaf nodes.
virtual SomethingToEggConverter * make_copy()
Allocates and returns a new copy of the converter.
static LMatrix4d scale_mat(const LVecBase3d &scale)
Returns a matrix that applies the indicated scale in each of the three axes.
EggData * get_egg_data()
Returns the EggData structure.
static LMatrix4d translate_mat(const LVecBase3d &trans)
Returns a matrix that applies the indicated translation.
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension)...
This is our own Panda specialization on the default STL vector.
virtual string get_extension() const
Returns the common extension of the file type this converter supports.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
void clear_error()
Resets the error flag to the no-error state.
The name of a file, such as a texture file or an Egg file.
static const LMatrix4d & ident_mat()
Returns an identity matrix.
Decodes the vertices and faces in a VRML indexed face set, and creates the corresponding egg geometry...
This class supervises the construction of an EggData structure from a VRML file.
bool had_error() const
Returns true if an error was detected during the conversion process (unless _allow_errors is true)...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.
This is a base class for a family of converter classes that manage a conversion from some file type t...