| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #ifndef SLIDESHOWCONSTRUCTOR |
|---|
| 14 | #define SLIDESHOWCONSTRUCTOR |
|---|
| 15 | |
|---|
| 16 | #include <osg/Vec3> |
|---|
| 17 | #include <osg/Vec4> |
|---|
| 18 | #include <osg/Group> |
|---|
| 19 | #include <osg/ClearNode> |
|---|
| 20 | #include <osg/Switch> |
|---|
| 21 | #include <osg/AnimationPath> |
|---|
| 22 | #include <osg/ImageStream> |
|---|
| 23 | #include <osgText/Text> |
|---|
| 24 | #include <osgGA/GUIEventAdapter> |
|---|
| 25 | |
|---|
| 26 | #include <osgDB/FileUtils> |
|---|
| 27 | |
|---|
| 28 | #include "AnimationMaterial.h" |
|---|
| 29 | #include "SlideEventHandler.h" |
|---|
| 30 | |
|---|
| 31 | namespace osgPresentation |
|---|
| 32 | { |
|---|
| 33 | |
|---|
| 34 | class SlideShowConstructor |
|---|
| 35 | { |
|---|
| 36 | public: |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | enum CoordinateFrame { SLIDE, MODEL }; |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | LayerAttributes* getOrCreateLayerAttributes(osg::Node* node); |
|---|
| 43 | |
|---|
| 44 | void setDuration(osg::Node* node,double duration) |
|---|
| 45 | { |
|---|
| 46 | getOrCreateLayerAttributes(node)->setDuration(duration); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | void addKey(osg::Node* node,const KeyPosition& kp) |
|---|
| 50 | { |
|---|
| 51 | getOrCreateLayerAttributes(node)->addKey(kp); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void addRunString(osg::Node* node, const std::string& runString) |
|---|
| 55 | { |
|---|
| 56 | getOrCreateLayerAttributes(node)->addRunString(runString); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | void setJump(osg::Node* node, bool relativeJump, int slideNum, int layerNum) |
|---|
| 60 | { |
|---|
| 61 | getOrCreateLayerAttributes(node)->setJump(relativeJump, slideNum, layerNum); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | void addPresentationKey(const KeyPosition& kp) |
|---|
| 65 | { |
|---|
| 66 | if (!_presentationSwitch) createPresentation(); |
|---|
| 67 | if (_presentationSwitch.valid()) addKey( _presentationSwitch.get(), kp); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | void addPresentationRunString(const std::string& runString) |
|---|
| 71 | { |
|---|
| 72 | if (!_presentationSwitch) createPresentation(); |
|---|
| 73 | if (_presentationSwitch.valid()) addRunString( _presentationSwitch.get(),runString); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | void addSlideKey(const KeyPosition& kp) |
|---|
| 77 | { |
|---|
| 78 | if (!_slide) addSlide(); |
|---|
| 79 | if (_slide.valid()) addKey(_slide.get(),kp); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void addSlideRunString(const std::string& runString) |
|---|
| 83 | { |
|---|
| 84 | if (!_slide) addSlide(); |
|---|
| 85 | if (_slide.valid()) addRunString(_slide.get(),runString); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void setSlideJump(bool relativeJump, int switchNum, int layerNum) |
|---|
| 89 | { |
|---|
| 90 | if (!_slide) addSlide(); |
|---|
| 91 | if (_slide.valid()) setJump(_slide.get(),relativeJump, switchNum, layerNum); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | void addLayerKey(const KeyPosition& kp) |
|---|
| 95 | { |
|---|
| 96 | if (!_currentLayer) addLayer(); |
|---|
| 97 | if (_currentLayer.valid()) addKey(_currentLayer.get(),kp); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | void addLayerRunString(const std::string& runString) |
|---|
| 101 | { |
|---|
| 102 | if (!_currentLayer) addLayer(); |
|---|
| 103 | if (_currentLayer.valid()) addRunString(_currentLayer.get(),runString); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | void setLayerJump(bool relativeJump, int switchNum, int layerNum) |
|---|
| 108 | { |
|---|
| 109 | if (!_currentLayer) addLayer(); |
|---|
| 110 | if (_currentLayer.valid()) setJump(_currentLayer.get(),relativeJump, switchNum, layerNum); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | struct PositionData |
|---|
| 116 | { |
|---|
| 117 | PositionData(): |
|---|
| 118 | frame(SlideShowConstructor::SLIDE), |
|---|
| 119 | position(0.0f,1.0f,0.0f), |
|---|
| 120 | |
|---|
| 121 | scale(1.0f,1.0f,1.0f), |
|---|
| 122 | rotate(0.0f,0.0f,0.0f,1.0f), |
|---|
| 123 | rotation(0.0f,0.0f,1.0f,0.0f), |
|---|
| 124 | absolute_path(false), |
|---|
| 125 | inverse_path(false), |
|---|
| 126 | path_time_offset(0.0), |
|---|
| 127 | path_time_multiplier(1.0f), |
|---|
| 128 | path_loop_mode(osg::AnimationPath::NO_LOOPING), |
|---|
| 129 | animation_material_time_offset(0.0), |
|---|
| 130 | animation_material_time_multiplier(1.0), |
|---|
| 131 | animation_material_loop_mode(ss3d::AnimationMaterial::NO_LOOPING) {} |
|---|
| 132 | |
|---|
| 133 | bool requiresPosition() const |
|---|
| 134 | { |
|---|
| 135 | return (position[0]!=0.0f || position[1]!=1.0f || position[2]!=1.0f); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | bool requiresScale() const |
|---|
| 139 | { |
|---|
| 140 | return (scale[0]!=1.0f || scale[1]!=1.0f || scale[2]!=1.0f); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | bool requiresRotate() const |
|---|
| 144 | { |
|---|
| 145 | return rotate[0]!=0.0f; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | bool requiresAnimation() const |
|---|
| 149 | { |
|---|
| 150 | return (rotation[0]!=0.0f || !path.empty()); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | bool requiresMaterialAnimation() const |
|---|
| 154 | { |
|---|
| 155 | return !animation_material_filename.empty() || !fade.empty(); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | CoordinateFrame frame; |
|---|
| 159 | osg::Vec3 position; |
|---|
| 160 | osg::Vec3 scale; |
|---|
| 161 | osg::Vec4 rotate; |
|---|
| 162 | osg::Vec4 rotation; |
|---|
| 163 | std::string animation_name; |
|---|
| 164 | bool absolute_path; |
|---|
| 165 | bool inverse_path; |
|---|
| 166 | double path_time_offset; |
|---|
| 167 | double path_time_multiplier; |
|---|
| 168 | osg::AnimationPath::LoopMode path_loop_mode; |
|---|
| 169 | std::string path; |
|---|
| 170 | double animation_material_time_offset; |
|---|
| 171 | double animation_material_time_multiplier; |
|---|
| 172 | ss3d::AnimationMaterial::LoopMode animation_material_loop_mode; |
|---|
| 173 | std::string animation_material_filename; |
|---|
| 174 | std::string fade; |
|---|
| 175 | }; |
|---|
| 176 | |
|---|
| 177 | struct ModelData |
|---|
| 178 | { |
|---|
| 179 | ModelData(): |
|---|
| 180 | effect("") {} |
|---|
| 181 | |
|---|
| 182 | std::string effect; |
|---|
| 183 | }; |
|---|
| 184 | |
|---|
| 185 | struct ImageData |
|---|
| 186 | { |
|---|
| 187 | ImageData(): |
|---|
| 188 | width(1.0f), |
|---|
| 189 | height(1.0f), |
|---|
| 190 | region(0.0f,0.0f,1.0f,1.0f), |
|---|
| 191 | region_in_pixel_coords(false), |
|---|
| 192 | texcoord_rotate(0.0f), |
|---|
| 193 | loopingMode(osg::ImageStream::NO_LOOPING), |
|---|
| 194 | page(-1), |
|---|
| 195 | backgroundColor(1.0f,1.0f,1.0f,1.0f) {} |
|---|
| 196 | |
|---|
| 197 | float width; |
|---|
| 198 | float height; |
|---|
| 199 | osg::Vec4 region; |
|---|
| 200 | bool region_in_pixel_coords; |
|---|
| 201 | float texcoord_rotate; |
|---|
| 202 | osg::ImageStream::LoopingMode loopingMode; |
|---|
| 203 | int page; |
|---|
| 204 | osg::Vec4 backgroundColor; |
|---|
| 205 | }; |
|---|
| 206 | |
|---|
| 207 | struct FontData |
|---|
| 208 | { |
|---|
| 209 | FontData(): |
|---|
| 210 | font("fonts/arial.ttf"), |
|---|
| 211 | layout(osgText::Text::LEFT_TO_RIGHT), |
|---|
| 212 | alignment(osgText::Text::LEFT_BASE_LINE), |
|---|
| 213 | axisAlignment(osgText::Text::XZ_PLANE), |
|---|
| 214 | characterSize(0.04f), |
|---|
| 215 | maximumHeight(1.0f), |
|---|
| 216 | maximumWidth(1.0f), |
|---|
| 217 | color(1.0f,1.0f,1.0f,1.0f) {} |
|---|
| 218 | |
|---|
| 219 | std::string font; |
|---|
| 220 | osgText::Text::Layout layout; |
|---|
| 221 | osgText::Text::AlignmentType alignment; |
|---|
| 222 | osgText::Text::AxisAlignment axisAlignment; |
|---|
| 223 | float characterSize; |
|---|
| 224 | float maximumHeight; |
|---|
| 225 | float maximumWidth; |
|---|
| 226 | osg::Vec4 color; |
|---|
| 227 | }; |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | SlideShowConstructor(); |
|---|
| 231 | |
|---|
| 232 | void createPresentation(); |
|---|
| 233 | |
|---|
| 234 | void setBackgroundColor(const osg::Vec4& color, bool updateClearNode); |
|---|
| 235 | const osg::Vec4& getBackgroundColor() const { return _backgroundColor; } |
|---|
| 236 | |
|---|
| 237 | void setTextColor(const osg::Vec4& color); |
|---|
| 238 | const osg::Vec4& getTextColor() const { return _textFontDataDefault.color; } |
|---|
| 239 | |
|---|
| 240 | void setPresentationName(const std::string& name); |
|---|
| 241 | |
|---|
| 242 | void setPresentationAspectRatio(float aspectRatio); |
|---|
| 243 | |
|---|
| 244 | void setPresentationAspectRatio(const std::string& str); |
|---|
| 245 | |
|---|
| 246 | void setPresentationDuration(double duration); |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | void addSlide(); |
|---|
| 250 | |
|---|
| 251 | void selectSlide(int slideNum); |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | void setSlideTitle(const std::string& name, PositionData& positionData, FontData& fontData) |
|---|
| 255 | { |
|---|
| 256 | _titlePositionData = positionData; |
|---|
| 257 | _titleFontData = fontData; |
|---|
| 258 | _slideTitle = name; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | void setSlideBackground(const std::string& name) { _slideBackgroundImageFileName = name; } |
|---|
| 262 | |
|---|
| 263 | void setSlideDuration(double duration); |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | void addLayer(bool inheritPreviousLayers=true, bool defineAsBaseLayer=false); |
|---|
| 267 | |
|---|
| 268 | void selectLayer(int layerNum); |
|---|
| 269 | |
|---|
| 270 | void setLayerDuration(double duration); |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | FontData& getTitleFontData() { return _titleFontData; } |
|---|
| 275 | FontData& getTitleFontDataDefault() { return _titleFontDataDefault; } |
|---|
| 276 | |
|---|
| 277 | PositionData& getTitlePositionData() { return _titlePositionData; } |
|---|
| 278 | PositionData& getTitlePositionDataDefault() { return _titlePositionDataDefault; } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | FontData& getTextFontData() { return _textFontData; } |
|---|
| 282 | FontData& getTextFontDataDefault() { return _textFontDataDefault; } |
|---|
| 283 | |
|---|
| 284 | PositionData& getTextPositionData() { return _textPositionData; } |
|---|
| 285 | PositionData& getTextPositionDataDefault() { return _textPositionDataDefault; } |
|---|
| 286 | |
|---|
| 287 | void translateTextCursor(const osg::Vec3& delta) { _textPositionData.position += delta; } |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | PositionData& getImagePositionData() { return _imagePositionData; } |
|---|
| 291 | PositionData& getImagePositionDataDefault() { return _imagePositionDataDefault; } |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | PositionData& getModelPositionData() { return _modelPositionData; } |
|---|
| 295 | PositionData& getModelPositionDataDefault() { return _modelPositionDataDefault; } |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | void layerClickToDoOperation(Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); |
|---|
| 299 | void layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); |
|---|
| 300 | void layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); |
|---|
| 301 | |
|---|
| 302 | void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData); |
|---|
| 303 | |
|---|
| 304 | void addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData); |
|---|
| 305 | |
|---|
| 306 | void addImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData); |
|---|
| 307 | |
|---|
| 308 | void addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight,const ImageData& imageDataRight, const PositionData& positionData); |
|---|
| 309 | |
|---|
| 310 | void addVNC(const std::string& filename,const PositionData& positionData, const ImageData& imageData); |
|---|
| 311 | void addBrowser(const std::string& filename,const PositionData& positionData, const ImageData& imageData); |
|---|
| 312 | void addPDF(const std::string& filename,const PositionData& positionData, const ImageData& imageData); |
|---|
| 313 | osg::Image* addInteractiveImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData); |
|---|
| 314 | |
|---|
| 315 | void addModel(osg::Node* subgraph, const PositionData& positionData, const ModelData& modelData); |
|---|
| 316 | |
|---|
| 317 | void addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData); |
|---|
| 318 | |
|---|
| 319 | void addVolume(const std::string& filename, const PositionData& positionData); |
|---|
| 320 | |
|---|
| 321 | osg::Group* takePresentation() { return _root.release(); } |
|---|
| 322 | |
|---|
| 323 | osg::Group* getPresentation() { return _root.get(); } |
|---|
| 324 | |
|---|
| 325 | osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); } |
|---|
| 326 | |
|---|
| 327 | osg::Switch* getCurrentSlide() { return _slide.get(); } |
|---|
| 328 | |
|---|
| 329 | osg::Group* getCurrentLayer() { return _currentLayer.get(); } |
|---|
| 330 | |
|---|
| 331 | void setLoopPresentation(bool loop) { _loopPresentation = loop; } |
|---|
| 332 | bool getLoopPresentation() const { return _loopPresentation; } |
|---|
| 333 | |
|---|
| 334 | void setAutoSteppingActive(bool flag = true) { _autoSteppingActive = flag; } |
|---|
| 335 | bool getAutoSteppingActive() const { return _autoSteppingActive; } |
|---|
| 336 | |
|---|
| 337 | protected: |
|---|
| 338 | |
|---|
| 339 | void findImageStreamsAndAddCallbacks(osg::Node* node); |
|---|
| 340 | |
|---|
| 341 | osg::Geometry* createTexturedQuadGeometry(const osg::Vec3& pos, const osg::Vec4& rotation, float width,float height, osg::Image* image, bool& usedTextureRectangle); |
|---|
| 342 | |
|---|
| 343 | osg::Vec3 computePositionInModelCoords(const PositionData& positionData) const; |
|---|
| 344 | void updatePositionFromInModelCoords(const osg::Vec3& vertex, PositionData& positionData) const; |
|---|
| 345 | |
|---|
| 346 | osg::Vec3 convertSlideToModel(const osg::Vec3& position) const; |
|---|
| 347 | osg::Vec3 convertModelToSlide(const osg::Vec3& position) const; |
|---|
| 348 | |
|---|
| 349 | osg::AnimationPath* readPivotPath(const std::string& filename) const; |
|---|
| 350 | osg::AnimationPath* readRotationPath(const std::string& filename) const; |
|---|
| 351 | |
|---|
| 352 | osg::AnimationPathCallback* getAnimationPathCallback(const PositionData& positionData); |
|---|
| 353 | |
|---|
| 354 | osg::Node* attachMaterialAnimation(osg::Node* model, const PositionData& positionData); |
|---|
| 355 | bool attachTexMat(osg::StateSet* stateset, const ImageData& imageData, float s, float t, bool textureRectangle); |
|---|
| 356 | |
|---|
| 357 | osg::StateSet* createTransformStateSet() |
|---|
| 358 | { |
|---|
| 359 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 360 | stateset->setMode(GL_NORMALIZE,osg::StateAttribute::ON); |
|---|
| 361 | return stateset; |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | osg::Vec3 _slideOrigin; |
|---|
| 365 | osg::Vec3 _eyeOrigin; |
|---|
| 366 | float _slideWidth; |
|---|
| 367 | float _slideHeight; |
|---|
| 368 | float _slideDistance; |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | FontData _titleFontData; |
|---|
| 372 | FontData _titleFontDataDefault; |
|---|
| 373 | |
|---|
| 374 | PositionData _titlePositionData; |
|---|
| 375 | PositionData _titlePositionDataDefault; |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | FontData _textFontData; |
|---|
| 379 | FontData _textFontDataDefault; |
|---|
| 380 | |
|---|
| 381 | PositionData _textPositionData; |
|---|
| 382 | PositionData _textPositionDataDefault; |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | PositionData _imagePositionData; |
|---|
| 386 | PositionData _imagePositionDataDefault; |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | PositionData _modelPositionData; |
|---|
| 390 | PositionData _modelPositionDataDefault; |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | bool _loopPresentation; |
|---|
| 394 | bool _autoSteppingActive; |
|---|
| 395 | osg::Vec4 _backgroundColor; |
|---|
| 396 | std::string _presentationName; |
|---|
| 397 | double _presentationDuration; |
|---|
| 398 | |
|---|
| 399 | osg::ref_ptr<osg::Group> _root; |
|---|
| 400 | osg::ref_ptr<osg::Switch> _presentationSwitch; |
|---|
| 401 | |
|---|
| 402 | osg::ref_ptr<osg::ClearNode> _slideClearNode; |
|---|
| 403 | osg::ref_ptr<osg::Switch> _slide; |
|---|
| 404 | std::string _slideTitle; |
|---|
| 405 | std::string _slideBackgroundImageFileName; |
|---|
| 406 | |
|---|
| 407 | osg::ref_ptr<osg::Group> _previousLayer; |
|---|
| 408 | osg::ref_ptr<osg::Group> _currentLayer; |
|---|
| 409 | |
|---|
| 410 | osg::ref_ptr<FilePathData> _filePathData; |
|---|
| 411 | |
|---|
| 412 | std::string findFileAndRecordPath(const std::string& filename); |
|---|
| 413 | |
|---|
| 414 | }; |
|---|
| 415 | |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | #endif |
|---|