Debian Codegraph @

plugins/dm.editing/ShaderReplacer.h

raw
1 #ifndef _SHADER_REPLACER_H_
2 #define _SHADER_REPLACER_H_
3
4 #include "inode.h"
5 #include "ipatch.h"
6 #include "ibrush.h"
7
8 class ShaderReplacer :
9 public scene::NodeVisitor
10 {
11 std::string _oldShader;
12 std::string _newShader;
13
14 std::size_t _count;
15 public:
16 ShaderReplacer(const std::string& oldShader, const std::string& newShader) :
17 _oldShader(oldShader),
18 _newShader(newShader),
19 _count(0)
20 {}
21
22 bool pre(const scene::INodePtr& node)
23 {
24 // Check for patch
25 IPatchNodePtr patchNode = std::dynamic_pointer_cast<IPatchNode>(node);
26
27 if (patchNode != NULL)
28 {
29 if (patchNode->getPatch().getShader() == _oldShader)
30 {
31 patchNode->getPatch().setShader(_newShader);
32 _count++;
33 }
34 }
35 else
36 {
37 // Check for brush
38 IBrush* brush = Node_getIBrush(node);
39
40 if (brush != NULL)
41 {
42 for (std::size_t i = 0; i < brush->getNumFaces(); ++i)
43 {
44 IFace& face = brush->getFace(i);
45
46 if (face.getShader() == _oldShader)
47 {
48 face.setShader(_newShader);
49 _count++;
50 }
51 }
52 }
53 }
54
55 return true;
56 }
57
58 std::size_t getReplaceCount() const
59 {
60 return _count;
61 }
62 };
63
64 #endif /* _SHADER_REPLACER_H_ */