Project

General

Profile

SO3Engine
SO3Material.cpp
Go to the documentation of this file.
1
11#include "SO3Renderer/SO3Root.h"
15
16namespace SO3
17{
18
19SMaterial::SMaterial(SScene* scene, const std::string& groupname, const std::string& materialName, const bool& loadedFromScript) : SData(materialName)
20{
21 ogreMaterial.reset();
23 mIgnoreSlicePlane = false;
24 mScene = scene;
25 mGroupName = groupname;
26
27 // For materials that are dynamicaly created inside SO3, but for which no SMaterial was setted.
28 ogreMaterial = mScene->O3MaterialManager->getByName(materialName, groupname);
29
30 // Clone base white to prevent modifications. Change the resource group of the clone.
31 if (materialName == std::string("BaseWhite") && ogreMaterial)
32 ogreMaterial = ogreMaterial.get()->clone(materialName, groupname);
33
34 // If no material is found, it's either that scol user asked for the creation of a new material, or that the SResourceLoader (that "listens" to ogre script loading)
35 // asked for a new material
36 if (!ogreMaterial)
37 {
38 // Create a new Ogre::Material in the targeted resource group.
39 ogreMaterial = Ogre::MaterialManager::getSingleton().create(materialName, mGroupName);
40
41 // If not loaded from Ogre's script, then create a minimal material with one texture unit, and bind STechnique to Ogre::Technique. We do not do that for content loaded
42 // from script because Ogre's script translator call "removeAllTechnique" just after SMaterial creation, leading to an orfan "STechnique" (mem leak).
43 if(!loadedFromScript)
44 {
45 //ogreMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();
47 }
48 }
49 else
50 {
51 // Bind STechnique to Ogre::Technique
53 }
54}
55
56SMaterial::SMaterial() : SData("")
57{
58 // Forbiden (private)
59}
60
62{
63 // Unbind STechnique from Ogre::Technique
65
66 //Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeAllShaderBasedTechniques(GetName(), GetGroupName());
67
68 if (ogreMaterial)
69 {
70 //cleanup all subentity using this material
71 Ogre::SceneManager::MovableObjectMap EntityList = mScene->GetOgreScenePointer()->getMovableObjects("Entity");
72 Ogre::Entity* CurrentEntity = NULL;
73
74 for (Ogre::SceneManager::MovableObjectMap::iterator iEntity = EntityList.begin(); iEntity != EntityList.end(); iEntity++)
75 {
76 CurrentEntity = static_cast<Ogre::Entity *>(iEntity->second);
77 for (unsigned int k = 0; k < CurrentEntity->getNumSubEntities(); k++)
78 {
79 Ogre::SubEntity* subent = CurrentEntity->getSubEntity(k);
80 if (subent->getMaterial() == ogreMaterial)
81 subent->setMaterialName("BaseWhite");
82 }
83 }
84 // Do not destroy Ogre's internals materials!
85 if ((ogreMaterial->getGroup() != Ogre::RGN_INTERNAL) && (ogreMaterial->getGroup() == mGroupName))
86 {
87 ogreMaterial->unload();
88 Ogre::MaterialManager::getSingletonPtr()->remove(ogreMaterial->getHandle());
89 }
90 }
91}
92
94{
97
98 // Generate techniques
99 Ogre::Material::Techniques techs = ogreMaterial->getTechniques();
100 for(unsigned int techid = 0; techid < techs.size(); techid++)
101 {
102 Ogre::Technique* ogreTechnique = techs[techid];
103 STechnique* technique = new STechnique(this, ogreTechnique);
104 ogreTechnique->getUserObjectBindings().setUserAny("STechnique", Ogre::Any(technique));
105 }
106}
107
109{
110 // Destroy techniques
111 Ogre::Material::Techniques techs = ogreMaterial->getTechniques();
112 for (unsigned int techid = 0; techid < techs.size(); techid++)
113 {
114 Ogre::Technique* ogreTechnique = techs[techid];
115 Ogre::Any bindedSTechnique = ogreTechnique->getUserObjectBindings().getUserAny("STechnique");
116 if(bindedSTechnique.has_value())
117 {
118 STechnique* technique = Ogre::any_cast<STechnique*> (bindedSTechnique);
119 SO3_SAFE_DELETE(technique);
120 }
121 }
122}
123
125{
126 Ogre::MaterialPtr nmat = mScene->O3MaterialManager->getByName(name, mGroupName);
127 if (!nmat)
128 return;
129
131
132 //apply all subentity using this material with new pointer
133 Ogre::SceneManager::MovableObjectMap EntityList = mScene->GetOgreScenePointer()->getMovableObjects("Entity");
134 Ogre::Entity* CurrentEntity = NULL;
135
136 for (Ogre::SceneManager::MovableObjectMap::iterator iEntity = EntityList.begin(); iEntity != EntityList.end(); iEntity++)
137 {
138 CurrentEntity = static_cast<Ogre::Entity *>(iEntity->second);
139 for (unsigned int k = 0; k < CurrentEntity->getNumSubEntities(); k++)
140 {
141 Ogre::SubEntity* subent = CurrentEntity->getSubEntity(k);
142 if (subent->getMaterial() == ogreMaterial)
143 subent->setMaterial(nmat);
144 }
145 }
146
147 ogreMaterial.reset();
148
149 // For materials that are dynamicaly created inside SO3, but for which no SMaterial was setted.
150 ogreMaterial = nmat;
151
152 // Clone base white to prevent modifications. Change the resource group of the clone.
153 if (name == std::string("BaseWhite") && ogreMaterial)
154 ogreMaterial = ogreMaterial.get()->clone(name, mGroupName);
155}
156
158{
159 return ogreMaterial;
160}
161
163{
164 return mScene;
165}
166
168{
169 return mGroupName;
170}
171
173{
174 assert(ogreMaterial);
175 return ogreMaterial->getNumTechniques();
176}
177
178STechnique* SMaterial::GetTechnique(const unsigned int& technique)
179{
180 assert(ogreMaterial);
181 if ((technique >= 0) && (technique < ogreMaterial->getNumTechniques()))
182 {
183 Ogre::Technique* ogreTechnique = ogreMaterial->getTechnique(technique);
184 Ogre::Any bindedSTechnique = ogreTechnique->getUserObjectBindings().getUserAny("STechnique");
185
186 if (!bindedSTechnique.has_value())
187 return 0;
188
189 STechnique* matTechnique = Ogre::any_cast<STechnique*> (bindedSTechnique);
190 return matTechnique;
191 }
192 else
193 return 0;
194}
195
196int SMaterial::GetTechniqueIndexByName(const std::string& techname)
197{
198 assert(ogreMaterial);
199
200 bool found = false;
201 int index = -1;
202 int numTech = GetNumTechniques();
203 int p = 0;
204
205 while(!found && p<numTech)
206 {
207 Ogre::Technique* myTec = ogreMaterial->getTechnique(p);
208 if (myTec != 0)
209 {
210 if(myTec->getName() == techname)
211 {
212 index = p;
213 found = true;
214 }
215 }
216 p++;
217 }
218
219 return index;
220}
221
226
227void SMaterial::SetAssociatedWidget(SWidget* newAssociatedWidget)
228{
229 // Allow only one widget on a material at a time.
230 if((associatedWidget != 0) && (newAssociatedWidget != 0))
231 OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, "Cannot set widget on material: This material is already associated to a widget instance!", "SMaterial::SetAssociatedWidget");
232
233 associatedWidget = newAssociatedWidget;
234}
235
237{
238 assert(ogreMaterial);
239 return ogreMaterial->getReceiveShadows();
240}
241
242void SMaterial::SetReceiveShadows(const bool& state)
243{
244 assert(ogreMaterial);
245 ogreMaterial->setReceiveShadows(state);
246}
247
248void SMaterial::SetLightingEnabled(const bool& state)
249{
250 assert(ogreMaterial);
251 ogreMaterial->setLightingEnabled(state);
252
254}
255
256void SMaterial::SetAmbientColor(const int& color)
257{
258 assert(ogreMaterial);
260
262}
263
264void SMaterial::SetDiffuseColor(const int& color)
265{
266 assert(ogreMaterial);
268
270}
271
272void SMaterial::SetSpecularColor(const int& color)
273{
274 assert(ogreMaterial);
276
278}
279
281{
282 assert(ogreMaterial);
283 ogreMaterial->setSelfIllumination(ConversionTools::ScolToOgreColorRGBA(color));
284
286}
287
288void SMaterial::SetAmbientColor(float r, float g, float b, float a)
289{
290 assert(ogreMaterial);
291 ogreMaterial->setAmbient(Ogre::ColourValue(r, g, b, a));
292
294}
295
296void SMaterial::SetDiffuseColor(float r, float g, float b, float a)
297{
298 assert(ogreMaterial);
299 ogreMaterial->setDiffuse(Ogre::ColourValue(r, g, b, a));
300
302}
303
304void SMaterial::SetSpecularColor(float r, float g, float b, float a)
305{
306 assert(ogreMaterial);
307 ogreMaterial->setSpecular(Ogre::ColourValue(r, g, b, a));
308
310}
311
312void SMaterial::SetSelfIlluminationColor(float r, float g, float b, float a)
313{
314 assert(ogreMaterial);
315 ogreMaterial->setSelfIllumination(Ogre::ColourValue(r, g, b, a));
316
318}
319
320void SMaterial::SetShininess(const float& value)
321{
322 assert(ogreMaterial);
323 ogreMaterial->setShininess(value);
324
326}
327
329{
330 // Generate technique
331 Ogre::Technique* ogreTechnique = ogreMaterial->createTechnique();
332 STechnique* technique = new STechnique(this, ogreTechnique);
333 ogreTechnique->getUserObjectBindings().setUserAny("STechnique", Ogre::Any(technique));
334}
335
336void SMaterial::RemoveTechnique(const unsigned int& technique)
337{
338 //update generated materials
340
341 if ((technique >= 0) && (technique < ogreMaterial->getNumTechniques()))
342 {
343 Ogre::Technique* ogreTechnique = ogreMaterial->getTechnique(technique);
344 Ogre::Any bindedSTechnique = ogreTechnique->getUserObjectBindings().getUserAny("STechnique");
345 assert(bindedSTechnique.has_value());
346 STechnique* matTechnique = Ogre::any_cast<STechnique*> (bindedSTechnique);
347 SO3_SAFE_DELETE(matTechnique);
348 }
349}
350
351void SMaterial::SetPointSize(Ogre::Real size)
352{
353 Ogre::Material::Techniques techs = ogreMaterial->getTechniques();
354 for (unsigned int i = 0; i < techs.size(); i++)
355 {
356 Ogre::Technique* ogreTechnique = techs[i];
357 Ogre::Technique::Passes ogrePasses = ogreTechnique->getPasses();
358 for (unsigned int j = 0; j < ogrePasses.size(); j++)
359 {
360 if (ogrePasses[j]->getPolygonMode() == Ogre::PM_POINTS)
361 ogrePasses[j]->setPointSize(size);
362 }
363 }
364
366}
367
369{
370 Ogre::Material::Techniques techs = mat->getTechniques();
371 unsigned int id = 0;
372 for (unsigned int i = 0; i < techs.size(); i++, id++)
373 {
374 Ogre::Technique* tech = techs[i];
375
376 //remove generated techniques like SSAO
377 if (tech->getSchemeName().find(std::string(SO3_INTERNAL_RESOURCE_GROUP)) != Ogre::String::npos)
378 {
379 mat->removeTechnique(id);
380 id--;
381 continue;
382 }
383
384 Ogre::Technique::Passes passes = tech->getPasses();
385 for (unsigned int j = 0; j < passes.size(); j++)
386 {
387 Ogre::Any bindedSPass = passes[j]->getUserObjectBindings().getUserAny("SPass");
388 if (bindedSPass.has_value())
389 {
390 SPass* pass = Ogre::any_cast<SPass*> (bindedSPass);
391 if (pass && pass->IsShaderGenerated())
392 {
393 pass->BuildShader();
394 }
395 }
396 }
397 }
398}
399
401{
403
404 Ogre::Material::Techniques techs = ogreMaterial->getTechniques();
405 unsigned int id = 0;
406 for (unsigned int i = 0; i < techs.size(); i++, id++)
407 {
408 Ogre::Technique* tech = techs[i];
409
410 //remove generated techniques like SSAO
411 if (tech->getSchemeName().find(std::string(SO3_INTERNAL_RESOURCE_GROUP)) != Ogre::String::npos)
412 {
413 ogreMaterial->removeTechnique(id);
414 id--;
415 continue;
416 }
417 }
418}
419
420void SMaterial::WriteMaterialFile(std::string path)
421{
422 Ogre::MaterialSerializer ogreMaterialSerializer;
423 std::vector<SPass*> generatedShaderPasses;
424 std::vector<STechnique*> generatedShadowTechs;
425 std::vector<STechnique*> generatedShaderGenTechs;
426 std::vector<STechnique*> generatedShaderLegacyTechs;
427
428 //save in the original material file
429 Ogre::String matPath = (path.empty()) ? ogreMaterial->getOrigin() : path;
430
431 if (matPath.empty())
432 return; //nothing to do with no filename
433
434 //Get file from user partition
435 packdir mypack = (packdir)SCgetExtra("FirstPack");
436 boost::filesystem::path upartitionPath(mypack->path);
437 upartitionPath = upartitionPath.generic_string();
438
439 std::string ufilepath(matPath);
440
441 while (mypack)
442 {
443 std::string curPart = boost::filesystem::path(mypack->path).generic_string();
444 if (matPath.find(curPart) != std::string::npos)
445 {
446 ufilepath = upartitionPath.append(ufilepath.substr(curPart.length())).generic_string();
447 //Create all folders
448 if (!boost::filesystem::exists(ufilepath))
449 {
450 boost::system::error_code ec;
451 boost::filesystem::path subd(ufilepath);
452 subd.remove_filename();
453 boost::filesystem::create_directories(subd, ec);
454 }
455
456 break;
457 }
458
459 mypack = mypack->next;
460 }
461
462 bool addnew = true;
463
464 Ogre::ResourceManager::ResourceMapIterator it = Ogre::MaterialManager::getSingleton().getResourceIterator();
465 while (it.hasMoreElements())
466 {
467 Ogre::MaterialPtr mat = Ogre::static_pointer_cast<Ogre::Material>(it.getNext());
468 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeAllShaderBasedTechniques(*mat.get());
469
470 if (mat->getGroup() == ogreMaterial->getGroup() && mat->getOrigin() == matPath)
471 {
472 if (mat == ogreMaterial)
473 addnew = false;
474
475 Ogre::Material::Techniques techs = mat->getTechniques();
476 unsigned int id = 0;
477 for (unsigned int i = 0; i < techs.size(); i++, id++)
478 {
479 Ogre::Technique* tech = techs[i];
480
481 //remove generated techniques like SSAO
482 if (tech->getSchemeName().find(std::string(SO3_INTERNAL_RESOURCE_GROUP)) != Ogre::String::npos)
483 {
484 mat->removeTechnique(id);
485 id--;
486 continue;
487 }
488
489 //remove shadow pass
490 Ogre::Any bindedSTechnique = tech->getUserObjectBindings().getUserAny("STechnique");
491 if (bindedSTechnique.has_value())
492 {
493 STechnique* stechnique = Ogre::any_cast<STechnique*> (bindedSTechnique);
494
495 if (tech->getSchemeName() == Ogre::MSN_SHADERGEN)
496 {
497 tech->setSchemeName(Ogre::MSN_DEFAULT);
498 generatedShaderGenTechs.push_back(stechnique);
499 }
500
501 if (tech->getSchemeName() == "SO3_LEGACY")
502 {
503 tech->setSchemeName(Ogre::MSN_DEFAULT);
504 generatedShaderLegacyTechs.push_back(stechnique);
505 }
506
507 if (stechnique->GetParentMaterial()->GetScene()->GetShadowManager())
508 {
510 generatedShadowTechs.push_back(stechnique);
511 }
512 }
513
514 Ogre::Technique::Passes passes = tech->getPasses();
515 for (unsigned int j = 0; j < passes.size(); j++)
516 {
517 Ogre::Any bindedSPass = passes[j]->getUserObjectBindings().getUserAny("SPass");
518 if (bindedSPass.has_value())
519 {
520 SPass* pass = Ogre::any_cast<SPass*> (bindedSPass);
521 if (pass && pass->IsShaderGenerated())
522 {
523 pass->CleanGeneratedShader();
524 generatedShaderPasses.push_back(pass);
525 }
526 }
527 }
528 }
529
530 ogreMaterialSerializer.queueForExport(mat);
531 }
532 }
533
534 if (addnew)
535 {
536 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeAllShaderBasedTechniques(*ogreMaterial.get());
537 Ogre::Material::Techniques techs = ogreMaterial->getTechniques();
538 unsigned int id = 0;
539 for (unsigned int i = 0; i < techs.size(); i++, id++)
540 {
541 Ogre::Technique* tech = techs[i];
542
543 //remove generated techniques like SSAO
544 if (tech->getSchemeName().find(std::string(SO3_INTERNAL_RESOURCE_GROUP)) != Ogre::String::npos)
545 {
546 ogreMaterial->removeTechnique(id);
547 id--;
548 continue;
549 }
550
551 //remove shadow pass
552 Ogre::Any bindedSTechnique = tech->getUserObjectBindings().getUserAny("STechnique");
553 if (bindedSTechnique.has_value())
554 {
555 STechnique* stechnique = Ogre::any_cast<STechnique*> (bindedSTechnique);
556
557 if (tech->getSchemeName() == Ogre::MSN_SHADERGEN)
558 {
559 tech->setSchemeName(Ogre::MSN_DEFAULT);
560 generatedShaderGenTechs.push_back(stechnique);
561 }
562
563 if (tech->getSchemeName() == "SO3_LEGACY")
564 {
565 tech->setSchemeName(Ogre::MSN_DEFAULT);
566 generatedShaderLegacyTechs.push_back(stechnique);
567 }
568
569 if (stechnique->GetParentMaterial()->GetScene()->GetShadowManager())
570 {
572 generatedShadowTechs.push_back(stechnique);
573 }
574 }
575
576 Ogre::Technique::Passes passes = tech->getPasses();
577 for (unsigned int j = 0; j < passes.size(); j++)
578 {
579 Ogre::Any bindedSPass = passes[j]->getUserObjectBindings().getUserAny("SPass");
580 if (bindedSPass.has_value())
581 {
582 SPass* pass = Ogre::any_cast<SPass*> (bindedSPass);
583 if (pass && pass->IsShaderGenerated())
584 {
585 pass->CleanGeneratedShader();
586 generatedShaderPasses.push_back(pass);
587 }
588 }
589 }
590 }
591
592 //set ogreMaterial Origin
593 ogreMaterial->_notifyOrigin(matPath);
594
595 ogreMaterialSerializer.queueForExport(ogreMaterial);
596 }
597
598 //write file
599 ogreMaterialSerializer.exportQueued(ufilepath);
600
601 //rebuild generated shaders
602 for (unsigned int i = 0; i < generatedShaderPasses.size(); i++)
603 {
604 generatedShaderPasses[i]->BuildShader(true);
605 }
606
607 for (unsigned int i = 0; i < generatedShaderGenTechs.size(); i++)
608 {
609 generatedShaderGenTechs[i]->SetSchemeName(Ogre::MSN_SHADERGEN);
610 }
611
612 for (unsigned int i = 0; i < generatedShaderLegacyTechs.size(); i++)
613 {
614 generatedShaderLegacyTechs[i]->SetSchemeName("SO3_LEGACY");
615 }
616
617 // update shadows
618 for (unsigned int i = 0; i < generatedShadowTechs.size(); i++)
619 {
620 STechnique* stech = generatedShadowTechs[i];
622 }
623}
624
626{
627 Ogre::MaterialSerializer ogreMaterialSerializer;
628 std::vector<SPass*> generatedShaderPasses;
629 std::vector<STechnique*> generatedShadowTechs;
630 std::vector<STechnique*> generatedShaderGenTechs;
631 std::vector<STechnique*> generatedShaderLegacyTechs;
632
633 if (path.empty())
634 return; //nothing to do with no filename
635
636 //Get file from user partition
637 packdir mypack = (packdir)SCgetExtra("FirstPack");
638 boost::filesystem::path upartitionPath(mypack->path);
639 upartitionPath = upartitionPath.generic_string();
640
641 std::string ufilepath(path);
642
643 while (mypack)
644 {
645 std::string curPart = boost::filesystem::path(mypack->path).generic_string();
646 if (path.find(curPart) != std::string::npos)
647 {
648 ufilepath = upartitionPath.append(ufilepath.substr(curPart.length())).generic_string();
649
650 //Create all folders
651 if (!boost::filesystem::exists(ufilepath))
652 {
653 boost::system::error_code ec;
654 boost::filesystem::path subd(ufilepath);
655 subd.remove_filename();
656 boost::filesystem::create_directories(subd, ec);
657 }
658 break;
659 }
660
661 mypack = mypack->next;
662 }
663
664 Ogre::ResourceManager::ResourceMapIterator it = Ogre::MaterialManager::getSingleton().getResourceIterator();
665 while (it.hasMoreElements())
666 {
667 Ogre::MaterialPtr mat = Ogre::static_pointer_cast<Ogre::Material>(it.getNext());
668 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeAllShaderBasedTechniques(*mat.get());
669
670 if (mat->getOrigin() == path)
671 {
672 Ogre::Material::Techniques techs = mat->getTechniques();
673 unsigned int id = 0;
674 for (unsigned int i = 0; i < techs.size(); i++, id++)
675 {
676 Ogre::Technique* tech = techs[i];
677
678 //remove generated techniques like SSAO
679 if (tech->getSchemeName().find(std::string(SO3_INTERNAL_RESOURCE_GROUP)) != Ogre::String::npos)
680 {
681 mat->removeTechnique(id);
682 id--;
683 continue;
684 }
685
686 //remove shadow pass
687 Ogre::Any bindedSTechnique = tech->getUserObjectBindings().getUserAny("STechnique");
688 if (bindedSTechnique.has_value())
689 {
690 STechnique* stechnique = Ogre::any_cast<STechnique*> (bindedSTechnique);
691 if (tech->getSchemeName() == Ogre::MSN_SHADERGEN)
692 {
693 tech->setSchemeName(Ogre::MSN_DEFAULT);
694 generatedShaderGenTechs.push_back(stechnique);
695 }
696
697 if (tech->getSchemeName() == "SO3_LEGACY")
698 {
699 tech->setSchemeName(Ogre::MSN_DEFAULT);
700 generatedShaderLegacyTechs.push_back(stechnique);
701 }
702
703
704 if (stechnique->GetParentMaterial()->GetScene()->GetShadowManager())
705 {
707 generatedShadowTechs.push_back(stechnique);
708 }
709 }
710
711 Ogre::Technique::Passes passes = tech->getPasses();
712 for (unsigned int j = 0; j < passes.size(); j++)
713 {
714 Ogre::Any bindedSPass = passes[j]->getUserObjectBindings().getUserAny("SPass");
715 if (bindedSPass.has_value())
716 {
717 SPass* pass = Ogre::any_cast<SPass*> (bindedSPass);
718 if (pass && pass->IsShaderGenerated())
719 {
720 pass->CleanGeneratedShader();
721 generatedShaderPasses.push_back(pass);
722 }
723 }
724 }
725 }
726
727 ogreMaterialSerializer.queueForExport(mat);
728 }
729 }
730
731 //write file
732 ogreMaterialSerializer.exportQueued(ufilepath);
733
734 //rebuild generated shaders
735 for (unsigned int i = 0; i < generatedShaderPasses.size(); i++)
736 {
737 generatedShaderPasses[i]->BuildShader(true);
738 }
739
740 for (unsigned int i = 0; i < generatedShaderGenTechs.size(); i++)
741 {
742 generatedShaderGenTechs[i]->SetSchemeName(Ogre::MSN_SHADERGEN);
743 }
744
745 for (unsigned int i = 0; i < generatedShaderLegacyTechs.size(); i++)
746 {
747 generatedShaderLegacyTechs[i]->SetSchemeName("SO3_LEGACY");
748 }
749
750 // update shadows
751 for (unsigned int i = 0; i < generatedShadowTechs.size(); i++)
752 {
753 STechnique* stech = generatedShadowTechs[i];
755 }
756}
757
759{
760 int numMats = 0;
761 Ogre::ResourceManager::ResourceMapIterator it = Ogre::MaterialManager::getSingleton().getResourceIterator();
762 while (it.hasMoreElements())
763 {
764 Ogre::MaterialPtr mat = Ogre::static_pointer_cast<Ogre::Material>(it.getNext());
765 if (mat->getOrigin() == path)
766 {
767 numMats++;
768 }
769 }
770 return numMats;
771}
772
774{
775 mIgnoreSlicePlane = state;
776
778
779 //update shaders
780 Ogre::Material::Techniques techs = ogreMaterial->getTechniques();
781 for (unsigned int i = 0; i < techs.size(); i++)
782 {
783 Ogre::Technique* tech = techs[i];
784 Ogre::Technique::Passes passes = tech->getPasses();
785 for (unsigned int j = 0; j < passes.size(); j++)
786 {
787 Ogre::Any bindedSPass = passes[j]->getUserObjectBindings().getUserAny("SPass");
788 if (bindedSPass.has_value())
789 {
790 SPass* pass = Ogre::any_cast<SPass*> (bindedSPass);
791 if (pass && pass->IsShaderGenerated())
792 {
793 pass->BuildShader(true);
794 }
795 }
796 }
797
798 //generate shadow pass
799 if (GetScene()->GetShadowManager())
801 }
802}
803
808
810{
811 if (full)
813 else
815
816 Ogre::Material::Techniques techs = ogreMaterial->getTechniques();
817 unsigned int id = 0;
818 for (unsigned int i = 0; i < techs.size(); i++, id++)
819 {
820 Ogre::Technique* tech = techs[i];
821 Ogre::Technique::Passes passes = tech->getPasses();
822
823 for (unsigned int passid = 0; passid < passes.size(); passid++)
824 {
825 Ogre::Pass* ogrePass = passes[passid];
826 Ogre::Any bindedSPass = ogrePass->getUserObjectBindings().getUserAny("SPass");
827 if (bindedSPass.has_value())
828 {
829 SPass* matPass = Ogre::any_cast<SPass*> (bindedSPass);
830
831 if (matPass->IsShaderGenerated())
832 matPass->BuildShader(full);
833 }
834 }
835
836 //generate shadow pass
837 if (GetScene()->GetShadowManager())
839 }
840}
841
842}
static Ogre::ColourValue ScolToOgreColorRGBA(const int &scolColor)
std::string name
Definition SO3DataScol.h:44
void SetAssociatedWidget(SWidget *newAssociatedWidget)
void CleanUpGeneratedTechniques()
SScene * mScene
Definition SO3Material.h:48
Ogre::MaterialPtr getOgreMaterialPointer()
bool GetReceiveShadows()
void SetLightingEnabled(const bool &state)
SScene * GetScene()
void UpdateGeneratedMaterial(bool full=false)
void SetDiffuseColor(const int &color)
std::string mGroupName
Definition SO3Material.h:50
STechnique * GetTechnique(const unsigned int &technique)
SWidget * GetAssociatedWidget()
void SetSpecularColor(const int &color)
void SetSelfIlluminationColor(const int &color)
void WriteMaterialFile(std::string path="")
void _BindTechniquesToOgre()
void SetIgnoreSlicePlane(bool state)
static void UpdateMaterialScript(std::string path)
void SetAmbientColor(const int &color)
void _UnbindTechniquesToOgre()
void SetReceiveShadows(const bool &state)
void SetPointSize(Ogre::Real size)
void RemoveTechnique(const unsigned int &technique)
std::string GetGroupName()
Ogre::MaterialPtr ogreMaterial
Definition SO3Material.h:47
void SetShininess(const float &value)
int GetTechniqueIndexByName(const std::string &techname)
bool mIgnoreSlicePlane
Definition SO3Material.h:51
static int CountMaterialsInScript(std::string path)
SWidget * associatedWidget
Definition SO3Material.h:49
bool GetIgnoreSlicePlane()
void _UpdateOgreMaterialPointer()
bool IsShaderGenerated()
Definition SO3Pass.cpp:151
void BuildShader(bool force=false)
Definition SO3Pass.cpp:165
void CleanGeneratedShader()
Definition SO3Pass.cpp:156
void RemoveGeneratedMaterial(Ogre::Material *mat)
Definition SO3Root.cpp:2343
static SRoot * getSingletonPtr()
Definition SO3Root.cpp:111
SShadowManager * GetShadowManager()
Ogre::MaterialManager * O3MaterialManager
Definition SO3Scene.h:129
Ogre::SceneManager * GetOgreScenePointer()
Definition SO3Scene.cpp:449
void UpdateShadowMaterial(Ogre::Technique *tech)
void CleanShadowMaterial(Ogre::Technique *tech)
SMaterial * GetParentMaterial()
Ogre::Technique * GetOgreTechniquePointer()