diff options
author | Ananya Sen | 2012-07-09 16:52:49 -0700 |
---|---|---|
committer | Ananya Sen | 2012-07-09 16:52:49 -0700 |
commit | 2eb84584f44b8c774479d1af2ee1d810597474cf (patch) | |
tree | 64cb3e09a8daeb340261dd7f3869c73f7b90b643 /js/lib/rdge/materials/fly-material.js | |
parent | bf9dba001ec84243e2f12cd13b0c0ae020fba4a2 (diff) | |
parent | cee0deca695359ab468bd06d0e05ed3b2010b338 (diff) | |
download | ninja-2eb84584f44b8c774479d1af2ee1d810597474cf.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into codemirror-custom-theme-removal
Conflicts:
js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css
js/code-editor/codemirror-ninja/theme/xq-dark-ninja.css
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/fly-material.js')
-rw-r--r-- | js/lib/rdge/materials/fly-material.js | 173 |
1 files changed, 92 insertions, 81 deletions
diff --git a/js/lib/rdge/materials/fly-material.js b/js/lib/rdge/materials/fly-material.js index b4bf0972..d5298120 100644 --- a/js/lib/rdge/materials/fly-material.js +++ b/js/lib/rdge/materials/fly-material.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -35,13 +36,13 @@ var FlyMaterial = function FlyMaterial() { | |||
35 | /////////////////////////////////////////////////////////////////////// | 36 | /////////////////////////////////////////////////////////////////////// |
36 | // Instance variables | 37 | // Instance variables |
37 | /////////////////////////////////////////////////////////////////////// | 38 | /////////////////////////////////////////////////////////////////////// |
38 | this._name = "Fly"; | 39 | this._name = "Fly"; |
39 | this._shaderName = "fly"; | 40 | this._shaderName = "fly"; |
40 | 41 | ||
41 | this._defaultTexMap = 'assets/images/rocky-normal.jpg'; | 42 | this._defaultTexMap = 'assets/images/rocky-normal.jpg'; |
42 | 43 | ||
43 | this._time = 0.0; | 44 | this._time = 0.0; |
44 | this._dTime = 0.01; | 45 | this._dTime = 0.01; |
45 | 46 | ||
46 | // array textures indexed by shader uniform name | 47 | // array textures indexed by shader uniform name |
47 | this._glTextures = []; | 48 | this._glTextures = []; |
@@ -49,95 +50,105 @@ var FlyMaterial = function FlyMaterial() { | |||
49 | /////////////////////////////////////////////////////////////////////// | 50 | /////////////////////////////////////////////////////////////////////// |
50 | // Properties | 51 | // Properties |
51 | /////////////////////////////////////////////////////////////////////// | 52 | /////////////////////////////////////////////////////////////////////// |
52 | // all defined in parent PulseMaterial.js | 53 | // all defined in parent PulseMaterial.js |
53 | // load the local default value | 54 | // load the local default value |
54 | var u_tex0_index = 0, u_speed_index = 1; | 55 | var u_tex0_index = 0, u_speed_index = 1; |
55 | this._propNames = ["u_tex0", "u_speed" ]; | 56 | this._propNames = ["u_tex0", "u_speed" ]; |
56 | this._propLabels = ["Texture map", "Speed" ]; | 57 | this._propLabels = ["Texture map", "Speed" ]; |
57 | this._propTypes = ["file", "float" ]; | 58 | this._propTypes = ["file", "float" ]; |
58 | this._propValues = []; | 59 | this._propValues = []; |
59 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); | 60 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); |
60 | this._propValues[this._propNames[u_speed_index]] = 1.0; | 61 | this._propValues[this._propNames[u_speed_index]] = 1.0; |
61 | 62 | ||
62 | /////////////////////////////////////////////////////////////////////// | 63 | /////////////////////////////////////////////////////////////////////// |
63 | // Material Property Accessors | 64 | // Material Property Accessors |
64 | /////////////////////////////////////////////////////////////////////// | 65 | /////////////////////////////////////////////////////////////////////// |
65 | this.isAnimated = function() { return true; }; | 66 | this.isAnimated = function() { return true; }; |
66 | this.getShaderDef = function() { return flyMaterialDef; }; | 67 | this.getShaderDef = function() { return flyMaterialDef; }; |
67 | 68 | ||
68 | /////////////////////////////////////////////////////////////////////// | 69 | /////////////////////////////////////////////////////////////////////// |
69 | // Methods | 70 | // Methods |
70 | /////////////////////////////////////////////////////////////////////// | 71 | /////////////////////////////////////////////////////////////////////// |
71 | // duplcate method requirde | 72 | // duplcate method requirde |
72 | 73 | ||
73 | this.init = function( world ) { | 74 | this.init = function( world ) { |
74 | // save the world | 75 | // save the world |
75 | if (world) this.setWorld( world ); | 76 | if (world) this.setWorld( world ); |
76 | 77 | ||
77 | // set up the shader | 78 | // set up the shader |
78 | this._shader = new RDGE.jshader(); | 79 | this._shader = new RDGE.jshader(); |
79 | this._shader.def = flyMaterialDef; | 80 | this._shader.def = flyMaterialDef; |
80 | this._shader.init(); | 81 | this._shader.init(); |
81 | 82 | ||
82 | // set up the material node | 83 | // set up the material node |
83 | this._materialNode = RDGE.createMaterialNode("flyMaterial" + "_" + world.generateUniqueNodeID()); | 84 | this._materialNode = RDGE.createMaterialNode("flyMaterial" + "_" + world.generateUniqueNodeID()); |
84 | this._materialNode.setShader(this._shader); | 85 | this._materialNode.setShader(this._shader); |
85 | 86 | ||
86 | this._time = 0; | 87 | this._time = 0; |
87 | if (this._shader && this._shader['default']) { | 88 | if (this._shader && this._shader['default']) { |
88 | this._shader['default'].u_time.set( [this._time] ); | 89 | this._shader['default'].u_time.set( [this._time] ); |
89 | } | 90 | } |
90 | 91 | ||
91 | // set the shader values in the shader | 92 | // set the shader values in the shader |
92 | this.setShaderValues(); | 93 | this.setShaderValues(); |
93 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); | 94 | this.setResolution( [world.getViewportWidth(),world.getViewportHeight()] ); |
94 | this.update( 0 ); | 95 | this.update( 0 ); |
95 | }; | 96 | }; |
97 | |||
98 | this.resetToDefault = function() | ||
99 | { | ||
100 | this._propValues[this._propNames[u_tex0_index]] = this._defaultTexMap.slice(0); | ||
101 | this._propValues[this._propNames[u_speed_index]] = 1.0; | ||
102 | |||
103 | var nProps = this._propNames.length; | ||
104 | for (var i=0; i<nProps; i++) | ||
105 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | ||
106 | }; | ||
96 | }; | 107 | }; |
97 | 108 | ||
98 | /////////////////////////////////////////////////////////////////////////////////////// | 109 | /////////////////////////////////////////////////////////////////////////////////////// |
99 | // RDGE shader | 110 | // RDGE shader |
100 | 111 | ||
101 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) | 112 | // shader spec (can also be loaded from a .JSON file, or constructed at runtime) |
102 | var flyMaterialDef = | 113 | var flyMaterialDef = |
103 | { | 114 | { |
104 | 'shaders': | 115 | 'shaders': |
105 | { | 116 | { |
106 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", | 117 | 'defaultVShader':"assets/shaders/Basic.vert.glsl", |
107 | 'defaultFShader':"assets/shaders/Fly.frag.glsl" | 118 | 'defaultFShader':"assets/shaders/Fly.frag.glsl" |
108 | }, | 119 | }, |
109 | 'techniques': | 120 | 'techniques': |
110 | { | 121 | { |
111 | 'default': | 122 | 'default': |
112 | [ | 123 | [ |
113 | { | 124 | { |
114 | 'vshader' : 'defaultVShader', | 125 | 'vshader' : 'defaultVShader', |
115 | 'fshader' : 'defaultFShader', | 126 | 'fshader' : 'defaultFShader', |
116 | // attributes | 127 | // attributes |
117 | 'attributes' : | 128 | 'attributes' : |
118 | { | 129 | { |
119 | 'vert' : { 'type' : 'vec3' }, | 130 | 'vert' : { 'type' : 'vec3' }, |
120 | 'normal' : { 'type' : 'vec3' }, | 131 | 'normal' : { 'type' : 'vec3' }, |
121 | 'texcoord' : { 'type' : 'vec2' } | 132 | 'texcoord' : { 'type' : 'vec2' } |
122 | }, | 133 | }, |
123 | // parameters | 134 | // parameters |
124 | 'params' : | 135 | 'params' : |
125 | { | 136 | { |
126 | 'u_tex0': { 'type' : 'tex2d' }, | 137 | 'u_tex0': { 'type' : 'tex2d' }, |
127 | 'u_time' : { 'type' : 'float' }, | 138 | 'u_time' : { 'type' : 'float' }, |
128 | 'u_speed' : { 'type' : 'float' }, | 139 | 'u_speed' : { 'type' : 'float' }, |
129 | 'u_resolution' : { 'type' : 'vec2' }, | 140 | 'u_resolution' : { 'type' : 'vec2' }, |
130 | }, | 141 | }, |
131 | 142 | ||
132 | // render states | 143 | // render states |
133 | 'states' : | 144 | 'states' : |
134 | { | 145 | { |
135 | 'depthEnable' : true, |