Skip to content

Commit

Permalink
Breaking: Update glossiness API, to be able to have a default specula…
Browse files Browse the repository at this point in the history
…r color if none provided
  • Loading branch information
Farhad Ghayour committed Jul 8, 2015
1 parent 5881578 commit 7adf5b9
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions webgl-renderables/Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 7adf5b9

Please sign in to comment.