| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | #include <osgDB/ReadFile> |
|---|
| 13 | #include <osgDB/FileUtils> |
|---|
| 14 | #include <osgUtil/Optimizer> |
|---|
| 15 | #include <osgUtil/CullVisitor> |
|---|
| 16 | #include <osgProducer/Viewer> |
|---|
| 17 | |
|---|
| 18 | #include <osg/MatrixTransform> |
|---|
| 19 | #include <osgUtil/TransformCallback> |
|---|
| 20 | #include <osgParticle/PrecipitationEffect> |
|---|
| 21 | |
|---|
| 22 | class MyGustCallback : public osg::NodeCallback |
|---|
| 23 | { |
|---|
| 24 | |
|---|
| 25 | public: |
|---|
| 26 | |
|---|
| 27 | MyGustCallback() {} |
|---|
| 28 | |
|---|
| 29 | virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) |
|---|
| 30 | { |
|---|
| 31 | osgParticle::PrecipitationEffect* pe = dynamic_cast<osgParticle::PrecipitationEffect*>(node); |
|---|
| 32 | |
|---|
| 33 | float value = sin(nv->getFrameStamp()->getReferenceTime()); |
|---|
| 34 | if (value<-0.5) |
|---|
| 35 | { |
|---|
| 36 | pe->snow(1.0); |
|---|
| 37 | } |
|---|
| 38 | else |
|---|
| 39 | { |
|---|
| 40 | pe->rain(0.5); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | traverse(node, nv); |
|---|
| 44 | } |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | int main( int argc, char **argv ) |
|---|
| 49 | { |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
|---|
| 56 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example provides an interactive viewer for visualising point clouds.."); |
|---|
| 57 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 58 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 59 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 60 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 61 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 62 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 63 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 64 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 65 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 66 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 67 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 68 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | osgProducer::Viewer viewer(arguments); |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 79 | |
|---|
| 80 | osg::ref_ptr<osgParticle::PrecipitationEffect> precipitationEffect = new osgParticle::PrecipitationEffect; |
|---|
| 81 | |
|---|
| 82 | float intensity; |
|---|
| 83 | while (arguments.read("--snow", intensity)) precipitationEffect->snow(intensity); |
|---|
| 84 | while (arguments.read("--rain", intensity)) precipitationEffect->rain(intensity); |
|---|
| 85 | |
|---|
| 86 | float value; |
|---|
| 87 | while (arguments.read("--particleSize", value)) precipitationEffect->setParticleSize(value); |
|---|
| 88 | |
|---|
| 89 | osg::Vec4 color; |
|---|
| 90 | while (arguments.read("--particleColor", color.r(), color.g(), color.b(), color.a())) precipitationEffect->setParticleColor(color); |
|---|
| 91 | while (arguments.read("--particleColour", color.r(), color.g(), color.b(), color.a())) precipitationEffect->setParticleColor(color); |
|---|
| 92 | |
|---|
| 93 | osg::Vec3 wind; |
|---|
| 94 | while (arguments.read("--wind", wind.x(), wind.y(), wind.z())) precipitationEffect->setWind(wind); |
|---|
| 95 | |
|---|
| 96 | while (arguments.read("--particleSpeed", value)) precipitationEffect->setParticleSpeed(value); |
|---|
| 97 | |
|---|
| 98 | while (arguments.read("--nearTransition", value )) precipitationEffect->setNearTransition(value); |
|---|
| 99 | while (arguments.read("--farTransition", value )) precipitationEffect->setFarTransition(value); |
|---|
| 100 | |
|---|
| 101 | while (arguments.read("--particleDensity", value )) precipitationEffect->setMaximumParticleDensity(value); |
|---|
| 102 | |
|---|
| 103 | osg::Vec3 cellSize; |
|---|
| 104 | while (arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z())) precipitationEffect->setCellSize(cellSize); |
|---|
| 105 | |
|---|
| 106 | osg::BoundingBox bb; |
|---|
| 107 | while (arguments.read("--boundingBox", bb.xMin(), |
|---|
| 108 | bb.yMin(), |
|---|
| 109 | bb.zMin(), |
|---|
| 110 | bb.xMax(), |
|---|
| 111 | bb.yMax(), |
|---|
| 112 | bb.zMax())) {} |
|---|
| 113 | |
|---|
| 114 | while (arguments.read("--fogDensity", value )) precipitationEffect->getFog()->setDensity(value); |
|---|
| 115 | while (arguments.read("--fogColor", color.r(), color.g(), color.b(), color.a() )) precipitationEffect->getFog()->setColor(color); |
|---|
| 116 | while (arguments.read("--fogColour", color.r(), color.g(), color.b(), color.a() )) precipitationEffect->getFog()->setColor(color); |
|---|
| 117 | |
|---|
| 118 | while (arguments.read("--useFarLineSegments")) { precipitationEffect->setUseFarLineSegments(true); } |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | viewer.setClearColor( precipitationEffect->getFog()->getColor() ); |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 126 | { |
|---|
| 127 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 128 | return 1; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | if (arguments.errors()) |
|---|
| 136 | { |
|---|
| 137 | arguments.writeErrorMessages(std::cout); |
|---|
| 138 | return 1; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 143 | if (!loadedModel) |
|---|
| 144 | { |
|---|
| 145 | std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; |
|---|
| 146 | return 1; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | osg::ref_ptr<osg::Group> group = new osg::Group; |
|---|
| 153 | group->addChild(precipitationEffect.get()); |
|---|
| 154 | |
|---|
| 155 | group->addChild(loadedModel.get()); |
|---|
| 156 | loadedModel->getOrCreateStateSet()->setAttributeAndModes(precipitationEffect->getFog()); |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | osg::LightSource* lightSource = new osg::LightSource; |
|---|
| 160 | group->addChild(lightSource); |
|---|
| 161 | |
|---|
| 162 | osg::Light* light = lightSource->getLight(); |
|---|
| 163 | light->setLightNum(0); |
|---|
| 164 | light->setPosition(osg::Vec4(0.0f,0.0f,1.0f,0.0f)); |
|---|
| 165 | light->setAmbient(osg::Vec4(0.8f,0.8f,0.8f,1.0f)); |
|---|
| 166 | light->setDiffuse(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); |
|---|
| 167 | light->setSpecular(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | viewer.setSceneData(group.get()); |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | viewer.realize(); |
|---|
| 175 | |
|---|
| 176 | while( !viewer.done() ) |
|---|
| 177 | { |
|---|
| 178 | |
|---|
| 179 | viewer.sync(); |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | viewer.update(); |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | viewer.frame(); |
|---|
| 187 | |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | viewer.sync(); |
|---|
| 192 | |
|---|
| 193 | return 0; |
|---|
| 194 | } |
|---|