1 #include <osg/TexMat> 2 3 #include <osgDB/Registry> 4 #include <osgDB/Input> 5 #include <osgDB/Output> 6 7 using namespace osg; 8 using namespace osgDB; 9 10 // forward declare functions to use later. 11 bool TexMat_readLocalData(Object& obj, Input& fr); 12 bool TexMat_writeLocalData(const Object& obj, Output& fw); 13 14 // register the read and write functions with the osgDB::Registry. 15 REGISTER_DOTOSGWRAPPER(TexMat) 16 ( 17 new osg::TexMat, 18 "TexMat", 19 "Object StateAttribute TexMat", 20 &TexMat_readLocalData, 21 &TexMat_writeLocalData 22 ); 23 TexGenNode_readLocalData(Object & obj,Input & fr)24 25 bool TexMat_readLocalData(Object& obj, Input& fr) 26 { 27 bool iteratorAdvanced = false; 28 29 TexMat& texmat = static_cast<TexMat&>(obj); 30 31 bool matched = true; 32 for(int k=0;k<16 && matched;++k) 33 { 34 matched = fr[k].isFloat(); 35 } 36 if (matched) 37 { 38 39 Matrix& matrix = texmat.getMatrix(); 40 41 int k=0; 42 double v; 43 for(int i=0;i<4;++i) 44 { 45 for(int j=0;j<4;++j) 46 { 47 fr[k].getFloat(v); 48 matrix(i,j)=v; 49 k++; 50 } 51 } 52 fr += 16; 53 iteratorAdvanced = true; 54 } 55 56 if (fr[0].matchWord("scaleByTextureRectangleSize")) 57 { 58 if (fr[1].matchWord("TRUE")) 59 { 60 texmat.setScaleByTextureRectangleSize(true); 61 fr +=2 ; 62 iteratorAdvanced = true; 63 } 64 else if (fr[1].matchWord("FALSE")) 65 { 66 texmat.setScaleByTextureRectangleSize(false); 67 fr +=2 ; 68 iteratorAdvanced = true; 69 } 70 } 71 72 return iteratorAdvanced; 73 } 74 75 76 bool TexMat_writeLocalData(const Object& obj, Output& fw) 77 { 78 const TexMat& texmat = static_cast<const TexMat&>(obj); 79 const Matrix& matrix = texmat.getMatrix(); 80 fw.indent() << matrix(0,0) << " " << matrix(0,1) << " " << matrix(0,2) << " " << matrix(0,3) << std::endl; 81 fw.indent() << matrix(1,0) << " " << matrix(1,1) << " " << matrix(1,2) << " " << matrix(1,3) << std::endl; 82 fw.indent() << matrix(2,0) << " " << matrix(2,1) << " " << matrix(2,2) << " " << matrix(2,3) << std::endl; 83 fw.indent() << matrix(3,0) << " " << matrix(3,1) << " " << matrix(3,2) << " " << matrix(3,3) << std::endl; 84 85 if (texmat.getScaleByTextureRectangleSize()) 86 { 87 fw.indent() << "scaleByTextureRectangleSize TRUE"<<std::endl; 88 } 89 90 return true; 91 } 92