]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/EffectBuilder.cxx
Effects in models working for transparent materials and chrome animation
[simgear.git] / simgear / scene / material / EffectBuilder.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <simgear_config.h>
3 #endif
4
5 #include <simgear/scene/tgdb/userdata.hxx>
6
7 #include <simgear/math/SGMath.hxx>
8
9 #include "EffectBuilder.hxx"
10 #include "Effect.hxx"
11
12 namespace simgear
13 {
14
15 // Given a property node from a pass, get its value either from it or
16 // from the effect parameters.
17 const SGPropertyNode* getEffectPropertyNode(Effect* effect,
18                                             const SGPropertyNode* prop)
19 {
20     if (!prop)
21         return 0;
22     if (prop->nChildren() > 0) {
23         const SGPropertyNode* useProp = prop->getChild("use");
24         if (!useProp || !effect->parametersProp)
25             return prop;
26         return effect->parametersProp->getNode(useProp->getStringValue());
27     }
28     return prop;
29 }
30
31 // Get a named child property from pass parameters or effect
32 // parameters.
33 const SGPropertyNode* getEffectPropertyChild(Effect* effect,
34                                              const SGPropertyNode* prop,
35                                              const char* name)
36 {
37     const SGPropertyNode* child = prop->getChild(name);
38     if (!child)
39         return 0;
40     else
41         return getEffectPropertyNode(effect, child);
42 }
43
44 string getGlobalProperty(const SGPropertyNode* prop)
45 {
46     if (!prop)
47         return string();
48     const SGPropertyNode* useProp = prop->getChild("use");
49     if (!useProp)
50         return string();
51     return useProp->getStringValue();
52 }
53
54 BuilderException::BuilderException()
55 {
56 }
57
58 BuilderException::BuilderException(const char* message, const char* origin)
59   : sg_exception(message, origin)
60 {
61 }
62
63 BuilderException::BuilderException(const std::string& message,
64                                    const std::string& origin)
65   : sg_exception(message, origin)
66 {
67 }
68
69 BuilderException::~BuilderException() throw()
70 {
71
72 }
73
74 bool isAttributeActive(Effect* effect, const SGPropertyNode* prop)
75 {
76     const SGPropertyNode* activeProp
77         = getEffectPropertyChild(effect, prop, "active");
78     return !activeProp || activeProp->getValue<bool>();
79 }
80
81 namespace effect
82 {
83 const char* colorFields[] = {"red", "green", "blue", "alpha"};
84 }
85 }