diff options
Diffstat (limited to 'js/models')
-rwxr-xr-x | js/models/color-model.js | 56 | ||||
-rwxr-xr-x | js/models/materials-model.js | 91 | ||||
-rwxr-xr-x | js/models/properties-3d.js | 48 | ||||
-rwxr-xr-x | js/models/shape-model.js | 10 |
4 files changed, 136 insertions, 69 deletions
diff --git a/js/models/color-model.js b/js/models/color-model.js index 4189fbef..764feeb5 100755 --- a/js/models/color-model.js +++ b/js/models/color-model.js | |||
@@ -589,18 +589,54 @@ exports.ColorModel = Montage.create(Component, { | |||
589 | } | 589 | } |
590 | }, | 590 | }, |
591 | //////////////////////////////////////////////////////////////////// | 591 | //////////////////////////////////////////////////////////////////// |
592 | //Returns CSS string given a WebGL color array in [r, g, b, a] format where the values are [0,1] | 592 | //Returns a color object given a WebGL color array/object with gradient stops |
593 | webGlToCss: { | 593 | webGlToColor: { |
594 | enumerable: true, | 594 | enumerable: true, |
595 | value: function (color) { | 595 | value: function (c) { |
596 | if(color && (color.length === 4)) | 596 | if(c) { |
597 | { | 597 | if(c.gradientMode) { |
598 | return 'rgba(' + color[0]*255 + ', ' + color[1]*255 + ', ' + color[2]*255 + ', ' + color[3] +')'; | 598 | // Gradient |
599 | } | 599 | var i = 0, |
600 | else | 600 | len, |
601 | { | 601 | css, |
602 | return null; | 602 | stops = c.color, |
603 | gradient; | ||
604 | |||
605 | // Create the CSS string | ||
606 | if (c.gradientMode === 'radial') { | ||
607 | css = '-webkit-radial-gradient(center, ellipse cover'; | ||
608 | } else { | ||
609 | css = '-webkit-gradient(linear, left top, right top'; | ||
610 | } | ||
611 | |||
612 | //Sorting array (must be sorted for radial gradients, at least in Chrome | ||
613 | stops.sort(function(a,b){return a.position - b.position}); | ||
614 | //Looping through stops in gradient to create CSS | ||
615 | |||
616 | len = stops.length; | ||
617 | for (i=0; i < len; i++) { | ||
618 | //Adding to CSS String | ||
619 | if (c.gradientMode === 'radial' && stops[i].value) { | ||
620 | css += ', '+stops[i].value.css+' '+stops[i].position+'% '; | ||
621 | } else if (stops[i].value){ | ||
622 | css += ', color-stop('+stops[i].position+'%,'+stops[i].value.css+')'; | ||
623 | } | ||
624 | } | ||
625 | //Closing the CSS strings | ||
626 | css += ')'; | ||
627 | |||
628 | gradient = {stops: c.color, mode: c.gradientMode, gradientMode: c.gradientMode, css: css}; | ||
629 | return {mode: 'gradient', value: gradient, color: gradient}; | ||
630 | } else if(c.length === 4) { | ||
631 | // CSS | ||
632 | return this.application.ninja.colorController.getColorObjFromCss('rgba(' + c[0]*255 + ', ' | ||
633 | + c[1]*255 + ', ' | ||
634 | + c[2]*255 + ', ' | ||
635 | + c[3] +')'); | ||
636 | } | ||
603 | } | 637 | } |
638 | |||
639 | return null; | ||
604 | } | 640 | } |
605 | } | 641 | } |
606 | //////////////////////////////////////////////////////////////////// | 642 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/models/materials-model.js b/js/models/materials-model.js index d8fb4016..44364aa2 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 | |||
17 | var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; | 17 | var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial; |
18 | var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; | 18 | var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial; |
19 | var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; | 19 | var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial; |
20 | var RaidersMaterial = require("js/lib/rdge/materials/radial-blur-material").RaidersMaterial; | ||
20 | var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; | 21 | var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial; |
21 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; | 22 | var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial; |
22 | var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; | 23 | var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial; |
@@ -24,6 +25,7 @@ var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material | |||
24 | var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; | 25 | var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial; |
25 | var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; | 26 | var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial; |
26 | var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; | 27 | var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial; |
28 | var ParisMaterial = require("js/lib/rdge/materials/water-material").ParisMaterial; | ||
27 | var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; | 29 | var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial; |
28 | var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; | 30 | var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial; |
29 | var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial; | 31 | var 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 | { |