diff options
Diffstat (limited to 'js/lib/rdge/materials/flat-material.js')
-rwxr-xr-x | js/lib/rdge/materials/flat-material.js | 97 |
1 files changed, 30 insertions, 67 deletions
diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index 9442ae5b..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 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | ||
8 | var Material = require("js/lib/rdge/materials/material").Material; | 7 | var 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 | /////////////////////////////////////////////////////////////////////// |
13 | var FlatMaterial = function FlatMaterial() { | 13 | var FlatMaterial = function FlatMaterial() |
14 | { | ||
14 | /////////////////////////////////////////////////////////////////////// | 15 | /////////////////////////////////////////////////////////////////////// |
15 | // Instance variables | 16 | // Instance variables |
16 | /////////////////////////////////////////////////////////////////////// | 17 | /////////////////////////////////////////////////////////////////////// |
@@ -22,21 +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 true; }; | ||
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 () { return new FlatMaterial(); }; | ||
38 | 34 | ||
39 | this.init = function (world) { | 35 | this.init = function (world) |
36 | { | ||
40 | // save the world | 37 | // save the world |
41 | if (world) { | 38 | if (world) { |
42 | this.setWorld(world); | 39 | this.setWorld(world); |
@@ -46,12 +43,11 @@ var FlatMaterial = function FlatMaterial() { | |||
46 | this._shader.def = flatShaderDef; | 43 | this._shader.def = flatShaderDef; |
47 | this._shader.init(); | 44 | this._shader.init(); |
48 | 45 | ||
49 | // set the defaults | ||
50 | this._shader.colorMe.color.set(this.getColor()); | ||
51 | |||
52 | // set up the material node | 46 | // set up the material node |
53 | this._materialNode = RDGE.createMaterialNode("flatMaterial_" + world.generateUniqueNodeID()); | 47 | this._materialNode = RDGE.createMaterialNode("flatMaterial_" + world.generateUniqueNodeID()); |
54 | this._materialNode.setShader(this._shader); | 48 | this._materialNode.setShader(this._shader); |
49 | |||
50 | this.setShaderValues(); | ||
55 | } | 51 | } |
56 | else | 52 | else |
57 | throw new Error("GLWorld not supplied to material initialization"); | 53 | throw new Error("GLWorld not supplied to material initialization"); |
@@ -67,39 +63,6 @@ var FlatMaterial = function FlatMaterial() { | |||
67 | this._propValues = []; | 63 | this._propValues = []; |
68 | 64 | ||
69 | this._propValues[this._propNames[0]] = this._color; | 65 | this._propValues[this._propNames[0]] = this._color; |
70 | |||
71 | this.setProperty = function (prop, value) { | ||
72 | // make sure we have legitimate input | ||
73 | if (this.validateProperty(prop, value)) { | ||
74 | this._propValues[prop] = value; | ||
75 | if (this._shader && this._shader.colorMe) { | ||
76 | this._shader.colorMe[prop].set(value); | ||
77 | } | ||
78 | } | ||
79 | }; | ||
80 | /////////////////////////////////////////////////////////////////////// | ||
81 | |||
82 | this.exportJSON = function () { | ||
83 | var jObj = | ||
84 | { | ||
85 | 'material': this.getShaderName(), | ||
86 | 'name': this.getName(), | ||
87 | 'color': this._propValues["color"] | ||
88 | }; | ||
89 | |||
90 | return jObj; | ||
91 | }; | ||
92 | |||
93 | this.importJSON = function (jObj) { | ||
94 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); | ||
95 | this.setName(jObj.name); | ||
96 | |||
97 | var color = jObj.color; | ||
98 | this.setProperty("color", color); | ||
99 | }; | ||
100 | |||
101 | this.update = function (time) { | ||
102 | }; | ||
103 | }; | 66 | }; |
104 | 67 | ||
105 | /////////////////////////////////////////////////////////////////////////////////////// | 68 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -108,31 +71,31 @@ var FlatMaterial = function FlatMaterial() { | |||
108 | // 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) |
109 | flatShaderDef = | 72 | flatShaderDef = |
110 | { | 73 | { |
111 | 'shaders': { // shader files | 74 | 'shaders': { // shader files |
112 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | 75 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", |
113 | 'defaultFShader':"assets/shaders/Basic.frag.glsl" | 76 | 'defaultFShader':"assets/shaders/Basic.frag.glsl" |
114 | }, | 77 | }, |
115 | 'techniques': { // rendering control | 78 | 'techniques': { // rendering control |
116 | 'colorMe':[ // simple color pass | 79 | 'colorMe':[ // simple color pass |
117 | { | 80 | { |
118 | 'vshader' : 'defaultVShader', | 81 | 'vshader' : 'defaultVShader', |
119 | 'fshader' : 'defaultFShader', | 82 | 'fshader' : 'defaultFShader', |
120 | 83 | ||
121 | // attributes | 84 | // attributes |
122 | 'attributes' : | 85 | 'attributes' : |
123 | { | 86 | { |
124 | 'vert' : { 'type' : 'vec3' }, | 87 | 'vert' : { 'type' : 'vec3' }, |
125 | 'normal' : { 'type' : 'vec3' }, | 88 | 'normal' : { 'type' : 'vec3' }, |
126 | 'texcoord' : { 'type' : 'vec2' } | 89 | 'texcoord' : { 'type' : 'vec2' } |
127 | }, | 90 | }, |
128 | // attributes | 91 | // attributes |
129 | 'params' : | 92 | 'params' : |
130 | { | 93 | { |
131 | 'color' : { 'type' : 'vec4' } | 94 | 'color' : { 'type' : 'vec4' } |
132 | } | 95 | } |
133 | } | 96 | } |
134 | ] | 97 | ] |
135 | } | 98 | } |
136 | }; | 99 | }; |
137 | 100 | ||
138 | FlatMaterial.prototype = new Material(); | 101 | FlatMaterial.prototype = new Material(); |