/*
Copyright (c) 2012, Motorola Mobility LLC.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Motorola Mobility LLC nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////
// MaterialsLibrary module -- Contains an array of GLMaterials.
///////////////////////////////////////////////////////////////////////
var Montage = require("montage/core/core").Montage,
Component = require("montage/ui/component").Component,
AppModel = require("js/models/app-model").AppModel;
var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial;
var LinearGradientMaterial = require("js/lib/rdge/materials/linear-gradient-material").LinearGradientMaterial;
var RadialGradientMaterial = require("js/lib/rdge/materials/radial-gradient-material").RadialGradientMaterial;
var BumpMetalMaterial = require("js/lib/rdge/materials/bump-metal-material").BumpMetalMaterial;
var UberMaterial = require("js/lib/rdge/materials/uber-material").UberMaterial;
//var CloudMaterial = require("js/lib/rdge/materials/cloud-material").CloudMaterial;
var RadialBlurMaterial = require("js/lib/rdge/materials/radial-blur-material").RadialBlurMaterial;
var RaidersMaterial = require("js/lib/rdge/materials/radial-blur-material").RaidersMaterial;
var PlasmaMaterial = require("js/lib/rdge/materials/plasma-material").PlasmaMaterial;
var PulseMaterial = require("js/lib/rdge/materials/pulse-material").PulseMaterial;
var TunnelMaterial = require("js/lib/rdge/materials/tunnel-material").TunnelMaterial;
var ReliefTunnelMaterial = require("js/lib/rdge/materials/relief-tunnel-material").ReliefTunnelMaterial;
var FlagMaterial = require("js/lib/rdge/materials/flag-material").FlagMaterial;
var SquareTunnelMaterial = require("js/lib/rdge/materials/square-tunnel-material").SquareTunnelMaterial;
var FlyMaterial = require("js/lib/rdge/materials/fly-material").FlyMaterial;
var WaterMaterial = require("js/lib/rdge/materials/water-material").WaterMaterial;
var ParisMaterial = require("js/lib/rdge/materials/water-material").ParisMaterial;
var ZInvertMaterial = require("js/lib/rdge/materials/z-invert-material").ZInvertMaterial;
var DeformMaterial = require("js/lib/rdge/materials/deform-material").DeformMaterial;
var StarMaterial = require("js/lib/rdge/materials/star-material").StarMaterial;
var TwistMaterial = require("js/lib/rdge/materials/twist-material").TwistMaterial;
var TwistVertMaterial = require("js/lib/rdge/materials/twist-vert-material").TwistVertMaterial;
var TaperMaterial = require("js/lib/rdge/materials/taper-material").TaperMaterial;
var JuliaMaterial = require("js/lib/rdge/materials/julia-material").JuliaMaterial;
var KeleidoscopeMaterial = require("js/lib/rdge/materials/keleidoscope-material").KeleidoscopeMaterial;
var MandelMaterial = require("js/lib/rdge/materials/mandel-material").MandelMaterial;
exports.MaterialsModel = Montage.create(Component, {
hasTemplate: {
value: false
},
deserializedFromTemplate: {
value: function() {
// Load all the materials
this.addMaterial(new FlatMaterial());
this.addMaterial(new BumpMetalMaterial());
//this.addMaterial(new CloudMaterial());
this.addMaterial(new DeformMaterial());
this.addMaterial(new FlagMaterial());
this.addMaterial(new FlyMaterial());
this.addMaterial(new JuliaMaterial());
this.addMaterial(new KeleidoscopeMaterial());
this.addMaterial(new LinearGradientMaterial());
this.addMaterial(new MandelMaterial());
this.addMaterial(new ParisMaterial());
this.addMaterial(new PlasmaMaterial());
this.addMaterial(new PulseMaterial());
this.addMaterial(new RadialBlurMaterial());
this.addMaterial(new RadialGradientMaterial());
this.addMaterial(new RaidersMaterial());
this.addMaterial(new ReliefTunnelMaterial());
this.addMaterial(new SquareTunnelMaterial());
this.addMaterial(new StarMaterial());
this.addMaterial(new TaperMaterial());
this.addMaterial(new TunnelMaterial());
this.addMaterial(new TwistMaterial());
this.addMaterial(new TwistVertMaterial());
this.addMaterial(new UberMaterial());
this.addMaterial(new WaterMaterial());
this.addMaterial(new ZInvertMaterial());
}
},
_materials : {
value: AppModel.materials
},
materials : {
get: function() {
return this._materials;
}
},
addMaterial: {
value: function (material) {
this._materials.push(material);
}
},
addMaterialAt: {
value: function (material, index) {
this._materials.splice(index, 0, material);
}
},
removeMaterialAt: {
value: function (index) {
return this._materials.splice(index, 1);
}
},
removeMaterial: {
value: function (materialName) {
var index = this.getIndexOfMaterial(materialName);
if(index !== -1) {
return this.removeMaterialAt(index);
}
}
},
getMaterialAt: {
value: function (index) {
return this._materials[index];
}
},
getMaterial: {
value: function (materialName) {
var index = this.getIndexOfMaterial(materialName);
if(index !== -1) {
return this._materials[index];
}
}
},
getMaterialByShader:
{
value: function( shaderName )
{
var index = this.getIndexOfMaterialByShader( shaderName );
if (index >= 0)
return this._materials[index];
}
},
getIndexOfMaterialByShader: {
value: function (shaderName) {
var len = this._materials.length;
for(var i=0; i