diff options
author | hwc487 | 2012-04-03 09:36:14 -0700 |
---|---|---|
committer | hwc487 | 2012-04-03 09:36:14 -0700 |
commit | 4b199cf04af83f59895d4d1e9a2d8443c1ec8e06 (patch) | |
tree | a1875bed6d6c225304bb2fa286d1ab435c2b9633 /js | |
parent | 19c975cfb16f1cccc9e9f86255575499315d421e (diff) | |
download | ninja-4b199cf04af83f59895d4d1e9a2d8443c1ec8e06.tar.gz |
started the flag material
Diffstat (limited to 'js')
-rwxr-xr-x | js/lib/geom/geom-obj.js | 2 | ||||
-rw-r--r-- | js/lib/rdge/materials/flag-material.js | 142 | ||||
-rwxr-xr-x | js/models/materials-model.js | 3 |
3 files changed, 147 insertions, 0 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 11b9303a..0c0d7c01 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js | |||
@@ -309,6 +309,7 @@ var GeomObj = function GLGeomObj() { | |||
309 | case "tunnel": | 309 | case "tunnel": |
310 | case "reliefTunnel": | 310 | case "reliefTunnel": |
311 | case "squareTunnel": | 311 | case "squareTunnel": |
312 | case "flag": | ||
312 | case "twist": | 313 | case "twist": |
313 | case "fly": | 314 | case "fly": |
314 | case "julia": | 315 | case "julia": |
@@ -382,6 +383,7 @@ var GeomObj = function GLGeomObj() { | |||
382 | case "tunnel": | 383 | case "tunnel": |
383 | case "reliefTunnel": | 384 | case "reliefTunnel": |
384 | case "squareTunnel": | 385 | case "squareTunnel": |
386 | case "flag": | ||
385 | case "twist": | 387 | case "twist": |
386 | case "fly": | 388 | case "fly": |
387 | case "julia": | 389 | case "julia": |
diff --git a/js/lib/rdge/materials/flag-material.js b/js/lib/rdge/materials/flag-material.js new file mode 100644 index 00000000..77991a8c --- /dev/null +++ b/js/lib/rdge/materials/flag-material.js | |||
@@ -0,0 +1,142 @@ | |||
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 | |||
7 | |||
8 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | ||
9 | var Texture = require("js/lib/rdge/texture").Texture; | ||
10 | |||
11 | var FlagMaterial = function FlagMaterial() { | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | // Instance variables | ||
14 | /////////////////////////////////////////////////////////////////////// | ||
15 | this._name = "FlagMaterial"; | ||
16 | this._shaderName = "flag"; | ||
17 | |||
18 | this._texMap = 'assets/images/us_flag.png'; | ||
19 | |||
20 | this._time = 0.0; | ||
21 | this._dTime = 0.1; | ||
22 | |||
23 | this._defaultWaveWidth = 1.0; | ||
24 | this._defaultWaveHeight = 1.0; | ||
25 | |||
26 | /////////////////////////////////////////////////////////////////////// | ||
27 | // Properties | ||
28 | /////////////////////////////////////////////////////////////////////// | ||
29 | // all defined in parent PulseMaterial.js | ||
30 | // load the local default value | ||
31 | this._propNames = ["texmap", "wavewidth", "waveheight" ]; | ||
32 | this._propLabels = ["Texture map", "Wave Width", "Wave Height" ]; | ||
33 | this._propTypes = ["file", "float", "float" ]; | ||
34 | this._propValues = []; | ||
35 | |||
36 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); | ||
37 | this._propValues[ this._propNames[1] ] = this._defaultWaveWidth; | ||
38 | this._propValues[ this._propNames[2] ] = this._defaultWaveHeight; | ||
39 | |||
40 | /////////////////////////////////////////////////////////////////////// | ||
41 | // Methods | ||
42 | /////////////////////////////////////////////////////////////////////// | ||
43 | // duplcate method requirde | ||
44 | this.dup = function( world ) { | ||
45 | // allocate a new uber material | ||
46 | var newMat = new FlagMaterial(); | ||
47 | |||
48 | // copy over the current values; | ||
49 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | ||
50 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | ||
51 | var n = propNames.length; | ||
52 | for (var i=0; i<n; i++) { | ||
53 | newMat.setProperty( propNames[i], propValues[i] ); | ||
54 | } | ||
55 | |||
56 | return newMat; | ||
57 | }; | ||
58 | |||
59 | this.init = function( world ) | ||
60 | { | ||
61 | // save the world | ||
62 | if (world) this.setWorld( world ); | ||
63 | |||
64 | // set up the shader | ||
65 | this._shader = new jshader(); | ||
66 | this._shader.def = flagMaterialDef; | ||
67 | this._shader.init(); | ||
68 | |||
69 | // set up the material node | ||
70 | this._materialNode = createMaterialNode("flagMaterial" + "_" + world.generateUniqueNodeID()); | ||
71 | this._materialNode.setShader(this._shader); | ||
72 | |||
73 | this._time = 0; | ||
74 | if (this._shader && this._shader['default']) { | ||
75 | this._shader['default'].u_time.set( [this._time] ); | ||
76 | this._shader['default'].u_waveWidth.set( [this._propValues[ this._propNames[1] ]] ); | ||
77 | this._shader['default'].u_waveHeight.set( [this._propValues[ this._propNames[2] ]] ); | ||
78 | } | ||
79 | |||
80 | // set up the texture | ||
81 | var texMapName = this._propValues[this._propNames[0]]; | ||
82 | this._glTex = new Texture( world, texMapName ); | ||
83 | |||
84 | // set the shader values in the shader | ||
85 | this.updateTexture(); | ||
86 | this.update( 0 ); | ||
87 | } | ||
88 | }; | ||
89 | |||
90 | /////////////////////////////////////////////////////////////////////////////////////// | ||
91 | // RDGE shader | ||
92 | |||
93 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | ||
94 | var flagMaterialDef = | ||
95 | {'shaders': | ||
96 | { | ||
97 | 'defaultVShader':"assets/shaders/Flag.vert.glsl", | ||
98 | 'defaultFShader':"assets/shaders/Flag.frag.glsl" | ||
99 | }, | ||
100 | 'techniques': | ||
101 | { | ||
102 | 'default': | ||
103 | [ | ||
104 | { | ||
105 | 'vshader' : 'defaultVShader', | ||
106 | 'fshader' : 'defaultFShader', | ||
107 | // attributes | ||
108 | 'attributes' : | ||
109 | { | ||
110 | 'vert' : { 'type' : 'vec3' }, | ||
111 | 'normal' : { 'type' : 'vec3' }, | ||
112 | 'texcoord' : { 'type' : 'vec2' } | ||
113 | }, | ||
114 | // parameters | ||
115 | 'params' : | ||
116 | { | ||
117 | 'u_tex0': { 'type' : 'tex2d' }, | ||
118 | 'u_time' : { 'type' : 'float' }, | ||
119 | 'u_waveWidth' : { 'type' : 'float' }, | ||
120 | 'u_waveHeight' : { 'type' : 'float' } | ||
121 | }, | ||
122 | |||
123 | // render states | ||
124 | 'states' : | ||
125 | { | ||
126 | 'depthEnable' : true, | ||
127 | 'offset':[1.0, 0.1] | ||
128 | } | ||
129 | } | ||
130 | ] | ||
131 | } | ||
132 | }; | ||
133 | |||
134 | FlagMaterial.prototype = new PulseMaterial(); | ||
135 | |||
136 | if (typeof exports === "object") { | ||
137 | exports.FlagMaterial = FlagMaterial; | ||
138 | } | ||
139 | |||
140 | |||
141 | |||
142 | |||
diff --git a/js/models/materials-model.js b/js/models/materials-model.js index 692ac09a..97a48f5a 100755 --- a/js/models/materials-model.js +++ b/js/models/materials-model.js | |||
@@ -22,6 +22,7 @@ var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMate | |||
22 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | 22 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; |
23 | var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; | 23 | var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; |
24 | var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial; | 24 | var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial; |
25 | var FlagMaterial = require("js/lib/rdge/materials/flag-material").FlagMaterial; | ||
25 | var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; | 26 | var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; |
26 | var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; | 27 | var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; |
27 | var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; | 28 | var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; |
@@ -55,6 +56,7 @@ exports.MaterialsModel = Montage.create(Component, { | |||
55 | this.addMaterial(new PulseMaterial()); | 56 | this.addMaterial(new PulseMaterial()); |
56 | this.addMaterial(new TunnelMaterial()); | 57 | this.addMaterial(new TunnelMaterial()); |
57 | this.addMaterial(new ReliefTunnelMaterial()); | 58 | this.addMaterial(new ReliefTunnelMaterial()); |
59 | this.addMaterial(new FlagMaterial()); | ||
58 | this.addMaterial(new SquareTunnelMaterial()); | 60 | this.addMaterial(new SquareTunnelMaterial()); |
59 | this.addMaterial(new FlyMaterial()); | 61 | this.addMaterial(new FlyMaterial()); |
60 | this.addMaterial(new WaterMaterial()); | 62 | this.addMaterial(new WaterMaterial()); |
@@ -235,6 +237,7 @@ exports.MaterialsModel = Montage.create(Component, { | |||
235 | case "tunnel": mat = new TunnelMaterial(); break; | 237 | case "tunnel": mat = new TunnelMaterial(); break; |
236 | case "reliefTunnel": mat = new ReliefTunnelMaterial(); break; | 238 | case "reliefTunnel": mat = new ReliefTunnelMaterial(); break; |
237 | case "squareTunnel": mat = new SquareTunnelMaterial(); break; | 239 | case "squareTunnel": mat = new SquareTunnelMaterial(); break; |
240 | case "flag": mat = new FlagMaterial(); break; | ||
238 | case "fly": mat = new FlyMaterial(); break; | 241 | case "fly": mat = new FlyMaterial(); break; |
239 | case "water": mat = new WaterMaterial(); break; | 242 | case "water": mat = new WaterMaterial(); break; |
240 | case "paris": mat = new ParisMaterial(); break; | 243 | case "paris": mat = new ParisMaterial(); break; |