| 1 | #include "osg/TextureCubeMap" |
|---|
| 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 TextureCubeMap_readLocalData(Object& obj, Input& fr); |
|---|
| 14 | bool TextureCubeMap_writeLocalData(const Object& obj, Output& fw); |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | REGISTER_DOTOSGWRAPPER(TextureCubeMap) |
|---|
| 18 | ( |
|---|
| 19 | new osg::TextureCubeMap, |
|---|
| 20 | "TextureCubeMap", |
|---|
| 21 | "Object StateAttribute TextureCubeMap TextureBase", |
|---|
| 22 | &TextureCubeMap_readLocalData, |
|---|
| 23 | &TextureCubeMap_writeLocalData |
|---|
| 24 | ); |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #define READ_IMAGE(FACE)\ |
|---|
| 28 | matched = false;\ |
|---|
| 29 | if (fr[1].matchWord(#FACE)) \ |
|---|
| 30 | {\ |
|---|
| 31 | if (fr[2].matchWord("ImageSequence") || fr[2].matchWord("Image")) \ |
|---|
| 32 | { \ |
|---|
| 33 | fr += 2;\ |
|---|
| 34 | osg::Image* image = fr.readImage(); \ |
|---|
| 35 | if (image) texture.setImage(osg::TextureCubeMap::FACE,image); \ |
|---|
| 36 | iteratorAdvanced = true; \ |
|---|
| 37 | matched = true;\ |
|---|
| 38 | } \ |
|---|
| 39 | else if (fr[2].isString())\ |
|---|
| 40 | { \ |
|---|
| 41 | Image* image = fr.readImage(fr[2].getStr());\ |
|---|
| 42 | if (image) texture.setImage(osg::TextureCubeMap::FACE,image);\ |
|---|
| 43 | fr += 3;\ |
|---|
| 44 | iteratorAdvanced = true; \ |
|---|
| 45 | matched = true;\ |
|---|
| 46 | }\ |
|---|
| 47 | }\ |
|---|
| 48 | |
|---|
| 49 | bool TextureCubeMap_readLocalData(Object& obj, Input& fr) |
|---|
| 50 | { |
|---|
| 51 | bool iteratorAdvanced = false; |
|---|
| 52 | |
|---|
| 53 | TextureCubeMap& texture = static_cast<TextureCubeMap&>(obj); |
|---|
| 54 | |
|---|
| 55 | bool matched=true; |
|---|
| 56 | while (fr[0].matchWord("image") && matched) |
|---|
| 57 | { |
|---|
| 58 | READ_IMAGE(POSITIVE_X) |
|---|
| 59 | else READ_IMAGE(NEGATIVE_X) |
|---|
| 60 | else READ_IMAGE(POSITIVE_Y) |
|---|
| 61 | else READ_IMAGE(NEGATIVE_Y) |
|---|
| 62 | else READ_IMAGE(POSITIVE_Z) |
|---|
| 63 | else READ_IMAGE(NEGATIVE_Z) |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | return iteratorAdvanced; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | #define WRITE_IMAGE(FACE) \ |
|---|
| 71 | {\ |
|---|
| 72 | const osg::Image* image = texture.getImage(osg::TextureCubeMap::FACE);\ |
|---|
| 73 | if (image)\ |
|---|
| 74 | {\ |
|---|
| 75 | const osg::ImageSequence* is = dynamic_cast<const osg::ImageSequence*>(image); \ |
|---|
| 76 | if (is) \ |
|---|
| 77 | { \ |
|---|
| 78 | fw.indent() << "image "<<#FACE<<std::endl; \ |
|---|
| 79 | fw.writeObject(*is); \ |
|---|
| 80 | } \ |
|---|
| 81 | else \ |
|---|
| 82 | { \ |
|---|
| 83 | std::string fileName = image->getFileName();\ |
|---|
| 84 | if (fw.getOutputTextureFiles())\ |
|---|
| 85 | {\ |
|---|
| 86 | if (fileName.empty())\ |
|---|
| 87 | {\ |
|---|
| 88 | fileName = fw.getTextureFileNameForOutput();\ |
|---|
| 89 | }\ |
|---|
| 90 | osgDB::writeImageFile(*image, fileName);\ |
|---|
| 91 | }\ |
|---|
| 92 | if (!fileName.empty())\ |
|---|
| 93 | {\ |
|---|
| 94 | fw.indent() << "image "<<#FACE<<" "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl;\ |
|---|
| 95 | }\ |
|---|
| 96 | }\ |
|---|
| 97 | } \ |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | bool TextureCubeMap_writeLocalData(const Object& obj, Output& fw) |
|---|
| 101 | { |
|---|
| 102 | const TextureCubeMap& texture = static_cast<const TextureCubeMap&>(obj); |
|---|
| 103 | |
|---|
| 104 | WRITE_IMAGE(POSITIVE_X) |
|---|
| 105 | WRITE_IMAGE(NEGATIVE_X) |
|---|
| 106 | WRITE_IMAGE(POSITIVE_Y) |
|---|
| 107 | WRITE_IMAGE(NEGATIVE_Y) |
|---|
| 108 | WRITE_IMAGE(POSITIVE_Z) |
|---|
| 109 | WRITE_IMAGE(NEGATIVE_Z) |
|---|
| 110 | |
|---|
| 111 | return true; |
|---|
| 112 | } |
|---|
| 113 | |
|---|