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