diff options
author | hwc487 | 2012-03-22 15:47:11 -0700 |
---|---|---|
committer | hwc487 | 2012-03-22 15:47:11 -0700 |
commit | e927e4702d7dbd4a878f6979b3f56b46758f93de (patch) | |
tree | e6bb8951374a6504bd6c745ce7233da5cd4869dc /js/models | |
parent | 00cd98e49c959906d7c44bb6adcdef1f3d5148ae (diff) | |
parent | 31e924e1b8b8da8342b3ff2341c8284915486c0b (diff) | |
download | ninja-e927e4702d7dbd4a878f6979b3f56b46758f93de.tar.gz |
Merge branch 'integration' of github.com:ericmueller/ninja-internal into Textures
Diffstat (limited to 'js/models')
-rwxr-xr-x | js/models/materials-model.js | 90 |
1 files changed, 66 insertions, 24 deletions
diff --git a/js/models/materials-model.js b/js/models/materials-model.js index d8fb4016..692ac09a 100755 --- a/js/models/materials-model.js +++ b/js/models/materials-model.js | |||
@@ -17,6 +17,7 @@ var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-mate | |||
17 | var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; | 17 | var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; |
18 | var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; | 18 | var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; |
19 | var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; | 19 | var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; |
20 | var RaidersMaterial = require("js/lib/rdge/materials/radial-blur-material").RaidersMaterial; | ||
20 | var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; | 21 | var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; |
21 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | 22 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; |
22 | var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; | 23 | var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; |
@@ -24,6 +25,7 @@ var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material | |||
24 | var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; | 25 | var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; |
25 | var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; | 26 | var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; |
26 | var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; | 27 | var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; |
28 | var ParisMaterial = require("js/lib/rdge/materials/water-material").ParisMaterial; | ||
27 | var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; | 29 | var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; |
28 | var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; | 30 | var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; |
29 | var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial; | 31 | var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial; |
@@ -48,6 +50,7 @@ exports.MaterialsModel = Montage.create(Component, { | |||
48 | this.addMaterial(new BumpMetalMaterial()); | 50 | this.addMaterial(new BumpMetalMaterial()); |
49 | this.addMaterial(new UberMaterial()); | 51 | this.addMaterial(new UberMaterial()); |
50 | this.addMaterial(new RadialBlurMaterial()); | 52 | this.addMaterial(new RadialBlurMaterial()); |
53 | this.addMaterial(new RaidersMaterial()); | ||
51 | this.addMaterial(new PlasmaMaterial()); | 54 | this.addMaterial(new PlasmaMaterial()); |
52 | this.addMaterial(new PulseMaterial()); | 55 | this.addMaterial(new PulseMaterial()); |
53 | this.addMaterial(new TunnelMaterial()); | 56 | this.addMaterial(new TunnelMaterial()); |
@@ -55,6 +58,7 @@ exports.MaterialsModel = Montage.create(Component, { | |||
55 | this.addMaterial(new SquareTunnelMaterial()); | 58 | this.addMaterial(new SquareTunnelMaterial()); |
56 | this.addMaterial(new FlyMaterial()); | 59 | this.addMaterial(new FlyMaterial()); |
57 | this.addMaterial(new WaterMaterial()); | 60 | this.addMaterial(new WaterMaterial()); |
61 | this.addMaterial(new ParisMaterial()); | ||
58 | this.addMaterial(new ZInvertMaterial()); | 62 | this.addMaterial(new ZInvertMaterial()); |
59 | this.addMaterial(new DeformMaterial()); | 63 | this.addMaterial(new DeformMaterial()); |
60 | this.addMaterial(new StarMaterial()); | 64 | this.addMaterial(new StarMaterial()); |
@@ -112,10 +116,34 @@ exports.MaterialsModel = Montage.create(Component, { | |||
112 | value: function (materialName) { | 116 | value: function (materialName) { |
113 | var index = this.getIndexOfMaterial(materialName); | 117 | var index = this.getIndexOfMaterial(materialName); |
114 | if(index !== -1) { | 118 | if(index !== -1) { |
115 | return this._materials[index]; | 119 | return this._materials[index].dup(); |
116 | } | 120 | } |
117 | } | 121 | } |
118 | }, | 122 | }, |
123 | |||
124 | getMaterialByShader: | ||
125 | { | ||
126 | value: function( shaderName ) | ||
127 | { | ||
128 | var index = this.getIndexOfMaterialByShader( shaderName ); | ||
129 | if (index >= 0) | ||
130 | return this._materials[index].dup(); | ||
131 | } | ||
132 | }, | ||
133 | |||
134 | getIndexOfMaterialByShader: { | ||
135 | value: function (shaderName) { | ||
136 | var len = this._materials.length; | ||
137 | for(var i=0; i<len; i++) { | ||
138 | var material = this._materials[i]; | ||
139 | if(material.getShaderName() === shaderName) { | ||
140 | return i; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | return -1; | ||
145 | } | ||
146 | }, | ||
119 | 147 | ||
120 | getIndexOfMaterial: { | 148 | getIndexOfMaterial: { |
121 | value: function (materialName) { | 149 | value: function (materialName) { |
@@ -143,37 +171,54 @@ exports.MaterialsModel = Montage.create(Component, { | |||
143 | } | 171 | } |
144 | }, | 172 | }, |
145 | 173 | ||
146 | exportMaterials: { | 174 | getDefaultMaterialName: { |
147 | value: function() { | 175 | value: function() { |
176 | return "FlatMaterial"; | ||
177 | } | ||
178 | }, | ||
148 | 179 | ||
149 | var exportStr = "MaterialLibrary: \n"; | 180 | exportMaterials: { |
150 | 181 | value: function() | |
182 | { | ||
183 | var matArray = []; | ||
151 | var nMats = this._materials.length; | 184 | var nMats = this._materials.length; |
152 | |||
153 | for (var i=0; i<nMats; i++) { | 185 | for (var i=0; i<nMats; i++) { |
154 | var material = this._materials[i]; | 186 | var material = this._materials[i]; |
155 | exportStr += material.export(); | 187 | var matObj = material.exportJSON(); |
188 | matArray.push( matObj ); | ||
156 | } | 189 | } |
157 | 190 | ||
158 | exportStr += "endMatLib\n"; | 191 | var jObj = |
159 | return exportStr; | 192 | { |
193 | 'materialLibrary': 1.0, | ||
194 | 'materials': matArray | ||
195 | }; | ||
196 | |||
197 | // prepend an identifiable string to aid parsing when the | ||
198 | // material model is loaded. | ||
199 | var jStr = "materialLibrary;" + JSON.stringify( jObj ); | ||
200 | |||
201 | return jStr; | ||
160 | } | 202 | } |
161 | }, | 203 | }, |
162 | 204 | ||
163 | importMaterials: { | 205 | importMaterials: { |
164 | value: function( importStr ) { | 206 | value: function( jObj ) |
207 | { | ||
208 | // make sure we have some materials to import before doing anything | ||
209 | var matArray = jObj.materials; | ||
210 | if (!matArray) return; | ||
211 | |||
165 | // we replace allmaterials, so remove anything | 212 | // we replace allmaterials, so remove anything |
166 | // that is currently there. | 213 | // that is currently there. |
167 | this.clearAllMaterials(); | 214 | this.clearAllMaterials(); |
168 | 215 | ||
169 | var pu = new MaterialParser( importStr ); | 216 | var nMats = matArray.length; |
170 | 217 | for (var i=0; i<nMats; i++) | |
171 | var type = pu.nextValue( "material: ", "\n", false ); | 218 | { |
172 | 219 | var mat = null; | |
173 | while (type) { | 220 | var jMatObj = matArray[i]; |
174 | 221 | var type = jMatObj.material; | |
175 | var mat = null; | ||
176 | |||
177 | switch (type) | 222 | switch (type) |
178 | { | 223 | { |
179 | case "flat": mat = new FlatMaterial(); break; | 224 | case "flat": mat = new FlatMaterial(); break; |
@@ -192,6 +237,7 @@ exports.MaterialsModel = Montage.create(Component, { | |||
192 | case "squareTunnel": mat = new SquareTunnelMaterial(); break; | 237 | case "squareTunnel": mat = new SquareTunnelMaterial(); break; |
193 | case "fly": mat = new FlyMaterial(); break; | 238 | case "fly": mat = new FlyMaterial(); break; |
194 | case "water": mat = new WaterMaterial(); break; | 239 | case "water": mat = new WaterMaterial(); break; |
240 | case "paris": mat = new ParisMaterial(); break; | ||
195 | case "zinvert": mat = new ZInvertMaterial(); break; | 241 | case "zinvert": mat = new ZInvertMaterial(); break; |
196 | case "deform": mat = new DeformMaterial(); break; | 242 | case "deform": mat = new DeformMaterial(); break; |
197 | case "star": mat = new StarMaterial(); break; | 243 | case "star": mat = new StarMaterial(); break; |
@@ -203,20 +249,16 @@ exports.MaterialsModel = Montage.create(Component, { | |||
203 | 249 | ||
204 | default: | 250 | default: |
205 | throw new Error( "Unrecognized material type: " + type ); | 251 | throw new Error( "Unrecognized material type: " + type ); |
206 | pu.advancePastToken( "endMaterial\n" ); | ||
207 | break; | 252 | break; |
208 | } | 253 | } |
209 | 254 | ||
210 | if (mat) { | 255 | if (mat) { |
211 | importStr = mat.import( importStr ); | 256 | importStr = mat.importJSON( jMatObj ); |
212 | pu._strBuffer = importStr; | ||
213 | this.addMaterial( mat ); | 257 | this.addMaterial( mat ); |
214 | } | 258 | } |
215 | |||
216 | type = pu.nextValue( "material: ", "\n", false ); | ||
217 | } | 259 | } |
218 | 260 | ||
219 | return pu._strBuffer; | 261 | return; |
220 | } | 262 | } |
221 | } | 263 | } |
222 | 264 | ||