- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/geo/ReaderWriterGEO.cpp
r12577 r13041 3 3 // supports geometry and group & face level animations. 4 4 // Vertex level animation partly supported - defines movement (translate, rotate, colour)! 5 // Loader has been divided into two parts 6 // 1- general geometry (here) & 5 // Loader has been divided into two parts 6 // 1- general geometry (here) & 7 7 // 2- animation (see geoActions.cpp). 8 8 // ver 1.2 GWM Nov 2003 … … 81 81 delete useVars; 82 82 delete extVars; 83 83 84 84 if (color_palette) 85 85 { … … 100 100 return st; 101 101 } 102 double *geoHeaderGeo::getVar(const unsigned fid) const { 102 double *geoHeaderGeo::getVar(const unsigned fid) const { 103 103 double *dv=NULL; 104 104 dv=intVars->getVar(fid); … … 120 120 osg::Timer_t _frameTick = _timer.tick(); 121 121 _lastFrameTick=_frameTick; 122 122 123 123 double time = _frameStamp->getSimulationTime(); 124 124 intVars->update( _frameStamp); … … 227 227 // gr is tha vertex; gface is the face containing the vertex 228 228 bool hbeh=false; // true if this vertex has a behaviour 229 if (gr->getType()==DB_DSK_VERTEX || 230 gr->getType()==DB_DSK_FAT_VERTEX || 229 if (gr->getType()==DB_DSK_VERTEX || 230 gr->getType()==DB_DSK_FAT_VERTEX || 231 231 gr->getType()==DB_DSK_SLIM_VERTEX) { 232 232 const geoField *gfshade=gface->getField(GEO_DB_POLY_SHADEMODEL); // shaded gouraud, flat... … … 324 324 if (gfd) { 325 325 uvc=(float *)gfd->getstore(0); 326 326 327 327 if (uvc) { // then there are tx coords 328 328 osg::Vec2 uv(uvc[0], uvc[1]); … … 377 377 output << "Nind " << i << " = " << (*normindices)[i] << std::endl; 378 378 } 379 return output; // to enable cascading, monkey copy from osg\plane or \quat, Ubyte4, vec2,3,4,... 379 return output; // to enable cascading, monkey copy from osg\plane or \quat, Ubyte4, vec2,3,4,... 380 380 } 381 381 private: … … 441 441 if (fin.is_open() ) 442 442 { // read the input file. 443 // code for setting up the database path so that internally referenced file are searched for on relative paths. 444 osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ? 445 static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : 443 // code for setting up the database path so that internally referenced file are searched for on relative paths. 444 osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ? 445 static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : 446 446 new osgDB::ReaderWriter::Options; 447 447 local_opt->setDatabasePath(osgDB::getFilePath(fileName)); … … 480 480 nodeList=makeosg(sorted, local_opt.get()); // make a list of osg nodes 481 481 geotxlist.clear(); 482 geomatlist.clear(); 482 geomatlist.clear(); 483 483 txlist.clear(); 484 484 txenvlist.clear(); … … 527 527 // OSG_WARN << *itr << std::endl; 528 528 // now parse for push/pops and add to lists 529 529 530 530 switch ((*itr).getType()) { 531 531 case 101: // old header - not appropriate! … … 547 547 curparent= &(*itr); 548 548 sorted.push_back(&(*itr)); 549 cpalrec=NULL; 549 cpalrec=NULL; 550 550 break; 551 551 case DB_DSK_INTERNAL_VARS: // attach to parent … … 644 644 (*itr).setparent(curparent); 645 645 curparent->addchild(&(*itr)); 646 } 646 } 647 647 break; 648 648 } … … 733 733 if (shademodel==GEO_POLY_SHADEMODEL_LIT || 734 734 shademodel==GEO_POLY_SHADEMODEL_LIT_GOURAUD) dstate->setMode( GL_LIGHTING, osg::StateAttribute::ON ); 735 else 735 else 736 736 dstate->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); 737 737 { // reclaim the colours … … 864 864 gfd=gr->getField(GEO_DB_TEXT_MATRIX); 865 865 if (gfd) { 866 float *fmat=gfd->getMat44Arr(); 866 float *fmat=gfd->getMat44Arr(); 867 867 // text->setPosition(osg::Vec3(fmat[12],fmat[13],fmat[14])); 868 868 numt->setMatrix(Matrix(fmat)); … … 934 934 ++itr) 935 935 { 936 if ((*itr)->getType()==DB_DSK_VERTEX || 937 (*itr)->getType()==DB_DSK_FAT_VERTEX || 936 if ((*itr)->getType()==DB_DSK_VERTEX || 937 (*itr)->getType()==DB_DSK_FAT_VERTEX || 938 938 (*itr)->getType()==DB_DSK_SLIM_VERTEX) 939 939 { // light point vertices … … 1017 1017 gfd=(*itr)->getField(GEO_DB_POLY_DSTYLE); // solid, wire... 1018 1018 int dstyle= gfd ? gfd->getInt() : GEO_POLY_DSTYLE_SOLID; 1019 if (!usemat && 1019 if (!usemat && 1020 1020 (shademodel== GEO_POLY_SHADEMODEL_LIT ||shademodel== GEO_POLY_SHADEMODEL_LIT_GOURAUD) ) { // get the per vertex colours OR per face colours. 1021 1021 gfd=(*itr)->getField(GEO_DB_POLY_PACKED_COLOR); // the colour … … 1126 1126 // std::vector<osg::Geometry *> geom; 1127 1127 if (gr.size()>0) { 1128 std::vector<class geoInfo> ia; // list of texture indices & vinfo found in this geode; sort into new 1128 std::vector<class geoInfo> ia; // list of texture indices & vinfo found in this geode; sort into new 1129 1129 const geoField *gfd=grec.getField(GEO_DB_RENDERGROUP_CULLING); // back, front, none 1130 1130 unsigned int bothsides=gfd ? gfd->getUInt() : 0; … … 1142 1142 int shademodel=gfd ? gfd->getInt() : GEO_POLY_SHADEMODEL_LIT_GOURAUD; 1143 1143 geoInfo *gi=getGeometry((*itr), nug, &ia, imat,shademodel, bothsides); 1144 1144 1145 1145 //shade models GEO_POLY_SHADEMODEL_FLAT GEO_POLY_SHADEMODEL_GOURAUD 1146 1146 // GEO_POLY_SHADEMODEL_LIT GEO_POLY_SHADEMODEL_LIT_GOURAUD 1147 1147 gfd=(*itr)->getField(GEO_DB_POLY_USE_MATERIAL_DIFFUSE); // true: use material... 1148 1148 bool usemat= gfd ? gfd->getBool() : false; 1149 if (!usemat || 1149 if (!usemat || 1150 1150 shademodel== GEO_POLY_SHADEMODEL_LIT /*||shademodel== GEO_POLY_SHADEMODEL_LIT_GOURAUD) */ ) { // get the per vertex colours OR per face colours. 1151 1151 gfd=(*itr)->getField(GEO_DB_POLY_PACKED_COLOR); // the colour … … 1176 1176 } 1177 1177 if (hasColorAction(bhv)) addPolyActions(bhv, *gi, nv); 1178 1178 1179 1179 if (dstyle==GEO_POLY_DSTYLE_SOLID_BOTH_SIDES || dstyle == GEO_POLY_DSTYLE_SOLID) { 1180 osg::DrawArrays *drw=new osg::DrawArrays(osg::PrimitiveSet::POLYGON,gi->getStart(nv),nv); 1180 osg::DrawArrays *drw=new osg::DrawArrays(osg::PrimitiveSet::POLYGON,gi->getStart(nv),nv); 1181 1181 gi->getGeom()->addPrimitiveSet(drw); 1182 1182 } … … 1218 1218 std::vector<osg::Geometry *> geom; 1219 1219 if (gr.size()>0) { 1220 std::vector<int> ia; // list of texture indices found in this geode; sort into new 1220 std::vector<int> ia; // list of texture indices found in this geode; sort into new 1221 1221 for (std::vector<georecord *>::const_iterator itr=gr.begin(); 1222 1222 itr!=gr.end(); … … 1235 1235 // in geo text is defined with a matrix included in the geo.geode (gr is this geo.geode) 1236 1236 // - we need to create this tree to render text 1237 #if 1 1237 #if 1 1238 1238 return NULL; // temporary disable april 2003 1239 1239 #else … … 1252 1252 #endif 1253 1253 } 1254 1254 1255 1255 Group *makeLightPointGeodes(const georecord *gr) { 1256 1256 Group *nug=new Group; … … 1268 1268 Group *makeAnimatedGeodes(const georecord *gr) 1269 1269 { // create a group full of animated geodes. Used for any animations applied to facets! 1270 // movement actions require a transform node to be inserted, and this cannot be 1270 // movement actions require a transform node to be inserted, and this cannot be 1271 1271 // derived from Geode. So create a group, add matrix transform(s) for each animated polygon 1272 1272 const geoField *gfd=gr->getField(GEO_DB_RENDERGROUP_MAT); … … 1363 1363 if (gfd) { 1364 1364 int imask; 1365 1365 1366 1366 imask=gfd->getInt(); 1367 1367 1368 1368 // set the bits in the osg::Switch. 1369 1369 int selector_mask = 0x1; 1370 1370 for(int pos=0;pos<32;++pos) 1371 1371 { 1372 sw->setValue(pos,((imask&selector_mask)!=0)); 1372 sw->setValue(pos,((imask&selector_mask)!=0)); 1373 1373 selector_mask <<= 1; 1374 1374 } … … 1384 1384 return sw; 1385 1385 } 1386 1386 1387 1387 osg::Sequence *makeSequence(const georecord *gr) 1388 1388 { … … 1411 1411 { // set up the Geometry that defines the clipped region. 1412 1412 osg::Geometry* geom = new osg::Geometry; 1413 1413 1414 1414 osg::Vec3Array* coords = new osg::Vec3Array(4); 1415 1415 (*coords)[0].set(xMin,yMax,z); … … 1418 1418 (*coords)[3].set(xMax,yMax,z); 1419 1419 geom->setVertexArray(coords); 1420 1420 1421 1421 geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); 1422 1422 1423 1423 return geom; 1424 1424 } … … 1490 1490 if ((*rcitr)->getType()==DB_DSK_INTERNAL_VARS) { 1491 1491 theHeader->addInternalVars(**rcitr); 1492 // theHeader->setUpdateCallback(theHeader->getInternalVars()); 1492 // theHeader->setUpdateCallback(theHeader->getInternalVars()); 1493 1493 } 1494 1494 if ((*rcitr)->getType()==DB_DSK_FLOAT_VAR) { … … 1570 1570 tx->setFilter(osg::Texture::MIN_FILTER, filt); 1571 1571 gfd=gr->getField(GEO_DB_TEX_MAGFILTER); 1572 if (gfd) { 1572 if (gfd) { 1573 1573 unsigned imod=gfd->getUInt(); 1574 1574 switch (imod) { … … 1613 1613 } 1614 1614 break; 1615 1615 1616 1616 case DB_DSK_SCALE_ACTION: { 1617 1617 geoMoveBehaviour *sb=new geoMoveBehaviour; … … 1628 1628 } 1629 1629 break; 1630 1630 1631 1631 case DB_DSK_COMPARE_ACTION: { 1632 1632 geoCompareBehaviour *cb=new geoCompareBehaviour; … … 1809 1809 (*itr)->setNode(holder); 1810 1810 break; 1811 /* holder= theHeader.get(); // makeHeader(gr);// 1811 /* holder= theHeader.get(); // makeHeader(gr);// 1812 1812 (*itr)->setNode(holder); 1813 1813 if (mtr) { … … 1837 1837 (*itr)->setNode(holder); 1838 1838 break; 1839 case DB_DSK_LOD: 1839 case DB_DSK_LOD: 1840 1840 holder=makeLOD(gr); 1841 1841 (*itr)->setNode(holder); … … 1913 1913 (*itr)->setNode(holder); 1914 1914 break; 1915 case DB_DSK_PERSPECTIVE_GRID_INFO: 1915 case DB_DSK_PERSPECTIVE_GRID_INFO: 1916 1916 { // relates to how model is viewed in Geo modeller 1917 1917 osg::Group *gp=new Group; … … 1927 1927 case DB_DSK_FLOAT3_VAR: 1928 1928 case DB_DSK_FLOAT4_VAR: 1929 case DB_DSK_INTERNAL_VARS: 1930 case DB_DSK_LOCAL_VARS: 1929 case DB_DSK_INTERNAL_VARS: 1930 case DB_DSK_LOCAL_VARS: 1931 1931 case DB_DSK_EXTERNAL_VARS: 1932 1932 case DB_DSK_CLAMP_ACTION: 1933 case DB_DSK_RANGE_ACTION: 1934 case DB_DSK_ROTATE_ACTION: 1935 case DB_DSK_TRANSLATE_ACTION: 1936 case DB_DSK_SCALE_ACTION: 1937 case DB_DSK_ARITHMETIC_ACTION: 1938 case DB_DSK_LOGIC_ACTION: 1939 case DB_DSK_CONDITIONAL_ACTION: 1940 case DB_DSK_LOOPING_ACTION: 1941 case DB_DSK_COMPARE_ACTION: 1942 case DB_DSK_VISIBILITY_ACTION: 1933 case DB_DSK_RANGE_ACTION: 1934 case DB_DSK_ROTATE_ACTION: 1935 case DB_DSK_TRANSLATE_ACTION: 1936 case DB_DSK_SCALE_ACTION: 1937 case DB_DSK_ARITHMETIC_ACTION: 1938 case DB_DSK_LOGIC_ACTION: 1939 case DB_DSK_CONDITIONAL_ACTION: 1940 case DB_DSK_LOOPING_ACTION: 1941 case DB_DSK_COMPARE_ACTION: 1942 case DB_DSK_VISIBILITY_ACTION: 1943 1943 case DB_DSK_STRING_CONTENT_ACTION: 1944 1944 default: { … … 2050 2050 return NULL; 2051 2051 } 2052 2052 2053 2053 private: 2054 2054 geoRecordList recs; // the records read from file … … 2085 2085 unsigned int fid=gfd ? gfd->getUInt():0; 2086 2086 geoValue *nm=new geoValue(tok,fid); 2087 2087 2088 2088 gfd= gr.getField(GEO_DB_FLOAT_VAR_NAME); 2089 2089 const char *name=gfd->getChar(); 2090 2090 nm->setName(name); 2091 2091 2092 2092 gfd= gr.getField(GEO_DB_FLOAT_VAR_VALUE); 2093 2093 nm->setVal(gfd ? gfd->getFloat():0.0f); … … 2096 2096 //nm->setdefault(gfd ? gfd->getFloat():0.0f); 2097 2097 //float fdef=gfd ? gfd->getFloat():0.0f; 2098 2098 2099 2099 gfd= gr.getField(GEO_DB_FLOAT_VAR_CONSTRAINED); 2100 2100 if (gfd) { … … 2133 2133 time_t long_time; 2134 2134 struct tm *newtime; 2135 2135 2136 2136 long_time=time( NULL ); // * Get time as long integer. 2137 2137 newtime = localtime( &long_time ); // * Convert to local time. … … 2198 2198 nread++; 2199 2199 } 2200 void geoField::readfile(std::ifstream &fin, const uint id) { // is part of a record id 2200 void geoField::readfile(std::ifstream &fin, const uint id) { // is part of a record id 2201 2201 unsigned char tokid, type; 2202 2202 unsigned short nits; … … 2252 2252 { 2253 2253 public: 2254 2254 2255 2255 ReaderWriterGEO() 2256 2256 { … … 2258 2258 supportsExtension("geo","CarbonGraphics Geo model format"); 2259 2259 } 2260 2260 2261 2261 virtual const char* className() const { return "GEO Reader/Writer"; } 2262 2262
