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); }
void VRMLWriter::writeMFInt32SeparatedByMinusValue(MFInt32& values) { out << ++indent << "[\n"; ++indent; out << indent; int n = values.size(); for(int i=0; i < n; i++){ out << values[i] << " "; if(values[i] < 0){ out << "\n"; if(i < n-1){ out << indent; } } } out << --indent << "]\n"; --indent; }
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; }
IndexedFaceSetNode::IndexedFaceSetNode() { setHeaderFlag(false); setType(INDEXEDFACESET_NODE); /////////////////////////// // Field /////////////////////////// // convex field convexField = new SFBool(true); convexField->setName(convexFieldString); addField(convexField); // creaseAngle field creaseAngleField = new SFFloat(0.0f); creaseAngleField->setName(creaseAngleFieldString); addField(creaseAngleField); // coordIndex field coordIdxField = new MFInt32(); coordIdxField->setName(coordIndexFieldString); addField(coordIdxField); // texCoordIndex field texCoordIndexField = new MFInt32(); texCoordIndexField->setName(texCoordIndexFieldString); addField(texCoordIndexField); // colorIndex field colorIndexField = new MFInt32(); colorIndexField->setName(colorIndexFieldString); addField(colorIndexField); // normalIndex field normalIndexField = new MFInt32(); normalIndexField->setName(normalIndexFieldString); addField(normalIndexField); /////////////////////////// // EventIn /////////////////////////// // coordIndex EventIn MFInt32 *setCoordIdxField = new MFInt32(); setCoordIdxField->setName(coordIndexFieldString); addEventIn(setCoordIdxField); // texCoordIndex EventIn MFInt32 *setTexCoordIndex = new MFInt32(); setTexCoordIndex->setName(texCoordIndexFieldString); addEventIn(setTexCoordIndex); // colorIndex EventIn MFInt32 *setColorIndex = new MFInt32(); setColorIndex->setName(colorIndexFieldString); addEventIn(setColorIndex); // normalIndex EventIn MFInt32 *setNormalIndex = new MFInt32(); setNormalIndex->setName(normalIndexFieldString); addEventIn(setNormalIndex); }