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