/*
This file contains proprietary software owned by Motorola Mobility, Inc.
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
*/
var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
var Material = require("js/lib/rdge/materials/material").Material;
var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive;
var LinearGradientMaterial = function LinearGradientMaterial() {
///////////////////////////////////////////////////////////////////////
// Instance variables
///////////////////////////////////////////////////////////////////////
this._name = "Linear Gradient";
this._shaderName = "linearGradient";
this._color1 = [1, 0, 0, 1];
this._color2 = [0, 1, 0, 1];
this._color3 = [0, 0, 1, 1];
this._color4 = [0, 1, 1, 1];
this._colorStop1 = 0.0;
this._colorStop2 = 0.3;
this._colorStop3 = 0.6;
this._colorStop4 = 1.0;
// this._colorCount = 4;
this._angle = 0.0; // the shader takes [cos(a), sin(a)]
this._textureTransform = [1,0,0, 0,1,0, 0,0,1];
///////////////////////////////////////////////////////////////////////
// Property Accessors
///////////////////////////////////////////////////////////////////////
this.getShaderDef = function() { return linearGradientMaterialDef; }
///////////////////////////////////////////////////////////////////////
// Material Property Accessors
///////////////////////////////////////////////////////////////////////
this._propNames = ["u_color1", "u_color2", "u_color3", "u_color4", "u_colorStop1", "u_colorStop2", "u_colorStop3", "u_colorStop4", "u_cos_sin_angle"];
this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4", "Angle"];
this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float", "vector2d"];
this._propValues = [];
this._propValues[this._propNames[0]] = this._color1.slice(0);
this._propValues[this._propNames[1]] = this._color2.slice(0);
this._propValues[this._propNames[2]] = this._color3.slice(0);
this._propValues[this._propNames[3]] = this._color4.slice(0);
this._propValues[this._propNames[4]] = this._colorStop1;
this._propValues[this._propNames[5]] = this._colorStop2;
this._propValues[this._propNames[6]] = this._colorStop3;
this._propValues[this._propNames[7]] = this._colorStop4;
this._propValues[this._propNames[8]] = [ Math.cos(this._angle), Math.sin(this._angle) ];
///////////////////////////////////////////////////////////////////////
// Methods
///////////////////////////////////////////////////////////////////////
// duplcate method requirde
this.init = function (world) {
this.setWorld(world);
// set up the shader
this._shader = new RDGE.jshader();
this._shader.def = linearGradientMaterialDef;
this._shader.init();
// set up the material node
this._materialNode = RDGE.createMaterialNode(this.getShaderName() + "_" + world.generateUniqueNodeID());
this._materialNode.setShader(this._shader);
if (this._shader && this._shader['default'])
this._shader['default'].u_texTransform.set( this._textureTransform );
// send the current values to the shader
this.setShaderValues();
this.update( 0 );
};
this.resetToDefault = function()
{
this._propValues[this._propNames[0]] = this._color1.slice(0);
this._propValues[this._propNames[1]] = this._color2.slice(0);
this._propValues[this._propNames[2]] = this._color3.slice(0);
this._propValues[this._propNames[3]] = this._color4.slice(0);
this._propValues[this._propNames[4]] = this._colorStop1;
this._propValues[this._propNames[5]] = this._colorStop2;
this._propValues[this._propNames[6]] = this._colorStop3;
this._propValues[this._propNames[7]] = this._colorStop4;
this._propValues[this._propNames[8]] = [ Math.cos(this._angle), Math.sin(this._angle) ];
var nProps = this._propNames.length;
for (var i=0; i