| 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->getParameters()->wind.set(5.0,0.0,0.0); |
|---|
| 35 | else pe->getParameters()->wind.set(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 | osgParticle::PrecipitationParameters& parameters = *precipitationEffect->getParameters(); |
|---|
| 134 | |
|---|
| 135 | float intensity; |
|---|
| 136 | while (arguments.read("--snow", intensity)) parameters.snow(intensity); |
|---|
| 137 | while (arguments.read("--rain", intensity)) parameters.rain(intensity); |
|---|
| 138 | |
|---|
| 139 | while (arguments.read("--particleSize", parameters.particleSize)) {} |
|---|
| 140 | while (arguments.read("--particleColor", parameters.particleColour.r(), parameters.particleColour.g(), parameters.particleColour.b(), parameters.particleColour.a())) {} |
|---|
| 141 | while (arguments.read("--particleColour", parameters.particleColour.r(), parameters.particleColour.g(), parameters.particleColour.b(), parameters.particleColour.a())) {} |
|---|
| 142 | |
|---|
| 143 | osg::Vec3 wind; |
|---|
| 144 | while (arguments.read("--wind", wind.x(), wind.y(), wind.z())) parameters.wind = wind; |
|---|
| 145 | |
|---|
| 146 | while (arguments.read("--particleVelocity", parameters.particleVelocity)) {} |
|---|
| 147 | |
|---|
| 148 | while (arguments.read("--nearTransition", parameters.nearTransition )) {} |
|---|
| 149 | while (arguments.read("--farTransition", parameters.farTransition )) {} |
|---|
| 150 | |
|---|
| 151 | while (arguments.read("--particleDensity", parameters.particleDensity )) {} |
|---|
| 152 | |
|---|
| 153 | while (arguments.read("--cellSizeX", parameters.cellSizeX )) {} |
|---|
| 154 | while (arguments.read("--cellSizeY", parameters.cellSizeY )) {} |
|---|
| 155 | while (arguments.read("--cellSizeZ", parameters.cellSizeZ )) {} |
|---|
| 156 | |
|---|
| 157 | while (arguments.read("--boundingBox", parameters.boundingBox.xMin(), |
|---|
| 158 | parameters.boundingBox.yMin(), |
|---|
| 159 | parameters.boundingBox.zMin(), |
|---|
| 160 | parameters.boundingBox.xMax(), |
|---|
| 161 | parameters.boundingBox.yMax(), |
|---|
| 162 | parameters.boundingBox.zMax())) {} |
|---|
| 163 | |
|---|
| 164 | while (arguments.read("--fogDensity", parameters.fogDensity )) {} |
|---|
| 165 | while (arguments.read("--fogExponent", parameters.fogExponent )) {} |
|---|
| 166 | while (arguments.read("--fogEnd", parameters.fogEnd )) {} |
|---|
| 167 | while (arguments.read("--fogColor", parameters.fogColour.r(), parameters.fogColour.g(), parameters.fogColour.b(), parameters.fogColour.a())) {} |
|---|
| 168 | while (arguments.read("--fogColour", parameters.fogColour.r(), parameters.fogColour.g(), parameters.fogColour.b(), parameters.fogColour.a())) {} |
|---|
| 169 | |
|---|
| 170 | while (arguments.read("--useFarLineSegments")) { parameters.useFarLineSegments = true; } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | viewer.setClearColor(parameters.clearColour); |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | precipitationEffect->update(); |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 183 | { |
|---|
| 184 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 185 | return 1; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | if (arguments.errors()) |
|---|
| 193 | { |
|---|
| 194 | arguments.writeErrorMessages(std::cout); |
|---|
| 195 | return 1; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 200 | if (!loadedModel) |
|---|
| 201 | { |
|---|
| 202 | std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; |
|---|
| 203 | return 1; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | osg::ref_ptr<osg::Group> group = new osg::Group; |
|---|
| 209 | group->addChild(precipitationEffect.get()); |
|---|
| 210 | group->addChild(loadedModel.get()); |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | viewer.setSceneData(group.get()); |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | viewer.realize(); |
|---|
| 217 | |
|---|
| 218 | while( !viewer.done() ) |
|---|
| 219 | { |
|---|
| 220 | |
|---|
| 221 | viewer.sync(); |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | viewer.update(); |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | viewer.frame(); |
|---|
| 229 | |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | viewer.sync(); |
|---|
| 234 | |
|---|
| 235 | return 0; |
|---|
| 236 | } |
|---|