From: Tim Moore Date: Tue, 8 Sep 2009 10:59:58 +0000 (+0200) Subject: Dump texture attributes of StateSet into effect property tree X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=14e5e87a4d4f62f2fac873f5cee856b561f8568a;p=simgear.git Dump texture attributes of StateSet into effect property tree Also, decode blend function. --- diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index eba40dd7..2e682234 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -922,6 +922,17 @@ bool makeParametersFromStateSet(SGPropertyNode* paramRoot, const StateSet* ss) } } paramRoot->getChild("cull-face", 0, true)->setStringValue(cullFaceString); + const BlendFunc* blendFunc = getStateAttribute(ss); + if (blendFunc) { + string sourceMode = findName(blendFuncModes, blendFunc->getSource()); + string destMode = findName(blendFuncModes, blendFunc->getDestination()); + SGPropertyNode* blendNode = paramRoot->getChild("blend", 0, true); + blendNode->getChild("source", 0, true)->setStringValue(sourceMode); + blendNode->getChild("destination", 0, true)->setStringValue(destMode); + blendNode->getChild("mode", 0, true)->setValue(true); + } + makeTextureParameters(paramRoot, ss); + return true; } // Walk the techniques property tree, building techniques and diff --git a/simgear/scene/material/Effect.hxx b/simgear/scene/material/Effect.hxx index 2a3c896e..2b3942fe 100644 --- a/simgear/scene/material/Effect.hxx +++ b/simgear/scene/material/Effect.hxx @@ -71,5 +71,8 @@ Effect* makeEffect(const std::string& name, Effect* makeEffect(SGPropertyNode* prop, bool realizeTechniques, const osgDB::ReaderWriter::Options* options = 0); + +bool makeParametersFromStateSet(SGPropertyNode* paramRoot, + const osg::StateSet* ss); } #endif diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index cc927341..9103fe59 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -31,8 +31,8 @@ #include #include - #include +#include #include "Noise.hxx" @@ -283,4 +283,26 @@ namespace TextureBuilder::Registrar installNoise("noise", new NoiseBuilder); } +bool makeTextureParameters(SGPropertyNode* paramRoot, const StateSet* ss) +{ + const Texture* tex = getStateAttribute(0, ss); + const Texture2D* texture = dynamic_cast(tex); + if (!tex) + return false; + const Image* image = texture->getImage(); + string imageName; + if (image) + imageName = image->getFileName(); + string wrapS = findName(wrapModes, texture->getWrap(Texture::WRAP_S)); + string wrapT = findName(wrapModes, texture->getWrap(Texture::WRAP_T)); + string wrapR = findName(wrapModes, texture->getWrap(Texture::WRAP_R)); + SGPropertyNode* texUnit = makeChild(paramRoot, "texture-unit"); + makeChild(texUnit, "unit")->setValue(0); + makeChild(texUnit, "image")->setStringValue(imageName); + makeChild(texUnit, "wrap-s")->setStringValue(wrapS); + makeChild(texUnit, "wrap-t")->setStringValue(wrapT); + makeChild(texUnit, "wrap-r")->setStringValue(wrapR); + return true; +} + } diff --git a/simgear/scene/material/TextureBuilder.hxx b/simgear/scene/material/TextureBuilder.hxx index 259ef614..395ca382 100644 --- a/simgear/scene/material/TextureBuilder.hxx +++ b/simgear/scene/material/TextureBuilder.hxx @@ -17,6 +17,7 @@ #ifndef SIMGEAR_TEXTUREBUILDER_HXX #define SIMGEAR_TEXTUREBUILDER_HXX 1 +#include #include #include "EffectBuilder.hxx" @@ -30,5 +31,7 @@ public: const SGPropertyNode*props, const osgDB::ReaderWriter::Options* options); }; + +bool makeTextureParameters(SGPropertyNode* paramRoot, const osg::StateSet* ss); } #endif