aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-vert-material.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 11:38:39 -0800
committerJonathan Duran2012-03-06 11:38:39 -0800
commit342fb451bd251358068a0dcb10e9dc218b79a176 (patch)
treeaa0195d581c3934fb6dc09981506b3c070002806 /js/lib/rdge/materials/twist-vert-material.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
downloadninja-342fb451bd251358068a0dcb10e9dc218b79a176.tar.gz
Squashed commit of the following:
commit 1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f Author: Jose Antonio Marquez <kgq387@motorola.com> Date: Tue Mar 6 11:24:25 2012 -0800 Fixing WebGL not available bug commit 84332ab81c1b445195f1d9be8bbeae0725c8e758 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Mar 6 10:58:25 2012 -0800 Squashed commit of preload-fix into Master - Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 13f52cf0c74f53a919fa864f86669e8155f82961 Merge: dced508 abc04f3 Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:46:11 2012 -0800 Merge pull request #93 from imix23ways/Timeline Timeline: Critical bug fixes commit dced508bb19a7bcd467ff1b86b5df5bbec4be794 Merge: 0aeb400 cc772ef Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:45:35 2012 -0800 Merge pull request #92 from mqg734/WebGLFixes Selection Tool Fixes for elements flying off into space when they overlap commit 0aeb400070762cf01d83cf9f9ee25a5595098b7f Merge: ff0a956 aabb48a Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 14:05:21 2012 -0800 Merge pull request #94 from ericguzman/PresetsPanel Presets Panel - Fix single-click activation, and transition cut-off bug. commit cc772ef3333ed419d269a2bda7aea5b0150a7bd9 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:34:58 2012 -0800 Fixing flying off into space bug for translate tool too. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit abc04f3d50311ed1c21067344bc7e448686f8c5c Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:26:25 2012 -0800 Timeline Fix timing function Signed-off-by: Jonathan Duran <jduran@motorola.com> commit aabb48a1c8d34bc968f4c6b0ffee4e31c1d5d286 Author: Eric Guzman <ericg@motorola.com> Date: Fri Mar 2 11:22:44 2012 -0800 Presets Panel - Fix single-click activation, and transition cut-off bug. Use double-click as the activation event for transition presets. Also fixed the bug when applying a style preset before the transition preset, which disabled transitions after the first one. commit f3207f39ea9d8c1c34246217a23d3a689671903d Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:21:29 2012 -0800 Don't draw transform handles if the stage is the target element. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 5425be91e7125c22955b4459a62412ff574e49a8 Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:11:48 2012 -0800 Timeline: Fix for animation iteration count Add default webkit css properties to allow animations with integer iteration counts. Signed-off-by: Jonathan Duran <jduran@motorola.com> commit 1760bac1da9218315ad1bacdcf3a157495a049e8 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 10:48:41 2012 -0800 Fix for jumping issue when moving items that have any 3d on them. We can't translate 3d moves into 2d space due to perspective, so we must update the matrix3d values instead of the top-left values if items have 3d. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 2c04935f0ccb1cb7c98371fc10b43155f2d956c4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 22:20:06 2012 -0800 Fix for elements flying off into space when moving elements that overlap. This was happening because our hit record's element and the browser's element from point did not match. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 50058746779f714ed9b0287f49e56c9f0d35593e Merge: 500426d ff0a956 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 21:49:44 2012 -0800 Merge branch 'refs/heads/ninja-internal' into WebGLFixes commit 500426dea0ca95a6b45be8ea8d132cfdb4d2c940 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:11:39 2012 -0800 Fixed logic error when resizing with the top-left transform handles. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 7980d9bde2b43aa5a494ddf6f1db5c4959a57b91 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:04:15 2012 -0800 Re-fixing IKNinja-940 - Can't select objects when in side/top view. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit f04cc0146d8f7573628678613a99c270116768e4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Feb 29 16:45:40 2012 -0800 Last-used material (instead of FlatMaterial) is applied to shape when turning on use WebGL checkbox in the PI. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/twist-vert-material.js')
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js248
1 files changed, 248 insertions, 0 deletions
</
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
new file mode 100644
index 00000000..c2573071
--- /dev/null
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -0,0 +1,248 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8///////////////////////////////////////////////////////////////////////
9// Class GLMaterial
10// RDGE representation of a material.
11///////////////////////////////////////////////////////////////////////
12function TwistVertMaterial()
13{
14 // initialize the inherited members
15 this.inheritedFrom = GLMaterial;
16 this.inheritedFrom();
17
18 ///////////////////////////////////////////////////////////////////////
19 // Instance variables
20 ///////////////////////////////////////////////////////////////////////
21 this._name = "TwistVertMaterial";
22 this._shaderName = "twistVert";
23
24 this._color = [1,0,0,1];
25
26 this._tex0 = 'assets/images/rocky-normal.jpg';
27 this._tex1 = 'assets/images/metal.png';
28
29 this._angle = 0.0;
30 this._deltaTime = 0.01;
31
32 ///////////////////////////////////////////////////////////////////////
33 // Property Accessors
34 ///////////////////////////////////////////////////////////////////////
35 this.getColor = function() { return this._color; }
36 this.getShaderName = function() { return this._shaderName; }
37
38 this.isAnimated = function() { return true; }
39 this.hasVertexDeformation = function() { return this._hasVertexDeformation; }
40 this._hasVertexDeformation = true;
41 this._vertexDeformationTolerance = 0.02; // should be a property
42
43 ///////////////////////////////////////////////////////////////////////
44 // Methods
45 ///////////////////////////////////////////////////////////////////////
46 // duplcate method requirde
47 this.dup = function() { return new TwistVertMaterial(); }
48
49 this.init = function()
50 {
51 // set up the shader
52 this._shader = new jshader();
53 this._shader.def = twistVertShaderDef;
54 this._shader.init();
55
56 // set the defaults
57 this._shader.twistMe.color.set( this.getColor() );
58
59 // set up the material node
60 this._materialNode = createMaterialNode("twistVertMaterial");
61 this._materialNode.setShader(this._shader);
62
63 // initialize the twist vert properties
64 this.updateShaderValues();
65 }
66
67
68 ///////////////////////////////////////////////////////////////////////
69 // Material Property Accessors
70 ///////////////////////////////////////////////////////////////////////
71 this._propNames = ["color", "u_limit1", "u_limit2", "u_center", "u_twistAmount", "u_tex0", "u_tex1" ];
72 this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Center", "Twist Amount", "Front facing texture map", "Back facing texture map"];
73 this._propTypes = ["color", "float", "float", "float", "float", "file", "file"];
74 this._propValues = [];
75
76 // initialize the property values
77 this._propValues[ this._propNames[0] ] = this._color.slice();
78 this._propValues[ this._propNames[1] ] = 0.25;
79 this._propValues[ this._propNames[2] ] = 0.75;
80 this._propValues[ this._propNames[3] ] = 0.0;
81 this._propValues[ this._propNames[4] ] = 2.0*Math.PI;
82 this._propValues[ this._propNames[5] ] = this._tex0.slice();
83 this._propValues[ this._propNames[6] ] = this._tex1.slice();
84
85 this.setProperty = function( prop, value )
86 {
87 // make sure we have legitimate input
88 if (this.validateProperty( prop, value ))
89 {
90 switch (prop)
91 {
92 case "color":
93 case "u_tex1":
94 case "u_tex0": this._propValues[prop] = value.slice(); break;
95 default: this._propValues[prop] = value; break;
96 }
97
98 this.updateShaderValues();
99 }
100 }
101 ///////////////////////////////////////////////////////////////////////
102
103 this.export = function()
104 {
105 // this function should be overridden by subclasses
106 var exportStr = "material: " + this.getShaderName() + "\n";
107 exportStr += "name: " + this.getName() + "\n";
108
109 if (this._shader)
110 exportStr += "color: " + String(this._shader.twistMe.color) + "\n";
111 else
112 exportStr += "color: " + this.getColor() + "\n";
113 exportStr += "endMaterial\n";
114
115 return exportStr;
116 }
117
118 this.import = function( importStr )
119 {
120 var pu = new MaterialParser( importStr );
121 var material = pu.nextValue( "material: " );
122 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
123 this.setName( pu.nextValue( "name: ") );
124
125 var rtnStr;
126 try
127 {
128 var color = eval( "[" + pu.nextValue( "color: " ) + "]" );
129
130 this.setProperty( "color", color);
131
132 var endKey = "endMaterial\n";
133 var index = importStr.indexOf( endKey );
134 index += endKey.length;
135 rtnStr = importStr.substr( index );
136 }
137 catch (e)
138 {
139 throw new Error( "could not import material: " + importStr );
140 }
141
142 return rtnStr;
143 }
144
145 this.update = function( time )
146 {
147 if (this._shader && this._shader.twistMe)
148 {
149 var angle = this._angle;
150 angle += this._deltaTime;
151 if (angle > this._propValues[ "u_twistAmount" ])
152 {
153 angle = this._propValues[ "u_twistAmount" ];
154 this._deltaTime = -this._deltaTime;
155 }
156 else if (angle < 0.0)
157 {
158 angle = 0;
159 this._deltaTime = -this._deltaTime;
160 }
161 this._angle = angle;
162 this._shader.twistMe["u_twistAmount"].set( [angle] );
163 }
164 }
165
166 this.updateShaderValues = function()
167 {
168 if (this._shader && this._shader.twistMe)
169 {
170 var nProps = this._propNames.length;
171 for (var i=0; i<nProps; i++)
172 {
173 var propName = this._propNames[i];
174 var propValue = this._propValues[propName];
175 switch (propName)
176 {
177 case "u_tex0":
178 case "u_tex1":
179 case "color": this._shader.twistMe[propName].set( propValue ); break;
180 default: this._shader.twistMe[propName].set( [propValue] ); break;
181 }
182 }
183 }
184 }
185
186 this.updateTextures = function()
187 {
188 var material = this._materialNode;
189 if (material)
190 {
191 var technique = material.shaderProgram['default'];
192 var renderer = g_Engine.getContext().renderer;
193 if (renderer && technique)