aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/backup-delete/MaterialsLibrary.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-03-06 17:04:40 -0800
committerPushkar Joshi2012-03-06 17:04:40 -0800
commit7a43958033906b2273de88bc2a26cda7a905d202 (patch)
treef71817e712c4b07a48257a4f0b206cf9033421df /js/helper-classes/backup-delete/MaterialsLibrary.js
parent264e3d8e6d3624083d2fab9fe2560234553bb2ad (diff)
parent2e3943a8f751ec572066f168b58464c24b9f29e5 (diff)
downloadninja-7a43958033906b2273de88bc2a26cda7a905d202.tar.gz
Merge branch 'master' into brushtool
Diffstat (limited to 'js/helper-classes/backup-delete/MaterialsLibrary.js')
-rwxr-xr-xjs/helper-classes/backup-delete/MaterialsLibrary.js230
1 files changed, 230 insertions, 0 deletions
diff --git a/js/helper-classes/backup-delete/MaterialsLibrary.js b/js/helper-classes/backup-delete/MaterialsLibrary.js
new file mode 100755
index 00000000..8f55f2bc
--- /dev/null
+++ b/js/helper-classes/backup-delete/MaterialsLibrary.js
@@ -0,0 +1,230 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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// Class MaterialsLibrary
8// Contains an array of GLMaterials.
9///////////////////////////////////////////////////////////////////////
10var MaterialsLibrary = Object.create(Object.prototype, {
11
12 _materials : { value: [], writable: true, enumerable: true, configurable: true },
13
14 materials : {
15 get: function() {
16 return this._materials;
17 }
18 },
19
20 addMaterial: {
21 value: function (material)
22 {
23 this._materials.push(material);
24 }
25 },
26
27 addMaterialAt: {
28 value: function (material, index)
29 {
30 this._materials.splice(index, 0, material);
31 }
32 },
33
34 removeMaterialAt: {
35 value: function (index)
36 {
37 return this._materials.splice(index, 1);
38 }
39 },
40
41 removeMaterial: {
42 value: function (materialName)
43 {
44 var index = this.getIndexOfMaterial(materialName);
45 if(index !== -1)
46 {
47 return this.removeMaterialAt(index);
48 }
49 }
50 },
51
52 getMaterialAt: {
53 value: function (index)
54 {
55 return this._materials[index];
56 }
57 },
58
59 getMaterial: {
60 value: function (materialName)
61 {
62 var index = this.getIndexOfMaterial(materialName);
63 if(index !== -1)
64 {
65 return this._materials[index];
66 }
67 }
68 },
69
70 getIndexOfMaterial: {
71 value: function (materialName)
72 {
73 var len = this._materials.length;
74 for(var i=0; i<len; i++)
75 {
76 var material = this._materials[i];
77 if(material.getName() === materialName)
78 {
79 return i;
80 }
81 }
82
83 return -1;
84 }
85 },
86
87 clearAllMaterials:
88 {
89 value: function()
90 {
91 this._materials = [];
92 }
93 },
94
95 export:
96 {
97 value: function()
98 {
99 var exportStr = "MaterialLibrary: \n"
100
101 var nMats = this._materials.length;
102 for (var i=0; i<nMats; i++)
103 {
104 var material = this._materials[i];
105 exportStr += material.export();
106 }
107
108 exportStr += "endMatLib\n";
109 return exportStr;
110 }
111 },
112
113 import:
114 {
115 value: function( importStr )
116 {
117 // we replace allmaterials, so remove anything
118 // that is currently there.
119 this.clearAllMaterials();
120
121 var pu = new ParseUtils( importStr );
122
123 var type = pu.nextValue( "material: ", "\n", false );
124 while (type)
125 {
126 var mat = null;
127 switch (type)
128 {
129 case "flat": mat = new FlatMaterial(); break;
130 case "linearGradient": mat = new LinearGradientMaterial(); break;
131 case "radialGradient": mat = new RadialGradientMaterial(); break;
132 case "bumpMetal": mat = new BumpMetalMaterial(); break;
133 case "uber": mat = new UberMaterial(); break;
134
135 case "taper": mat = new TaperMaterial(); break;
136 case "twistVert": mat = new TwistVertMaterial(); break;
137 case "radialBlur": mat = new RadialBlurMaterial(); break;
138 case "plasma": mat = new PlasmaMaterial(); break;
139 case "pulse": mat = new PulseMaterial(); break;
140 case "tunnel": mat = new TunnelMaterial(); break;
141 case "reliefTunnel": mat = new ReliefTunnelMaterial(); break;
142 case "squareTunnel": mat = new SquareTunnelMaterial(); break;
143 case "fly": mat = new FlyMaterial(); break;
144 case "water": mat = new WaterMaterial(); break;
145 case "zinvert": mat = new ZInvertMaterial(); break;
146 case "deform": mat = new DeformMaterial(); break;
147 case "star": mat = new StarMaterial(); break;
148 case "twist": mat = new TwistMaterial(); break;
149 case "julia": mat = new JuliaMaterial(); break;
150 case "keleidoscope": mat = new KeleidoscopeMaterial(); break;
151 case "mandel": mat = new MandelMaterial(); break;
152
153
154 default:
155 throw new Error( "Unrecognized material type: " + type );
156 pu.advancePastToken( "endMaterial\n" );
157 break;
158 }
159
160 if (mat)
161 {
162 importStr = mat.import( importStr );
163 pu.setBuffer( importStr );
164 this.addMaterial( mat );
165 }
166
167 type = pu.nextValue( "material: ", "\n", false );
168 }
169
170 return pu.getBuffer();
171 }
172 }
173
174});
175
176
177// create the library of stroke and fill materials
178
179var flatMaterial = new FlatMaterial();
180var linearGradientMaterial = new LinearGradientMaterial();
181var radialGradientMaterial = new RadialGradientMaterial();
182var bumpMetalMaterial = new BumpMetalMaterial();
183var uberMaterial = new UberMaterial();
184
185//var taperMaterial = new TaperMaterial();
186//var twistVertMaterial = new TwistVertMaterial();
187var radialBlurMaterial = new RadialBlurMaterial();
188var plasmaMaterial = new PlasmaMaterial();
189var pulseMaterial = new PulseMaterial();
190var tunnelMaterial = new TunnelMaterial();
191var reliefTunnelMaterial = new ReliefTunnelMaterial();
192var squareTunnelMaterial = new SquareTunnelMaterial();
193var flyMaterial = new FlyMaterial();
194var waterMaterial = new WaterMaterial();
195var zInvertMaterial = new ZInvertMaterial();
196var deformMaterial = new DeformMaterial();
197var starMaterial = new StarMaterial();
198var twistMaterial = new TwistMaterial();
199var juliaMaterial = new JuliaMaterial();
200var keleidoscopeMaterial = new KeleidoscopeMaterial();
201var mandelMaterial = new MandelMaterial();
202
203
204MaterialsLibrary.addMaterial(flatMaterial);
205MaterialsLibrary.addMaterial(linearGradientMaterial);