aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/flat-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/flat-material.js')
-rwxr-xr-xjs/lib/rdge/materials/flat-material.js113
1 files changed, 30 insertions, 83 deletions
diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js
index e5498b65..579813b8 100755
--- a/js/lib/rdge/materials/flat-material.js
+++ b/js/lib/rdge/materials/flat-material.js
@@ -4,13 +4,14 @@
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */ 5 </copyright> */
6 6
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material; 7var Material = require("js/lib/rdge/materials/material").Material;
8
9/////////////////////////////////////////////////////////////////////// 9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial 10// Class GLMaterial
11// RDGE representation of a material. 11// RDGE representation of a material.
12/////////////////////////////////////////////////////////////////////// 12///////////////////////////////////////////////////////////////////////
13var FlatMaterial = function FlatMaterial() { 13var FlatMaterial = function FlatMaterial()
14{
14 /////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////
15 // Instance variables 16 // Instance variables
16 /////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////
@@ -22,36 +23,17 @@ var FlatMaterial = function FlatMaterial() {
22 /////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////
23 // Property Accessors 24 // Property Accessors
24 /////////////////////////////////////////////////////////////////////// 25 ///////////////////////////////////////////////////////////////////////
25 this.getColor = function () { return this._color; };
26 this.getShaderName = function () { return this._shaderName; }; 26 this.getShaderName = function () { return this._shaderName; };
27 this.isAnimated = function () { return false; };
28 this.getTechniqueName = function() { return 'colorMe' };
27 29
28 this.isAnimated = function () { return false; }; 30 ///////////////////////////////////////////////////////////////////////
29 this.hasVertexDeformation = function() { return false; };
30 this._hasVertexDeformation = true;
31 this._vertexDeformationTolerance = 0.2;
32
33 //////////////////////////////////s/////////////////////////////////////
34 // Methods 31 // Methods
35 /////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////
36 // duplcate method requirde 33 // duplcate method requirde
37 this.dup = function( world )
38 {
39 // get the current values;
40 var propNames = [], propValues = [], propTypes = [], propLabels = [];
41 this.getAllProperties(propNames, propValues, propTypes, propLabels);
42
43 // allocate a new material
44 var newMat = new FlatMaterial();
45
46 // copy over the current values;
47 var n = propNames.length;
48 for (var i = 0; i < n; i++)
49 newMat.setProperty(propNames[i], propValues[i]);
50 34
51 return newMat; 35 this.init = function (world)
52 }; 36 {
53
54 this.init = function (world) {
55 // save the world 37 // save the world
56 if (world) { 38 if (world) {
57 this.setWorld(world); 39 this.setWorld(world);
@@ -61,12 +43,11 @@ var FlatMaterial = function FlatMaterial() {
61 this._shader.def = flatShaderDef; 43 this._shader.def = flatShaderDef;
62 this._shader.init(); 44 this._shader.init();
63 45
64 // set the defaults
65 this._shader.colorMe.color.set(this.getColor());
66
67 // set up the material node 46 // set up the material node
68 this._materialNode = RDGE.createMaterialNode("flatMaterial_" + world.generateUniqueNodeID()); 47 this._materialNode = RDGE.createMaterialNode("flatMaterial_" + world.generateUniqueNodeID());
69 this._materialNode.setShader(this._shader); 48 this._materialNode.setShader(this._shader);
49
50 this.setShaderValues();
70 } 51 }
71 else 52 else
72 throw new Error("GLWorld not supplied to material initialization"); 53 throw new Error("GLWorld not supplied to material initialization");
@@ -82,40 +63,6 @@ var FlatMaterial = function FlatMaterial() {
82 this._propValues = []; 63 this._propValues = [];
83 64
84 this._propValues[this._propNames[0]] = this._color; 65 this._propValues[this._propNames[0]] = this._color;
85
86 this.setProperty = function (prop, value) {
87 // make sure we have legitimate input
88 if (this.validateProperty(prop, value)) {
89 this._propValues[prop] = value;
90 if (prop === 'color') this._color = value.slice();
91 if (this._shader && this._shader.colorMe) {
92 this._shader.colorMe[prop].set(value);
93 }
94 }
95 };
96 ///////////////////////////////////////////////////////////////////////
97
98 this.exportJSON = function () {
99 var jObj =
100 {
101 'material': this.getShaderName(),
102 'name': this.getName(),
103 'color': this._propValues["color"]
104 };
105
106 return jObj;
107 };
108
109 this.importJSON = function (jObj) {
110 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
111 this.setName(jObj.name);
112
113 var color = jObj.color;
114 this.setProperty("color", color);
115 };
116
117 this.update = function (time) {
118 };
119}; 66};
120 67
121/////////////////////////////////////////////////////////////////////////////////////// 68///////////////////////////////////////////////////////////////////////////////////////
@@ -124,31 +71,31 @@ var FlatMaterial = function FlatMaterial() {
124// shader spec (can also be loaded from a .JSON file, or constructed at runtime) 71// shader spec (can also be loaded from a .JSON file, or constructed at runtime)
125flatShaderDef = 72flatShaderDef =
126{ 73{
127 'shaders': { // shader files 74 'shaders': { // shader files
128 'defaultVShader':"assets/shaders/Basic.vert.glsl", 75 'defaultVShader':"assets/shaders/Basic.vert.glsl",
129 'defaultFShader':"assets/shaders/Basic.frag.glsl" 76 'defaultFShader':"assets/shaders/Basic.frag.glsl"
130 }, 77 },
131 'techniques': { // rendering control 78 'techniques': { // rendering control
132 'colorMe':[ // simple color pass 79 'colorMe':[ // simple color pass
133 { 80 {
134 'vshader' : 'defaultVShader', 81 'vshader' : 'defaultVShader',
135 'fshader' : 'defaultFShader', 82 'fshader' : 'defaultFShader',
136 83
137 // attributes 84 // attributes
138 'attributes' : 85 'attributes' :
139 { 86 {
140 'vert' : { 'type' : 'vec3' }, 87 'vert' : { 'type' : 'vec3' },
141 'normal' : { 'type' : 'vec3' }, 88 'normal' : { 'type' : 'vec3' },
142 'texcoord' : { 'type' : 'vec2' } 89 'texcoord' : { 'type' : 'vec2' }
143 }, 90 },
144 // attributes 91 // attributes
145 'params' : 92 'params' :
146 { 93 {
147 'color' : { 'type' : 'vec4' } 94 'color' : { 'type' : 'vec4' }
148 } 95 }
149 } 96 }
150 ] 97 ]
151 } 98 }
152}; 99};
153 100
154FlatMaterial.prototype = new Material(); 101FlatMaterial.prototype = new Material();