From f04f3240ab8e308e197d55748491d6f792d4c82b Mon Sep 17 00:00:00 2001 From: Farhad Ghayour Date: Fri, 12 Jun 2015 13:09:36 -0700 Subject: [PATCH 1/3] Clean: Update glossiness docs --- webgl-renderables/Mesh.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webgl-renderables/Mesh.js b/webgl-renderables/Mesh.js index 4fe8bab3..33831403 100644 --- a/webgl-renderables/Mesh.js +++ b/webgl-renderables/Mesh.js @@ -291,8 +291,8 @@ Mesh.prototype.getNormals = function getNormals (materialExpression) { * * @method * - * @param {MaterialExpression|Color} glossiness Accepts either a material expression or Color instance - * @param {Number} strength Optional value for changing the strength of the glossiness + * @param {MaterialExpression|Number} glossiness Accepts either a material expression or a number setting its strength + * @param {Color} specularColor Optional value for being able to change the specular color for glossiness. * * @return {Mesh} Mesh */ From 121642f1b98121a24037a4c4761abe75855deaed Mon Sep 17 00:00:00 2001 From: Farhad Ghayour Date: Fri, 12 Jun 2015 15:39:23 -0700 Subject: [PATCH 2/3] Breaking: Update glossiness API, to be able to have a default specular color if none provided --- webgl-renderables/Mesh.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/webgl-renderables/Mesh.js b/webgl-renderables/Mesh.js index 33831403..4ae0413c 100644 --- a/webgl-renderables/Mesh.js +++ b/webgl-renderables/Mesh.js @@ -54,9 +54,12 @@ function Mesh (node, options) { color: null, expressions: {}, flatShading: null, - glossiness: null, positionOffset: null, - normals: null + normals: null, + glossiness: { + factor: null, + color: [0, 0, 0] + } }; if (options) this.setDrawOptions(options); @@ -296,19 +299,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) { @@ -445,11 +453,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()) { - this._node.sendDrawCommand(Commands.GL_UNIFORMS); + 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); } @@ -649,7 +657,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); From a260d157c00c600f9af97e5ba5f72eb3b868ac1e Mon Sep 17 00:00:00 2001 From: Farhad Ghayour Date: Wed, 8 Jul 2015 13:22:33 -0700 Subject: [PATCH 3/3] Fix: Update Mesh getGlossiness tests --- webgl-renderables/Mesh.js | 14 +++++++------- webgl-renderables/test/Mesh.js | 8 +++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/webgl-renderables/Mesh.js b/webgl-renderables/Mesh.js index 4ae0413c..45364428 100644 --- a/webgl-renderables/Mesh.js +++ b/webgl-renderables/Mesh.js @@ -57,7 +57,7 @@ function Mesh (node, options) { positionOffset: null, normals: null, glossiness: { - factor: null, + strength: null, color: [0, 0, 0] } }; @@ -304,18 +304,18 @@ Mesh.prototype.setGlossiness = function setGlossiness(glossiness, specularColor) var hasSpecularColor = specularColor && specularColor.getNormalizedRGB; if (isMaterial) { - this.value.glossiness.factor = null; + this.value.glossiness.strength = null; this.value.expressions.glossiness = glossiness; } else { this.value.expressions.glossiness = null; - this.value.glossiness.factor = glossiness; + this.value.glossiness.strength = 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); + glossinessValue.push(this.value.glossiness.strength); glossiness = glossinessValue; } @@ -334,7 +334,7 @@ Mesh.prototype.setGlossiness = function setGlossiness(glossiness, specularColor) * * @method * - * @returns {MaterialExpress|Number} MaterialExpress or Number + * @returns {MaterialExpress|Object} MaterialExpression or Glossiness */ Mesh.prototype.getGlossiness = function getGlossiness() { return this.value.expressions.glossiness || this.value.glossiness; @@ -457,7 +457,7 @@ Mesh.prototype.onUpdate = function onUpdate() { this._node.sendDrawCommand('GL_UNIFORMS'); this._node.sendDrawCommand('u_glossiness'); var glossiness = this.value.glossiness.color.getNormalizedRGB(); - glossiness.push(this.value.glossiness.factor); + glossiness.push(this.value.glossiness.strength); this._node.sendDrawCommand(glossiness); this._node.requestUpdateOnNextTick(this._id); } @@ -657,7 +657,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.factor != null) this.setGlossiness.apply(this, value.glossiness.factor); + if (value.glossiness.strength != null) this.setGlossiness.apply(this, value.glossiness.strength); if (value.drawOptions != null) this.setDrawOptions(value.drawOptions); if (value.flatShading != null) this.setFlatShading(value.flatShading); diff --git a/webgl-renderables/test/Mesh.js b/webgl-renderables/test/Mesh.js index 06cd1a91..4a7d03d4 100644 --- a/webgl-renderables/test/Mesh.js +++ b/webgl-renderables/test/Mesh.js @@ -385,9 +385,11 @@ test('Mesh', function(t) { 'should be able to return the glossiness expression'); var x = new MockColor(); - mesh.setGlossiness(x, 10); - t.equal(mesh.getGlossiness()[0], x, - 'should be able to return the glossiness value'); + mesh.setGlossiness(10, x); + t.equal(mesh.getGlossiness().strength, 10, + 'should be able to return the glossiness strength'); + t.equal(mesh.getGlossiness().color, x, + 'should be able to return the glossiness color'); t.end(); });