Ejemplo n.º 1
0
bool PrefabStore::loadNamedPrefab(const QString &name, LoadingContext &ctx) //groupFileLoadFromName
{
    GeoStoreDef *geo_store = groupGetFileEntryPtr(name);
    if (!geo_store)
        return false;
    if (geo_store->loaded)
        return true;

    geo_store->loaded = true;
    loadSubgraph(geo_store->geopath,ctx,*this);
    loadPrefabForNode(getNodeByName(*ctx.m_target,name), ctx);
    return true;
}
Ejemplo n.º 2
0
 virtual osgDB::ReaderWriter::ReadResult readNode( const std::string& filename, const osgDB::Options* options )
 {
     OpenThreads::ScopedLock<OpenThreads::Mutex> lock( _shareMutex );
     osg::Node* node = getNodeByName( filename );
     if ( !node )
     {
         osgDB::ReaderWriter::ReadResult rr = 
             osgDB::Registry::instance()->readNodeImplementation( filename, options );
         if ( rr.success() ) _nodeMap[filename] = rr.getNode();
         return rr;
     }
     else
         std::cout << "[SHARING] The name " << filename << " is already added to the sharing list." << std::endl;
     return node;
 }
Ejemplo n.º 3
0
NodePtr SpaceNavigatorSSM::getNodeByName(NodePtr rootNode, const Char8 *nodeName)
{
	if (getName(rootNode))
	{
		if (getName(rootNode) == std::string(nodeName))
			return rootNode;
	}

	for (int i = 0; i < rootNode->getNChildren(); i++)
	{
		NodePtr r = getNodeByName(rootNode->getChild(i), nodeName);
	
		if (r != NullFC)
			return r;
	}

	return NullFC;
}
Ejemplo n.º 4
0
int getCoolness(char *name)
{
   int node;
   int degree;
   int nodeCount;

   // Get the starting node in the network
   node = getNodeByName(name);

   // If this person isn't in the network, their coolness is zero
   if (node < 0)
      return 0;

   // Get the "degree" of this node, which is the number of people
   // directly connected to it.  This is the first part of the coolness
   degree = getDegree(node);

   // Get the number of nodes directly or indirectly connected to this node
   nodeCount = componentCount(node);

   // Return the "coolness", which is the degree plus the node count, minus
   // one (we don't count ourselves in the coolness factor)
   return degree + nodeCount - 1;
}
Ejemplo n.º 5
0
	void DemoKeeper::loadFromFile(const std::string& _filename)
	{
		MyGUI::xml::Document doc;

		if (!doc.open(_filename))
			return;

		MyGUI::xml::ElementPtr root = doc.getRoot();
		if (root == nullptr || root->getName() != "AnimationGraph")
			return;

		MyGUI::xml::ElementEnumerator node = root->getElementEnumerator();
		while (node.next())
		{
			if (node->getName() == "Node")
			{
				BaseAnimationNode* anim_node = createNode(node->findAttribute("type"), node->findAttribute("name"));
				anim_node->deserialization(node.current());
			}
			else if (node->getName() == "Connections")
			{
				MyGUI::xml::ElementEnumerator conn = node->getElementEnumerator();
				BaseAnimationNode* anim_node = getNodeByName(node.current()->findAttribute("node"));
				if (anim_node)
				{
					while (conn.next("Connection"))
					{
						BaseAnimationNode* anim_node2 = getNodeByName(conn.current()->findAttribute("node"));
						if (anim_node2)
						{
							//соединить точки в ноде
							const std::string& from_point = conn.current()->findAttribute("from");
							const std::string& to_point = conn.current()->findAttribute("to");

							wraps::BaseGraphConnection* from_conn = anim_node->getConnectionByName(from_point, "EventOut");
							if (!from_conn) from_conn = anim_node->getConnectionByName(from_point, "PositionOut");
							if (!from_conn) from_conn = anim_node->getConnectionByName(from_point, "WeightOut");

							wraps::BaseGraphConnection* to_conn = anim_node2->getConnectionByName(to_point, "EventIn");
							if (!to_conn) to_conn = anim_node2->getConnectionByName(to_point, "PositionIn");
							if (!to_conn) to_conn = anim_node2->getConnectionByName(to_point, "WeightIn");

							if (from_conn && to_conn)
							{
								from_conn->addConnectionPoint(to_conn);
								connectPoints(anim_node, anim_node2, from_point, to_point);
							}
						}
					}
				}
			}
			else if (node->getName() == "EditorData")
			{
				MyGUI::xml::ElementEnumerator item_data = node->getElementEnumerator();
				while (item_data.next("Node"))
				{
					BaseAnimationNode* anim_node = getNodeByName(item_data.current()->findAttribute("name"));
					if (anim_node)
					{
						anim_node->setCoord(MyGUI::IntCoord::parse(item_data.current()->findAttribute("coord")));
					}
				}
			}
		}

	}
