aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/pulse-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/pulse-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/pulse-material.js')
-rw-r--r--js/lib/rdge/materials/pulse-material.js258
1 files changed, 258 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js
new file mode 100644
index 00000000..63cab2f4
--- /dev/null
+++ b/js/lib/rdge/materials/pulse-material.js
@@ -0,0 +1,258 @@
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;
8var Material = require("js/lib/rdge/materials/material").Material;
9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial
11// RDGE representation of a material.
12///////////////////////////////////////////////////////////////////////
13var PulseMaterial = function PulseMaterial() {
14 ///////////////////////////////////////////////////////////////////////
15 // Instance variables
16 ///////////////////////////////////////////////////////////////////////
17 this._name = "PulseMaterial";
18 this._shaderName = "pulse";
19
20 this._texMap = 'assets/images/cubelight.png';
21
22 this._time = 0.0;
23 this._dTime = 0.01;
24
25 ///////////////////////////////////////////////////////////////////////
26 // Property Accessors
27 ///////////////////////////////////////////////////////////////////////
28 this.getName = function() { return this._name; };
29 this.getShaderName = function() { return this._shaderName; };
30
31 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null };
32 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); };
33
34 this.isAnimated = function() { return true; };
35
36 ///////////////////////////////////////////////////////////////////////
37 // Material Property Accessors
38 ///////////////////////////////////////////////////////////////////////
39 this._propNames = ["texmap"];
40 this._propLabels = ["Texture map"];
41 this._propTypes = ["file"];
42 this._propValues = [];
43
44 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
45
46 this.setProperty = function( prop, value ) {
47 // make sure we have legitimate imput
48 var ok = this.validateProperty( prop, value );
49 if (!ok) {
50 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
51 }
52
53 switch (prop)
54 {
55 case "texmap":
56 this.setTextureMap(value);
57 break;
58
59 case "color":
60 break;
61 }
62 };
63 ///////////////////////////////////////////////////////////////////////
64
65
66 ///////////////////////////////////////////////////////////////////////
67 // Methods
68 ///////////////////////////////////////////////////////////////////////
69 // duplcate method requirde
70 this.dup = function( world )
71 {
72 // save the world
73 if (world) this.setWorld( world );
74
75 // allocate a new uber material
76 var newMat = new PulseMaterial();
77
78 // copy over the current values;
79 var propNames = [], propValues = [], propTypes = [], propLabels = [];
80 this.getAllProperties( propNames, propValues, propTypes, propLabels);
81 var n = propNames.length;
82 for (var i=0; i<n; i++) {
83 newMat.setProperty( propNames[i], propValues[i] );
84 }
85
86 return newMat;
87 };
88
89 this.init = function( world )
90 {
91 // save the world
92 if (world) this.setWorld( world );
93
94 // this variable declared above is inherited set to a smaller delta.
95 // the pulse material runs a little faster
96 this._dTime = 0.01;
97
98 // set up the shader
99 this._shader = new jshader();
100 this._shader.def = pulseMaterialDef;
101 this._shader.init();
102
103 // set up the material node
104 this._materialNode = createMaterialNode("pulseMaterial");
105 this._materialNode.setShader(this._shader);
106
107 this._time = 0;
108 if (this._shader && this._shader['default']) {
109 this._shader['default'].u_time.set( [this._time] );
110 }
111
112
113 // set the shader values in the shader
114 this.updateTexture();
115 this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] );
116 this.update( 0 );
117 };
118
119 this.updateTexture = function() {
120 var material = this._materialNode;
121 if (material) {
122 var technique = material.shaderProgram['default'];
123 var renderer = g_Engine.getContext().renderer;
124 if (renderer && technique) {
125 var texMapName = this._propValues[this._propNames[0]];
126 var wrap = 'REPEAT', mips = true;
127 var tex = this.loadTexture( texMapName, wrap, mips );
128
129 /*
130 var glTex = new GLTexture( this.getWorld() );
131 var prevWorld = this.findPreviousWorld();
132 if (prevWorld)
133 {
134 var srcCanvas = prevWorld.getCanvas();
135 tex = glTex.loadFromCanvas( srcCanvas );
136 }
137 else
138 tex = glTex.loadFromFile( texMapName, wrap, mips );
139 */
140
141 if (tex) {
142 technique.u_tex0.set( tex );
143 }
144 }
145 }
146 };
147
148 this.update = function( time )
149 {
150 var material = this._materialNode;
151 if (material)
152 {
153 var technique = material.shaderProgram['default'];
154 var renderer = g_Engine.getContext().renderer;
155 if (renderer && technique) {
156 if (this._shader && this._shader['default']) {
157 this._shader['default'].u_time.set( [this._time] );
158 }
159 this._time += this._dTime;
160
161 if (this._time > 200.0) this._time = 0.0;
162 }
163 }
164 };
165
166 this.setResolution = function( res ) {
167 var material = this._materialNode;
168 if (material) {
169 var technique = material.shaderProgram['default'];
170 var renderer = g_Engine.getContext().renderer;
171 if (renderer && technique) {
172 technique.u_resolution.set( res );
173 }
174 }
175 };
176
177 this.export = function() {
178 // every material needs the base type and instance name
179 var exportStr = "material: " + this.getShaderName() + "\n";
180 exportStr += "name: " + this.getName() + "\n";
181
182 // every material needs to terminate like this
183 exportStr += "endMaterial\n";
184
185 return exportStr;
186 };
187
188 this.import = function( importStr ) {
189 var pu = new MaterialParser( importStr );
190 var material = pu.nextValue( "material: " );
191 if (material != this.getShaderName()) throw new Error( "ill-formed material" );
192 this.setName( pu.nextValue( "name: ") );
193
194 var rtnStr;
195 try {
196 var endKey = "endMaterial\n";
197 var index = importStr.indexOf( endKey );
198 index += endKey.length;
199 rtnStr = importStr.substr( index );
200 }