Changeset 13041 for OpenSceneGraph/trunk/src/osgPlugins/txp/TXPParser.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/txp/TXPParser.cpp
r11541 r13041 39 39 public: 40 40 LayerGroup() : osg::Group() {} 41 41 42 42 LayerGroup(const LayerGroup& gg,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): 43 43 osg::Group(gg, copyop) 44 44 {}; 45 45 46 46 META_Node(txp, LayerGroup); 47 47 protected: … … 100 100 101 101 _childRefCB = dynamic_cast<childRefRead *>(GetCallback(TRPG_CHILDREF)); 102 102 103 103 if (getenv("OSG_TXP_DEFAULT_MAX_ANISOTROPY")) 104 104 { 105 105 _defaultMaxAnisotropy = osg::asciiToFloat(getenv("OSG_TXP_DEFAULT_MAX_ANISOTROPY")); 106 106 } 107 107 108 108 } 109 109 … … 113 113 114 114 osg::Group *TXPParser::parseScene( 115 trpgReadBuffer &buf, 115 trpgReadBuffer &buf, 116 116 std::map<int,osg::ref_ptr<osg::StateSet> > &materials, 117 117 std::map<int,osg::ref_ptr<osg::Node> > &models, … … 159 159 160 160 //modified by Brad Anderegg May-27-08 161 //running the optimizer on the terrain fixes some major preformance issues, unfortunately the texture atlas builder seems to get messed up 161 //running the optimizer on the terrain fixes some major preformance issues, unfortunately the texture atlas builder seems to get messed up 162 162 //on some of the textures (usually around buildings) and the tri stripper seems to occasionally crash and also mess up the indices on certain buildings. 163 163 osgUtil::Optimizer opt; … … 232 232 _currentTop = _currentNode->asGroup(); 233 233 } 234 234 235 235 return true; 236 236 } … … 275 275 276 276 DeferredLightAttribute& TXPParser::getLightAttribute(int ix) 277 { 278 return _archive->getLightAttribute(ix); 277 { 278 return _archive->getLightAttribute(ix); 279 279 } 280 280 … … 343 343 hints 344 344 ); 345 345 346 346 if (lod==0) 347 347 { … … 403 403 { 404 404 osg::StateSet* osg_state_set = new osg::StateSet; 405 405 406 406 trpgLocalMaterial locmat; 407 407 tile_head->GetLocalMaterial(i,locmat); 408 408 409 409 const trpgMaterial* mat = 0; 410 410 const trpgTexture *tex = 0; … … 440 440 break; 441 441 } 442 442 443 443 osg_state_set->setTextureAttribute(texNo,osg_texenv); 444 444 445 445 image_helper.GetNthImageInfoForLocalMat(&locmat, texNo, &mat,&tex,size); 446 446 447 447 trpgTexture::ImageMode mode; 448 448 tex->GetImageMode(mode); 449 449 osg::Texture2D* osg_texture = 0L; 450 if(mode == trpgTexture::Template) 450 if(mode == trpgTexture::Template) 451 451 osg_texture = getTemplateTexture(image_helper,&locmat, tex, texNo); 452 else if(mode == trpgTexture::Local) 452 else if(mode == trpgTexture::Local) 453 453 osg_texture = getLocalTexture(image_helper,tex); 454 454 else if(mode == trpgTexture::Global) … … 472 472 osg_state_set->setTextureAttributeAndModes(texNo,osg_texture, osg::StateAttribute::ON); 473 473 474 int wrap_s, wrap_t; 474 int wrap_s, wrap_t; 475 475 texEnv.GetWrap(wrap_s, wrap_t); 476 476 osg_texture->setWrap(osg::Texture2D::WRAP_S, wrap_s == trpgTextureEnv::Repeat ? osg::Texture2D::REPEAT: osg::Texture2D::CLAMP_TO_EDGE ); 477 477 osg_texture->setWrap(osg::Texture2D::WRAP_T, wrap_t == trpgTextureEnv::Repeat ? osg::Texture2D::REPEAT: osg::Texture2D::CLAMP_TO_EDGE ); 478 478 479 479 // by default is anisotropic filtering. 480 480 osg_texture->setMaxAnisotropy(_defaultMaxAnisotropy); … … 487 487 488 488 osg::Material *osg_material = new osg::Material; 489 489 490 490 float64 alpha; 491 491 mat->GetAlpha(alpha); 492 492 493 493 trpgColor color; 494 494 mat->GetAmbient(color); 495 osg_material->setAmbient( osg::Material::FRONT_AND_BACK , 495 osg_material->setAmbient( osg::Material::FRONT_AND_BACK , 496 496 osg::Vec4(color.red, color.green, color.blue, alpha)); 497 497 mat->GetDiffuse(color); 498 osg_material->setDiffuse(osg::Material::FRONT_AND_BACK , 498 osg_material->setDiffuse(osg::Material::FRONT_AND_BACK , 499 499 osg::Vec4(color.red, color.green, color.blue, alpha)); 500 500 501 501 mat->GetSpecular(color); 502 osg_material->setSpecular(osg::Material::FRONT_AND_BACK , 502 osg_material->setSpecular(osg::Material::FRONT_AND_BACK , 503 503 osg::Vec4(color.red, color.green, color.blue, alpha)); 504 504 mat->GetEmission(color); 505 osg_material->setEmission(osg::Material::FRONT_AND_BACK , 505 osg_material->setEmission(osg::Material::FRONT_AND_BACK , 506 506 osg::Vec4(color.red, color.green, color.blue, alpha)); 507 507 508 508 float64 shinines; 509 509 mat->GetShininess(shinines); 510 510 osg_material->setShininess(osg::Material::FRONT_AND_BACK , (float)shinines); 511 511 512 512 osg_material->setAlpha(osg::Material::FRONT_AND_BACK ,(float)alpha); 513 513 osg_state_set->setAttributeAndModes(osg_material, osg::StateAttribute::ON); … … 520 520 osg_state_set->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); 521 521 } 522 523 522 523 524 524 /* This controls what alpha values in a texture mean. It can take the values: 525 525 None,Always,Equal,GreaterThanOrEqual,GreaterThan, … … 539 539 int cullMode; 540 540 mat->GetCullMode(cullMode); 541 541 542 542 // Culling mode in txp means opposite from osg i.e. Front-> show front face 543 543 if( cullMode != trpgMaterial::FrontAndBack) … … 560 560 } 561 561 562 bool TXPParser::requestModel(int ix) 563 { 564 return _archive->loadModel(ix); 562 bool TXPParser::requestModel(int ix) 563 { 564 return _archive->loadModel(ix); 565 565 } 566 566 … … 601 601 osgLod->setRange( 602 602 0, 603 _parse->checkAndGetMinRange(minRange), 603 _parse->checkAndGetMinRange(minRange), 604 604 _parse->checkAndGetMaxRange(maxRange) 605 605 ); 606 606 #endif 607 607 608 608 // Our LODs are binary so we need to add a group under this LOD and attach stuff 609 609 // to that instead of the LOD … … 651 651 (float)mat[12],(float)mat[13],(float)mat[14],(float)mat[15] 652 652 ); 653 653 654 654 // Note: Array check before you do this 655 655 osg::Node *osg_Model = NULL; … … 750 750 void* childRefRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) 751 751 { 752 752 753 753 // This object contribute nothing to the scenegraph, except 754 754 // where the children tile should connect. … … 805 805 806 806 lpNode->setMaxPixelSize(perfAttr.maxPixelSize); 807 lpNode->setMinPixelSize(perfAttr.minPixelSize); 807 lpNode->setMinPixelSize(perfAttr.minPixelSize); 808 808 809 809 trpg3dPoint norm; … … 818 818 light.GetVertex(i, pt); 819 819 820 osgSim::LightPoint lp( 821 true, 822 osg::Vec3(pt.x,pt.y,pt.z), 823 osg::Vec4(col.red, col.green,col.blue, 1.0), 820 osgSim::LightPoint lp( 821 true, 822 osg::Vec3(pt.x,pt.y,pt.z), 823 osg::Vec4(col.red, col.green,col.blue, 1.0), 824 824 inten 825 825 ); … … 834 834 ref->GetHLobeAngle(tmp); 835 835 lobeHorz = osg::DegreesToRadians( tmp ); 836 836 837 837 ref->GetVLobeAngle(tmp); 838 838 lobeVert = osg::DegreesToRadians( tmp ); 839 839 840 840 ref->GetLobeRollAngle(tmp); 841 841 lobeRoll = osg::DegreesToRadians( tmp ); … … 852 852 ref->GetHLobeAngle(tmp); 853 853 lobeHorz = osg::DegreesToRadians( tmp ); 854 854 855 855 ref->GetVLobeAngle(tmp); 856 856 lobeVert = osg::DegreesToRadians( tmp ); 857 857 858 858 ref->GetLobeRollAngle(tmp); 859 859 lobeRoll = osg::DegreesToRadians( tmp ); … … 865 865 ref->GetBackIntensity(inten); 866 866 867 osgSim::LightPoint lp2( 868 true, 869 osg::Vec3(pt.x,pt.y,pt.z), 870 osg::Vec4(col.red, col.green,col.blue, 1.0), 867 osgSim::LightPoint lp2( 868 true, 869 osg::Vec3(pt.x,pt.y,pt.z), 870 osg::Vec4(col.red, col.green,col.blue, 1.0), 871 871 inten 872 872 ); … … 889 889 #if 0 890 890 891 DefferedLightAttribute& dla = _parse->getLightAttribute(attr_index); 891 DefferedLightAttribute& dla = _parse->getLightAttribute(attr_index); 892 892 osgSim::LightPointNode* node = dla.lightPoint.get(); 893 893 … … 1001 1001 break; 1002 1002 } 1003 1003 1004 1004 } 1005 1005 if (lb.length()) os << lb; … … 1024 1024 1025 1025 const trpgLabelPropertyTable *labelPropertyTable = _parse->getArchive()->GetLabelPropertyTable(); 1026 const trpgLabelProperty *labelProperty = labelPropertyTable ? 1026 const trpgLabelProperty *labelProperty = labelPropertyTable ? 1027 1027 labelPropertyTable->GetPropertyRef(label.GetProperty()) : 0; 1028 1028 1029 1029 bool addTextGeodeIntoSceneGraph = true; 1030 1030 if (labelProperty) … … 1173 1173 } 1174 1174 } 1175 1175 1176 1176 switch (supStyle->GetType()) 1177 1177 { … … 1195 1195 linesGeom->setColorArray(colors); 1196 1196 linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 1197 1197 1198 1198 osg::Vec3Array* normals = new osg::Vec3Array; 1199 1199 normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); … … 1216 1216 { 1217 1217 const trpg3dPoint& supPt = (*supports)[i]; 1218 1218 1219 1219 osg::Vec3 supPos(supPt.x,supPt.y,supPt.z); 1220 1220 osg::Vec3 supCenter = (supPos+pos)/2.f; … … 1237 1237 1238 1238 } 1239 1239 1240 1240 _parse->getCurrTop()->addChild(supGeode.get()); 1241 1241 } … … 1245 1245 } 1246 1246 1247 1247 1248 1248 } 1249 1249 } … … 1276 1276 _im.invert(_m); 1277 1277 } 1278 1278 1279 1279 virtual ~TransformFunctor() {} 1280 1280 … … 1289 1289 } 1290 1290 } 1291 else 1291 else 1292 1292 if (type == osg::Drawable::NORMALS) 1293 1293 { … … 1324 1324 geom.GetNumVertex(numVert); 1325 1325 geom.GetNumNormal(numNorm); 1326 1326 1327 1327 // Get vertices 1328 1328 osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(numVert); 1329 1329 geom.GetVertices((float *)&(vertices->front())); 1330 1330 1331 1331 // Turn the trpgGeometry into something osg can understand 1332 1332 osg::ref_ptr<osg::Geometry> geometry; 1333 1333 1334 1334 // Get texture coordinates 1335 1335 ; … … 1343 1343 { 1344 1344 tex_coords[texno] = new osg::Vec2Array(numVert); 1345 const float* sourcePtr = &(td->floatData[0]); 1345 const float* sourcePtr = &(td->floatData[0]); 1346 1346 float* destinationPtr = (float*)&((*tex_coords[texno])[0]); 1347 1347 for (int i=0 ;i < numVert; ++i) … … 1352 1352 } 1353 1353 } 1354 1354 1355 1355 // The normals 1356 1356 osg::ref_ptr<osg::Vec3Array> normals; … … 1360 1360 geom.GetNormals((float*)&(normals->front())); 1361 1361 } 1362 1362 1363 1363 // Set up the primitive type 1364 1364 switch (primType) … … 1423 1423 break; 1424 1424 }; 1425 1426 1425 1426 1427 1427 // Add it to the current parent group 1428 1428 osg::Group *top = _parse->getCurrTop(); … … 1435 1435 1436 1436 //modifed by Brad Anderegg on May-27-08 1437 //using display lists actually increases our framerate by 1437 //using display lists actually increases our framerate by 1438 1438 //a fair amount, on certain laptops it increased by as much as 1000% 1439 1439 geometry->setUseDisplayList(true); … … 1462 1462 tmp_ss = (*_parse->getMaterials())[matId]; 1463 1463 } 1464 if(sset.valid()) 1464 if(sset.valid()) 1465 1465 { 1466 1466 if(tmp_ss.valid()) 1467 1467 { 1468 1468 osg::StateAttribute* texenv0 = tmp_ss->getTextureAttribute(0,osg::StateAttribute::TEXENV); 1469 if(texenv0) 1469 if(texenv0) 1470 1470 sset->setTextureAttribute(n_mat,texenv0); 1471 1471 osg::StateAttribute* tex0 = tmp_ss->getTextureAttribute(0,osg::StateAttribute::TEXTURE); 1472 if(tex0) 1472 if(tex0) 1473 1473 sset->setTextureAttributeAndModes(n_mat,tex0,osg::StateAttribute::ON); 1474 1474 // submitted by a. danklefsen … … 1479 1479 // sset->merge(*tmp_ss.get()); 1480 1480 } 1481 else 1481 else 1482 1482 sset = tmp_ss; 1483 1483 } … … 1501 1501 billboard->setAxis(osg::Vec3(0.0f,0.0,1.0f) ); 1502 1502 billboard->setNormal(osg::Vec3(0.0f,-1.0,0.0f)); 1503 1503 1504 1504 geometry->setUseDisplayList(true); 1505 1505 … … 1605 1605 } 1606 1606 } 1607 #endif 1608 1607 #endif 1608 1609 1609 } 1610 1610 else … … 1612 1612 OSG_WARN<<"Detected potential memory leak in TXPParser.cpp"<<std::endl; 1613 1613 } 1614 1614 1615 1615 return (void *) 1; 1616 1616 } … … 1701 1701 trpgTexture::ImageType type; 1702 1702 tex->GetImageType(type); 1703 1703 1704 1704 GLenum internalFormat = (GLenum)-1; 1705 1705 GLenum pixelFormat = (GLenum)-1; … … 1707 1707 1708 1708 check_format(type,depth,internalFormat , pixelFormat , dataType); 1709 1709 1710 1710 if(pixelFormat!=(GLenum)-1) 1711 1711 { 1712 1712 osg_texture = new osg::Texture2D(); 1713 1713 1714 // make sure the Texture unref's the Image after apply, when it is no longer needed. 1714 // make sure the Texture unref's the Image after apply, when it is no longer needed. 1715 1715 osg_texture->setUnRefImageDataAfterApply(true); 1716 1716 … … 1746 1746 osg::Image::MipmapDataType mipmaps; 1747 1747 // number of offsets in osg is one less than num_mipmaps 1748 // because it's assumed that first offset iz 0 1748 // because it's assumed that first offset iz 0 1749 1749 mipmaps.resize(num_mipmaps-1); 1750 1750 for( int k = 1 ; k < num_mipmaps;k++ ) … … 1774 1774 trpgTexture::ImageType type; 1775 1775 tex->GetImageType(type); 1776 1776 1777 1777 GLenum internalFormat = (GLenum)-1; 1778 1778 GLenum pixelFormat = (GLenum)-1; … … 1780 1780 1781 1781 check_format(type,depth,internalFormat , pixelFormat , dataType); 1782 1782 1783 1783 if(pixelFormat!=(GLenum)-1) 1784 1784 { 1785 1785 osg_texture = new osg::Texture2D(); 1786 1786 1787 // make sure the Texture unref's the Image after apply, when it is no longer needed. 1787 // make sure the Texture unref's the Image after apply, when it is no longer needed. 1788 1788 osg_texture->setUnRefImageDataAfterApply(true); 1789 1789 … … 1822 1822 osg::Image::MipmapDataType mipmaps; 1823 1823 // number of offsets in osg is one less than num_mipmaps 1824 // because it's assumed that first offset iz 0 1824 // because it's assumed that first offset iz 0 1825 1825 mipmaps.resize(num_mipmaps-1); 1826 1826 for( int k = 1 ; k < num_mipmaps;k++ )
