diff options
Diffstat (limited to 'js/helper-classes/backup-delete/MaterialsLibrary.js')
-rwxr-xr-x | js/helper-classes/backup-delete/MaterialsLibrary.js | 230 |
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> | ||
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 | // Class MaterialsLibrary | ||
8 | // Contains an array of GLMaterials. | ||
9 | /////////////////////////////////////////////////////////////////////// | ||
10 | var 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 | |||
179 | var flatMaterial = new FlatMaterial(); | ||
180 | var linearGradientMaterial = new LinearGradientMaterial(); | ||
181 | var radialGradientMaterial = new RadialGradientMaterial(); | ||
182 | var bumpMetalMaterial = new BumpMetalMaterial(); | ||
183 | var uberMaterial = new UberMaterial(); | ||
184 | |||
185 | //var taperMaterial = new TaperMaterial(); | ||
186 | //var twistVertMaterial = new TwistVertMaterial(); | ||
187 | var radialBlurMaterial = new RadialBlurMaterial(); | ||
188 | var plasmaMaterial = new PlasmaMaterial(); | ||
189 | var pulseMaterial = new PulseMaterial(); | ||
190 | var tunnelMaterial = new TunnelMaterial(); | ||
191 | var reliefTunnelMaterial = new ReliefTunnelMaterial(); | ||
192 | var squareTunnelMaterial = new SquareTunnelMaterial(); | ||
193 | var flyMaterial = new FlyMaterial(); | ||
194 | var waterMaterial = new WaterMaterial(); | ||
195 | var zInvertMaterial = new ZInvertMaterial(); | ||
196 | var deformMaterial = new DeformMaterial(); | ||
197 | var starMaterial = new StarMaterial(); | ||
198 | var twistMaterial = new TwistMaterial(); | ||
199 | var juliaMaterial = new JuliaMaterial(); | ||
200 | var keleidoscopeMaterial = new KeleidoscopeMaterial(); | ||
201 | var mandelMaterial = new MandelMaterial(); | ||
202 | |||
203 | |||
204 | MaterialsLibrary.addMaterial(flatMaterial); | ||
205 | MaterialsLibrary.addMaterial(linearGradientMaterial); | ||
206 | MaterialsLibrary.addMaterial(radialGradientMaterial); | ||
207 | MaterialsLibrary.addMaterial(bumpMetalMaterial); | ||
208 | MaterialsLibrary.addMaterial(uberMaterial); | ||
209 | |||
210 | //MaterialsLibrary.addMaterial(taperMaterial); | ||
211 | //MaterialsLibrary.addMaterial(twistVertMaterial); | ||