aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/MaterialsLibrary.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/MaterialsLibrary.js')
-rw-r--r--js/helper-classes/RDGE/MaterialsLibrary.js197
1 files changed, 197 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/MaterialsLibrary.js b/js/helper-classes/RDGE/MaterialsLibrary.js
new file mode 100644
index 00000000..edc4f7da
--- /dev/null
+++ b/js/helper-classes/RDGE/MaterialsLibrary.js
@@ -0,0 +1,197 @@
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 "brick": mat = new BrickMaterial(); break;
131 case "iridescentScales": mat = new IridescentScalesMaterial(); break;
132 case "quilt_1": mat = new QuiltMaterial01(); break;
133 case "quilt_2": mat = new QuiltMaterial02(); break;
134 case "linearGradient": mat = new LinearGradientMaterial(); break;
135 case "radialGradient": mat = new RadialGradientMaterial(); break;
136 case "radialBlur": mat = new RadiaBlurMaterial(); break;
137 case "pulse": mat = new PulseMaterial(); break;
138 case "tunnel": mat = new TunnelMaterial(); break;
139 case "twist": mat = new TwistMaterial(); break;
140 case "keleidoscope": mat = new KeleidoscopeMaterial(); break;
141 case "julia": mat = new JuliaMaterial(); break;
142 case "mandel": mat = new MandelMaterial(); break;
143 case "plasma": mat = new PlasmaMaterial(); break;
144 case "bumpMetal": mat = new PlasmaMaterial(); break;
145 case "uber": mat = new UberMaterial(); break;
146
147 default:
148 throw new Error( "Unrecognized material type: " + type );
149 pu.advancePastToken( "endMaterial\n" );
150 break;
151 }
152
153 if (mat)
154 {
155 importStr = mat.import( importStr );
156 pu.setBuffer( importStr );
157 this.addMaterial( mat );
158 }
159
160 type = pu.nextValue( "material: ", "\n", false );
161 }
162
163 return pu.getBuffer();
164 }
165 }
166
167});
168
169
170// create the library of stroke and fill materials
171
172var uberMaterial = new UberMaterial();
173//var linearGradientMaterial = new LinearGradientMaterial();
174//var radialGradientMaterial = new RadialGradientMaterial();
175//var radialBlurMaterial = new RadialBlurMaterial();
176//var pulseMaterial = new PulseMaterial();
177//var tunnelMaterial = new TunnelMaterial();
178//var twistMaterial = new TwistMaterial();
179//var keleidoscopeMaterial = new KeleidoscopeMaterial();
180//var juliaMaterial = new JuliaMaterial();
181//var mandelMaterial = new MandelMaterial();
182//var plasmaMaterial = new PlasmaMaterial();
183var bumpMetalMaterial = new BumpMetalMaterial();
184
185//MaterialsLibrary.addMaterial(linearGradientMaterial);
186//MaterialsLibrary.addMaterial(radialGradientMaterial);
187//MaterialsLibrary.addMaterial(radialBlurMaterial);
188//MaterialsLibrary.addMaterial(pulseMaterial);
189//MaterialsLibrary.addMaterial(tunnelMaterial);
190//MaterialsLibrary.addMaterial(twistMaterial);
191//MaterialsLibrary.addMaterial(keleidoscopeMaterial);
192//MaterialsLibrary.addMaterial(juliaMaterial);
193//MaterialsLibrary.addMaterial(mandelMaterial);
194//MaterialsLibrary.addMaterial(plasmaMaterial);
195MaterialsLibrary.addMaterial(bumpMetalMaterial);
196MaterialsLibrary.addMaterial(uberMaterial);
197