aboutsummaryrefslogtreecommitdiff
path: root/js/models
diff options
context:
space:
mode:
authorValerio Virgillito2012-03-06 10:58:25 -0800
committerValerio Virgillito2012-03-06 10:58:25 -0800
commit84332ab81c1b445195f1d9be8bbeae0725c8e758 (patch)
treee322baa1f98d4507ec255279198fa2284b2dff3c /js/models
parent13f52cf0c74f53a919fa864f86669e8155f82961 (diff)
downloadninja-84332ab81c1b445195f1d9be8bbeae0725c8e758.tar.gz
Squashed commit of preload-fix into Master
- Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/models')
-rwxr-xr-xjs/models/materials-model.js225
-rwxr-xr-xjs/models/properties-3d.js24
2 files changed, 237 insertions, 12 deletions
diff --git a/js/models/materials-model.js b/js/models/materials-model.js
new file mode 100755
index 00000000..d8fb4016
--- /dev/null
+++ b/js/models/materials-model.js
@@ -0,0 +1,225 @@
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// MaterialsLibrary module -- Contains an array of GLMaterials.
8///////////////////////////////////////////////////////////////////////
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component,
11 AppModel = require("js/models/app-model").AppModel;
12
13var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
14var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial;
15var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial;
16var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial;
17var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial;
18var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial;
19var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial;
20var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial;
21var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
22var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial;
23var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial;
24var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial;
25var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial;
26var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial;
27var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial;
28var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial;
29var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial;
30var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial;
31var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial;
32var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial;
33var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial;
34
35
36exports.MaterialsModel = Montage.create(Component, {
37
38 hasTemplate: {
39 value: false
40 },
41
42 deserializedFromTemplate: {
43 value: function() {
44 // Load all the materials
45 this.addMaterial(new FlatMaterial());
46 this.addMaterial(new LinearGradientMaterial());
47 this.addMaterial(new RadialGradientMaterial());
48 this.addMaterial(new BumpMetalMaterial());
49 this.addMaterial(new UberMaterial());
50 this.addMaterial(new RadialBlurMaterial());
51 this.addMaterial(new PlasmaMaterial());
52 this.addMaterial(new PulseMaterial());
53 this.addMaterial(new TunnelMaterial());
54 this.addMaterial(new ReliefTunnelMaterial());
55 this.addMaterial(new SquareTunnelMaterial());
56 this.addMaterial(new FlyMaterial());
57 this.addMaterial(new WaterMaterial());
58 this.addMaterial(new ZInvertMaterial());
59 this.addMaterial(new DeformMaterial());
60 this.addMaterial(new StarMaterial());
61 this.addMaterial(new TwistMaterial());
62 this.addMaterial(new JuliaMaterial());
63 this.addMaterial(new KeleidoscopeMaterial());
64 this.addMaterial(new MandelMaterial());
65 }
66 },
67
68 _materials : {
69 value: AppModel.materials
70 },
71
72 materials : {
73 get: function() {
74 return this._materials;
75 }
76 },
77
78 addMaterial: {
79 value: function (material) {
80 this._materials.push(material);
81 }
82 },
83
84 addMaterialAt: {
85 value: function (material, index) {
86 this._materials.splice(index, 0, material);
87 }
88 },
89
90 removeMaterialAt: {
91 value: function (index) {
92 return this._materials.splice(index, 1);
93 }
94 },
95
96 removeMaterial: {
97 value: function (materialName) {
98 var index = this.getIndexOfMaterial(materialName);
99 if(index !== -1) {
100 return this.removeMaterialAt(index);
101 }
102 }
103 },
104
105 getMaterialAt: {
106 value: function (index) {
107 return this._materials[index];
108 }
109 },
110
111 getMaterial: {
112 value: function (materialName) {
113 var index = this.getIndexOfMaterial(materialName);
114 if(index !== -1) {
115 return this._materials[index];
116 }
117 }
118 },
119
120 getIndexOfMaterial: {
121 value: function (materialName) {
122 var len = this._materials.length;
123 for(var i=0; i<len; i++) {
124 var material = this._materials[i];
125 if(material.getName() === materialName) {
126 return i;
127 }
128 }
129
130 return -1;
131 }
132 },
133
134 clearAllMaterials: {
135 value: function() {
136 this._materials = [];
137 }
138 },
139
140 exportFlatMaterial: {
141 value: function() {
142 return new FlatMaterial();
143 }
144 },
145
146 exportMaterials: {
147 value: function() {
148
149 var exportStr = "MaterialLibrary: \n";
150
151 var nMats = this._materials.length;
152
153 for (var i=0; i<nMats; i++) {
154 var material = this._materials[i];
155 exportStr += material.export();
156 }
157
158 exportStr += "endMatLib\n";
159 return exportStr;
160 }
161 },
162
163 importMaterials: {
164 value: function( importStr ) {
165 // we replace allmaterials, so remove anything
166 // that is currently there.
167 this.clearAllMaterials();
168
169 var pu = new MaterialParser( importStr );
170
171 var type = pu.nextValue( "material: ", "\n", false );
172
173 while (type) {
174
175 var mat = null;
176
177 switch (type)
178 {
179 case "flat": mat = new FlatMaterial(); break;
180 case "linearGradient": mat = new LinearGradientMaterial(); break;
181 case "radialGradient": mat = new RadialGradientMaterial(); break;
182 case "bumpMetal": mat = new BumpMetalMaterial(); break;
183 case "uber": mat = new UberMaterial(); break;
184
185 case "taper": mat = new TaperMaterial(); break;
186 case "twistVert": mat = new TwistVertMaterial(); break;
187 case "radialBlur": mat = new RadialBlurMaterial(); break;
188 case "plasma": mat = new PlasmaMaterial(); break;
189 case "pulse": mat = new PulseMaterial(); break;
190 case "tunnel": mat = new TunnelMaterial(); break;
191 case "reliefTunnel": mat = new ReliefTunnelMaterial(); break;
192 case "squareTunnel": mat = new SquareTunnelMaterial(); break;
193 case "fly": mat = new FlyMaterial(); break;
194 case "water": mat = new WaterMaterial(); break;
195 case "zinvert": mat = new ZInvertMaterial(); break;
196 case "deform": mat = new DeformMaterial(); break;
197 case "star": mat = new StarMaterial(); break;
198 case "twist": mat = new TwistMaterial(); break;
199 case "julia": mat = new JuliaMaterial(); break;
200 case "keleidoscope": mat = new KeleidoscopeMaterial(); break;
201 case "mandel": mat = new MandelMaterial(); break;
202
203
204 default:
205 throw new Error( "Unrecognized material type: " + type );
206 pu.advancePastToken( "endMaterial\n" );
207 break;
208 }
209
210 if (mat) {
211 importStr = mat.import( importStr );
212 pu._strBuffer = importStr;
213 this.addMaterial( mat );
214 }
215
216 type = pu.nextValue( "material: ", "\n", false );
217 }
218
219 return pu._strBuffer;
220 }
221 }
222
223});
224