| 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) pe->setWind(osg::Vec3(5.0f,0.0f,0.0f)); |
|---|
| 35 | else pe->setWind(osg::Vec3(1.0,0.0,0.0)); |
|---|
| 36 | |
|---|
| 37 | traverse(node, nv); |
|---|
| 38 | } |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | #if 0 |
|---|
| 42 | osg::Node* createModel(osg::Node* loadedModel, osgParticle::PrecipitationParameters& parameters) |
|---|
| 43 | { |
|---|
| 44 | osg::Group* group = new osg::Group; |
|---|
| 45 | |
|---|
| 46 | osg::BoundingBox bb(0.0, 0.0, 0.0, 100.0, 100.0, 100.0); |
|---|
| 47 | |
|---|
| 48 | if (loadedModel) |
|---|
| 49 | { |
|---|
| 50 | group->addChild(loadedModel); |
|---|
| 51 | |
|---|
| 52 | osg::BoundingSphere bs = loadedModel->getBound(); |
|---|
| 53 | |
|---|
| 54 | bb.set( -500, -500, 0, +500, +500, 10); |
|---|
| 55 | |
|---|
| 56 | parameters.boundingBox = bb; |
|---|
| 57 | |
|---|
| 58 | osg::StateSet* stateset = loadedModel->getOrCreateStateSet(); |
|---|
| 59 | |
|---|
| 60 | osg::Fog* fog = new osg::Fog; |
|---|
| 61 | |
|---|
| 62 | if (parameters.fogExponent<1.0) |
|---|
| 63 | { |
|---|
| 64 | fog->setMode(osg::Fog::LINEAR); |
|---|
| 65 | } |
|---|
| 66 | else if (parameters.fogExponent<2.0) |
|---|
| 67 | { |
|---|
| 68 | fog->setMode(osg::Fog::EXP); |
|---|
| 69 | } |
|---|
| 70 | else |
|---|
| 71 | { |
|---|
| 72 | fog->setMode(osg::Fog::EXP2); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | fog->setDensity(parameters.fogDensity); |
|---|
| 76 | fog->setStart(0.0f); |
|---|
| 77 | fog->setEnd(parameters.fogEnd); |
|---|
| 78 | fog->setColor(parameters.fogColour); |
|---|
| 79 | stateset->setAttributeAndModes(fog, osg::StateAttribute::ON); |
|---|
| 80 | |
|---|
| 81 | osg::LightSource* lightSource = new osg::LightSource; |
|---|
| 82 | group->addChild(lightSource); |
|---|
| 83 | |
|---|
| 84 | osg::Light* light = lightSource->getLight(); |
|---|
| 85 | light->setLightNum(0); |
|---|
| 86 | light->setPosition(osg::Vec4(0.0f,0.0f,1.0f,0.0f)); |
|---|
| 87 | light->setAmbient(osg::Vec4(0.8f,0.8f,0.8f,1.0f)); |
|---|
| 88 | light->setDiffuse(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); |
|---|
| 89 | light->setSpecular(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | group->addChild(createCellRainEffect(parameters)); |
|---|
| 95 | |
|---|
| 96 | return group; |
|---|
| 97 | } |
|---|
| 98 | #endif |
|---|
| 99 | |
|---|
| 100 | int main( int argc, char **argv ) |
|---|
| 101 | { |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
|---|
| 108 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example provides an interactive viewer for visualising point clouds.."); |
|---|
| 109 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 110 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 111 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 112 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 113 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 114 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 115 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 116 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 117 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 118 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 119 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 120 | arguments.getApplicationUsage()->addCommandLineOption("",""); |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | osgProducer::Viewer viewer(arguments); |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 131 | |
|---|
| 132 | osg::ref_ptr<osgParticle::PrecipitationEffect> precipitationEffect = new osgParticle::PrecipitationEffect; |
|---|
| 133 | |
|---|
| 134 | float intensity; |
|---|
| 135 | while (arguments.read("--snow", intensity)) precipitationEffect->snow(intensity); |
|---|
| 136 | while (arguments.read("--rain", intensity)) precipitationEffect->rain(intensity); |
|---|
| 137 | |
|---|
| 138 | float value; |
|---|
| 139 | while (arguments.read("--particleSize", value)) precipitationEffect->setParticleSize(value); |
|---|
| 140 | |
|---|
| 141 | osg::Vec4 color; |
|---|
| 142 | while (arguments.read("--particleColor", color.r(), color.g(), color.b(), color.a())) precipitationEffect->setParticleColor(color); |
|---|
| 143 | while (arguments.read("--particleColour", color.r(), color.g(), color.b(), color.a())) precipitationEffect->setParticleColor(color); |
|---|
| 144 | |
|---|
| 145 | osg::Vec3 wind; |
|---|
| 146 | while (arguments.read("--wind", wind.x(), wind.y(), wind.z())) precipitationEffect->setWind(wind); |
|---|
| 147 | |
|---|
| 148 | while (arguments.read("--particleSpeed", value)) precipitationEffect->setParticleSpeed(value); |
|---|
| 149 | |
|---|
| 150 | while (arguments.read("--nearTransition", value )) precipitationEffect->setNearTransition(value); |
|---|
| 151 | while (arguments.read("--farTransition", value )) precipitationEffect->setFarTransition(value); |
|---|
| 152 | |
|---|
| 153 | while (arguments.read("--particleDensity", value )) precipitationEffect->setMaximumParticleDensity(value); |
|---|
| 154 | |
|---|
| 155 | osg::Vec3 cellSize; |
|---|
| 156 | while (arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z())) precipitationEffect->setCellSize(cellSize); |
|---|
| 157 | |
|---|
| 158 | osg::BoundingBox bb; |
|---|
| 159 | while (arguments.read("--boundingBox", bb.xMin(), |
|---|
| 160 | bb.yMin(), |
|---|
| 161 | bb.zMin(), |
|---|
| 162 | bb.xMax(), |
|---|
| 163 | bb.yMax(), |
|---|
| 164 | bb.zMax())) {} |
|---|
| 165 | |
|---|
| 166 | while (arguments.read("--fogDensity", value )) precipitationEffect->getFog()->setDensity(value); |
|---|
| 167 | while (arguments.read("--fogColor", color.r(), color.g(), color.b(), color.a() )) precipitationEffect->getFog()->setColor(color); |
|---|
| 168 | while (arguments.read("--fogColour", color.r(), color.g(), color.b(), color.a() )) precipitationEffect->getFog()->setColor(color); |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | viewer.setClearColor( precipitationEffect->getFog()->getColor() ); |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | precipitationEffect->update(); |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 181 | { |
|---|
| 182 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 183 | return 1; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | if (arguments.errors()) |
|---|
| 191 | { |
|---|
| 192 | arguments.writeErrorMessages(std::cout); |
|---|
| 193 | return 1; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 198 | if (!loadedModel) |
|---|
| 199 | { |
|---|
| 200 | std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; |
|---|
| 201 | return 1; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | osg::ref_ptr<osg::Group> group = new osg::Group; |
|---|
| 208 | group->addChild(precipitationEffect.get()); |
|---|
| 209 | |
|---|
| 210 | group->addChild(loadedModel.get()); |
|---|
| 211 | loadedModel->getOrCreateStateSet()->setAttributeAndModes(precipitationEffect->getFog()); |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | osg::LightSource* lightSource = new osg::LightSource; |
|---|
| 215 | group->addChild(lightSource); |
|---|
| 216 | |
|---|
| 217 | osg::Light* light = lightSource->getLight(); |
|---|
| 218 | light->setLightNum(0); |
|---|
| 219 | light->setPosition(osg::Vec4(0.0f,0.0f,1.0f,0.0f)); |
|---|
| 220 | light->setAmbient(osg::Vec4(0.8f,0.8f,0.8f,1.0f)); |
|---|
| 221 | light->setDiffuse(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); |
|---|
| 222 | light->setSpecular(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | viewer.setSceneData(group.get()); |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | viewer.realize(); |
|---|
| 232 | |
|---|
| 233 | while( !viewer.done() ) |
|---|
| 234 | { |
|---|
| 235 | |
|---|
| 236 | viewer.sync(); |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | viewer.update(); |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | viewer.frame(); |
|---|
| 244 | |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | viewer.sync(); |
|---|
| 249 | |
|---|
| 250 | return 0; |
|---|
| 251 | } |
|---|