Ejemplo n.º 1
0
void X3DFIAttributes::getSFImage(int index, SFImage& value) const {
  MFInt32 signedVector;
  SFImage result;
	getIntArray(getValueAt(index), signedVector);
  for(MFInt32::const_iterator I = signedVector.begin(); I != signedVector.end(); I++)
  {
    result.push_back(static_cast<unsigned int>(*I));
  }
  std::swap(result, value);
} 
Ejemplo n.º 2
0
int X3DXIOTNodeHandler::startIndexedFaceSet(const X3DAttributes &attr)
{
	std::cout << "Start IndexedFaceSet" << std::endl;

	ccMesh* mesh = new ccMesh(0);
	unsigned realFaceNumber=0;

	if (attr.isDEF())
		mesh->setName(attr.getDEF().c_str());

	//Vertices indexes
	int vertIndex = attr.getAttributeIndex(ID::coordIndex);
	if (vertIndex != -1)
	{
		MFInt32 streamIndexes;
		attr.getMFInt32(vertIndex,streamIndexes);

		int triIndexes[3];
		int pos=0;
		for (MFInt32::const_iterator it = streamIndexes.begin(); it != streamIndexes.end(); ++it)
		{
			if (*it == -1) //end of polygon
			{
				if (pos<3)
				{
					//incomplete dataset?
					//TODO: warn user
				}
				pos = 0;
				++realFaceNumber;
			}
			else //new vertex index
			{
				if (pos<3)
				{
					triIndexes[pos]=*it;
				}
				else
				{
					//FIXME: simplistic fan triangulation (hum, hum)
					triIndexes[1]=triIndexes[2];
					triIndexes[2]=*it;
				}
				++pos;
			}

			//new face
			if (pos==3)
			{
				//we check that we are at the end of the polygon (we don't handle non triangular meshes yet!)
				if (it+1 == streamIndexes.end() || *(it+1)==-1)
				{
					//we must reserve some more space for storage!
					if (mesh->size() == mesh->maxSize())
					{
						if (!mesh->reserve(mesh->maxSize() + 100))
						{
							delete mesh;
							return ABORT; //not enough memory!
						}
					}
					mesh->addTriangle(triIndexes[0],triIndexes[1],triIndexes[2]);
				}
				else
				{
					//TODO: we don't handle non triangle faces yet!
				}
			}
		}

		if (mesh->size() < mesh->maxSize())
		{
			//unhandled type of mesh
			if (mesh->size()==0)
			{
				delete mesh;
				return SKIP_CHILDREN;
			}
			mesh->resize(mesh->size());
		}
	}

	//Normals (per face)
	int normIndex = attr.getAttributeIndex(ID::normalIndex);
	if (normIndex != -1)
	{
		//per-triangle normals!
		if (mesh->size() == realFaceNumber)
		{
			if (mesh->reservePerTriangleNormalIndexes())
			{
				MFInt32 perFaceNormIndexes;
				attr.getMFInt32(normIndex,perFaceNormIndexes);
				for (unsigned i=0;i<perFaceNormIndexes.size();++i)
					mesh->addTriangleNormalIndexes(i,i,i);

				mesh->showTriNorms(true);
			}
			else
			{
				//TODO: not enough memory!
			}
		}
		else
		{
			//TODO: we can't load per-face normals with non-triangular meshes yet!
		}
	}

	//Normals (per vertex)
//	normIndex = attr.getAttributeIndex(ID::normalPerVertex);
//	bool perVertexNormals=(normIndex != -1 ? attr.getSFBool(normIndex) : true);
	//DGM: in fact we don't care

	assert(m_currentLeaf);
	mesh->setVisible(true);
	m_currentLeaf->addChild(mesh);
	m_currentLeaf = mesh;

	return CONTINUE;
}