diff --git a/src/osgPlugins/txp/ReaderWriterTXP.cpp b/src/osgPlugins/txp/ReaderWriterTXP.cpp index a42fad360..59511e3e8 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.cpp +++ b/src/osgPlugins/txp/ReaderWriterTXP.cpp @@ -51,7 +51,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::strin { txpNode->setOptions(options->getOptionString()); } - + //modified by Brad Anderegg on May-27-08 //calling getArchive will create a new TXPArchive if the specified one does not exist @@ -119,25 +119,24 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::strin archive->GetVersion(majorVersion, minorVersion); if(majorVersion ==2 && minorVersion >=1) { - // Version 2.1 and over - // The tile table only contains lod 0 and the children - // info are stored in its parent. SO if we do not want - // to be forced to reparse the parent we need to save that - // info. For now we just add it to the node name + // Version 2.1 and over + // The tile table only contains lod 0 and the children + // info are stored in its parent. SO if we do not want + // to be forced to reparse the parent we need to save that + // info. For now we just add it to the node name - if(childrenLoc.size() > 0) - { - asChildren = true; - createChildrenLocationString(childrenLoc, childrenInfoStr); - } + if(childrenLoc.size() > 0) + { + asChildren = true; + createChildrenLocationString(childrenLoc, childrenInfoStr); + } } else { - if (lod < (numLods-1)) - asChildren = true; + if (lod < (numLods-1)) asChildren = true; } - if (asChildren) + if (asChildren) { char pagedLODfile[1024]; sprintf(pagedLODfile,"%s\\subtiles%d_%dx%d_%d", @@ -218,64 +217,64 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::strin std::vector locs; bool status = true; status = extractChildrenLocations(name, lod, locs, nbChild); - if(majorVersion >= TRPG_NOMERGE_VERSION_MAJOR && minorVersion >=TRPG_NOMERGE_VERSION_MINOR && archive->GetHeader()->GetIsMaster()) - { - for(int idx=0;idx= TRPG_NOMERGE_VERSION_MAJOR && minorVersion >=TRPG_NOMERGE_VERSION_MINOR && archive->GetHeader()->GetIsMaster()) + { + for(int idx=0;idxGetHeader(); trpgHeader::trpgTileType tileType; header->GetTileOriginType(tileType); - TXPArchive::TileLocationInfo plInfo; - plInfo.x = x; - plInfo.y = y; - plInfo.lod = lod; + TXPArchive::TileLocationInfo plInfo; + plInfo.x = x; + plInfo.y = y; + plInfo.lod = lod; TXPArchive::TileInfo parentInfo; archive->getTileInfo(plInfo,parentInfo); for(int idx = 0; idx < nbChild; ++idx) { - std::vector childrenChildLoc; - - TXPArchive::TileLocationInfo& loc = locs[idx]; - - TXPArchive::TileInfo info; - if (!archive->getTileInfo(loc,info)) - continue; + std::vector childrenChildLoc; - osg::ref_ptr tileContent = getTileContent(info, loc, archive, childrenChildLoc); + TXPArchive::TileLocationInfo& loc = locs[idx]; - tileContent->setName("TileContent"); + TXPArchive::TileInfo info; + if (!archive->getTileInfo(loc,info)) + continue; - if(childrenChildLoc.size() > 0) - { - std::string childInfoStr; - createChildrenLocationString(childrenChildLoc, childInfoStr); + osg::ref_ptr tileContent = getTileContent(info, loc, archive, childrenChildLoc); - char pagedLODfile[1024]; - sprintf(pagedLODfile,"%s\\subtiles%d_%dx%d_%d%s.txp", - archive->getDir(), - loc.lod, - loc.x, - loc.y, - archive->getId(), - childInfoStr.c_str()); + tileContent->setName("TileContent"); + + if(childrenChildLoc.size() > 0) + { + std::string childInfoStr; + createChildrenLocationString(childrenChildLoc, childInfoStr); + + char pagedLODfile[1024]; + sprintf(pagedLODfile,"%s\\subtiles%d_%dx%d_%d%s.txp", + archive->getDir(), + loc.lod, + loc.x, + loc.y, + archive->getId(), + childInfoStr.c_str()); // there are tile sets which do not maintain the z extents in // the tile table. This attempt to address the issue by using @@ -289,151 +288,151 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::strin info.radius = bSphere.radius(); } - osg::ref_ptr pagedLOD = new TXPPagedLOD; - // note: use maximum(info.maxRange,1e7) as just maxRange would result in some corner tiles from being culled out. - pagedLOD->addChild(tileContent.get(),info.minRange,osg::maximum(info.maxRange,1e7)); - pagedLOD->setFileName(1,pagedLODfile); - pagedLOD->setRange(1,0,info.minRange); - pagedLOD->setCenter(info.center); - pagedLOD->setRadius(info.radius); - pagedLOD->setPriorityOffset(0,numLods - loc.lod); - pagedLOD->setPriorityScale(0,1.0f); - pagedLOD->setNumChildrenThatCannotBeExpired(1); - pagedLOD->setTileId(loc.x, loc.y, loc.lod); + osg::ref_ptr pagedLOD = new TXPPagedLOD; + // note: use maximum(info.maxRange,1e7) as just maxRange would result in some corner tiles from being culled out. + pagedLOD->addChild(tileContent.get(),info.minRange,osg::maximum(info.maxRange,1e7)); + pagedLOD->setFileName(1,pagedLODfile); + pagedLOD->setRange(1,0,info.minRange); + pagedLOD->setCenter(info.center); + pagedLOD->setRadius(info.radius); + pagedLOD->setPriorityOffset(0,numLods - loc.lod); + pagedLOD->setPriorityScale(0,1.0f); + pagedLOD->setNumChildrenThatCannotBeExpired(1); + pagedLOD->setTileId(loc.x, loc.y, loc.lod); - if(tileType == trpgHeader::TileLocal) - { - osg::Vec3d center(info.center - parentInfo.bbox._min); - osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min); - sw[2] = 0.0; - pagedLOD->setCenter(center - sw); - osg::Matrix offset; - offset.setTrans(sw); - osg::MatrixTransform *tform = new osg::MatrixTransform(offset); - tform->addChild(pagedLOD.get()); - subtiles->addChild(tform); - } - else - subtiles->addChild(pagedLOD.get()); - subtiles->setUserData(new TileIdentifier(loc.x, loc.y, loc.lod)); // is this really needed? - } - else - { - subtiles->setUserData(new TileIdentifier(loc.x, loc.y, loc.lod)); - if(tileType == trpgHeader::TileLocal) - { - osg::Vec3d center(info.center - parentInfo.bbox._min); - osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min); - sw[2] = 0.0; - osg::Matrix offset; - offset.setTrans(sw); - osg::MatrixTransform *tform = new osg::MatrixTransform(offset); - tform->addChild(tileContent.get()); - subtiles->addChild(tform); - } - else - subtiles->addChild(tileContent.get()); - } + if(tileType == trpgHeader::TileLocal) + { + osg::Vec3d center(info.center - parentInfo.bbox._min); + osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min); + sw[2] = 0.0; + pagedLOD->setCenter(center - sw); + osg::Matrix offset; + offset.setTrans(sw); + osg::MatrixTransform *tform = new osg::MatrixTransform(offset); + tform->addChild(pagedLOD.get()); + subtiles->addChild(tform); + } + else + subtiles->addChild(pagedLOD.get()); + subtiles->setUserData(new TileIdentifier(loc.x, loc.y, loc.lod)); // is this really needed? + } + else + { + subtiles->setUserData(new TileIdentifier(loc.x, loc.y, loc.lod)); + if(tileType == trpgHeader::TileLocal) + { + osg::Vec3d center(info.center - parentInfo.bbox._min); + osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min); + sw[2] = 0.0; + osg::Matrix offset; + offset.setTrans(sw); + osg::MatrixTransform *tform = new osg::MatrixTransform(offset); + tform->addChild(tileContent.get()); + subtiles->addChild(tform); + } + else + subtiles->addChild(tileContent.get()); + } } } else { - - int sizeX, sizeY; - archive->getLODSize(lod+1,sizeX,sizeY); - const trpgHeader* header = archive->GetHeader(); - trpgHeader::trpgTileType tileType; - header->GetTileOriginType(tileType); + int sizeX, sizeY; + archive->getLODSize(lod+1,sizeX,sizeY); - TXPArchive::TileInfo parentInfo; - archive->getTileInfo(x,y,lod,parentInfo); + const trpgHeader* header = archive->GetHeader(); + trpgHeader::trpgTileType tileType; + header->GetTileOriginType(tileType); - for (int ix = 0; ix < 2; ix++) - { - for (int iy = 0; iy < 2; iy++) - { - int tileX = x*2+ix; - int tileY = y*2+iy; - int tileLOD = lod+1; + TXPArchive::TileInfo parentInfo; + archive->getTileInfo(x,y,lod,parentInfo); - TXPArchive::TileInfo info; - if (!archive->getTileInfo(tileX,tileY,tileLOD,info)) - continue; - - osg::ref_ptr tileContent = getTileContent(info,tileX,tileY,tileLOD,archive, childrenLoc); - - tileContent->setName("TileContent"); - - if (tileLOD < (numLods-1)) + for (int ix = 0; ix < 2; ix++) { - char pagedLODfile[1024]; - sprintf(pagedLODfile,"%s\\subtiles%d_%dx%d_%d.txp", - archive->getDir(), - tileLOD, - tileX, - tileY, - archive->getId()); + for (int iy = 0; iy < 2; iy++) + { + int tileX = x*2+ix; + int tileY = y*2+iy; + int tileLOD = lod+1; - // there are tile sets which do not maintain the z extents in - // the tile table. This attempt to address the issue by using - // the geometry bounding sphere. The downside is that this is - // not coupled to the generation and may result in runtime cracks - if (info.center.z() == 0) - { - osg::BoundingSphere bSphere = tileContent->getBound(); + TXPArchive::TileInfo info; + if (!archive->getTileInfo(tileX,tileY,tileLOD,info)) + continue; - info.center.z() = bSphere.center().z(); - info.radius = bSphere.radius(); - } + osg::ref_ptr tileContent = getTileContent(info,tileX,tileY,tileLOD,archive, childrenLoc); - osg::ref_ptr pagedLOD = new TXPPagedLOD; - // note: use maximum(info.maxRange,1e7) as just maxRange would result in some corner tiles from being culled out. - pagedLOD->addChild(tileContent.get(),info.minRange,osg::maximum(info.maxRange,1e7)); - pagedLOD->setFileName(1,pagedLODfile); - pagedLOD->setRange(1,0,info.minRange); - pagedLOD->setCenter(info.center); - pagedLOD->setRadius(info.radius); - pagedLOD->setPriorityOffset(0,numLods-lod); - pagedLOD->setPriorityScale(0,1.0f); - pagedLOD->setNumChildrenThatCannotBeExpired(1); - pagedLOD->setTileId(tileX,tileY,tileLOD); + tileContent->setName("TileContent"); - if(tileType == trpgHeader::TileLocal) - { - osg::Vec3d center(info.center - parentInfo.bbox._min); - osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min); - sw[2] = 0.0; - pagedLOD->setCenter(center - sw); - osg::Matrix offset; - offset.setTrans(sw); - osg::MatrixTransform *tform = new osg::MatrixTransform(offset); - tform->addChild(pagedLOD.get()); - subtiles->addChild(tform); - } - else - subtiles->addChild(pagedLOD.get()); - } - else - { - subtiles->setUserData(new TileIdentifier(tileX,tileY,tileLOD)); - if(tileType == trpgHeader::TileLocal) - { - osg::Vec3d center(info.center - parentInfo.bbox._min); - osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min); - sw[2] = 0.0; - osg::Matrix offset; - offset.setTrans(sw); - osg::MatrixTransform *tform = new osg::MatrixTransform(offset); - tform->addChild(tileContent.get()); - subtiles->addChild(tform); - } - else - subtiles->addChild(tileContent.get()); - } + if (tileLOD < (numLods-1)) + { + char pagedLODfile[1024]; + sprintf(pagedLODfile,"%s\\subtiles%d_%dx%d_%d.txp", + archive->getDir(), + tileLOD, + tileX, + tileY, + archive->getId()); - } - } + // there are tile sets which do not maintain the z extents in + // the tile table. This attempt to address the issue by using + // the geometry bounding sphere. The downside is that this is + // not coupled to the generation and may result in runtime cracks + if (info.center.z() == 0) + { + osg::BoundingSphere bSphere = tileContent->getBound(); + + info.center.z() = bSphere.center().z(); + info.radius = bSphere.radius(); + } + + osg::ref_ptr pagedLOD = new TXPPagedLOD; + // note: use maximum(info.maxRange,1e7) as just maxRange would result in some corner tiles from being culled out. + pagedLOD->addChild(tileContent.get(),info.minRange,osg::maximum(info.maxRange,1e7)); + pagedLOD->setFileName(1,pagedLODfile); + pagedLOD->setRange(1,0,info.minRange); + pagedLOD->setCenter(info.center); + pagedLOD->setRadius(info.radius); + pagedLOD->setPriorityOffset(0,numLods-lod); + pagedLOD->setPriorityScale(0,1.0f); + pagedLOD->setNumChildrenThatCannotBeExpired(1); + pagedLOD->setTileId(tileX,tileY,tileLOD); + + if(tileType == trpgHeader::TileLocal) + { + osg::Vec3d center(info.center - parentInfo.bbox._min); + osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min); + sw[2] = 0.0; + pagedLOD->setCenter(center - sw); + osg::Matrix offset; + offset.setTrans(sw); + osg::MatrixTransform *tform = new osg::MatrixTransform(offset); + tform->addChild(pagedLOD.get()); + subtiles->addChild(tform); + } + else + subtiles->addChild(pagedLOD.get()); + } + else + { + subtiles->setUserData(new TileIdentifier(tileX,tileY,tileLOD)); + if(tileType == trpgHeader::TileLocal) + { + osg::Vec3d center(info.center - parentInfo.bbox._min); + osg::Vec3d sw(info.bbox._min - parentInfo.bbox._min); + sw[2] = 0.0; + osg::Matrix offset; + offset.setTrans(sw); + osg::MatrixTransform *tform = new osg::MatrixTransform(offset); + tform->addChild(tileContent.get()); + subtiles->addChild(tform); + } + else + subtiles->addChild(tileContent.get()); + } + + } + } } //osg::notify(osg::NOTICE) << "Subtiles for " << x << " " << y << " " << lod << " lodaded" << std::endl;