aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-vert-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/twist-vert-material.js')
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js362
1 files changed, 176 insertions, 186 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index 7d9dd6d6..4d5ab88d 100644
--- a/js/lib/rdge/materials/twist-vert-material.js
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -13,235 +13,227 @@ var Texture = require("js/lib/rdge/texture").Texture;
13/////////////////////////////////////////////////////////////////////// 13///////////////////////////////////////////////////////////////////////
14var TwistVertMaterial = function TwistVertMaterial() 14var TwistVertMaterial = function TwistVertMaterial()
15{ 15{
16 // initialize the inherited members 16 // initialize the inherited members
17 this.inheritedFrom = Material; 17 this.inheritedFrom = Material;
18 this.inheritedFrom(); 18 this.inheritedFrom();
19 19
20 /////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////
21 // Instance variables 21 // Instance variables
22 /////////////////////////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////////////////////////
23 this._name = "TwistVertMaterial"; 23 this._name = "TwistVertMaterial";
24 this._shaderName = "twistVert"; 24 this._shaderName = "twistVert";
25 25
26 this._color = [1, 0, 0, 1]; 26 this._tex0 = 'assets/images/rocky-normal.jpg';
27 27 this._tex1 = 'assets/images/metal.png';
28 this._tex0 = 'assets/images/rocky-normal.jpg';
29 this._tex1 = 'assets/images/metal.png';
30 28
31 this._glTex0; 29 this._glTex0;
32 this._glTex1; 30 this._glTex1;
33 31
34 this._angle = 0.0; 32 this._angle = 0.0;
35 this._deltaTime = 0.01; 33 this._deltaTime = 0.01;
34 this._speed = 1.0;
36 35
37 /////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////
38 // Property Accessors 37 // Property Accessors
39 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
40 this.getColor = function () { return this._color; }; 39 this.getShaderName = function () { return this._shaderName; };
41 this.getShaderName = function () { return this._shaderName; };
42 40
43 this.isAnimated = function () { return true; }; 41 this.isAnimated = function () { return true; };
44 42
45 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 43 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
46 this._hasVertexDeformation = true; 44 this._hasVertexDeformation = true;
47 this._vertexDeformationTolerance = 0.02; // should be a property 45 this._vertexDeformationTolerance = 0.02; // should be a property
48 46
49 /////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////
50 // Methods 48 // Methods
51 /////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////
52 // duplcate method requirde 50 // duplcate method requirde
53 this.dup = function() { 51 this.dup = function() {
54 // get the current values; 52 // get the current values;
55 var propNames = [], propValues = [], propTypes = [], propLabels = []; 53 var propNames = [], propValues = [], propTypes = [], propLabels = [];
56 this.getAllProperties(propNames, propValues, propTypes, propLabels); 54 this.getAllProperties(propNames, propValues, propTypes, propLabels);
57 55
58 // allocate a new material 56 // allocate a new material
59 var newMat = new TwistVertMaterial(); 57 var newMat = new TwistVertMaterial();
60 58
61 // copy over the current values; 59 // copy over the current values;
62 var n = propNames.length; 60 var n = propNames.length;
63 for (var i = 0; i < n; i++) 61 for (var i = 0; i < n; i++)
64 newMat.setProperty(propNames[i], propValues[i]); 62 newMat.setProperty(propNames[i], propValues[i]);
65 63
66 return newMat; 64 return newMat;
67 }; 65 };
68 66
69 this.init = function (world) 67 this.init = function (world)
70 { 68 {
71 this.setWorld(world); 69 this.setWorld(world);
72
73 // set up the shader
74 this._shader = new RDGE.jshader();
75 this._shader.def = twistVertShaderDef;
76 this._shader.init();
77 70
78 // set the defaults 71 // set up the shader
79 this._shader.twistMe.color.set(this.getColor()); 72 this._shader = new RDGE.jshader();
73 this._shader.def = twistVertShaderDef;
74 this._shader.init();
80 75
81 // set up the material node 76 // set up the material node
82 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); 77 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID());
83 this._materialNode.setShader(this._shader); 78 this._materialNode.setShader(this._shader);
84 79
85 // set up the texture maps 80 // set up the texture maps
86 this.updateTextures(); 81 this.updateTextures();
87 82
88 // initialize the twist vert properties 83 // initialize the twist vert properties
89 this.updateShaderValues(); 84 this.updateShaderValues();
90 }; 85 };
91 86
92 87
93 /////////////////////////////////////////////////////////////////////// 88 ///////////////////////////////////////////////////////////////////////
94 // Material Property Accessors 89 // Material Property Accessors
95 /////////////////////////////////////////////////////////////////////// 90 ///////////////////////////////////////////////////////////////////////
96 this._propNames = ["color", "u_limit1", "u_limit2", "u_center", "u_twistAmount", "u_tex0", "u_tex1"]; 91 this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"];
97 this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Center", "Twist Amount", "Front facing texture map", "Back facing texture map"]; 92 this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"];
98 this._propTypes = ["color", "float", "float", "float", "float", "file", "file"]; 93 this._propTypes = [ "float", "float", "angle", "float", "file", "file"];
99 this._propValues = []; 94 this._propValues = [];
100 95
101 // initialize the property values 96 // initialize the property values
102 this._propValues[this._propNames[0]] = this._color.slice(); 97 this._propValues[this._propNames[0]] = 0.0;
103 this._propValues[this._propNames[1]] = 0.25; 98 this._propValues[this._propNames[1]] = 1.0;
104 this._propValues[this._propNames[2]] = 0.75; 99 this._propValues[this._propNames[2]] = 2.0 * Math.PI;
105 this._propValues[this._propNames[3]] = 0.0; 100 this._propValues[this._propNames[3]] = this._speed;
106 this._propValues[this._propNames[4]] = 2.0 * Math.PI; 101 this._propValues[this._propNames[4]] = this._tex0.slice();
107 this._propValues[this._propNames[5]] = this._tex0.slice(); 102 this._propValues[this._propNames[5]] = this._tex1.slice();
108 this._propValues[this._propNames[6]] = this._tex1.slice(); 103
109 104 this.setProperty = function (prop, value)
110 this.setProperty = function (prop, value)
111 { 105 {
112 // make sure we have legitimate input 106 // make sure we have legitimate input
113 if (this.validateProperty(prop, value)) 107 if (this.validateProperty(prop, value))
114 { 108 {
115 switch (prop) { 109 switch (prop) {
116 case "color": 110 case "u_tex1":
117 case "u_tex1": 111 case "u_tex0": this._propValues[prop] = value ? value.slice() : null;
118 case "u_tex0": this._propValues[prop] = value.slice(); break; 112 this.updateTextures();
119 default: this._propValues[prop] = value; break; 113 break;
120 } 114
121 115 default:
122 this.updateShaderValues(); 116 this._propValues[prop] = value;
123 } 117 break;
124 }; 118 }
125 /////////////////////////////////////////////////////////////////////// 119
126 120 this.updateShaderValues();
127 this.exportJSON = function () { 121 }
128 var jObj = 122 };
123 ///////////////////////////////////////////////////////////////////////
124
125 this.exportJSON = function () {
126 var jObj =
129 { 127 {
130 'material': this.getShaderName(), 128 'material': this.getShaderName(),
131 'name': this.getName(), 129 'name': this.getName(),
132 'color': this._propValues["color"]
133 } 130 }
134 131
135 return jObj; 132 return jObj;
136 }; 133 };
137 134
138 this.importJSON = function (jObj) { 135 this.importJSON = function (jObj) {
139 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); 136 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
140 this.setName(jObj.name); 137 this.setName(jObj.name);
141 138
142 try { 139 try {
143 var color = jObj.color; 140 }
144 this.setProperty("color", color); 141 catch (e) {
145 } 142 throw new Error("could not import material: " + importStr);
146 catch (e) { 143 }
147 throw new Er