예제 #1
0
void    Plugin::ReadNode(domNodeRef node, ISceneNode *parentNode)
{
    MapNode::iterator it = _mapNode.find(node->getId());
    if (it != _mapNode.end())
        return;

    LOG_DEBUG << "Reading Scene Node " << node->getId() << std::endl;

    Object *newNode = new Object(Box3f(), _globalMatrix);
    if (parentNode != NULL)
        parentNode->As<Object>()->AddChild(newNode);
    _mapNode[node->getId()] = newNode;

    // get back the matrix tranformation
    ReadNodeTranforms(newNode, node, (parentNode != NULL) ? parentNode->As<Object>() : NULL);

    // Process Instance Geometries
    for (unsigned int i = 0; i < node->getInstance_geometry_array().getCount(); i++)
    {
        domInstance_geometryRef lib = node->getInstance_geometry_array()[i];
        xsAnyURI &urltype  = lib->getUrl();
        urltype.resolveElement();
        domElement *element = (domElement*)urltype.getElement();
        if (element == NULL) // this instance geometry is not found skip to the next one
            continue;

        ReadDrawable((domGeometry*)element, newNode);
    }
    if (node->getInstance_geometry_array().getCount() > 0)
        newNode->ChooseDefaultMaterial();

/*
    // Process Instance Controllers
    for (int i = 0; i < node->getInstance_controller_array().getCount(); i++)
    {
        domInstance_controller *icontroller  = node->getInstance_controller_array()[i];
        CrtInstanceController * instanceController = ReadInstanceController(icontroller);
        if (instanceController==NULL) //if instance Controller can not be created, skip to the next one
            continue;

        instanceController->Parent = crtNode;
        crtNode->InstanceControllers.push_back(instanceController);
        ControllerInstances.push_back(instanceController);
    }
*/

    // read childrens
    for (unsigned int i = 0; i < node->getNode_array().getCount(); i++)
        ReadNode(node->getNode_array()[i], newNode);

    // read children <instance_nodes>
    for (unsigned int i = 0; i < node->getInstance_node_array().getCount(); i++)
    {
        domInstance_node *instance_node = node->getInstance_node_array()[i];
        domNode *urlnode = (domNode*) (domElement*) instance_node->getUrl().getElement();
        if (urlnode)
            ReadNode(urlnode, newNode);
    }
}
예제 #2
0
SceneGraph::Vertex 
Scene::readNode(const domNodeRef node, SceneGraph::Vertex &parent)
{
  // just to experiment with fonts
  bool is_font_node = false;
  std::string::size_type pos = std::string(node->getId()).find(SceneGraph::font_name);
  if(pos != std::string::npos)
    is_font_node = true;

  SceneGraph::IdVertexMap::iterator findnode = this->scene_graph.id_vertex_map.find(node->getId());
  if(findnode != this->scene_graph.id_vertex_map.end())
    return findnode->second;

  this->scene_graph.printStatusMessage(std::string("  reading scene node ") + node->getID());
  size_t i;
  // Insert new node and connect to parent
  SceneGraph::NodeInfo new_node_info = {node->getId(), CheckString(node->getSid())};
  this->scene_graph.insertNode(parent,
                               CheckString(node->getName()),
                               node->getId(),
                               CheckString(node->getSid()));
  SceneGraph::node_id_map_t node_id_map = get(SceneGraph::node_info_t(), this->scene_graph.node_graph);
  // Read node transformations
  const SceneGraph::NodeInfo &parent_node_info = node_id_map[parent];
  const Node *parent_node = this->scene_graph.all_nodes.find(parent_node_info.id.c_str());
  Node &current_node = *this->scene_graph.all_nodes.find(new_node_info.id.c_str());
  current_node.is_font_node = is_font_node;
  SceneGraph::Vertex node_vertex = this->scene_graph.id_vertex_map.find(new_node_info.id)->second;

  this->readNodeTranforms(current_node, *parent_node, node);

  // Process Instance Geometries
  const domInstance_geometry_Array &geom_instances = node->getInstance_geometry_array();
	for(i = 0; i < geom_instances.getCount(); ++i)
		this->readInstanceGeometry(current_node, geom_instances[i]);

  // Process Instance Lights 
  const domInstance_light_Array &lia = node->getInstance_light_array();
	for(i = 0; i < lia.getCount(); ++i)
		this->readInstanceLight(current_node, lia[i]);
  if(!current_node.instance_lights.empty())
    this->scene_graph.light_nodes.push_back(new_node_info.id);

  // Process Instance Cameras 
  const domInstance_camera_Array &ica  = node->getInstance_camera_array();
	for(i = 0; i < ica.getCount(); ++i)
    this->readInstanceCamera(current_node, ica[i]);

  // Read in each child and recursively it's children 
  const domNode_Array &nodes = node->getNode_array();
  for(i = 0; i < nodes.getCount(); i++)
    this->readNode(nodes[i], node_vertex);

  // Read children <instance_nodes>, can be 0 or more
  const domInstance_node_Array &instance_nodes = node->getInstance_node_array();
  for(i = 0; i < instance_nodes.getCount(); i++)
  {
    domInstance_node *instance_node = instance_nodes[i];
    domNode *urlnode = (domNode*)(domElement*)instance_node->getUrl().getElement();
    if(urlnode)
      this->readNode(urlnode, node_vertex);
  }

  return node_vertex;
}