예제 #1
0
GroupNode* SceneLoader::LoadGroupNode(QDomElement element)
{
  if (element.nodeName() != QString ("node") ||
      QString::compare(element.attribute("type"), "group", Qt::CaseInsensitive) != 0)
    {
      printf ("ceXMLDataLoader::LoadGroupNode: Illegal data format: '%s' != 'group'\n", element.nodeName().toStdString().c_str()); fflush (stdout);
    }

  GroupNode* group = new GroupNode();

  QString name = element.attribute("name");
  if (!name.isNull())
    {
      group->SetName(name.toStdString());
    }

  for (QDomElement groupElement = element.firstChildElement();
       !groupElement.isNull();
       groupElement = groupElement.nextSiblingElement())

    {
      ceNode* node = LoadNode (groupElement);
      if (node)
        {
          group->AddNode(node);
        }
    }

  group->UpdateBoundingBox();
  return group;
}
예제 #2
0
void PointerNode::manipulate (int b)
{
    // Immediately when the user presses the manipulate button, we check to see
    // if we are pointing at a new node. ie, we make sure the user is NOT
    // pointing at a dragger anymore, and
    if (b && spinApp::Instance().getContext()->isServer())
    {
        if (1) //!getDraggerFromIntersections())
        {
            GroupNode *lastNode = dynamic_cast<GroupNode*>(lastManipulated->s_thing);
            GroupNode *newNode = dynamic_cast<GroupNode*>(getNodeFromIntersections(0));

            if (newNode && (newNode!=lastNode))
            {
                dragger_ = NULL;
                if (lastNode) lastNode->setManipulator("NULL");
                newNode->setManipulator(lastManipulatorType_.c_str());
                lastManipulated = newNode->getNodeSymbol();
            }
        }
    }

    // then we just set the 'doManipulation' flag, which will

    doManipulation = (bool) b;
    BROADCAST(this, "si", "manipulate", this->getManipulate());
}
예제 #3
0
파일: group-node.cpp 프로젝트: cjhoward/ogf
SceneNode* GroupNode::clone() const
{
    GroupNode* node = new GroupNode();

    for (auto child: children)
        node->addChild(child->clone());

    return node;
}
예제 #4
0
GroupNode *SceneGraph::findGroupNode(char *name) {
	if (!name || strlen(name) <= 0)
		return NULL;
	for (GroupNode *node = findGroupNode(); node; node = node->nextTraversal()) {
		const char *nodeName = node->getName();
		if (nodeName && strlen(nodeName)) {
			if (!strcmp(name, nodeName))
				return node;
		}
	}
	return NULL;
}
예제 #5
0
TEST(NodeTest, children)
{
  GroupNode root;
  Node *child1 = new Node;
  Node *child2 = new Node;
  root.addChild(child1);
  root.addChild(child2);

  EXPECT_EQ(&root, child1->parent());
  EXPECT_EQ(&root, child2->parent());
  EXPECT_EQ(child1, root.child(0));
  EXPECT_EQ(child2, root.child(1));
}
void ExecutionSystemHelper::addbNodeTree(ExecutionSystem &system, int nodes_start, bNodeTree *tree, bNodeInstanceKey parent_key)
{
	vector<Node *>& nodes = system.getNodes();
	vector<SocketConnection *>& links = system.getConnections();
	
	const bNodeTree *basetree = system.getContext().getbNodeTree();
	/* update viewers in the active edittree as well the base tree (for backdrop) */
	bool is_active_group = ((parent_key.value == basetree->active_viewer_key.value) ||
	                        (tree == basetree));
	
	/* add all nodes of the tree to the node list */
	bNode *node = (bNode *)tree->nodes.first;
	while (node != NULL) {
		Node *nnode = addNode(nodes, node, is_active_group, system.getContext().isFastCalculation());
		if (nnode) {
			nnode->setbNodeTree(tree);
			nnode->setInstanceKey(BKE_node_instance_key(parent_key, tree, node));
		}
		node = node->next;
	}

	NodeRange node_range(nodes.begin() + nodes_start, nodes.end());

	/* add all nodelinks of the tree to the link list */
	bNodeLink *nodelink = (bNodeLink *)tree->links.first;
	while (nodelink != NULL) {
		addNodeLink(node_range, links, nodelink);
		nodelink = nodelink->next;
	}

	/* Expand group nodes
	 * Only go up to nodes_end, to avoid ungrouping nested node groups repeatedly.
	 */
	int nodes_end = nodes.size();
	for (unsigned int i = nodes_start; i < nodes_end; ++i) {
		Node *execnode = nodes[i];
		if (execnode->isGroupNode()) {
			GroupNode *groupNode = (GroupNode *)execnode;
			groupNode->ungroup(system);
		}
	}
}
예제 #7
0
GroupNode *PointerNode::getNodeFromIntersections(int index)
{
    // return first GroupNode encountered with interaction mode greater than passthru

    if ((index>=0) && (index < intersectList.size()))
    {
        ReferencedNode *t = intersectList[index];
        while (t)
        {
            GroupNode *g = dynamic_cast<GroupNode*>(t);
            if (g && (g->getInteractionMode()>(int)GroupNode::PASSTHRU))
            {
                return g;
            }
            t = dynamic_cast<ReferencedNode*>(t->getParentNode(0));
        }
    }

    return NULL;
}
예제 #8
0
void PointerNode::setManipulator(const char *manipulatorType)
{
    if (spinApp::Instance().getContext()->isServer())
    {
        GroupNode *lastNode = dynamic_cast<GroupNode*>(lastManipulated->s_thing);

        // see if there is an intersection with a GroupNode, and if so, tell
        // that node to enable the manipulator
        GroupNode *n = dynamic_cast<GroupNode*>(getNodeFromIntersections(0));
        if (n)
        {
            // if we're targetting a new node, make sure that the last
            // manipulated node's dragger gets turned off:
            if ((lastNode) && (n != lastNode))
                lastNode->setManipulator("NULL");

            n->setManipulator(manipulatorType);
            lastManipulated = n->getNodeSymbol();
        }

        // if there was no intersection, load the manipulator on the last object
        // that was manipulated
        else if (lastNode)
        {
            lastNode->setManipulator(manipulatorType);
        }

        lastManipulatorType_ = std::string(manipulatorType);
    }
    else
    {
        BROADCAST(this, "ss", "setManipulator", manipulatorType);
    }
}
예제 #9
0
std::vector<QueryResult> SelectionQuery::CastRay(const int64_t selection_mask,
    const QVector3D& start, const QVector3D& dir) {
 std::vector<QueryResult> result;

 std::deque<SceneNode*> to_query = { scene_->Root() };

 while (!to_query.empty()) {
   SceneNode* node = to_query.front();
   to_query.pop_front();

   const AxisAlignedBox& node_box = node->WorldBoundingBox();
   double node_t;
   if (!Intersection(node_box, start, dir, &node_t)) {
     // No intersection. Move along.
     continue;
   }

   // Intersection with this node.
   // 1. Schedule its children for testing.
   if (node->NodeType() == SceneNodeType::kGroupNode) {
     GroupNode* group = static_cast<GroupNode*>(node);
     const std::vector<SceneNode*>& children = group->Children();
     to_query.insert(to_query.end(), children.begin(), children.end());
   }

   // 2. If the node passes the selection mask, then add it to the result list.
   if (node->GetSelectionMask() & selection_mask) {
     result.emplace_back(node, node_t);
   }
 }

 // Sort nodes by distance.
 std::sort(result.begin(), result.end(), [](const QueryResult& result_a,
       const QueryResult& result_b) {
      return result_a.distance < result_b.distance;
     });

 return result;
}
예제 #10
0
SceneNode *Factory::CopyNode(SceneNode *pNode)
{
  DbgEnter();
  //check if node already belongs to some parent
  if (pNode && pNode->GetCount() > 0)
  {
    GroupNode *pGroup = dynamic_cast<GroupNode *>(pNode);
    if (pGroup)
    {
      //save list of child nodes
      SceneNodeList &nodes = pGroup->GetNodeList();
      //create new group node
      pGroup = NewObject<GroupNode>();
      //add copies of all child nodes to new group node
      for (SceneNodeList::iterator it = nodes.begin(); it != nodes.end(); it++)
      {
        pGroup->AddNode(CopyNode(*it));
      }
      return pGroup;
    }
  }
  //return original node
  return pNode;
}
예제 #11
0
void NodeVisitorXML::visit( GroupNode &n ) const
{
	startElement( n );
	output << std::endl;
	increaseIndent();
	
	GroupNode::NodeIteratorPair iterPair = n.getChildren();
	GroupNode::NodeList::iterator iter;
	for( iter = iterPair.first; iter != iterPair.second; iter++ )
	{
		(*iter)->accept( *this );
	}
	
	decreaseIndent();
	output << indentString;
	endElement( n );
}
예제 #12
0
TEST(NodeTest, removeChild)
{
  GroupNode root;
  Node *child1 = new Node;
  Node *child2 = new Node;
  root.addChild(child1);
  root.addChild(child2);

  EXPECT_EQ(child1, root.child(0));
  EXPECT_EQ(root.removeChild(child1), true);
  EXPECT_EQ(root.removeChild(child1), false);
  EXPECT_EQ(child2, root.child(0));
  EXPECT_EQ(NULL, child1->parent());
  EXPECT_EQ(&root, child2->parent());
  EXPECT_EQ(root.removeChild(child2), true);
  delete child1;
  delete child2;
}
예제 #13
0
void PointerNode::lockToTarget(const char *nodeToLock)
{
    if (!spinApp::Instance().getContext()->isServer())
        return;

    GroupNode *node = dynamic_cast<GroupNode*>(sceneManager_->getNode(nodeToLock));
    if (node)
    {
        GroupNode *target = dynamic_cast<GroupNode*>(getNodeFromIntersections(0));
        if (target)
        {
            node->setOrientationMode(GroupNode::POINT_TO_TARGET_CENTROID);
            node->setOrientationTarget(target->getID().c_str());
        }
        else
        {
            // What do we do if there is no target?
            node->setOrientationTarget(lastManipulated->s_name);
        }
    }

}
예제 #14
0
void GroupNode::CopyAsChildren(Scene* scene, GroupNode* root) {
  const std::vector<SceneNode*>& tocopy_children = root->Children();
  std::deque<SceneNode*>
    to_process(tocopy_children.begin(), tocopy_children.end());

  SetTranslation(root->Translation());
  SetRotation(root->Rotation());
  SetScale(root->Scale());
  SetVisible(root->Visible());

  while (!to_process.empty()) {
    SceneNode* to_copy = to_process.front();
    to_process.pop_front();
    SceneNode* node_copy = nullptr;

    switch (to_copy->NodeType()) {
      case SceneNodeType::kGroupNode:
        {
          GroupNode* child = scene->MakeGroup(this, Scene::kAutoName);
          GroupNode* group_to_copy =
            dynamic_cast<GroupNode*>(to_copy);
          child->CopyAsChildren(scene, group_to_copy);
          node_copy = child;
        }
        break;
      case SceneNodeType::kCameraNode:
        {
          CameraNode* child = scene->MakeCamera(this, Scene::kAutoName);
          const CameraNode* camera_to_copy =
            dynamic_cast<const CameraNode*>(to_copy);
          child->CopyFrom(*camera_to_copy);
          node_copy = child;
        }
        break;
      case SceneNodeType::kLightNode:
        {
          LightNode* child = scene->MakeLight(this, Scene::kAutoName);
          const LightNode* light_to_copy =
            dynamic_cast<const LightNode*>(to_copy);
//          *child = *light_to_copy;
          (void)light_to_copy;
          node_copy = child;
        }
        break;
      case SceneNodeType::kDrawNode:
        {
          DrawNode* node_to_copy =
            dynamic_cast<DrawNode*>(to_copy);
          DrawNode* child = scene->MakeDrawNode(this, Scene::kAutoName);
          for (const Drawable::Ptr& item : node_to_copy->Drawables()) {
            child->Add(item);
          }
          node_copy = child;
        }
        break;
    }

    node_copy->SetTranslation(to_copy->Translation());
    node_copy->SetRotation(to_copy->Rotation());
    node_copy->SetScale(to_copy->Scale());
    node_copy->SetVisible(to_copy->Visible());
  }
}