From: Braden M. <br...@en...> - 2006-04-25 03:24:38
|
On Mon, 2006-04-24 at 17:43 -0700, Dean Mann wrote: > Hi Braden, > > Thanks for the quick reply. > > > > But still I cant get the coordinates, texture and their indices off the > > > IndexedFaceSet > > > node, either the file name of the texture image. > > > >What have you tried? > > This is what I did, where the MyNodeTraverser class inherits from > openvrml::node_traverser. > > void MyNodeTraverser::on_entering(openvrml::node & n) > { > > if (n.type().id() == "Material") > { > openvrml::vrml97_node::material_node mtrNode (n.type(),n.scope()); The above line creates a new node, which is probably not what you want to do. You certainly don't want to do it by directly invoking this class' constructor. You should avoid using anything in the openvrml::vrml97node namespace; stick to what's in the openvrml namespace when you possibly can. (The openvrml::vrml97node namespace isn't part of the API at all in the forthcoming release of OpenVRML.) > ambientIntensity = mtrNode.ambient_intensity(); // the value is always 0.2 > no matter what is in the VRML file Since you just created a new node, naturally the field has its default value. Rather than create a new node, you want to use the reference to the existing one: openvrml::material_node * m = openvrml::node_cast<openvrml::material_node*>(&n); float ambient_intensity = m->ambient_intensity(); That approach works fine if the data you need to get is exposed via the abstract node classes in the openvrml namespace. You can get arbitrary field data like this: const openvrml::sffloat & ambient_intensity_field = static_cast<const openvrml::sffloat &>(n.field("ambientIntensity"); float ambient_intensity = ambient_intensity_field.value; > if (n.type().id() == "ImageTexture") > { > openvrml::vrml97_node::image_texture_node imgTxtNode (n.type(),n.scope()); > > // no idea what to do next I hope the above examples shed some light on this. You can use the latter form to access any field you need--it's a generic mechanism. > if (n.type().id() == "IndexedFaceSet") > { > openvrml::vrml97_node::indexed_face_set_node idxFSNode > (n.type(),n.scope()); > > openvrml::sfnode sfNode = (openvrml::sfnode)idxFSNode.GetCoord(); Is GetCoord something you've added? I don't know what it returns; but converting it to a nonpointer, nonreference type with a C-style cast isn't likely to end well. You should virtually never use C-style casts in C++ code. > openvrml::node* nodePtr = sfNode.value.get(); // here nodePtr becomes > undefined If we assume the C-style cast wasn't somehow deleterious, the explanation is that, as before, you created a new node so the field has its default value. Again, I hope the code fragments I wrote above sufficiently indicate what you need to do here. Let me know if anything is still unclear. -- Braden McDaniel e-mail: <br...@en...> <http://endoframe.com> Jabber: <br...@ja...> |