17 #include "vrmlNodeType.h" 19 #include "vrmlParser.h" 29 VRMLToEggConverter() {
45 ~VRMLToEggConverter() {
91 if (scene ==
nullptr) {
95 if (_egg_data->get_coordinate_system() == CS_default) {
96 _egg_data->set_coordinate_system(CS_yup_right);
102 VrmlScene::iterator si;
103 for (si = scene->begin(); si != scene->end(); ++si) {
104 get_all_defs((*si)._node, nodes);
109 VrmlScene::const_iterator csi;
110 for (csi = scene->begin(); csi != scene->end(); ++csi) {
111 vrml_node((*csi)._node,
get_egg_data(), LMatrix4d::ident_mat());
123 void VRMLToEggConverter::
127 switch (vrml._type) {
128 case SFNodeRef::T_def:
130 nassertv(vrml._name !=
nullptr);
131 nassertv(vrml._p !=
nullptr);
140 nodes[vrml._name] = vrml._p;
143 case SFNodeRef::T_use:
145 nassertv(vrml._name !=
nullptr);
146 ni = nodes.find(vrml._name);
147 if (ni == nodes.end()) {
148 std::cerr <<
"Unknown node reference: " << vrml._name <<
"\n";
151 (*ni).second->_use_count++;
155 vrml._p = (*ni).second;
164 if (node !=
nullptr) {
165 VrmlNode::Fields::iterator fi;
166 for (fi = node->_fields.begin(); fi != node->_fields.end(); ++fi) {
167 if ((*fi)._type->type == SFNODE) {
168 get_all_defs((*fi)._value._sfnode, nodes);
169 }
else if ((*fi)._type->type == MFNODE) {
170 MFArray *children = (*fi)._value._mf;
171 MFArray::iterator ci;
172 for (ci = children->begin(); ci != children->end(); ++ci) {
173 get_all_defs((*ci)._sfnode, nodes);
184 void VRMLToEggConverter::
186 const LMatrix4d &net_transform) {
188 if (node !=
nullptr) {
190 if (strcmp(node->_type->getName(),
"Group") == 0) {
191 vrml_grouping_node(vrml, egg, net_transform,
192 &VRMLToEggConverter::vrml_group);
193 }
else if (strcmp(node->_type->getName(),
"Transform") == 0) {
194 vrml_grouping_node(vrml, egg, net_transform,
195 &VRMLToEggConverter::vrml_transform);
196 }
else if (strcmp(node->_type->getName(),
"Shape") == 0) {
197 vrml_grouping_node(vrml, egg, net_transform,
198 &VRMLToEggConverter::vrml_shape);
209 void VRMLToEggConverter::
211 const LMatrix4d &net_transform,
214 const LMatrix4d &net_transform)) {
216 nassertv(node !=
nullptr);
218 if (vrml._name !=
nullptr) {
241 LMatrix4d next_transform = net_transform;
243 if (node->_use_count > 0) {
246 group->set_group_type(EggGroup::GT_instance);
247 next_transform = LMatrix4d::ident_mat();
253 (this->*process_func)(node, group, next_transform);
260 void VRMLToEggConverter::
262 const LMatrix4d &net_transform) {
263 const MFArray *children = node->get_value(
"children")._mf;
264 MFArray::const_iterator ci;
265 for (ci = children->begin(); ci != children->end(); ++ci) {
266 vrml_node((*ci)._sfnode, group, net_transform);
273 void VRMLToEggConverter::
275 const LMatrix4d &net_transform) {
276 const double *scale = node->get_value(
"scale")._sfvec;
277 const double *rotation = node->get_value(
"rotation")._sfvec;
278 const double *translation = node->get_value(
"translation")._sfvec;
280 const double *center = node->get_value(
"center")._sfvec;
281 const double *o = node->get_value(
"scaleOrientation")._sfvec;
283 LMatrix4d local_transform = LMatrix4d::ident_mat();
285 bool any_transform =
false;
287 if (scale[0] != 1.0 || scale[1] != 1.0 || scale[2] != 1.0) {
288 any_transform =
true;
289 if (center[0] != 0.0 || center[1] != 0.0 || center[2] != 0.0) {
291 LMatrix4d::translate_mat(-center[0], -center[1], -center[2]);
295 LMatrix4d::rotate_mat(rad_2_deg(-o[3]), LVector3d(o[0], o[1], o[2]));
297 LMatrix4d::scale_mat(scale[0], scale[1], scale[2]);
299 LMatrix4d::rotate_mat(rad_2_deg(o[3]), LVector3d(o[0], o[1], o[2]));
303 LMatrix4d::scale_mat(scale[0], scale[1], scale[2]);
306 LMatrix4d::translate_mat(center[0], center[1], center[2]);
311 LMatrix4d::rotate_mat(rad_2_deg(-o[3]), LVector3d(o[0], o[1], o[2]));
313 LMatrix4d::scale_mat(scale[0], scale[1], scale[2]);
315 LMatrix4d::rotate_mat(rad_2_deg(o[3]), LVector3d(o[0], o[1], o[2]));
319 LMatrix4d::scale_mat(scale[0], scale[1], scale[2]);
324 if (rotation[3] != 0.0) {
325 any_transform =
true;
326 if (center[0] != 0.0 || center[1] != 0.0 || center[2] != 0.0) {
328 LMatrix4d::translate_mat(-center[0], -center[1], -center[2]);
330 LMatrix4d::rotate_mat(rad_2_deg(rotation[3]),
331 LVector3d(rotation[0], rotation[1], rotation[2]));
333 LMatrix4d::translate_mat(center[0], center[1], center[2]);
337 LMatrix4d::rotate_mat(rad_2_deg(rotation[3]),
338 LVector3d(rotation[0], rotation[1], rotation[2]));
342 if (translation[0] != 0.0 ||
343 translation[1] != 0.0 ||
344 translation[2] != 0.0) {
345 any_transform =
true;
347 LMatrix4d::translate_mat(translation[0], translation[1], translation[2]);
354 LMatrix4d next_transform = local_transform * net_transform;
356 const MFArray *children = node->get_value(
"children")._mf;
357 MFArray::const_iterator ci;
358 for (ci = children->begin(); ci != children->end(); ++ci) {
359 vrml_node((*ci)._sfnode, group, next_transform);
367 void VRMLToEggConverter::
369 const LMatrix4d &net_transform) {
370 const VrmlNode *geometry = node->get_value(
"geometry")._sfnode._p;
372 if (geometry !=
nullptr) {
373 VRMLAppearance appearance(node->get_value(
"appearance")._sfnode._p);
375 if (strcmp(geometry->_type->getName(),
"IndexedFaceSet") == 0) {
377 ifs.convert_to_egg(group, net_transform);
379 std::cerr <<
"Ignoring " << geometry->_type->getName() <<
"\n";
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
bool had_error() const
Returns true if an error was detected during the conversion process (unless _allow_errors is true),...
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.
EggData * get_egg_data()
Returns the EggData structure.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
VrmlScene * parse_vrml(Filename filename)
Reads the named VRML file and returns a corresponding VrmlScene, or NULL if there is a parse error.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
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.
virtual std::string get_extension() const
Returns the common extension of the file type this converter supports.
The name of a file, such as a texture file or an Egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension),...
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
virtual std::string get_name() const
Returns the English name of the file type this converter supports.