Esempio n. 1
0
    void CollectAllNodes (csHash<csRef<BodyChainNode>, CS::Animation::BoneID>& nodeHash,
                          BodyChainNode* rootNode)
    {
        nodeHash.Put (rootNode->GetAnimeshBone (), rootNode);

        for (size_t i = 0; i < rootNode->GetChildCount (); i++)
            CollectAllNodes (nodeHash, (BodyChainNode*) rootNode->GetChild (i));
    }
Esempio n. 2
0
bool celHNavStructBuilder::ParseMeshes (iDocumentNode* node, csHash<csRef<iSector>, const char*>& sectors, 
                                        celHNavStruct* navStruct, iVFS* vfs, iCelNavMeshParams* params)
{
  csRef<iEngine> engine = csLoadPluginCheck<iEngine>(objectRegistry, "crystalspace.engine.3d");
  if (!engine)
  {
    return false;
  }

  csRef<iDocumentNodeIterator> it = node->GetNodes("navmesh");
  while (it->HasNext())
  {
    csRef<iDocumentNode> navMeshNode = it->Next();

    // Get sector
    const char* sectorName = navMeshNode->GetAttributeValue("sector");
    csString sectorNameString(sectorName);
    if(!sectors.In(sectorName))
    {
      iSector* sector = engine->FindSector(sectorName);
      if(sector)
      {
          sectors.Put(sectorName, sector);
      }
      else
      {
          csString msg;
          msg.Format("invalid sector %s in navmesh\n", sectorName);
          CS_ASSERT_MSG(msg.GetData(),false);
      }
    }

    // Get navmesh
    int id = navMeshNode->GetAttributeValueAsInt("id");
    csString fileName;
    fileName = id;
    csRef<iFile> file = vfs->Open(fileName.GetDataSafe(), VFS_FILE_READ);
    csRef<iCelNavMeshBuilder> builder = csLoadPluginCheck<iCelNavMeshBuilder>(objectRegistry, "cel.navmeshbuilder");
    csRef<iCelNavMesh> navMesh = builder->LoadNavMesh(file);
    navStruct->AddNavMesh(navMesh);
  }
  return true;
}
Esempio n. 3
0
bool celHNavStructBuilder::ParseGraph (iDocumentNode* node, iCelGraph* graph, csHash<csRef<iSector>, const char*> sectors)
{
  csRef<iDocumentNode> nodesNode = node->GetNode("nodes");
  csRef<iDocumentNodeIterator> it = nodesNode->GetNodes("node");
  size_t nodeCount = it->GetEndPosition();
  csArray<csRef<iCelNode> > celNodes(nodeCount);
  celNodes.SetSize(nodeCount);
  while (it->HasNext())
  {
    csRef<iDocumentNode> graphNode = it->Next();
    size_t id = graphNode->GetAttributeValueAsInt("id");

    // Get sector
    const char* sectorName = graphNode->GetAttributeValue("sector");
    csRef<iSector> sector = sectors.Get(sectorName, 0);
    if(!sector.IsValid())
    {
        csString msg;
        msg.Format("invalid sector %s in navmesh graph node\n", sectorName);
        CS_ASSERT_MSG(msg.GetData(),false);
    }

    // Get position
    csVector3 position;
    float x = graphNode->GetAttributeValueAsFloat("x");
    float y = graphNode->GetAttributeValueAsFloat("y");
    float z = graphNode->GetAttributeValueAsFloat("z");
    position.Set(x, y, z);
    
    // Crete node
    csRef<iCelNode> node = graph->CreateEmptyNode(id);
    celNodes[id] = node;
    csRef<iMapNode> mapNode;
    mapNode.AttachNew(new csMapNode("n"));
    mapNode->SetPosition(position);
    mapNode->SetSector(sector);
    node->SetMapNode(mapNode);
  }

  csRef<iDocumentNode> edgesNode = node->GetNode("edges");
  it = edgesNode->GetNodes("edge");
  while (it->HasNext())
  {
    csRef<iDocumentNode> graphEdge = it->Next();
    int from = graphEdge->GetAttributeValueAsInt("from");
    int to = graphEdge->GetAttributeValueAsInt("to");
    float weight = graphEdge->GetAttributeValueAsFloat("weight");
    celNodes[from]->AddSuccessor(celNodes[to], true, weight);
  }

  return true;
}
Esempio n. 4
0
void csStencilShadowCacheEntry::HandleEdge (EdgeInfo *e,
	csHash<EdgeInfo*>& edge_stack)
{
  double mplier = PI * 1e6;
  uint32 hash;
  hash = (uint32)(mplier * e->a.x + mplier * e->a.y + mplier * e->a.z);
  hash += (uint32)(mplier * e->b.x + mplier * e->b.y + mplier * e->b.z);

  csHash<EdgeInfo*>::Iterator it = edge_stack.GetIterator (hash);
  bool found = false;
  while (it.HasNext ()) 
  {
    EdgeInfo *t = it.Next ();
    if (e->a == t->b && e->b == t->a) 
    {
      found = true;
      edge_indices[edge_count*3 + 0] = e->ind_a;
      edge_indices[edge_count*3 + 1] = t->ind_b;
      edge_indices[edge_count*3 + 2] = t->ind_a;
      // edge_normals[edge_count] = t->norm;
      edge_midpoints[edge_count] = (t->a + t->b) / 2;
      edge_count ++;

      edge_indices[edge_count*3 + 0] = t->ind_a;
      edge_indices[edge_count*3 + 1] = e->ind_b;
      edge_indices[edge_count*3 + 2] = e->ind_a;
      // edge_normals[edge_count] = e->norm;
      edge_midpoints[edge_count] = (e->a + e->b) / 2;
      edge_count ++;
		    
      edge_stack.Delete (hash, t);
      break;
    }
  }
  if (!found) 
  { 
    edge_stack.Put (hash, e); 
  }
}
Esempio n. 5
0
bool csDriverDBReader::ParseConfigs (iDocumentNode* node)
{
  csRef<iDocumentNodeIterator> it (node->GetNodes ());
  while (it->HasNext())
  {
    csRef<iDocumentNode> child = it->Next();
    if (child->GetType() != CS_NODE_ELEMENT) continue;
    csStringID token = tokens.Request (child->GetValue ());

    switch (token)
    {
      case XMLTOKEN_CONFIG:
	{
	  const char* name = child->GetAttributeValue ("name");
	  if (!name)
	  {
	    db->Report (
	      CS_REPORTER_SEVERITY_WARNING,
	      child,
	      "<config> has no name");
	    return false;
	  }
	  csRef<csConfigDocument> cfg (configs.Get (name, 
	    (csConfigDocument*)0));
	  if (!cfg.IsValid ())
	  {
	    cfg.AttachNew (new csConfigDocument ());
	    configs.Put (name, cfg);
	  }
	  cfg->LoadNode (child, true, true);
	}
	break;
      default:
	db->ReportBadToken (child);
	return false;
    }
  }
  return true;
}
Esempio n. 6
0
bool csDriverDBReader::Apply (iDocumentNode* node)
{
  csRef<iDocumentNodeIterator> it (node->GetNodes ());
  while (it->HasNext())
  {
    csRef<iDocumentNode> child = it->Next();
    if (child->GetType() != CS_NODE_ELEMENT) continue;
    csStringID token = tokens.Request (child->GetValue ());

    switch (token)
    {
      case XMLTOKEN_USECFG:
	{
	  const char* cfgname = child->GetContentsValue ();
	  csRef<csConfigDocument> cfg (configs.Get (cfgname, 
	    (csConfigDocument*)0));
	  if (!cfg.IsValid ())
	  {
	    db->Report (
	      CS_REPORTER_SEVERITY_WARNING,
	      child,
	      "unknown config %s", cfgname);
	  }
	  else
	  {
	    cfgmgr->AddDomain (cfg, usedCfgPrio);
	    db->addedConfigs.Push (cfg);
	  }
	}
	break;
      default:
	db->ReportBadToken (child);
	return false;
    }
  }
  return true;
}