aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/flat-material.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-06-19 10:25:16 -0700
committerJose Antonio Marquez2012-06-19 10:25:16 -0700
commit4d2a5acd1631f0cf4e38f127c886f481668ddce0 (patch)
tree3bc8f2b21826c0ee6d37bc77753d45a882783cbf /js/lib/rdge/materials/flat-material.js
parent616b31a644ee221edcbc19f821b2194e8edf9fad (diff)
parent483ad57efcd6475776f580c3af5b60e6deeaf781 (diff)
downloadninja-4d2a5acd1631f0cf4e38f127c886f481668ddce0.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into FileIO
Diffstat (limited to 'js/lib/rdge/materials/flat-material.js')
-rwxr-xr-xjs/lib/rdge/materials/flat-material.js99
1 files changed, 31 insertions, 68 deletions
diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js
index 9442ae5b..791dcc27 100755
--- a/js/lib/rdge/materials/flat-material.js
+++ b/js/lib/rdge/materials/flat-material.js
@@ -4,17 +4,18 @@
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 ///////////////////////////////////////////////////////////////////////
17 this._name = "FlatMaterial"; 18 this._name = "Flat";
18 this._shaderName = "flat"; 19 this._shaderName = "flat";
19 20
20 this._color = [1, 0, 0, 1]; 21 this._color = [1, 0, 0, 1];
@@ -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)
109flatShaderDef = 72flatShaderDef =
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
138FlatMaterial.prototype = new Material(); 101FlatMaterial.prototype = new Material();