Changeset 45
- Timestamp:
- Dec 13, 2004, 1:17:13 AM (20 years ago)
- Location:
- Swollen
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Swollen/INSTALL
r6 r45 7 7 OpenSceneGraph, OpenThreads, and Producer 8 8 - http://openscenegraph.sourceforge.net 9 - available as a bundle, OSG_OP_OT-0.9. 7-310 - this itself has 3rd party dependencies available11 a s a downloadable bundle9 - available as a bundle, OSG_OP_OT-0.9.8 10 - OpenSceneGraph has 3rd party dependencies, these are 11 available as a downloadable .zip for Windows. 12 12 - ensure you can run the examples that come with OSG 13 13 prior to building the viewer … … 39 39 /lib 40 40 /include 41 /3rdParty (Windows only) 41 42 42 43 NETCDF_DIR : root of NetCDF binary package with needed subdirs … … 47 48 48 49 49 3) For Visual Studio .NET, 50 51 (i) Open the solution in visualstudio subdir. 52 (ii) Open Menu Tools|Options|Projects|VC++Directories and add a 53 path to $(NETCDF_DIR)/bin and $(OSG_ROOT)/bin. 54 (iii) Build the solution 50 3) Compilation 55 51 56 52 57 4) For Mac OSX 53 WINDOWS 58 54 59 Run make in swwreader and swollen directories. 55 (i) Open the solution in visualstudio subdir. 56 (ii) Open Menu Tools|Options|Projects|VC++Directories and add a 57 path to $(NETCDF_DIR)/bin and $(OSG_ROOT)/bin. 58 (iii) Build the solution 60 59 61 60 62 5) For Linux 61 Mac OSX 63 62 64 Makefiles not yet written63 Run make in top-level OSG_ROOT directory. 65 64 65 66 Linux 67 68 Makefiles not yet written 69 70 71 72 4) The binary swollen (swollen.exe on Windows) lives in the distribution's 73 bin directory. Test the build with any of the sample datasets in the 74 distribution's data subdirectory, e.g., 75 "cd bin; ./swollen ../data/laminar.sww" 76 77 78 -
Swollen/include/swwreader.h
r44 r45 66 66 virtual osg::ref_ptr<osg::Vec3Array> getBedslopeVertexArray() {return _bedslopevertices;} 67 67 virtual osg::ref_ptr<osg::Vec3Array> getBedslopeNormalArray() {return _bedslopenormals;} 68 virtual osg::ref_ptr<osg:: UIntArray> getBedslopeIndexArray() {return _bedslopeindices;}68 virtual osg::ref_ptr<osg::DrawElementsUShort> getBedslopeIndexArray() {return _bedslopeindices;} 69 69 virtual osg::ref_ptr<osg::Vec3Array> getBedslopeCentroidArray() {return _bedslopecentroids;} 70 virtual osg::ref_ptr<osg::Vec2Array> getBedslopeTextureCoords() {return _bedslopetexcoords;} 70 71 71 72 // stage 72 73 virtual osg::ref_ptr<osg::Vec3Array> getStageVertexArray(unsigned int index); 73 virtual osg::ref_ptr<osg::UIntArray> getStageIndexArray() {return _stageindices;}74 74 virtual osg::ref_ptr<osg::Vec3Array> getStageVertexNormalArray() {return _stagevertexnormals;} 75 virtual osg::ref_ptr<osg::Vec3Array> getStagePrimitiveNormalArray() {return _stageprimitivenormals;}76 75 virtual osg::ref_ptr<osg::Vec3Array> getStageCentroidsArray() {return _stagecentroids;} 77 76 virtual osg::ref_ptr<osg::Vec4Array> getStageColorArray() {return _stagecolors;} … … 81 80 virtual size_t getNumberOfVertices() {return _npoints;} 82 81 virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;} 83 virtual int getNumberOfBedslopeIndices() {return _bedslopeindices->size();}84 virtual int getNumberOfStageIndices() {return _stageindices->size();}82 //virtual int getNumberOfBedslopeIndices() {return _bedslopeindices->size();} 83 //virtual int getNumberOfStageIndices() {return _stageindices->size();} 85 84 86 85 // stage culling … … 122 121 osg::ref_ptr<osg::Vec3Array> _bedslopevertices; 123 122 osg::ref_ptr<osg::Vec3Array> _bedslopenormals; 124 osg::ref_ptr<osg:: UIntArray> _bedslopeindices;123 osg::ref_ptr<osg::DrawElementsUShort> _bedslopeindices; 125 124 osg::ref_ptr<osg::Vec3Array> _bedslopecentroids; 125 osg::ref_ptr<osg::Vec2Array> _bedslopetexcoords; 126 126 127 127 // geometry that changes per timestep 128 128 osg::ref_ptr<osg::Vec3Array> _stagevertices; 129 129 osg::ref_ptr<osg::Vec3Array> _stageprimitivenormals; 130 osg::ref_ptr<osg::UIntArray> _stageindices;131 130 osg::ref_ptr<osg::Vec3Array> _stagevertexnormals; 132 131 osg::ref_ptr<osg::Vec3Array> _stagecentroids; … … 134 133 135 134 // bedslope vertex scale and shift factors (for normalizing to unit cube) 136 float _xscale, _yscale, _zscale ;135 float _xscale, _yscale, _zscale, _scale; 137 136 float _xoffset, _yoffset, _zoffset; 138 137 float _xcenter, _ycenter, _zcenter; -
Swollen/swollen/bedslope.cpp
r44 r45 16 16 { 17 17 18 // persistent 19 _sww = sww; 20 18 21 // bedslope geometry as triangles with shared vertices 19 22 _geom = new osg::Geometry; 20 23 21 24 // geometry from sww file 22 osg::Vec3Array* vertices = sww->getBedslopeVertexArray().get(); 23 osg::UIntArray* indices = sww->getBedslopeIndexArray().get(); 24 osg::Vec3Array* normals = sww->getBedslopeNormalArray().get(); 25 unsigned int nindices = sww->getNumberOfBedslopeIndices(); 25 osg::Vec3Array* vertices = _sww->getBedslopeVertexArray().get(); 26 osg::Vec3Array* normals = _sww->getBedslopeNormalArray().get(); 26 27 27 28 _geom->setUseDisplayList(true); 28 29 _geom->setVertexArray( vertices ); 29 _geom->setVertexIndices( indices ); 30 _geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, nindices )); 30 _geom->addPrimitiveSet( _sww->getBedslopeIndexArray().get() ); 31 31 _geom->setNormalArray( normals ); 32 32 _geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE ); 33 33 _geom->setTexCoordArray( 0, _sww->getBedslopeTextureCoords().get() ); 34 34 35 35 // geometry bounding box 36 36 osg::BoundingBox bbox = _geom->getBound(); 37 38 // bedslope texture coords scaled to range [0,1]39 osg::Vec2Array* texcoords = new osg::Vec2Array;40 osg::Vec3 v;41 float xrange = bbox.xMax() - bbox.xMin();42 float yrange = bbox.yMax() - bbox.yMin();43 for( unsigned int i=0; i < vertices->size(); i++ )44 {45 v = vertices->at(i);46 texcoords->push_back( osg::Vec2( (v.x()-bbox.xMin())/xrange, (v.y()-bbox.yMin())/yrange) );47 }48 _geom->setTexCoordArray( 0, texcoords );49 _geom->setTexCoordIndices( 0, indices );50 37 51 38 // bedslope texture … … 55 42 texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); 56 43 texture->setImage(osgDB::readImageFile("bedslope.jpg")); 57 58 59 // bedslope colour60 //osg::UByte4Array* colors = new osg::UByte4Array;61 //colors->push_back(osg::UByte4(DEF_BEDSLOPE_COLOUR));62 //_geom->setColorArray(colors);63 //_geom->setColorBinding(osg::Geometry::BIND_OVERALL);64 65 // material properties66 _material = new osg::Material;67 _material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_BEDSLOPE_COLOUR));68 _material->setSpecular(osg::Material::FRONT, osg::Vec4(1,0,0,1));69 _material->setShininess(osg::Material::FRONT, 128);70 71 44 72 45 _stateset = new osg::StateSet; … … 74 47 _stateset->setMode( GL_BLEND, osg::StateAttribute::ON ); 75 48 _stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON ); 76 _stateset->setAttribute(_material);77 78 79 80 49 81 50 _node = new osg::Geode; -
Swollen/swollen/bedslope.h
r6 r45 16 16 #include <SWWReader.h> 17 17 #include <osg/Geode> 18 #include <osg/Material>19 18 #include <osg/StateAttribute> 20 19 … … 36 35 osg::Geometry* _geom; 37 36 osg::StateSet* _stateset; 38 osg::Material* _material;39 37 virtual ~BedSlope(){;} 40 38 -
Swollen/swollen/main.cpp
r43 r45 36 36 // set up the usage document, in case we need to print out how to use this program. 37 37 arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()); 38 arguments.getApplicationUsage()->setCommandLineUsage("sw wviewer[options] swwfile ...");38 arguments.getApplicationUsage()->setCommandLineUsage("swollen [options] swwfile ..."); 39 39 arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 40 40 arguments.getApplicationUsage()->addCommandLineOption("-scale <s>","Vertical scale factor"); 41 arguments.getApplicationUsage()->addCommandLineOption("-tps <rate>","timesteps per second"); 41 42 42 43 // construct the viewer. … … 46 47 viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 47 48 viewer.setClearColor(osg::Vec4(DEF_BACKGROUND_COLOUR)); 48 //viewer.getCamera(0)->getRenderSurface()->setWindowRectangle(550,100,640,480);49 viewer.getCamera(0)->getRenderSurface()->setWindowRectangle(200,100,800,600); 49 50 50 51 … … 73 74 if (sww->isValid() == false) 74 75 { 75 std::cout << " Could not load " << swwfile << " ... quitting" << std::endl;76 std::cout << "Unable to load " << swwfile << " ... is this really an .sww file?" << std::endl; 76 77 return 1; 77 78 } … … 85 86 86 87 87 88 88 // root node 89 89 osg::Group* rootnode = new osg::Group; … … 105 105 HeadsUpDisplay* hud = new HeadsUpDisplay(); 106 106 hud->setTitle("pyVolution SWW Viewer"); 107 107 108 108 109 // Lighting … … 110 111 spotlight->setPosition( osg::Vec3(0,0,2) ); // overhead 111 112 spotlight->setSpotAngle( 45.0 ); 113 112 114 113 115 // scenegraph hierarchy … … 143 145 KeyboardEventHandler* event_handler = new KeyboardEventHandler(sww->getNumberOfTimesteps(), tps); 144 146 viewer.getEventHandlerList().push_front(event_handler); 147 145 148 146 149 // create the windows and run the threads. … … 148 151 149 152 150 // Initial camera position153 // initial camera position 151 154 viewer.getTrackball()->setNode( rootnode ); 152 155 viewer.getTrackball()->setAutoComputeHomePosition(false); 153 156 viewer.getTrackball()->setHomePosition( 154 osg::Vec3d(0,-4, 0),// camera location157 osg::Vec3d(0,-4,1), // camera location 155 158 osg::Vec3d(0,0,0), // camera target 156 159 osg::Vec3d(0,0,1) ); // camera up vector -
Swollen/swollen/watersurface.cpp
r44 r45 34 34 _geom = new osg::Geometry; 35 35 _stateset = new osg::StateSet; 36 _material = new osg::Material;37 36 _zoffset = DEF_ZOFFSET; 38 37 … … 41 40 _node->addDrawable(_geom); 42 41 _node->setStateSet(_stateset); 43 //_stateset->setAttribute(_material);44 42 45 43 _geom->setUseDisplayList(true); … … 47 45 // initial geometry 48 46 setTimeStep(0); 49 50 //_material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_WATER_COLOUR));51 //_material->setSpecular(osg::Material::FRONT, osg::Vec4(1,1,1,1));52 //_material->setTransparency(osg::Material::FRONT_AND_BACK, DEF_WATER_TRANSPARENCY);53 //_material->setShininess(osg::Material::FRONT, 128);54 47 55 48 // environment map … … 59 52 texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); 60 53 texture->setImage(osgDB::readImageFile("envmap.jpg")); 61 //_stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON );54 _stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON ); 62 55 _stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); 63 56 64 57 // surface transparency 65 //osg::BlendFunc* osgBlendFunc = new osg::BlendFunc();66 //osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);67 //_stateset->setAttribute(osgBlendFunc);68 //_stateset->setMode(GL_BLEND, osg::StateAttribute::ON);58 osg::BlendFunc* osgBlendFunc = new osg::BlendFunc(); 59 osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); 60 _stateset->setAttribute(osgBlendFunc); 61 _stateset->setMode(GL_BLEND, osg::StateAttribute::ON); 69 62 70 63 osg::AlphaFunc* alphaFunc = new osg::AlphaFunc; … … 83 76 texenv->setMode( osg::TexEnv::DECAL ); 84 77 texenv->setColor( osg::Vec4(0.6f,0.6f,0.6f,0.2f) ); 85 //_stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );86 //_stateset->setTextureAttribute( 1, texenv );78 _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON ); 79 _stateset->setTextureAttribute( 1, texenv ); 87 80 } 88 81 … … 103 96 // local reference to raw height field data 104 97 osg::ref_ptr<osg::Vec3Array> vertices = _sww->getStageVertexArray(ts); 105 osg::ref_ptr<osg::UIntArray> indices = _sww->getStageIndexArray();106 osg::ref_ptr<osg::Vec3Array> normals = _sww->getStagePrimitiveNormalArray();107 98 osg::ref_ptr<osg::Vec3Array> vertexnormals = _sww->getStageVertexNormalArray(); 108 99 osg::ref_ptr<osg::Vec4Array> colors = _sww->getStageColorArray(); … … 118 109 // geometry 119 110 _geom->setVertexArray( vertices.get() ); 120 _geom->setVertexIndices( indices.get() ); 121 _geom->addPrimitiveSet( new osg::DrawArrays( 122 osg::PrimitiveSet::TRIANGLES, 0, _sww->getNumberOfStageIndices() ) ); 111 _geom->addPrimitiveSet( _sww->getBedslopeIndexArray().get() ); 123 112 124 113 // per vertex colors (using only alpha) 125 114 _geom->setColorArray( colors.get() ); 126 _geom->setColorIndices( colorindices );127 115 _geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); 128 116 129 117 // normals 130 118 _geom->setNormalArray( vertexnormals.get() ); 131 _geom->setNormalIndices( indices.get() );132 119 _geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); 133 120 -
Swollen/swollen/watersurface.h
r13 r45 15 15 #include <SWWReader.h> 16 16 #include <osg/Geode> 17 #include <osg/Material>18 17 #include <osg/StateAttribute> 19 18 … … 38 37 osg::Geometry* _geom; 39 38 osg::StateSet* _stateset; 40 osg::Material* _material;41 39 virtual ~WaterSurface(); 42 40 float _zoffset; -
Swollen/swwreader/swwreader.cpp
r44 r45 121 121 xrange = xmax - xmin; 122 122 yrange = ymax - ymin; 123 zrange = zmax - zmin; 123 124 aspect_ratio = xrange/yrange; 125 _xscale = 1.0 / xrange; 126 _yscale = 1.0 / yrange; 127 _zscale = (zmax == 0.0) ? 1.0 : 1.0 / zrange; 128 _xoffset = xmin; 129 _yoffset = ymin; 130 _zoffset = zmin; 131 _xcenter = 0.5; 132 _ycenter = 0.5; 133 _zcenter = 0.0; 134 124 135 if( aspect_ratio > 1.0 ) 125 136 { 126 _xscale = 1.0 / xrange; 127 _xoffset = xmin; 128 _xcenter = 0.5; 129 130 _yscale = _xscale; 131 _yoffset = ymin; 132 _ycenter = 0.5 / aspect_ratio; 133 134 _zscale = _xscale; 135 _zoffset = zmin; 136 _zcenter = 0.0; 137 _scale = 1.0 / xrange; 138 _ycenter /= aspect_ratio; 137 139 } 138 140 else 139 141 { 140 _yscale = 1.0 / yrange; 141 _yoffset = ymin; 142 _ycenter = 0.5; 143 144 _xscale = _yscale; 145 _xoffset = xmin; 146 _xcenter = 0.5 / aspect_ratio; 147 148 _zscale = _yscale; 149 _zoffset = zmin; 150 _zcenter = 0.0; 142 _scale = 1.0 / yrange; 143 _xcenter /= aspect_ratio; 151 144 } 152 145 … … 180 173 } 181 174 182 // loadbedslope vertex array, shifting and scaling vertices to unit cube175 // bedslope vertex array, shifting and scaling vertices to unit cube 183 176 // centred about the origin 184 177 _bedslopevertices = new osg::Vec3Array; 185 178 for (iv=0; iv < _npoints; iv++) 186 _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_ xscale - _xcenter,187 (_py[iv]-_yoffset)*_ yscale - _ycenter,188 (_pz[iv]-_zoffset)*_ zscale - _zcenter) );189 190 // loadbedslope index array, pvolumes array indexes into x, y and z191 _bedslopeindices = new osg:: UIntArray;179 _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter, 180 (_py[iv]-_yoffset)*_scale - _ycenter, 181 (_pz[iv]-_zoffset)*_scale - _zcenter) ); 182 183 // bedslope index array, pvolumes array indexes into x, y and z 184 _bedslopeindices = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, _nvolumes*_nvertices); 192 185 for (iv=0; iv < _nvolumes*_nvertices; iv++) 193 _bedslopeindices->push_back( _pvolumes[iv] ); 186 (*_bedslopeindices)[iv] = _pvolumes[iv]; 187 188 189 // bedslope texture coords based on (x,y) locations scaled by extents into range [0,1] 190 _bedslopetexcoords = new osg::Vec2Array; 191 for( iv=0; iv < _npoints; iv++ ) 192 _bedslopetexcoords->push_back( osg::Vec2( (_px[iv]-_xoffset)*_xscale, (_py[iv]-_yoffset)*_yscale ) ); 193 194 194 195 195 196 // calculate bedslope primitive normal and centroid arrays … … 246 247 _stagevertices = new osg::Vec3Array; 247 248 for (iv=0; iv < _npoints; iv++) 248 _stagevertices->push_back( osg::Vec3( 249 (_px[iv]-_xoffset)*_xscale - _xcenter,250 (_py[iv]-_yoffset)*_yscale - _ycenter,251 (_pstage[iv]-_zoffset)*_zscale - _zcenter) ); 252 253 // stage index andper primitive normal and centroid arrays249 _stagevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter, 250 (_py[iv]-_yoffset)*_scale - _ycenter, 251 (_pstage[iv]-_zoffset)*_scale - _zcenter) ); 252 253 254 // stage index, per primitive normal and centroid arrays 254 255 _stageprimitivenormals = new osg::Vec3Array; 255 256 _stagecentroids = new osg::Vec3Array; 256 _stageindices = new osg::UIntArray;257 _stagecolors = new osg::Vec4Array;258 257 osg::Vec3 v1b, v2b, v3b; 259 258 osg::Vec3 v1s, v2s, v3s; 260 259 osg::Vec3 side1, side2, nrm; 261 260 unsigned int v1index, v2index, v3index; 262 osg::ref_ptr<osg::UIntArray> culledlist = new osg::UIntArray;263 std::vector<triangle_list> stageconnectivity = std::vector<triangle_list>(_npoints);264 261 265 262 // over all stage triangles 266 unsigned int nonculled = 0;267 float alphamin = 1.0;268 float alphamax = 0.0;269 263 for (iv=0; iv < _nvolumes; iv++){ 270 264 … … 280 274 v3b = _bedslopevertices->at(v3index); 281 275 282 // shallow water depth culling test283 if( (_cullsetting == CULLALL || _cullsetting == CULLNEARZERO) &&284 ((v1s.z()+v2s.z()+v3s.z())/3.0 - _bedslopecentroids->at(iv).z()) < _cullnearzero )285 {286 culledlist->push_back( iv );287 continue;288 }289 290 // steep bedslope culling test291 if( _cullsetting == CULLALL || _cullsetting == CULLSTEEPANGLE )292 {293 if( _bedslopenormals->at(iv) * osg::Vec3f(0,0,1) < _cullsteepangle )294 {295 culledlist->push_back( iv );296 continue;297 }298 }299 300 // pass through, current triangle is visible (not culled)301 _stageindices->push_back( v1index );302 _stageindices->push_back( v2index );303 _stageindices->push_back( v3index );304 305 // alpha value based on stage-bedslope height difference306 float alpha1 = ( v1s.z()-v1b.z() )*10.0;307 float alpha2 = ( v2s.z()-v2b.z() )*10.0;308 float alpha3 = ( v3s.z()-v3b.z() )*10.0;309 alphamax = MAX( alphamax, alpha1 );310 alphamax = MAX( alphamax, alpha2 );311 alphamax = MAX( alphamax, alpha3 );312 alphamin = MIN( alphamin, alpha1 );313 alphamin = MIN( alphamin, alpha2 );314 alphamin = MIN( alphamin, alpha3 );315 316 osg::Vec4 color1, color2, color3;317 color1.set( alpha1,alpha1,alpha1, 1.0 );318 color2.set( alpha2,alpha2,alpha2, 1.0 );319 color3.set( alpha3,alpha3,alpha3, 1.0 );320 //color1.set( alpha1,alpha1,alpha1, alpha1 );321 //color2.set( alpha2,alpha2,alpha2, alpha2 );322 //color3.set( alpha3,alpha3,alpha3, alpha3 );323 _stagecolors->push_back( color1 );324 _stagecolors->push_back( color2 );325 _stagecolors->push_back( color3 );326 327 276 // current triangle primitive normal 328 277 side1 = v2s - v1s; … … 331 280 nrm.normalize(); 332 281 333 // stage triangle connectivity, a list (indexed by vertex number) 334 // of lists (indices of non-culled triangles sharing this vertex) 335 stageconnectivity.at(v1index).push_back(nonculled); 336 stageconnectivity.at(v2index).push_back(nonculled); 337 stageconnectivity.at(v3index).push_back(nonculled); 338 339 // store centroid and primitive normal (both needed to visualize vectors) 282 // store centroid and primitive normal 340 283 _stagecentroids->push_back( (v1s+v2s+v3s)/3.0 ); 341 284 _stageprimitivenormals->push_back( nrm ); 342 285 343 // non-culled triangle count 344 nonculled++; 345 346 } 347 348 std::cout << "index: " << index << " AlphaMax: " << alphamax << std::endl; 349 std::cout << "index: " << index << " AlphaMin: " << alphamin << std::endl; 350 351 // per-vertex normals 286 } 287 288 289 float alpha; 290 _stagecolors = new osg::Vec4Array; 291 for (iv=0; iv < _npoints; iv++) 292 { 293 // FIXME: needs to be scaled appropriately 294 alpha = ( _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z() ) * 100.0; 295 _stagecolors->push_back( osg::Vec4( 1.0, 1.0, 1.0, alpha ) ); 296 } 297 298 299 // per-vertex normals calculated as average of primitive normals 300 // from contributing triangles 352 301 _stagevertexnormals = new osg::Vec3Array; 353 302 int num_shared_triangles, triangle_index; … … 355 304 { 356 305 nrm.set(0,0,0); 357 num_shared_triangles = stageconnectivity.at(iv).size();306 num_shared_triangles = _connectivity.at(iv).size(); 358 307 for (int i=0; i<num_shared_triangles; i++ ) 359 308 { 360 triangle_index = stageconnectivity.at(iv).at(i); 361 362 // summing of contributing primitive normals 309 triangle_index = _connectivity.at(iv).at(i); 363 310 nrm += _stageprimitivenormals->at(triangle_index); 364 311 } 365 312 366 // FIXME: Length of this list has to match vertex list length. 367 // We have vertices and normals that aren't being referenced. 368 if( 1 || num_shared_triangles ) // avoid vertices belonging only to culled triangles 369 { 370 nrm = nrm / num_shared_triangles; // average 371 nrm.normalize(); 372 _stagevertexnormals->push_back(nrm); 373 } 313 nrm = nrm / num_shared_triangles; // average 314 nrm.normalize(); 315 _stagevertexnormals->push_back(nrm); 374 316 } 375 317
Note: See TracChangeset
for help on using the changeset viewer.