1 | #include "OgreCubeMapRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreHierarchicalParticleSystemTechnique.h"
|
---|
4 | #include "OgreChildPSystemRenderingRun.h"
|
---|
5 |
|
---|
6 | OgreHierarchicalParticleSystemTechnique::OgreHierarchicalParticleSystemTechnique(
|
---|
7 | unsigned long startFrame,
|
---|
8 | unsigned long impostorUpdateInterval,
|
---|
9 | unsigned int impostorResolution,
|
---|
10 | unsigned char impostorTexID,
|
---|
11 | bool useDistCalc,
|
---|
12 | bool perspectiveRendering,
|
---|
13 | String childPSysScriptName,
|
---|
14 | bool useOwnMaterial,
|
---|
15 | String impostorMaterialName,
|
---|
16 | Pass* pass,
|
---|
17 | OgreRenderable* parentRenderable,
|
---|
18 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
19 | :OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
|
---|
20 | HierarchicalParticleSystemTechnique(startFrame, impostorUpdateInterval, impostorResolution, useDistCalc, perspectiveRendering, parentRenderable, parentTechniqueGroup),
|
---|
21 | RenderTechnique(parentRenderable, parentTechniqueGroup)
|
---|
22 | {
|
---|
23 | this->impostorTexID = impostorTexID;
|
---|
24 | this->childPSysScriptName = childPSysScriptName;
|
---|
25 | this->impostorMaterialName = impostorMaterialName;
|
---|
26 | this->useOwnMaterial = useOwnMaterial;
|
---|
27 |
|
---|
28 | //create the Particle system
|
---|
29 | childPSysName = parentOgreRenderable->getName() + "_small_PSYS";
|
---|
30 | ParticleSystem* psys = Root::getSingleton()._getCurrentSceneManager()->createParticleSystem(childPSysName, childPSysScriptName);
|
---|
31 | SceneNode* node = Root::getSingleton()._getCurrentSceneManager()->getRootSceneNode()->createChildSceneNode();
|
---|
32 | node->attachObject(psys);
|
---|
33 | psys->setVisible(false);
|
---|
34 |
|
---|
35 | if(sharedRuns->getRun(ILLUMRUN_HPP_IMPOSTOR) == 0)
|
---|
36 | sharedRuns->addRun(ILLUMRUN_HPP_IMPOSTOR, createChildPSysRenderingRun());
|
---|
37 |
|
---|
38 | impostorChanged(sharedRuns->getRun(ILLUMRUN_HPP_IMPOSTOR));
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | OgreHierarchicalParticleSystemTechnique::~OgreHierarchicalParticleSystemTechnique()
|
---|
43 | {
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 | void OgreHierarchicalParticleSystemTechnique::impostorChanged(RenderingRun* run)
|
---|
48 | {
|
---|
49 | OgreChildPSystemRenderingRun* r = (OgreChildPSystemRenderingRun*) run->asOgreRenderingRun();
|
---|
50 | pass->getTextureUnitState(impostorTexID)->setTextureName(r->getImpostorTextureName());
|
---|
51 | }
|
---|
52 |
|
---|
53 | RenderingRun* OgreHierarchicalParticleSystemTechnique::createChildPSysRenderingRun()
|
---|
54 | {
|
---|
55 | return new OgreChildPSystemRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(),
|
---|
56 | parentOgreRenderable->getName() + "_HPP_IMPOSTOR",
|
---|
57 | startFrame,
|
---|
58 | impostorUpdateInterval,
|
---|
59 | impostorResolution,
|
---|
60 | perspectiveRendering,
|
---|
61 | childPSysName,
|
---|
62 | childPSysScriptName,
|
---|
63 | useOwnMaterial,
|
---|
64 | impostorMaterialName);
|
---|
65 | }
|
---|
66 |
|
---|
67 | ///Technique Parsers
|
---|
68 | namespace HPSParsers
|
---|
69 | {
|
---|
70 | void parseStartFrame(String& params, RenderTechniqueFactory* factory)
|
---|
71 | {
|
---|
72 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
73 | f->startFrame = StringConverter::parseUnsignedLong(params);
|
---|
74 | }
|
---|
75 | void parseImpostorUpdateInterval(String& params, RenderTechniqueFactory* factory)
|
---|
76 | {
|
---|
77 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
78 | f->impostorUpdateInterval = StringConverter::parseUnsignedLong(params);
|
---|
79 | }
|
---|
80 |
|
---|
81 | void parseImpostorResolution(String& params, RenderTechniqueFactory* factory)
|
---|
82 | {
|
---|
83 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
84 | f->impostorResolution = StringConverter::parseUnsignedInt(params);
|
---|
85 | }
|
---|
86 |
|
---|
87 | void parseImpostorTexID(String& params, RenderTechniqueFactory* factory)
|
---|
88 | {
|
---|
89 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
90 | f->impostorTexID = StringConverter::parseUnsignedInt(params);
|
---|
91 | }
|
---|
92 |
|
---|
93 | void parseUseDistCalc(String& params, RenderTechniqueFactory* factory)
|
---|
94 | {
|
---|
95 | /* OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
96 | // format: on/off tolerance(float)
|
---|
97 | StringVector vecparams = StringUtil::split(params, " \t");
|
---|
98 |
|
---|
99 | if(StringConverter::parseBool(vecparams[0]))//on
|
---|
100 | {
|
---|
101 | f->useDistCalc = true;
|
---|
102 |
|
---|
103 | if(vecparams.size()>1)
|
---|
104 | {
|
---|
105 | f->distTolerance = StringConverter::parseReal(vecparams[1]);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | else
|
---|
109 | {
|
---|
110 | f->useDistCalc = false;
|
---|
111 | }*/
|
---|
112 | ///TODO
|
---|
113 | }
|
---|
114 |
|
---|
115 | void parsePerspectiveRendering(String& params, RenderTechniqueFactory* factory)
|
---|
116 | {
|
---|
117 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
118 | f->perspectiveRendering = StringConverter::parseBool(params);
|
---|
119 | }
|
---|
120 | void parseMaterialName(String& params, RenderTechniqueFactory* factory)
|
---|
121 | {
|
---|
122 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
123 | f->impostorMaterialName = params;
|
---|
124 | f->useOwnMaterial = false;
|
---|
125 | }
|
---|
126 | void parseScriptName(String& params, RenderTechniqueFactory* factory)
|
---|
127 | {
|
---|
128 | OgreHierarchicalParticleSystemTechniqueFactory* f = (OgreHierarchicalParticleSystemTechniqueFactory*) factory;
|
---|
129 | f->childPSysScriptName = params;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | }
|
---|
134 | ///Technique factory
|
---|
135 | OgreHierarchicalParticleSystemTechniqueFactory::OgreHierarchicalParticleSystemTechniqueFactory()
|
---|
136 | {
|
---|
137 | typeName = "HPS";
|
---|
138 |
|
---|
139 | using namespace HPSParsers;
|
---|
140 |
|
---|
141 | //register parsers
|
---|
142 | this->attributeParsers.insert(AttribParserList::value_type("start_frame", (ILLUM_ATTRIBUTE_PARSER) parseStartFrame));
|
---|
143 | this->attributeParsers.insert(AttribParserList::value_type("update_interval", (ILLUM_ATTRIBUTE_PARSER) parseImpostorUpdateInterval));
|
---|
144 | this->attributeParsers.insert(AttribParserList::value_type("resolution", (ILLUM_ATTRIBUTE_PARSER) parseImpostorResolution));
|
---|
145 | this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseImpostorTexID));
|
---|
146 | this->attributeParsers.insert(AttribParserList::value_type("distance_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseDistCalc));
|
---|
147 | this->attributeParsers.insert(AttribParserList::value_type("perspective", (ILLUM_ATTRIBUTE_PARSER) parsePerspectiveRendering));
|
---|
148 | this->attributeParsers.insert(AttribParserList::value_type("particle_script", (ILLUM_ATTRIBUTE_PARSER) parseScriptName));
|
---|
149 | this->attributeParsers.insert(AttribParserList::value_type("material", (ILLUM_ATTRIBUTE_PARSER) parseMaterialName));
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | OgreRenderTechnique* OgreHierarchicalParticleSystemTechniqueFactory::createInstance(
|
---|
154 | IllumTechniqueParams* params,
|
---|
155 | Pass* pass,
|
---|
156 | OgreRenderable* parentRenderable,
|
---|
157 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
158 | {
|
---|
159 | impostorUpdateInterval = 1;
|
---|
160 | impostorResolution = 256;
|
---|
161 | startFrame = 1;
|
---|
162 | useDistCalc = false;
|
---|
163 | impostorTexID = 0;
|
---|
164 | perspectiveRendering = true;
|
---|
165 | impostorMaterialName = "";
|
---|
166 | childPSysScriptName = "";
|
---|
167 | bool useOwnMaterial = true;
|
---|
168 |
|
---|
169 | parseParams(params);
|
---|
170 |
|
---|
171 | OgreHierarchicalParticleSystemTechnique* result = new OgreHierarchicalParticleSystemTechnique(
|
---|
172 | startFrame,
|
---|
173 | impostorUpdateInterval,
|
---|
174 | impostorResolution,
|
---|
175 | impostorTexID,
|
---|
176 | useDistCalc,
|
---|
177 | perspectiveRendering,
|
---|
178 | childPSysScriptName,
|
---|
179 | useOwnMaterial,
|
---|
180 | impostorMaterialName,
|
---|
181 | pass,
|
---|
182 | parentRenderable,
|
---|
183 | parentTechniqueGroup);
|
---|
184 |
|
---|
185 | return result;
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|