189{
190 float ambient_r(0.0f), ambient_g(0.0f), ambient_b(0.0f);
191 float diffuse_r(0.0f), diffuse_g(0.0f), diffuse_b(0.0f);
192 float specular_r(0.0f), specular_g(0.0f), specular_b(0.0f);
193 float emissive_r(0.0f), emissive_g(0.0f), emissive_b(0.0f);
194 float shininess(0.0f), transparency(0.0f);
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];
204 }
205
206 float n = 1.0f/matlist.size();
207 bool save =
mat->enableNotify(
false);
208 mat->ambientColor.setValue(
norm(n*ambient_r),
norm(n*ambient_g),
norm(n*ambient_b));
209 mat->diffuseColor.setValue(
norm(n*diffuse_r),
norm(n*diffuse_g),
norm(n*diffuse_b));
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));
214 if (save) {
215 mat->enableNotify(
true);
218 theclass->messageVerbose(
"Material ("+
str(mat)+
") updated and touched");
219 }
220 } else {
222 theclass->messageVerbose(
"Material ("+
str(mat)+
") updated but notifications were off");
223 }
224 }
225}