aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-vert-material.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-07-09 14:35:44 -0700
committerValerio Virgillito2012-07-09 14:35:44 -0700
commit84b3327bd92faafab7954b5eb64c7abe24a3fe13 (patch)
tree3f56cbed2f08c5a81ea79eaf0bcb9bd031d8a627 /js/lib/rdge/materials/twist-vert-material.js
parentc0a42c56f768a873ba637f5b86d5f6a84d4a3312 (diff)
parent40c6eb2c06b34f65a74d59ef9687251952858bab (diff)
downloadninja-84b3327bd92faafab7954b5eb64c7abe24a3fe13.tar.gz
Merge branch 'normalize' of https://github.com/kriskowal/ninja-internal
Conflicts: js/components/gradientpicker.reel/gradientpicker.js js/components/tools-properties/text-properties.reel/text-properties.js js/document/views/base.js js/document/views/design.js js/helper-classes/3D/StageLine.js js/helper-classes/3D/draw-utils.js js/lib/drawing/world.js js/lib/geom/circle.js js/lib/geom/line.js js/lib/geom/rectangle.js js/lib/geom/shape-primitive.js js/lib/rdge/materials/bump-metal-material.js js/lib/rdge/materials/flag-material.js js/lib/rdge/materials/fly-material.js js/lib/rdge/materials/julia-material.js js/lib/rdge/materials/keleidoscope-material.js js/lib/rdge/materials/mandel-material.js js/lib/rdge/materials/material.js js/lib/rdge/materials/plasma-material.js js/lib/rdge/materials/pulse-material.js js/lib/rdge/materials/radial-gradient-material.js js/lib/rdge/materials/taper-material.js js/lib/rdge/materials/twist-vert-material.js js/lib/rdge/materials/water-material.js js/panels/Materials/materials-library-panel.reel/materials-library-panel.html js/panels/Materials/materials-library-panel.reel/materials-library-panel.js js/panels/Materials/materials-popup.reel/materials-popup.html js/panels/Materials/materials-popup.reel/materials-popup.js js/tools/LineTool.js Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/twist-vert-material.js')
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js288
1 files changed, 144 insertions, 144 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index e0324e69..4f002e8f 100644
--- a/js/lib/rdge/materials/twist-vert-material.js
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -37,73 +37,73 @@ var Texture = require("js/lib/rdge/texture").Texture;
37/////////////////////////////////////////////////////////////////////// 37///////////////////////////////////////////////////////////////////////
38var TwistVertMaterial = function TwistVertMaterial() 38var TwistVertMaterial = function TwistVertMaterial()
39{ 39{
40 // initialize the inherited members 40 // initialize the inherited members
41 this.inheritedFrom = Material; 41 this.inheritedFrom = Material;
42 this.inheritedFrom(); 42 this.inheritedFrom();
43 43
44 /////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////
45 // Instance variables 45 // Instance variables
46 /////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////
47 this._name = "Twist Vertex"; 47 this._name = "Twist Vertex";
48 this._shaderName = "twistVert"; 48 this._shaderName = "twistVert";
49 49
50 this._tex0 = 'assets/images/rocky-normal.jpg'; 50 this._tex0 = 'assets/images/rocky-normal.jpg';
51 this._tex1 = 'assets/images/metal.png'; 51 this._tex1 = 'assets/images/metal.png';
52 52
53 this._angle = 0.0; 53 this._angle = 0.0;
54 this._deltaTime = 0.01; 54 this._deltaTime = 0.01;
55 this._speed = 1.0; 55 this._speed = 1.0;
56 56
57 /////////////////////////////////////////////////////////////////////// 57 ///////////////////////////////////////////////////////////////////////
58 // Property Accessors 58 // Property Accessors
59 /////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////
60 this.getShaderName = function () { return this._shaderName; }; 60 this.getShaderName = function () { return this._shaderName; };
61 this.isAnimated = function () { return true; }; 61 this.isAnimated = function () { return true; };
62 this.getShaderDef = function() { return twistVertShaderDef; }; 62 this.getShaderDef = function() { return twistVertShaderDef; };
63 this.getTechniqueName = function() { return 'twistMe' }; 63 this.getTechniqueName = function() { return 'twistMe' };
64 64
65 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 65 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
66 this._hasVertexDeformation = true; 66 this._hasVertexDeformation = true;
67 this._vertexDeformationTolerance = 0.02; // should be a property 67 this._vertexDeformationTolerance = 0.02; // should be a property
68 68
69 /////////////////////////////////////////////////////////////////////// 69 ///////////////////////////////////////////////////////////////////////
70 // Material Property Accessors 70 // Material Property Accessors
71 /////////////////////////////////////////////////////////////////////// 71 ///////////////////////////////////////////////////////////////////////
72 this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"]; 72 this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"];
73 this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"]; 73 this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"];
74 this._propTypes = [ "float", "float", "angle", "float", "file", "file"]; 74 this._propTypes = [ "float", "float", "angle", "float", "file", "file"];
75 this._propValues = []; 75 this._propValues = [];
76 76
77 // initialize the property values 77 // initialize the property values
78 this._propValues[this._propNames[0]] = 0.0; 78 this._propValues[this._propNames[0]] = 0.0;
79 this._propValues[this._propNames[1]] = 1.0; 79 this._propValues[this._propNames[1]] = 1.0;
80 this._propValues[this._propNames[2]] = 2.0 * Math.PI; 80 this._propValues[this._propNames[2]] = 2.0 * Math.PI;
81 this._propValues[this._propNames[3]] = this._speed; 81 this._propValues[this._propNames[3]] = this._speed;
82 this._propValues[this._propNames[4]] = this._tex0.slice(); 82 this._propValues[this._propNames[4]] = this._tex0.slice();
83 this._propValues[this._propNames[5]] = this._tex1.slice(); 83 this._propValues[this._propNames[5]] = this._tex1.slice();
84 /////////////////////////////////////////////////////////////////////// 84 ///////////////////////////////////////////////////////////////////////
85 85
86 /////////////////////////////////////////////////////////////////////// 86 ///////////////////////////////////////////////////////////////////////
87 // Methods 87 // Methods
88 /////////////////////////////////////////////////////////////////////// 88 ///////////////////////////////////////////////////////////////////////
89 89
90 this.init = function (world) 90 this.init = function (world)
91 { 91 {
92 this.setWorld(world); 92 this.setWorld(world);
93 93
94 // set up the shader 94 // set up the shader
95 this._shader = new RDGE.jshader(); 95 this._shader = new RDGE.jshader();
96 this._shader.def = twistVertShaderDef; 96 this._shader.def = twistVertShaderDef;
97 this._shader.init(); 97 this._shader.init();
98 98
99 // set up the material node 99 // set up the material node
100 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); 100 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID());
101 this._materialNode.setShader(this._shader); 101 this._materialNode.setShader(this._shader);
102 102
103 103
104 // initialize the twist vert properties 104 // initialize the twist vert properties
105 this.setShaderValues(); 105 this.setShaderValues();
106 }; 106 };
107 107
108 this.resetToDefault = function() 108 this.resetToDefault = function()
109 { 109 {
@@ -119,91 +119,91 @@ var TwistVertMaterial = function TwistVertMaterial()
119 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); 119 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
120 }; 120 };
121 121
122 this.update = function (time) 122 this.update = function (time)
123 { 123 {
124 if (this._shader && this._shader.twistMe) 124 if (this._shader && this._shader.twistMe)
125 { 125 {
126 var technique = this._shader.twistMe; 126 var technique = this._shader.twistMe;
127 127
128 var angle = this._angle; 128 var angle = this._angle;
129 angle += this._deltaTime * this._propValues["speed"]; 129 angle += this._deltaTime * this._propValues["speed"];
130 if (angle > this._propValues["u_twistAmount"]) 130 if (angle > this._propValues["u_twistAmount"])
131 { 131 {
132 angle = this._propValues["u_twistAmount"]; 132 angle = this._propValues["u_twistAmount"];
133 this._deltaTime = -this._deltaTime; 133 this._deltaTime = -this._deltaTime;
134 } 134 }
135 else if (angle < 0.0) 135 else if (angle < 0.0)
136 { 136 {
137 angle = 0; 137 angle = 0;
138 this._deltaTime = -this._deltaTime; 138 this._deltaTime = -this._deltaTime;
139 } 139 }
140 this._angle = angle; 140 this._angle = angle;
141 this._shader.twistMe["u_twistAmount"].set([angle]); 141 this._shader.twistMe["u_twistAmount"].set([angle]);
142 142
143 var tex; 143 var tex;
144 var glTex = this._glTextures["u_tex0"]; 144 var glTex = this._glTextures["u_tex0"];
145 if (glTex) 145 if (glTex)
146 { 146 {
147 //if (glTex.isAnimated()) 147 //if (glTex.isAnimated())
148 glTex.render(); 148 glTex.render();
149 tex = glTex.getTexture(); 149 tex = glTex.getTexture();
150 if (tex) 150 if (tex)
151 technique.u_tex0.set( tex ); 151 technique.u_tex0.set( tex );
152 } 152 }
153 153
154 glTex = this._glTextures["u_tex1"]; 154 glTex = this._glTextures["u_tex1"];
155 if (glTex) 155 if (glTex)
156 { 156 {
157 //if (glTex.isAnimated()) 157 //if (glTex.isAnimated())
158 glTex.render(); 158 glTex.render();
159 tex = glTex.getTexture(); 159 tex = glTex.getTexture();
160 if (tex) 160 if (tex)
161 technique.u_tex1.set( tex ); 161 technique.u_tex1.set( tex );
162 } 162 }
163 163
164 } 164 }
165 } 165 }
166}; 166};
167 167
168// shader spec (can also be loaded from a .JSON file, or constructed at runtime)