From 7adf5b9a80aa2ae05203593cae1885d1b4b82f43 Mon Sep 17 00:00:00 2001 From: Farhad Ghayour Date: Fri, 12 Jun 2015 15:39:23 -0700 Subject: [PATCH] Breaking: Update glossiness API, to be able to have a default specular color if none provided --- webgl-renderables/Mesh.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/webgl-renderables/Mesh.js b/webgl-renderables/Mesh.js index 2a3f98d9..12eb0982 100644 --- a/webgl-renderables/Mesh.js +++ b/webgl-renderables/Mesh.js @@ -51,9 +51,12 @@ function Mesh (node, options) { expressions: {}, geometry: null, flatShading: null, - glossiness: null, positionOffset: null, - normals: null + normals: null, + glossiness: { + factor: null, + color: [0, 0, 0] + } }; if (options) this.setDrawOptions(options); @@ -292,19 +295,24 @@ Mesh.prototype.getNormals = function getNormals (materialExpression) { * * @return {Mesh} Mesh */ -Mesh.prototype.setGlossiness = function setGlossiness(glossiness, strength) { +Mesh.prototype.setGlossiness = function setGlossiness(glossiness, specularColor) { var isMaterial = glossiness.__isAMaterial__; - var isColor = !!glossiness.getNormalizedRGB; + var hasSpecularColor = specularColor && specularColor.getNormalizedRGB; if (isMaterial) { - this.value.glossiness = [null, null]; + this.value.glossiness.factor = null; this.value.expressions.glossiness = glossiness; } - else if (isColor) { + else { this.value.expressions.glossiness = null; - this.value.glossiness = [glossiness, strength || 20]; - glossiness = glossiness ? glossiness.getNormalizedRGB() : [0, 0, 0]; - glossiness.push(strength || 20); + this.value.glossiness.factor = glossiness; + var glossinessValue = this.value.glossiness.color; + if (hasSpecularColor) { + this.value.glossiness.color = specularColor; + glossinessValue = this.value.glossiness.color.getNormalizedRGB(); + } + glossinessValue.push(this.value.glossiness.factor); + glossiness = glossinessValue; } if (this._initialized) { @@ -441,11 +449,11 @@ Mesh.prototype.onUpdate = function onUpdate() { this._node.sendDrawCommand(this.value.color.getNormalizedRGBA()); this._node.requestUpdateOnNextTick(this._id); } - if (this.value.glossiness && this.value.glossiness[0] && this.value.glossiness[0].isActive()) { + if (this.value.glossiness.color.isActive && this.value.glossiness.color.isActive()) { this._node.sendDrawCommand('GL_UNIFORMS'); this._node.sendDrawCommand('u_glossiness'); - var glossiness = this.value.glossiness[0].getNormalizedRGB(); - glossiness.push(this.value.glossiness[1]); + var glossiness = this.value.glossiness.color.getNormalizedRGB(); + glossiness.push(this.value.glossiness.factor); this._node.sendDrawCommand(glossiness); this._node.requestUpdateOnNextTick(this._id); } @@ -640,7 +648,7 @@ Mesh.prototype.draw = function draw () { if (value.geometry != null) this.setGeometry(value.geometry); if (value.color != null) this.setBaseColor(value.color); - if (value.glossiness != null) this.setGlossiness.apply(this, value.glossiness); + if (value.glossiness.factor != null) this.setGlossiness.apply(this, value.glossiness.factor); if (value.drawOptions != null) this.setDrawOptions(value.drawOptions); if (value.flatShading != null) this.setFlatShading(value.flatShading);