| 1 | #include "osg/Texture3D" |
|---|
| 2 | #include "osg/ImageSequence" |
|---|
| 3 | |
|---|
| 4 | #include "osgDB/Registry" |
|---|
| 5 | #include "osgDB/Input" |
|---|
| 6 | #include "osgDB/Output" |
|---|
| 7 | #include "osgDB/WriteFile" |
|---|
| 8 | |
|---|
| 9 | using namespace osg; |
|---|
| 10 | using namespace osgDB; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | bool Texture3D_readLocalData(Object& obj, Input& fr); |
|---|
| 14 | bool Texture3D_writeLocalData(const Object& obj, Output& fw); |
|---|
| 15 | |
|---|
| 16 | bool Texture3D_matchWrapStr(const char* str,Texture3D::WrapMode& wrap); |
|---|
| 17 | const char* Texture3D_getWrapStr(Texture3D::WrapMode wrap); |
|---|
| 18 | bool Texture3D_matchFilterStr(const char* str,Texture3D::FilterMode& filter); |
|---|
| 19 | const char* Texture3D_getFilterStr(Texture3D::FilterMode filter); |
|---|
| 20 | bool Texture3D_matchInternalFormatModeStr(const char* str,Texture3D::InternalFormatMode& mode); |
|---|
| 21 | const char* Texture3D_getInternalFormatModeStr(Texture3D::InternalFormatMode mode); |
|---|
| 22 | bool Texture3D_matchInternalFormatStr(const char* str,int& value); |
|---|
| 23 | const char* Texture3D_getInternalFormatStr(int value); |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | REGISTER_DOTOSGWRAPPER(Texture3D) |
|---|
| 27 | ( |
|---|
| 28 | new osg::Texture3D, |
|---|
| 29 | "Texture3D", |
|---|
| 30 | "Object StateAttribute Texture3D TextureBase", |
|---|
| 31 | &Texture3D_readLocalData, |
|---|
| 32 | &Texture3D_writeLocalData |
|---|
| 33 | ); |
|---|
| 34 | |
|---|
| 35 | bool Texture3D_readLocalData(Object& obj, Input& fr) |
|---|
| 36 | { |
|---|
| 37 | bool iteratorAdvanced = false; |
|---|
| 38 | |
|---|
| 39 | Texture3D& texture = static_cast<Texture3D&>(obj); |
|---|
| 40 | |
|---|
| 41 | if (fr[0].matchWord("file") && fr[1].isString()) |
|---|
| 42 | { |
|---|
| 43 | std::string filename = fr[1].getStr(); |
|---|
| 44 | Image* image = fr.readImage(filename.c_str()); |
|---|
| 45 | if (image) |
|---|
| 46 | { |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | texture.setImage(image); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | fr += 2; |
|---|
| 55 | iteratorAdvanced = true; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image")) |
|---|
| 59 | { |
|---|
| 60 | osg::Image* image = fr.readImage(); |
|---|
| 61 | if (image) texture.setImage(image); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | return iteratorAdvanced; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | bool Texture3D_writeLocalData(const Object& obj, Output& fw) |
|---|
| 68 | { |
|---|
| 69 | const Texture3D& texture = static_cast<const Texture3D&>(obj); |
|---|
| 70 | |
|---|
| 71 | if (texture.getImage()) |
|---|
| 72 | { |
|---|
| 73 | const osg::ImageSequence* is = dynamic_cast<const osg::ImageSequence*>(texture.getImage()); |
|---|
| 74 | if (is) |
|---|
| 75 | { |
|---|
| 76 | fw.writeObject(*is); |
|---|
| 77 | } |
|---|
| 78 | else |
|---|
| 79 | { |
|---|
| 80 | std::string fileName = texture.getImage()->getFileName(); |
|---|
| 81 | if (fw.getOutputTextureFiles()) |
|---|
| 82 | { |
|---|
| 83 | if (fileName.empty()) |
|---|
| 84 | { |
|---|
| 85 | fileName = fw.getTextureFileNameForOutput(); |
|---|
| 86 | } |
|---|
| 87 | osgDB::writeImageFile(*texture.getImage(), fileName); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | if (!fileName.empty()) |
|---|
| 91 | { |
|---|
| 92 | fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | return true; |
|---|
| 98 | } |
|---|