Ejemplo n.º 6
0
int main(void)
{
   FILE  *fp;
   char  line[256];
   char  *token;
   int   numNetworks;
   int   net;
   int   i;
   int   numConnections;
   char  name1[128];
   char  name2[128];
   int   node1, node2;
   int   yourCoolness;
   int   numQueries;
   char  *nl;
   int   coolness;

   // Open the input file
   fp = fopen("friends.in", "r");

   // Read the number of networks in the file
   fgets(line, sizeof(line), fp);
   sscanf(line, "%d", &numNetworks);

   // Process the individual networks
   for (net = 0; net < numNetworks; net++)
   {
      // Clear the names and connection matrix
      memset(people, 0, sizeof(people));
      numPeople = 0;
      memset(connectMatrix, 0, sizeof(connectMatrix));

      // Read the number of people on the network
      fgets(line, sizeof(line), fp);
      sscanf(line, "%d", &numPeople);

      // Read in the names of the people
      fgets(line, sizeof(line), fp);
      token = strtok(line, " \r\n");
      for (i = 0; i < numPeople; i++)
      {
         // Copy the person's name
         strcpy(people[i], token);

         // Get the next person's name
         token = strtok(NULL, " \r\n");
      }

      // Get the number of connections in the network
      fgets(line, sizeof(line), fp);
      sscanf(line, "%d", &numConnections);

      // Process the connections
      for (i = 0; i < numConnections; i++)
      {
         // Read the next line
         fgets(line, sizeof(line), fp);

         // Parse the two names that describe the connection
         token = strtok(line, " \r\n");
         strcpy(name1, token);
         token = strtok(NULL, " \r\n");
         strcpy(name2, token);

         // Get the two nodes from the names
         node1 = getNodeByName(name1);
         node2 = getNodeByName(name2);

         // Add the connection in both directions to the connection matrix
         connectMatrix[node1][node2] = true;
         connectMatrix[node2][node1] = true;
      }

      // Compute your coolness first
      yourCoolness = getCoolness("You");

      // Print the output header
      printf("Social Network %d:\n", net+1);

      // Process the queries
      fgets(line, sizeof(line), fp);
      sscanf(line, "%d", &numQueries);
      for (i = 0; i < numQueries; i++)
      {
         // Get the name and trim off the trailing '\n' character
         fgets(line, sizeof(line), fp);
         token = strtok(line, " \n\r");

         // Get this person's coolness
         coolness = getCoolness(token);

         // Compute the difference and output
         printf("   %s: Difference of %d point(s).\n", token,
            yourCoolness - coolness);
      }

      // Leave a blank line, as instructed
      printf("\n");
   }

   // Close the input file
   fclose(fp);
}
Ejemplo n.º 7
0
void NiAnimation::updateSkeletonAnimation(xn::UserGenerator &user_generator)
{
    XnUInt16 num_users = MAX_USERS;
    user_generator.GetUsers(all_users, num_users);

    // tracking only default (first) person
    if (!user_generator.GetSkeletonCap().IsTracking(DEFAULT_USER)) return;

    // POSITION

    // animik: x,y,z € <-196, 196>

    XnSkeletonJointPosition torso;
    user_generator.GetSkeletonCap().GetSkeletonJointPosition(all_users[0], XN_SKEL_TORSO, torso);
    if (torso.fConfidence == 1) setPosition(torso.position.X*MM0, torso.position.Y*MM0+40, 150-torso.position.Z*MM0);


    // ROTATION

    double x, y, z, tx, ty, tz;

    // hip -> abdomen -> chest -> ...
    if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, tx, ty, tz, MM1) &&
        calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x,  y,  z, MM1))
        setRotation(getNodeByName("hip"), (x+tx)/2, (y+ty)/2, (z+tz)/2);

    if (calculateRotation(user_generator, XN_SKEL_TORSO, x, y, z, MM1))
        setRotation(getNodeByName("abdomen"), x, y, z);

    if (calculateRotation(user_generator, XN_SKEL_NECK, tx, ty, tz, MM1)) // !!! + torso ^
        setRotation(getNodeByName("chest"), (x+tx)/2, (y+ty)/2, (z+tz)/2);

    // ... -> neck -> head
    if (calculateRotation(user_generator, XN_SKEL_NECK, x, y, z, MM1))
        setRotation(getNodeByName("neck"), x, y, z);

    if (calculateRotation(user_generator, XN_SKEL_HEAD, x, y, z, MM1))
        setRotation(getNodeByName("head"), x, y, z);

    if (!global_mirror)
    {
        // ... -> lCollar -> lShldr -> lForeArm -> lHand
        if (calculateRotation(user_generator, XN_SKEL_LEFT_COLLAR, x, y, z, MM2))
            setRotation(getNodeByName("rCollar"), x, y, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_SHOULDER, x, y, z, MM2))
            setRotation(getNodeByName("rShldr"), x, y*MM2, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_ELBOW, x, y, z, MM2))
            setRotation(getNodeByName("rForeArm"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_HAND, x, y, z, MM2))
            setRotation(getNodeByName("rHand"), x, y, z/MM2);

        // ... -> rCollar -> rShldr -> rForeArm -> rHand
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_COLLAR, x, y, z, MM2))
            setRotation(getNodeByName("lCollar"), x, y, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_SHOULDER, x, y, z, MM2))
            setRotation(getNodeByName("lShldr"), x, y*MM2, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_ELBOW, x, y, z, MM2))
            setRotation(getNodeByName("lForeArm"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_HAND, x, y, z, MM2))
            setRotation(getNodeByName("lHand"), x, y, z/MM2);

        // hip -> lThigh -> lShin -> lFoot
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x, y, z, MM3) )
            setRotation(getNodeByName("lThigh"), x/MM3, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_KNEE, x, y, z, MM3))
            setRotation(getNodeByName("lShin"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_FOOT, x, y, z, MM3))
            setRotation(getNodeByName("lFoot"), x/MM3, y, z);

        // hip -> rThigh -> rShin -> rFoot
        if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, x, y, z, MM3))
            setRotation(getNodeByName("rThigh"), x/MM3, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_KNEE, x, y, z, MM3))
            setRotation(getNodeByName("rShin"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_FOOT, x, y, z, MM3))
            setRotation(getNodeByName("rFoot"), x/MM3, y, z);
    }
    else
    {
        // ... -> lCollar -> lShldr -> lForeArm -> lHand
        if (calculateRotation(user_generator, XN_SKEL_LEFT_COLLAR, x, y, z, MM2))
            setRotation(getNodeByName("lCollar"), x, y, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_SHOULDER, x, y, z, MM2))
            setRotation(getNodeByName("lShldr"), x, y*MM2, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_ELBOW, x, y, z, MM2))
            setRotation(getNodeByName("lForeArm"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_HAND, x, y, z, MM2))
            setRotation(getNodeByName("lHand"), x, y, z/MM2);

        // ... -> rCollar -> rShldr -> rForeArm -> rHand
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_COLLAR, x, y, z, MM2))
            setRotation(getNodeByName("rCollar"), x, y, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_SHOULDER, x, y, z, MM2))
            setRotation(getNodeByName("rShldr"), x, y*MM2, z/MM2);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_ELBOW, x, y, z, MM2))
            setRotation(getNodeByName("rForeArm"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_HAND, x, y, z, MM2))
            setRotation(getNodeByName("rHand"), x, y, z/MM2);

        // hip -> lThigh -> lShin -> lFoot
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_HIP, x, y, z, MM3) )
            setRotation(getNodeByName("rThigh"), x/MM3, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_KNEE, x, y, z, MM3))
            setRotation(getNodeByName("rShin"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_RIGHT_FOOT, x, y, z, MM3))
            setRotation(getNodeByName("rFoot"), x/MM3, y, z);

        // hip -> rThigh -> rShin -> rFoot
        if (calculateRotation(user_generator, XN_SKEL_LEFT_HIP, x, y, z, MM3))
            setRotation(getNodeByName("lThigh"), x/MM3, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_KNEE, x, y, z, MM3))
            setRotation(getNodeByName("lShin"), x, y, z);
        if (calculateRotation(user_generator, XN_SKEL_LEFT_FOOT, x, y, z, MM3))
            setRotation(getNodeByName("lFoot"), x/MM3, y, z);
    }

    // add frame to animation
    if (is_recording)
    {
        setFrame(current_frame++);
        if (current_frame % 10 == 0) addKeyFrameAllJoints();
        else deleteKeyFrameAllJoints();
    }
}
Ejemplo n.º 8
0
/*! Finds the common ancestor for each remaining group in jointGroups,
these are our final skeleton roots
*/
void SLAssimpImporter::findSkeletonRoot()
{
    _skeletonRoot = nullptr;
    // early out if we don't have any joint bindings
    if (_jointOffsets.size() == 0) return;
    
	vector<SLVaiNode> ancestorList(_jointOffsets.size());
    SLint minDepth = INT_MAX;
    SLint index = 0;    

    logMessage(LV_detailed, "Building joint ancestor lists.\n");

    auto it = _jointOffsets.begin();
    for (; it != _jointOffsets.end(); it++, index++)
    {
        aiNode* node = getNodeByName(it->first);
        SLVaiNode& list = ancestorList[index];

        while (node)
        {   list.insert(list.begin(), node);
            node = node->mParent;
        }

        // log the gathered ancestor list if on diagnostic
        if (LV_diagnostic)
        {   logMessage(LV_diagnostic, "   '%s' ancestor list: ", it->first.c_str());
            for (SLint i = 0; i < list.size(); i++)
                logMessage(LV_diagnostic, "'%s' ", list[i]->mName.C_Str());
            logMessage(LV_diagnostic, "\n");
        } else
            logMessage(LV_detailed, "   '%s' lies at a depth of %d\n", it->first.c_str(), list.size());

        minDepth = min(minDepth, (SLint)list.size());
    }


    logMessage(LV_detailed, "Bone ancestor lists completed, min depth: %d\n", minDepth);
    
    logMessage(LV_detailed, "Searching ancestor lists for common ancestor.\n");
    // now we have a ancestor list for each joint node beginning with the root node
    for (SLint i = 0; i < minDepth; i++) 
    {
        SLbool failed = false;
        aiNode* lastMatch = ancestorList[0][i];
        for (SLint j = 1; j < ancestorList.size(); j++)
        {
            if (ancestorList[j][i] != lastMatch)
                failed = true;

            lastMatch = ancestorList[j][i];
        }

        // all ancestors matched
        if (!failed)
        {
            _skeletonRoot = lastMatch;
            logMessage(LV_detailed, "Found matching ancestor '%s'.\n", _skeletonRoot->mName.C_Str());
        }
        else
        {
            break;
        }
    }

    // seems like the above can be wrong, we should just select the common ancestor that is one below the assimps root
    // @todo fix this function up and make sure there exists a second element
    if (!_skeletonRoot)
    _skeletonRoot = ancestorList[0][1];

    logMessage(LV_normal, "Determined '%s' to be the skeleton's root node.\n", _skeletonRoot->mName.C_Str());
}