diff options
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-x | js/lib/geom/geom-obj.js | 152 |
1 files changed, 112 insertions, 40 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index a64980e0..75b7808b 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js | |||
@@ -5,26 +5,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 7 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
8 | var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; | ||
9 | var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial; | ||
10 | var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial; | ||
11 | var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; | ||
12 | var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; | ||
13 | var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; | ||
14 | var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; | ||
15 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | ||
16 | var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; | ||
17 | var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial; | ||
18 | var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; | ||
19 | var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; | ||
20 | var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; | ||
21 | var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; | ||
22 | var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; | ||
23 | var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial; | ||
24 | var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial; | ||
25 | var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial; | ||
26 | var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial; | ||
27 | var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial; | ||
28 | 8 | ||
29 | /////////////////////////////////////////////////////////////////////// | 9 | /////////////////////////////////////////////////////////////////////// |
30 | // Class GLGeomObj | 10 | // Class GLGeomObj |
@@ -265,6 +245,95 @@ var GeomObj = function GLGeomObj() { | |||
265 | return fillMaterial; | 245 | return fillMaterial; |
266 | }; | 246 | }; |
267 | 247 | ||
248 | this.exportMaterialsJSON = function() | ||
249 | { | ||
250 | var jObj; | ||
251 | if (this._materialArray && this._materialNodeArray) | ||
252 | { | ||
253 | var nMats = this._materialArray.length; | ||
254 | if (nMats > 0) | ||
255 | { | ||
256 | var arr = []; | ||
257 | |||
258 | for (var i=0; i<nMats; i++) | ||
259 | { | ||
260 | var matObj = | ||
261 | { | ||
262 | 'materialNodeName' : this._materialNodeArray[i].name, | ||
263 | 'material' : this._materialArray[i].exportJSON(), | ||
264 | 'type' : this._materialTypeArray[i] | ||
265 | } | ||
266 | arr.push( matObj ); | ||
267 | } | ||
268 | |||
269 | jObj = | ||
270 | { | ||
271 | 'nMaterials' : nMats, | ||
272 | 'materials' : arr | ||
273 | }; | ||
274 | } | ||
275 | } | ||
276 | |||
277 | return jObj; | ||
278 | } | ||
279 | |||
280 | this.importMaterialsJSON = function( jObj ) | ||
281 | { | ||
282 | this._materialArray = []; | ||
283 | this._materialTypeArray = []; | ||
284 | |||
285 | if (!jObj) return; | ||
286 | |||
287 | var nMaterials = jObj.nMaterials; | ||
288 | var matArray = jObj.materials; | ||
289 | for (var i=0; i<nMaterials; i++) | ||
290 | { | ||
291 | var mat; | ||
292 | var matObj = matArray[i].material; | ||
293 | var shaderName = matObj.material; | ||
294 | switch (shaderName) | ||
295 | { | ||
296 | case "flat": | ||
297 | case "radialGradient": | ||
298 | case "linearGradient": | ||
299 | case "bumpMetal": | ||
300 | case "uber": | ||
301 | case "plasma": | ||
302 | case "deform": | ||
303 | case "water": | ||
304 | case "tunnel": | ||
305 | case "reliefTunnel": | ||
306 | case "squareTunnel": | ||
307 | case "twist": | ||
308 | case "fly": | ||
309 | case "julia": | ||
310 | case "mandel": | ||
311 | case "star": | ||
312 | case "zinvert": | ||
313 | case "keleidoscope": | ||
314 | case "radialBlur": | ||
315 | case "pulse": | ||
316 | mat = MaterialsModel.getMaterialByShader( shaderName ); | ||
317 | if (mat) mat = mat.dup(); | ||
318 | break; | ||
319 | |||
320 | default: | ||
321 | console.log( "material type: " + shaderName + " is not supported" ); | ||
322 | break; | ||
323 | } | ||
324 | |||
325 | if (mat) | ||
326 | { | ||
327 | mat.importJSON( matObj ); | ||
328 | this._materialArray.push( mat ); | ||
329 | this._materialTypeArray.push( matObj.type ); | ||
330 | var type = matArray[i].type; | ||
331 | if (type == "fill") this._fillMaterial = mat; | ||
332 | else this._strokeMaterial = mat; | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | |||
268 | this.exportMaterials = function() | 337 | this.exportMaterials = function() |
269 | { | 338 | { |
270 | var rtnStr = ""; | 339 | var rtnStr = ""; |
@@ -296,26 +365,29 @@ var GeomObj = function GLGeomObj() { | |||
296 | var materialType = this.getPropertyFromString( "material: ", importStr ); | 365 | var materialType = this.getPropertyFromString( "material: ", importStr ); |
297 | switch (materialType) | 366 | switch (materialType) |
298 | { | 367 | { |
299 | case "flat": mat = new FlatMaterial(); break; | 368 | case "flat": |
300 | case "radialGradient": mat = new RadialGradientMaterial(); break; | 369 | case "radialGradient": |
301 | case "linearGradient": mat = new LinearGradientMaterial(); break; | 370 | case "linearGradient": |
302 | case "bumpMetal": mat = new BumpMetalMaterial(); break; | 371 | case "bumpMetal": |
303 | case "uber": mat = new UberMaterial(); break; | 372 | case "uber": |
304 | case "plasma": mat = new PlasmaMaterial(); break; | 373 | case "plasma": |
305 | case "deform": mat = new DeformMaterial(); break; | 374 | case "deform": |
306 | case "water": mat = new WaterMaterial(); break; | 375 | case "water": |
307 | case "tunnel": mat = new TunnelMaterial(); break; | 376 | case "tunnel": |
308 | case "reliefTunnel": mat = new ReliefTunnelMaterial(); break; | 377 | case "reliefTunnel": |
309 | case "squareTunnel": mat = new SquareTunnelMaterial(); break; | 378 | case "squareTunnel": |
310 | case "twist": mat = new TwiseMaterial(); break; | 379 | case "twist": |
311 | case "fly": mat = new FlyMaterial(); break; | 380 | case "fly": |
312 | case "julia": mat = new JuliaMaterial(); break; | 381 | case "julia": |
313 | case "mandel": mat = new MandelMaterial(); break; | 382 | case "mandel": |
314 | case "star": mat = new StarMaterial(); break; | 383 | case "star": |
315 | case "zinvert": mat = new ZInvertMaterial(); break; | 384 | case "zinvert": |
316 | case "keleidoscope": mat = new KeleidoscopeMaterial(); break; | 385 | case "keleidoscope": |
317 | case "radialBlur": mat = new RadialBlurMaterial(); break; | 386 | case "radialBlur": |
318 | case "pulse": mat = new PulseMaterial(); break; | 387 | case "pulse": |
388 | mat = MaterialsModel.getMaterialByShader( materialType ); | ||
389 | if (mat) mat = mat.dup(); | ||
390 | break; | ||
319 | 391 | ||
320 | default: | 392 | default: |
321 | console.log( "material type: " + materialType + " is not supported" ); | 393 | console.log( "material type: " + materialType + " is not supported" ); |