Skip to content

Commit c06672f

Browse files
author
Farhad Ghayour
committed
Clean: Update glossiness API, to be able to have a default specular color if none provided
1 parent 5881578 commit c06672f

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

webgl-renderables/Mesh.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ function Mesh (node, options) {
5151
expressions: {},
5252
geometry: null,
5353
flatShading: null,
54-
glossiness: null,
5554
positionOffset: null,
56-
normals: null
55+
normals: null,
56+
glossiness: {
57+
factor: null,
58+
color: [0, 0, 0]
59+
}
5760
};
5861

5962
if (options) this.setDrawOptions(options);
@@ -292,19 +295,24 @@ Mesh.prototype.getNormals = function getNormals (materialExpression) {
292295
*
293296
* @return {Mesh} Mesh
294297
*/
295-
Mesh.prototype.setGlossiness = function setGlossiness(glossiness, strength) {
298+
Mesh.prototype.setGlossiness = function setGlossiness(glossiness, specularColor) {
296299
var isMaterial = glossiness.__isAMaterial__;
297-
var isColor = !!glossiness.getNormalizedRGB;
300+
var hasSpecularColor = specularColor && specularColor.getNormalizedRGB;
298301

299302
if (isMaterial) {
300-
this.value.glossiness = [null, null];
303+
this.value.glossiness.factor = null;
301304
this.value.expressions.glossiness = glossiness;
302305
}
303-
else if (isColor) {
306+
else {
304307
this.value.expressions.glossiness = null;
305-
this.value.glossiness = [glossiness, strength || 20];
306-
glossiness = glossiness ? glossiness.getNormalizedRGB() : [0, 0, 0];
307-
glossiness.push(strength || 20);
308+
this.value.glossiness.factor = glossiness;
309+
var glossinessValue = this.value.glossiness.color;
310+
if (hasSpecularColor) {
311+
this.value.glossiness.color = specularColor;
312+
glossinessValue = this.value.glossiness.color.getNormalizedRGB();
313+
}
314+
glossinessValue.push(this.value.glossiness.factor);
315+
glossiness = glossinessValue;
308316
}
309317

310318
if (this._initialized) {
@@ -441,11 +449,11 @@ Mesh.prototype.onUpdate = function onUpdate() {
441449
this._node.sendDrawCommand(this.value.color.getNormalizedRGBA());
442450
this._node.requestUpdateOnNextTick(this._id);
443451
}
444-
if (this.value.glossiness && this.value.glossiness[0] && this.value.glossiness[0].isActive()) {
452+
if (this.value.glossiness.color.isActive && this.value.glossiness.color.isActive()) {
445453
this._node.sendDrawCommand('GL_UNIFORMS');
446454
this._node.sendDrawCommand('u_glossiness');
447-
var glossiness = this.value.glossiness[0].getNormalizedRGB();
448-
glossiness.push(this.value.glossiness[1]);
455+
var glossiness = this.value.glossiness.color.getNormalizedRGB();
456+
glossiness.push(this.value.glossiness.factor);
449457
this._node.sendDrawCommand(glossiness);
450458
this._node.requestUpdateOnNextTick(this._id);
451459
}
@@ -640,7 +648,7 @@ Mesh.prototype.draw = function draw () {
640648

641649
if (value.geometry != null) this.setGeometry(value.geometry);
642650
if (value.color != null) this.setBaseColor(value.color);
643-
if (value.glossiness != null) this.setGlossiness.apply(this, value.glossiness);
651+
if (value.glossiness.factor != null) this.setGlossiness.apply(this, value.glossiness.factor);
644652
if (value.drawOptions != null) this.setDrawOptions(value.drawOptions);
645653
if (value.flatShading != null) this.setFlatShading(value.flatShading);
646654

0 commit comments

Comments
 (0)