13 #include <Inventor/C/errors/debugerror.h>
14 #include <Inventor/nodes/SoMaterial.h>
15 #include <Inventor/sensors/SoNodeSensor.h>
23 static float norm(
const float&
x) {
return (
x<0.0
f?0.0
f:(
x>1.0
f?1.0
f:
x));}
72 for (it2=
it->first.begin(), it2E=
it->first.end();it2!=it2E;++it2)
79 std::map<SoMaterial*,double>::const_iterator it2,it2E;
81 for (it2=
it->first.begin(),it2E=
it->first.end();it2!=it2E;++it2)
106 +
") different material combinations. Try to use fewer combinations for better performance!");
111 ") different materials. Try to lower this number for better performance!");
121 &&
m->ambientColor.getNum() == 1
122 &&
m->diffuseColor.getNum() == 1
123 &&
m->specularColor.getNum() == 1
124 &&
m->emissiveColor.getNum() == 1
125 &&
m->transparency.getNum() == 1
126 &&
m->shininess.getNum() == 1;
133 SoMaterial *material = (SoMaterial *)
data;
134 if (!inputMaterialValid(material)) {
136 " (multiple values in a field). Ignore changes.");
141 if (
it!=sensor2matmixerimp.end())
142 it->second->materialChanged(material);
148 if (mat2sensors.find(
mat)!=mat2sensors.end())
153 sensor2matmixerimp[sensor] =
this;
154 mat2sensors[
mat]=sensor;
163 std::map<std::set<SoMaterial*>,SoMaterial*>::const_iterator
it,
itE = matlists2mixedmats.end();
164 for (
it = matlists2mixedmats.begin();
it!=
itE;++
it) {
166 for (;it2!=it2E;++it2) {
168 setMaterialFieldsAsAverageOfMatList(
it->second,
it->first);
174 std::map<std::map<SoMaterial*,double>,SoMaterial*>::const_iterator it3, it3E = matlists2mixedmats_weighted.end();
175 for (it3 = matlists2mixedmats_weighted.begin();it3!=it3E;++it3) {
176 std::map<SoMaterial*,double>::const_iterator it4(it3->first.begin()),it4E(it3->first.end());
177 for (;it4!=it4E;++it4) {
178 if (
mat==it4->first) {
179 setMaterialFieldsAsAverageOfMatList(it3->second,it3->first);
190 float ambient_r(0.0
f), ambient_g(0.0
f), ambient_b(0.0
f);
191 float diffuse_r(0.0
f), diffuse_g(0.0
f), diffuse_b(0.0
f);
192 float specular_r(0.0
f), specular_g(0.0
f), specular_b(0.0
f);
193 float emissive_r(0.0
f), emissive_g(0.0
f), emissive_b(0.0
f);
194 float shininess(0.0
f), transparency(0.0
f);
196 std::set<SoMaterial*>::const_iterator
it(matlist.begin()),
itE(matlist.end());
198 (*it)->ambientColor[0].getValue(
r,
g,
b); ambient_r +=
r; ambient_g +=
g; ambient_b +=
b;
199 (*it)->diffuseColor[0].getValue(
r,
g,
b); diffuse_r +=
r; diffuse_g +=
g; diffuse_b +=
b;
200 (*it)->specularColor[0].getValue(
r,
g,
b); specular_r +=
r; specular_g +=
g; specular_b +=
b;
201 (*it)->emissiveColor[0].getValue(
r,
g,
b); emissive_r +=
r; emissive_g +=
g; emissive_b +=
b;
202 shininess += (*it)->shininess[0];
203 transparency += (*it)->transparency[0];
206 float n = 1.0f/matlist.size();
207 bool save =
mat->enableNotify(
false);
210 mat->specularColor.setValue(
norm(
n*specular_r),
norm(
n*specular_g),
norm(
n*specular_b));
211 mat->emissiveColor.setValue(
norm(
n*emissive_r),
norm(
n*emissive_g),
norm(
n*emissive_b));
212 mat->shininess.setValue(
norm(
n*shininess));
213 mat->transparency.setValue(
norm(
n*transparency));
215 mat->enableNotify(
true);
218 theclass->messageVerbose(
"Material ("+
str(
mat)+
") updated and touched");
222 theclass->messageVerbose(
"Material ("+
str(
mat)+
") updated but notifications were off");
230 float w, totweight(0.0
f);
231 float ambient_r(0.0
f), ambient_g(0.0
f), ambient_b(0.0
f);
232 float diffuse_r(0.0
f), diffuse_g(0.0
f), diffuse_b(0.0
f);
233 float specular_r(0.0
f), specular_g(0.0
f), specular_b(0.0
f);
234 float emissive_r(0.0
f), emissive_g(0.0
f), emissive_b(0.0
f);
235 float shininess(0.0
f), transparency(0.0
f);
237 std::map<SoMaterial*,double>::const_iterator
it(matlist.begin()),
itE(matlist.end());
243 m->ambientColor[0].getValue(
r,
g,
b); ambient_r +=
w*
r; ambient_g +=
w*
g; ambient_b +=
w*
b;
244 m->diffuseColor[0].getValue(
r,
g,
b); diffuse_r +=
w*
r; diffuse_g +=
w*
g; diffuse_b +=
w*
b;
245 m->specularColor[0].getValue(
r,
g,
b); specular_r +=
w*
r; specular_g +=
w*
g; specular_b +=
w*
b;
246 m->emissiveColor[0].getValue(
r,
g,
b); emissive_r +=
w*
r; emissive_g +=
w*
g; emissive_b +=
w*
b;
247 shininess +=
m->shininess[0]*
w;
248 transparency +=
m->transparency[0]*
w;
251 float n = 1.0f/totweight;
252 bool save =
mat->enableNotify(
false);
255 mat->specularColor.setValue(
norm(
n*specular_r),
norm(
n*specular_g),
norm(
n*specular_b));
256 mat->emissiveColor.setValue(
norm(
n*emissive_r),
norm(
n*emissive_g),
norm(
n*emissive_b));
257 mat->shininess.setValue(
norm(
n*shininess));
258 mat->transparency.setValue(
norm(
n*transparency));
260 mat->enableNotify(
true);
263 theclass->messageVerbose(
"Material ("+
str(
mat)+
") updated and touched");
267 theclass->messageVerbose(
"Material ("+
str(
mat)+
") updated but notifications were off");
276 std::set<SoMaterial*>::const_iterator
it(matlist.begin()),
itE(matlist.end());
283 if (matlist.empty()) {
293 if (matlist.size()==1)
294 return *(matlist.begin());
297 std::map<std::set<SoMaterial*>,SoMaterial*>::const_iterator it2 =
m_d->
matlists2mixedmats.find(matlist);
302 SoMaterial * mixmat =
new SoMaterial;
306 std::set<SoMaterial*>::const_iterator it3(matlist.begin()), it3E(matlist.end());
307 for (;it3!=it3E;++it3) {
322 std::map<SoMaterial*,double>::const_iterator
it(matlist.begin()),
itE(matlist.end());
329 if (matlist.empty()) {
339 if (matlist.size()==1)
340 return matlist.begin()->first;
348 SoMaterial * mixmat =
new SoMaterial;
352 std::map<SoMaterial*,double>::const_iterator it3(matlist.begin()), it3E(matlist.end());
353 for (;it3!=it3E;++it3) {
366 std::set<SoMaterial*> matlist;
374 SoMaterial* mat2,
const double& weight2 )
376 std::map<SoMaterial*,double> matlist;
377 matlist[mat1] = weight1;
378 matlist[mat2] = weight2;