/*! Reads fields from the stream until an end marker (either a field name of "" or one in \a endMarkers) is encountered, skipping fields in \a excludeFields. This makes use of readFieldHeader and readFieldContent and also demonstates how these two functions can be used. \param[in] excludeFields Field names that should be skipped in the stream. \param[in] endMarkers Fields names (in additon to "") that will cause reading to stop. \return The last field name that was read, this can be "", if the end of the fields was reached. */ std::string OSBCommonElement::readFields(const std::string &excludeFields, const std::string &endMarkers ) { // BinaryReadHandler *rh = editRoot()->getReadHandler(); std::string fieldName = ""; PtrFieldListIt ptrFieldIt; while(true) { std::string fieldTypeName; UInt32 fieldSize; if(!readFieldHeader(endMarkers, fieldName, fieldTypeName, fieldSize)) { OSG_OSB_LOG(("OSBCommonElement::readFields: " "Reading stopped at field: [%s].\n", fieldName.c_str() )); break; } readFieldContent(fieldName, fieldTypeName, fieldSize, excludeFields, ptrFieldIt ); } return fieldName; }
void OSBShaderParameterMIntElement::read(const std::string &typeName) { OSG_OSB_LOG(("OSBShaderParameterMIntElement::read: [%s]\n", typeName.c_str())); BinaryReadHandler *rh = editRoot()->getReadHandler(); UInt8 ptrTypeId; UInt16 version; rh->getValue(ptrTypeId); rh->getValue(version ); OSG_OSB_LOG(("OSBShaderParameterMIntElement::read: version: [%u]\n", version)); std::string fieldName; std::string fieldTypeName; UInt32 fieldSize; PtrFieldListIt ptrFieldIt; while(readFieldHeader("", fieldName, fieldTypeName, fieldSize)) { if(fieldName == "name") { _name.copyFromBin(*rh); } else if(fieldName == "value") { _value.copyFromBin(*rh); } else { OSG_OSB_LOG(("Skipping [%d] bytes for field [%s]\n", fieldSize, fieldName.c_str())); rh->skip(fieldSize); } } // no container is created for this element, which means the root does // not automatically insert it into the IdElemMap - do it manually editRoot()->editIdElemMap().insert( OSBRootElement::IdElemMap::value_type(getFCIdFile(), this)); }
void OSBChunkBlockElement::read(const std::string &typeName) { OSG_OSB_LOG(("OSBChunkBlockElement::read [%s]\n", typeName.c_str())); BinaryReadHandler *rh = editRoot()->getReadHandler(); UInt8 ptrTypeId; UInt16 version; rh->getValue(ptrTypeId); rh->getValue(version ); OSG_OSB_LOG(("OSBChunkBlockElement::read: version: [%u]\n", version)); std::string fieldName; std::string fieldTypeName; UInt32 fieldSize; PtrFieldListIt ptrFieldIt; ChunkBlockUnrecPtr pMat = dynamic_pointer_cast<ChunkBlock>( FieldContainerFactory::the()->createContainer(typeName.c_str())); setContainer(pMat); while(readFieldHeader("", fieldName, fieldTypeName, fieldSize)) { if(fieldName == "chunks") { // keep an interator to the _mfChunks field contents readFieldContent(fieldName, fieldTypeName, fieldSize, "", _chunksPtrFieldIt); _chunksPtrFieldItValid = true; } else { readFieldContent(fieldName, fieldTypeName, fieldSize, "", ptrFieldIt); } } }
/*! Reads fields from the stream until an end marker (either a field name of "" or one in \a endMarkers) is encountered, skipping fields in \a excludeFields. This function is intended to be used when the next fields name was already consumed from the input stream, e.g. when readFields stopped on a non empty endMarkers entry. This makes use of readFieldHeader and readFieldContent and also demonstates how these two functions can be used. \param[in] fieldName Name of the next field in the stream. \param[in] excludeFields Field names that should be skipped in the stream. \param[in] endMarkers Fields names (in additon to "") that will cause reading to stop. \return The last field name that was read, this can be "", if the end of the fields was reached. */ std::string OSBCommonElement::readFieldsContinue(const std::string &fieldName, const std::string &excludeFields, const std::string &endMarkers ) { // BinaryReadHandler *rh = editRoot()->getReadHandler(); PtrFieldListIt ptrFieldIt; std::string fieldName2; std::string fieldTypeName; UInt32 fieldSize; // Read the first field specially - its name was already consumed if(!readFieldHeaderContinue(endMarkers, fieldName, fieldTypeName, fieldSize)) { OSG_OSB_LOG(("OSBCommonElement::readFieldsContinue: " "Reading stopped at field: [%s].\n", fieldName.c_str() )); return fieldName; } readFieldContent(fieldName, fieldTypeName, fieldSize, excludeFields, ptrFieldIt ); // continue reading normally while(true) { if(!readFieldHeader(endMarkers, fieldName2, fieldTypeName, fieldSize)) { OSG_OSB_LOG(("OSBCommonElement::readFieldsContinue: " "Reading stopped at field: [%s].\n", fieldName2.c_str() )); break; } readFieldContent(fieldName2, fieldTypeName, fieldSize, excludeFields, ptrFieldIt ); } return fieldName; }
USE_NAMESPACE VObject* VConverter::parse(const WCHAR* buffer) { if(!buffer) { return NULL; } WCHAR *objType = extractObjectType(buffer); WCHAR *objVersion = extractObjectVersion(buffer); if(!objType) return NULL; VObject* vo = VObjectFactory::createInstance(objType, objVersion); VProperty *prop; // Unfolding WCHAR* buffCopy = unfolding(buffer); while ( true ) { prop = readFieldHeader(buffCopy); if (!prop) { break; } if ( readFieldBody(buffCopy, prop )) { vo->addProperty(prop); } delete prop; } if(objType) { delete [] objType; objType = NULL; } if(objVersion) { delete [] objVersion; objVersion = NULL; } if (buffCopy) { delete [] buffCopy; buffCopy = NULL; } return vo; }
void OSBTextureChunkElement::read(const std::string &typeName) { OSG_OSB_LOG(("OSBTextureChunkElement::read: [%s]\n", typeName.c_str())); BinaryReadHandler *rh = editRoot()->getReadHandler(); UInt8 ptrTypeId; UInt16 version; rh->getValue(ptrTypeId); rh->getValue(version ); OSG_OSB_LOG(("OSBTextureChunkElement::read: version: [%u]\n", version)); // create the two replacement chunks _pTexObj = TextureObjChunk::create(); _pTexEnv = TextureEnvChunk::create(); std::string fieldName; std::string fieldTypeName; UInt32 fieldSize; PtrFieldListIt ptrFieldIt; while(readFieldHeader("", fieldName, fieldTypeName, fieldSize)) { // some fields need to be duplicated for the two replacement chunks if(fieldName == "parents") { // parent fields are ignored rh->skip(fieldSize); } else if(fieldName == "internal") { bool fieldValue; rh->getValue(fieldValue); _pTexObj->setInternal(fieldValue); _pTexEnv->setInternal(fieldValue); } else if(fieldName == "ignore") { bool fieldValue; rh->getValue(fieldValue); _pTexObj->setIgnore(fieldValue); _pTexEnv->setIgnore(fieldValue); } else if(isTexObjField(fieldName)) { // set TexObj as container for reading the field setContainer(_pTexObj); readFieldContent(fieldName, fieldTypeName, fieldSize, "", ptrFieldIt); } else if(isTexEnvField(fieldName)) { // set TexEnv as container for reading the field setContainer(_pTexEnv); readFieldContent(fieldName, fieldTypeName, fieldSize, "", ptrFieldIt); } else { FWARNING(("OSBTextureChunkElement::read: Skipping unrecognized " "field [%s].\n", fieldName.c_str())); rh->skip(fieldSize); } } // set TexObj as "the" container setContainer(_pTexObj); }
void OSBGeometryElement::readV100(void) { OSG_OSB_LOG(("OSBGeometryElement::readV100:\n")); OSBRootElement *root = editRoot(); BinaryReadHandler *rh = editRoot()->getReadHandler(); OSBGeometryHelper gh; GeometryUnrecPtr geo = Geometry::create(); setContainer(geo); // The "properties" mfield can be thought of the unification of the // "positions", "normals", etc sfields of the 1.x Geometry. // For the conversion the PtrFieldInfo structure for the "properties" // mfield is filled with the corresponding ids of the sfields from the // file. The remapping after postRead will fill in the right pointers. FieldDescriptionBase *propFieldDesc = geo->getFieldDescription("properties"); UInt32 propFieldId = propFieldDesc->getFieldId(); root->editPtrFieldList().push_back(PtrFieldInfo(geo, propFieldId)); PtrFieldInfo &propFieldPFI = root->editPtrFieldList().back(); propFieldPFI.editIdStore().resize(Geometry::MaxAttribs); while(true) { std::string fieldName; std::string fieldTypeName; UInt32 fieldSize; PtrFieldListIt ptrFieldIt; if(!readFieldHeader("", fieldName, fieldTypeName, fieldSize)) { OSG_OSB_LOG(("OSBGeometryElement::readV100: " "Reading stopped at field: [%s].\n", fieldName.c_str())); break; } if(fieldName == "indexMapping") { // read into temporary field MField<UInt16> indexMappingField; indexMappingField.copyFromBin(*rh); // copy to member for use in postRead indexMappingField.getValues().swap(_indexMapping); } else if(fieldName == "indices") { // read container id of indices property // postRead will handle the conversion of multi indices rh->getValue(_indicesId); } else if(fieldName == "positions") { UInt32 positionsId; rh->getValue(positionsId); propFieldPFI.editIdStore()[Geometry::PositionsIndex] = positionsId; } else if(fieldName == "normals") { UInt32 normalsId; rh->getValue(normalsId); propFieldPFI.editIdStore()[Geometry::NormalsIndex] = normalsId; } else if(fieldName == "colors") { UInt32 colorsId; rh->getValue(colorsId); propFieldPFI.editIdStore()[Geometry::ColorsIndex] = colorsId; } else if(fieldName == "secondaryColors") { UInt32 secondaryColorsId; rh->getValue(secondaryColorsId); propFieldPFI.editIdStore()[Geometry::SecondaryColorsIndex] = secondaryColorsId; } else if(fieldName == "texCoords") { UInt32 texCoordsId; rh->getValue(texCoordsId); propFieldPFI.editIdStore()[Geometry::TexCoordsIndex] = texCoordsId; } else if(fieldName == "texCoords1") { UInt32 texCoordsId1; rh->getValue(texCoordsId1); propFieldPFI.editIdStore()[Geometry::TexCoords1Index] = texCoordsId1; } else if(fieldName == "texCoords2") { UInt32 texCoordsId2; rh->getValue(texCoordsId2); propFieldPFI.editIdStore()[Geometry::TexCoords2Index] = texCoordsId2; } else if(fieldName == "texCoords3") { UInt32 texCoordsId3; rh->getValue(texCoordsId3); propFieldPFI.editIdStore()[Geometry::TexCoords3Index] = texCoordsId3; } else if(fieldName == "texCoords4") { UInt32 texCoordsId4; rh->getValue(texCoordsId4); propFieldPFI.editIdStore()[Geometry::TexCoords4Index] = texCoordsId4; } else if(fieldName == "texCoords5") { UInt32 texCoordsId5; rh->getValue(texCoordsId5); propFieldPFI.editIdStore()[Geometry::TexCoords5Index] = texCoordsId5; } else if(fieldName == "texCoords6") { UInt32 texCoordsId6; rh->getValue(texCoordsId6); propFieldPFI.editIdStore()[Geometry::TexCoords6Index] = texCoordsId6; } else if(fieldName == "texCoords7") { UInt32 texCoordsId7; rh->getValue(texCoordsId7); propFieldPFI.editIdStore()[Geometry::TexCoords7Index] = texCoordsId7; } else if(fieldName == "pindices") { UInt32 maxValue; UInt32 propSize; UInt32 byteSize; _indicesPacked = true; gh.readPackedIntegralPropertyHeader(rh, maxValue, propSize, byteSize); if(root->getOptions().unpack16BitIndices()) { if(maxValue > TypeTraits<UInt16>::getMax()) { GeoUInt32PropertyUnrecPtr ui32Indices = GeoUInt32Property::create(); gh.readPackedIntegralProperty(rh, ui32Indices, maxValue, propSize, byteSize ); _indices16Bit = false; _indices = ui32Indices; } else { GeoUInt16PropertyUnrecPtr ui16Indices = GeoUInt16Property::create(); gh.readPackedIntegralProperty(rh, ui16Indices, maxValue, propSize, byteSize ); _indices16Bit = true; _indices = ui16Indices; } } else { GeoUInt32PropertyUnrecPtr ui32Indices = GeoUInt32Property::create(); gh.readPackedIntegralProperty(rh, ui32Indices, maxValue, propSize, byteSize ); _indices16Bit = false; _indices = ui32Indices; } } else if(fieldName == "qpositions") { // Quantized positions are stored inside the geometry object, not // in the geo-property. They are always of type Pnt3f. GeoPnt3fPropertyUnrecPtr propPos = GeoPnt3fProperty::create(); UInt8 resolution; Real32 minValue; Real32 maxValue; UInt32 propSize; gh.readQuantizedVectorPropertyHeader(rh, resolution, minValue, maxValue, propSize ); gh.readQuantizedVectorProperty(rh, propPos, fieldSize, resolution, minValue, maxValue, propSize ); geo->setProperty(propPos, Geometry::PositionsIndex); } else if(fieldName == "qnormals") { // Quantized normals are stored inside the geometry object, not // in the geo-property. They are always of type Vec3f. GeoVec3fPropertyUnrecPtr propNorm = GeoVec3fProperty::create(); UInt8 resolution; Real32 minValue; Real32 maxValue; UInt32 propSize; gh.readQuantizedVectorPropertyHeader( rh, resolution, minValue, maxValue, propSize); gh.readQuantizedVectorProperty( rh, propNorm, fieldSize, resolution, minValue, maxValue, propSize ); geo->setProperty(propNorm, Geometry::NormalsIndex); } else if(fieldName == "qtexCoords") { // Quantized texCoords are stored inside the geometry object, not // in the geo-property. They are always of type Vec2f. GeoVec2fPropertyUnrecPtr propTexCoords = GeoVec2fProperty::create(); UInt8 resolution; Real32 minValue; Real32 maxValue; UInt32 propSize; gh.readQuantizedVectorPropertyHeader( rh, resolution, minValue, maxValue, propSize); gh.readQuantizedVectorProperty( rh, propTexCoords, fieldSize, resolution, minValue, maxValue, propSize ); geo->setProperty(propTexCoords, Geometry::NormalsIndex); } else { // 1.x Geometry has _sfVbo, it can be skipped readFieldContent(fieldName, fieldTypeName, fieldSize, "'vbo'", ptrFieldIt ); } } }