aboutsummaryrefslogtreecommitdiff
path: root/js/models
diff options
context:
space:
mode:
Diffstat (limited to 'js/models')
-rwxr-xr-xjs/models/materials-model.js90
-rwxr-xr-xjs/models/shape-model.js3
2 files changed, 68 insertions, 25 deletions
diff --git a/js/models/materials-model.js b/js/models/materials-model.js
index d8fb4016..692ac09a 100755
--- a/js/models/materials-model.js
+++ b/js/models/materials-model.js
@@ -17,6 +17,7 @@ var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-mate
17var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; 17var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial;
18var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; 18var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial;
19var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; 19var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial;
20var RaidersMaterial = require("js/lib/rdge/materials/radial-blur-material").RaidersMaterial;
20var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; 21var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial;
21var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; 22var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
22var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; 23var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial;
@@ -24,6 +25,7 @@ var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material
24var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; 25var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial;
25var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; 26var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial;
26var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; 27var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial;
28var ParisMaterial = require("js/lib/rdge/materials/water-material").ParisMaterial;
27var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; 29var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial;
28var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; 30var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial;
29var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial; 31var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial;
@@ -48,6 +50,7 @@ exports.MaterialsModel = Montage.create(Component, {
48 this.addMaterial(new BumpMetalMaterial()); 50 this.addMaterial(new BumpMetalMaterial());
49 this.addMaterial(new UberMaterial()); 51 this.addMaterial(new UberMaterial());
50 this.addMaterial(new RadialBlurMaterial()); 52 this.addMaterial(new RadialBlurMaterial());
53 this.addMaterial(new RaidersMaterial());
51 this.addMaterial(new PlasmaMaterial()); 54 this.addMaterial(new PlasmaMaterial());
52 this.addMaterial(new PulseMaterial()); 55 this.addMaterial(new PulseMaterial());
53 this.addMaterial(new TunnelMaterial()); 56 this.addMaterial(new TunnelMaterial());
@@ -55,6 +58,7 @@ exports.MaterialsModel = Montage.create(Component, {
55 this.addMaterial(new SquareTunnelMaterial()); 58 this.addMaterial(new SquareTunnelMaterial());
56 this.addMaterial(new FlyMaterial()); 59 this.addMaterial(new FlyMaterial());
57 this.addMaterial(new WaterMaterial()); 60 this.addMaterial(new WaterMaterial());
61 this.addMaterial(new ParisMaterial());
58 this.addMaterial(new ZInvertMaterial()); 62 this.addMaterial(new ZInvertMaterial());
59 this.addMaterial(new DeformMaterial()); 63 this.addMaterial(new DeformMaterial());
60 this.addMaterial(new StarMaterial()); 64 this.addMaterial(new StarMaterial());
@@ -112,10 +116,34 @@ exports.MaterialsModel = Montage.create(Component, {
112 value: function (materialName) { 116 value: function (materialName) {
113 var index = this.getIndexOfMaterial(materialName); 117 var index = this.getIndexOfMaterial(materialName);
114 if(index !== -1) { 118 if(index !== -1) {
115 return this._materials[index]; 119 return this._materials[index].dup();
116 } 120 }
117 } 121 }
118 }, 122 },
123
124 getMaterialByShader:
125 {
126 value: function( shaderName )
127 {
128 var index = this.getIndexOfMaterialByShader( shaderName );
129 if (index >= 0)
130 return this._materials[index].dup();
131 }
132 },
133
134 getIndexOfMaterialByShader: {
135 value: function (shaderName) {
136 var len = this._materials.length;
137 for(var i=0; i<len; i++) {
138 var material = this._materials[i];
139 if(material.getShaderName() === shaderName) {
140 return i;
141 }
142 }
143
144 return -1;
145 }
146 },
119 147
120 getIndexOfMaterial: { 148 getIndexOfMaterial: {
121 value: function (materialName) { 149 value: function (materialName) {
@@ -143,37 +171,54 @@ exports.MaterialsModel = Montage.create(Component, {
143 } 171 }
144 }, 172 },
145 173
146 exportMaterials: { 174 getDefaultMaterialName: {
147 value: function() { 175 value: function() {
176 return "FlatMaterial";
177 }
178 },
148 179
149 var exportStr = "MaterialLibrary: \n"; 180 exportMaterials: {
150 181 value: function()
182 {
183 var matArray = [];
151 var nMats = this._materials.length; 184 var nMats = this._materials.length;
152
153 for (var i=0; i<nMats; i++) { 185 for (var i=0; i<nMats; i++) {
154 var material = this._materials[i]; 186 var material = this._materials[i];
155 exportStr += material.export(); 187 var matObj = material.exportJSON();
188 matArray.push( matObj );
156 } 189 }
157 190
158 exportStr += "endMatLib\n"; 191 var jObj =
159 return exportStr; 192 {
193 'materialLibrary': 1.0,
194 'materials': matArray
195 };
196
197 // prepend an identifiable string to aid parsing when the
198 // material model is loaded.
199 var jStr = "materialLibrary;" + JSON.stringify( jObj );
200
201 return jStr;
160 } 202 }
161 }, 203 },
162 204
163 importMaterials: { 205 importMaterials: {
164 value: function( importStr ) { 206 value: function( jObj )
207 {
208 // make sure we have some materials to import before doing anything
209 var matArray = jObj.materials;
210 if (!matArray) return;
211
165 // we replace allmaterials, so remove anything 212 // we replace allmaterials, so remove anything
166 // that is currently there. 213 // that is currently there.
167 this.clearAllMaterials(); 214 this.clearAllMaterials();
168 215
169 var pu = new MaterialParser( importStr ); 216 var nMats = matArray.length;
170 217 for (var i=0; i<nMats; i++)
171 var type = pu.nextValue( "material: ", "\n", false ); 218 {
172 219 var mat = null;
173 while (type) { 220 var jMatObj = matArray[i];
174 221 var type = jMatObj.material;
175 var mat = null;
176
177 switch (type) 222 switch (type)
178 { 223 {
179 case "flat": mat = new FlatMaterial(); break; 224 case "flat": mat = new FlatMaterial(); break;
@@ -192,6 +237,7 @@ exports.MaterialsModel = Montage.create(Component, {
192 case "squareTunnel": mat = new SquareTunnelMaterial(); break; 237 case "squareTunnel": mat = new SquareTunnelMaterial(); break;
193 case "fly": mat = new FlyMaterial(); break; 238 case "fly": mat = new FlyMaterial(); break;
194 case "water": mat = new WaterMaterial(); break; 239 case "water": mat = new WaterMaterial(); break;
240 case "paris": mat = new ParisMaterial(); break;
195 case "zinvert": mat = new ZInvertMaterial(); break; 241 case "zinvert": mat = new ZInvertMaterial(); break;
196 case "deform": mat = new DeformMaterial(); break; 242 case "deform": mat = new DeformMaterial(); break;
197 case "star": mat = new StarMaterial(); break; 243 case "star": mat = new StarMaterial(); break;
@@ -203,20 +249,16 @@ exports.MaterialsModel = Montage.create(Component, {
203 249
204 default: 250 default:
205 throw new Error( "Unrecognized material type: " + type ); 251 throw new Error( "Unrecognized material type: " + type );
206 pu.advancePastToken( "endMaterial\n" );
207 break; 252 break;
208 } 253 }
209 254
210 if (mat) { 255 if (mat) {
211 importStr = mat.import( importStr ); 256 importStr = mat.importJSON( jMatObj );
212 pu._strBuffer = importStr;
213 this.addMaterial( mat ); 257 this.addMaterial( mat );
214 } 258 }
215
216 type = pu.nextValue( "material: ", "\n", false );
217 } 259 }
218 260
219 return pu._strBuffer; 261 return;
220 } 262 }
221 } 263 }
222 264
diff --git a/js/models/shape-model.js b/js/models/shape-model.js
index 58a88fd0..ea8c2cfc 100755
--- a/js/models/shape-model.js
+++ b/js/models/shape-model.js
@@ -10,7 +10,8 @@ var Montage = require("montage/core/core").Montage,
10exports.ShapeModel = Montage.create(Component, { 10exports.ShapeModel = Montage.create(Component, {
11 11
12 shapeCount: { value: 0 }, 12 shapeCount: { value: 0 },
13 useWebGl: { value: false }, 13 useWebGl: { value: false },
14 animate: { value: true },
14 15
15 GLWorld: { value: null }, 16 GLWorld: { value: null },
16 GLGeomObj: { value: null }, 17 GLGeomObj: { value: null },