2 # include <simgear_config.h>
5 #include <simgear/scene/model/SGReaderWriterXMLOptions.hxx>
6 #include <simgear/scene/tgdb/userdata.hxx>
8 #include <simgear/math/SGMath.hxx>
10 #include "EffectBuilder.hxx"
16 // Given a property node from a pass, get its value either from it or
17 // from the effect parameters.
18 const SGPropertyNode* getEffectPropertyNode(Effect* effect,
19 const SGPropertyNode* prop)
23 if (prop->nChildren() > 0) {
24 const SGPropertyNode* useProp = prop->getChild("use");
25 if (!useProp || !effect->parametersProp)
27 return effect->parametersProp->getNode(useProp->getStringValue());
32 // Get a named child property from pass parameters or effect
34 const SGPropertyNode* getEffectPropertyChild(Effect* effect,
35 const SGPropertyNode* prop,
38 const SGPropertyNode* child = prop->getChild(name);
42 return getEffectPropertyNode(effect, child);
45 string getGlobalProperty(const SGPropertyNode* prop,
46 const SGReaderWriterXMLOptions* options)
50 const SGPropertyNode* useProp = prop->getChild("use");
53 string propName = useProp->getStringValue();
54 SGPropertyNode_ptr propRoot;
55 if (propName[0] == '/') {
57 } else if ((propRoot = options->getPropRoot())) {
58 string result = propRoot->getPath();
60 result.append(propName);
64 BuilderException("No property root to use with relative name "
68 return useProp->getStringValue();
73 BuilderException::BuilderException()
77 BuilderException::BuilderException(const char* message, const char* origin)
78 : sg_exception(message, origin)
82 BuilderException::BuilderException(const std::string& message,
83 const std::string& origin)
84 : sg_exception(message, origin)
88 BuilderException::~BuilderException() throw()
94 bool isAttributeActive(Effect* effect, const SGPropertyNode* prop)
96 const SGPropertyNode* activeProp
97 = getEffectPropertyChild(effect, prop, "active");
98 return !activeProp || activeProp->getValue<bool>();
103 const char* colorFields[] = {"red", "green", "blue", "alpha"};