diff --git a/include/osgShadow/OccluderGeometry b/include/osgShadow/OccluderGeometry index 3bc022d6d..e24a22708 100644 --- a/include/osgShadow/OccluderGeometry +++ b/include/osgShadow/OccluderGeometry @@ -93,10 +93,14 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable ( delta * _triangleNormals[edge._t2] ); } + void setUpInternalStructures(); - void removeDuplicates(); + void removeDuplicateVertices(); + void computeNormals(); + void buildEdgeMaps(); Vec3List _vertices; + Vec3List _normals; Vec3List _triangleNormals; UIntList _triangleIndices; diff --git a/src/osgShadow/OccluderGeometry.cpp b/src/osgShadow/OccluderGeometry.cpp index 2f2ea21b3..0213f1b7e 100644 --- a/src/osgShadow/OccluderGeometry.cpp +++ b/src/osgShadow/OccluderGeometry.cpp @@ -156,9 +156,7 @@ void OccluderGeometry::computeOccluderGeometry(osg::Node* subgraph, osg::Matrix* CollectOccludersVisitor cov(this, matrix, sampleRatio); subgraph->accept(cov); - removeDuplicates(); - - dirtyDisplayList(); + setUpInternalStructures(); osg::Timer_t endTick = osg::Timer::instance()->tick(); @@ -169,9 +167,7 @@ void OccluderGeometry::computeOccluderGeometry(osg::Drawable* drawable, osg::Mat { processGeometry(drawable, matrix, sampleRatio); - removeDuplicates(); - - dirtyDisplayList(); + setUpInternalStructures(); } struct TriangleCollector @@ -302,6 +298,17 @@ void OccluderGeometry::processGeometry(osg::Drawable* drawable, osg::Matrix* mat #endif } +void OccluderGeometry::setUpInternalStructures() +{ + removeDuplicateVertices(); + + computeNormals(); + + buildEdgeMaps(); + + dirtyDisplayList(); +} + struct IndexVec3PtrPair { IndexVec3PtrPair(): @@ -326,7 +333,7 @@ struct IndexVec3PtrPair unsigned int index; }; -void OccluderGeometry::removeDuplicates() +void OccluderGeometry::removeDuplicateVertices() { if (_vertices.empty()) return; @@ -420,6 +427,58 @@ void OccluderGeometry::removeDuplicates() osg::notify(osg::NOTICE)<<"OccluderGeometry::removeDuplicates() after = "<<_vertices.size()<normalize(); + } + + +} + +void OccluderGeometry::buildEdgeMaps() +{ + osg::notify(osg::NOTICE)<<"OccluderGeometry::buildEdgeMaps()"<disableAllVertexArrays(); renderInfo.getState()->setVertexPointer( 3, GL_FLOAT, 0, &(_vertices.front()) ); + + if (!_normals.empty()) + { + renderInfo.getState()->setNormalPointer( GL_FLOAT, 0, &(_normals.front()) ); + } glDrawElements(GL_TRIANGLES, _triangleIndices.size(), GL_UNSIGNED_INT, &(_triangleIndices.front()) ); }