aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/html-document.js33
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js4
-rw-r--r--js/lib/rdge/materials/cloud-material.js300
-rw-r--r--js/lib/rdge/materials/plasma-material.js1
-rw-r--r--js/lib/rdge/materials/pulse-material.js4
-rw-r--r--js/lib/rdge/materials/radial-blur-material.js4
-rwxr-xr-xjs/lib/rdge/materials/uber-material.js5
-rwxr-xr-xjs/models/materials-model.js53
8 files changed, 355 insertions, 49 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 8b765501..3d109fdb 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -9,7 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 TextDocument = require("js/document/text-document").TextDocument, 10 TextDocument = require("js/document/text-document").TextDocument,
11 NJUtils = require("js/lib/NJUtils").NJUtils, 11 NJUtils = require("js/lib/NJUtils").NJUtils,
12 GLWorld = require("js/lib/drawing/world").World; 12 GLWorld = require("js/lib/drawing/world").World,
13 MaterialsModel = require("js/models/materials-model").MaterialsModel;
13//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
14// 15//
15exports.HTMLDocument = Montage.create(TextDocument, { 16exports.HTMLDocument = Montage.create(TextDocument, {
@@ -193,7 +194,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
193 var elt = this.iframe.contentWindow.document.getElementById("UserContent"); 194 var elt = this.iframe.contentWindow.document.getElementById("UserContent");
194 // 195 //
195 if (elt) { 196 if (elt) {
196 this._glData = []; 197 var matLib = MaterialsModel.exportMaterials();
198 this._glData = [matLib];
197 this.collectGLData(elt, this._glData ); 199 this.collectGLData(elt, this._glData );
198 } else { 200 } else {
199 this._glData = null 201 this._glData = null
@@ -231,12 +233,27 @@ exports.HTMLDocument = Montage.create(TextDocument, {
231 } 233 }
232 else 234 else
233 { 235 {
234 var startIndex = importStr.indexOf( "id: " ); 236 // at this point the data could be either the materials library or
235 if (startIndex >= 0) { 237 // an old style world. We can determine which by converting the string
236 var endIndex = importStr.indexOf( "\n", startIndex ); 238 // to an object via JSON.parse. That operation will fail if the string
237 if (endIndex > 0) 239 // is an old style world.
238 id = importStr.substring( startIndex+4, endIndex ); 240 var matLibStr = 'materialLibrary;';
239 } 241 index = importStr.indexOf( matLibStr );
242 if (index == 0)
243 {
244 importStr = importStr.substr( matLibStr.length );
245 var matLibObj = JSON.parse( importStr );
246 MaterialsModel.importMaterials( matLibObj );
247 }
248 else
249 {
250 var startIndex = importStr.indexOf( "id: " );
251 if (startIndex >= 0) {
252 var endIndex = importStr.indexOf( "\n", startIndex );
253 if (endIndex > 0)
254 id = importStr.substring( startIndex+4, endIndex );
255 }
256 }
240 } 257 }
241 258
242 if (id != null) 259 if (id != null)
diff --git a/js/lib/rdge/materials/bump-metal-material.js b/js/lib/rdge/materials/bump-metal-material.js
index 4a6e9ab8..2ef83227 100755
--- a/js/lib/rdge/materials/bump-metal-material.js
+++ b/js/lib/rdge/materials/bump-metal-material.js
@@ -154,10 +154,6 @@ var BumpMetalMaterial = function BumpMetalMaterial() {
154 154
155 this.exportJSON = function() 155 this.exportJSON = function()
156 { 156 {
157 var world = this.getWorld();
158 if (!world)
159 throw new Error( "no world in material.export, " + this.getName() );
160
161 var jObj = 157 var jObj =
162 { 158 {
163 'material' : this.getShaderName(), 159 'material' : this.getShaderName(),
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js
new file mode 100644
index 00000000..85088f91
--- /dev/null
+++ b/js/lib/rdge/materials/cloud-material.js
@@ -0,0 +1,300 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No 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
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material;
9///////////////////////////////////////////////////////////////////////
10// Class GLMaterial
11// RDGE representation of a material.
12///////////////////////////////////////////////////////////////////////
13var CloudMaterial = function CloudMaterial() {
14 ///////////////////////////////////////////////////////////////////////
15 // Instance variables
16 ///////////////////////////////////////////////////////////////////////
17 this._name = "CloudMaterial";
18 this._shaderName = "cloud";
19
20 this._texMap = 'assets/images/cloud2.jpg';
21 this._diffuseColor = [0.5, 0.5, 0.5, 0.5];
22
23 this._time = 0.0;
24 this._dTime = 0.01;
25
26 ///////////////////////////////////////////////////////////////////////
27 // Property Accessors
28 ///////////////////////////////////////////////////////////////////////
29 this.getName = function() { return this._name; };
30 this.getShaderName = function() { return this._shaderName; };
31
32 this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null };
33 this.setTextureMap = function(m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); };
34
35 this.setDiffuseColor = function(c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); };
36 this.getDiffuseColor = function() { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; };
37
38 this.isAnimated = function() { return true; };
39
40 ///////////////////////////////////////////////////////////////////////
41 // Material Property Accessors
42 ///////////////////////////////////////////////////////////////////////
43 this._propNames = ["texmap", "diffusecolor"];
44 this._propLabels = ["Texture map", "Diffuse Color"];
45 this._propTypes = ["file", "color"];
46 this._propValues = [];
47
48 this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
49 this._propValues[ this._propNames[1] ] = this._diffuseColor.slice();
50
51 this.setProperty = function( prop, value )
52 {
53 if (prop === 'color') prop = 'diffusecolor';
54
55 // make sure we have legitimate imput
56 var ok = this.validateProperty( prop, value );
57 if (!ok) {
58 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
59 }
60
61 switch (prop)
62 {
63 case "texmap":
64 this.setTextureMap(value);
65 break;
66
67 case "diffusecolor":
68 this.setDiffuseColor( value );
69 break;
70
71 case "color":
72 break;
73 }
74 };
75 ///////////////////////////////////////////////////////////////////////
76
77
78 ///////////////////////////////////////////////////////////////////////
79 // Methods
80 ///////////////////////////////////////////////////////////////////////
81 // duplcate method requirde
82 this.dup = function( world )
83 {
84 // save the world
85 if (world) this.setWorld( world );
86
87 // allocate a new uber material
88 var newMat = new CloudMaterial();
89
90 // copy over the current values;
91 var propNames = [], propValues = [], propTypes = [], propLabels = [];
92 this.getAllProperties( propNames, propValues, propTypes, propLabels);
93 var n = propNames.length;
94 for (var i=0; i<n; i++) {
95 newMat.setProperty( propNames[i], propValues[i] );
96 }
97
98 return newMat;
99 };
100
101 this.init = function( world )
102 {
103 // save the world
104 if (world) this.setWorld( world );
105
106 // this variable declared above is inherited set to a smaller delta.
107 // the cloud material runs a little faster
108 this._dTime = 0.01;
109
110 // set up the shader
111 this._shader = new jshader();
112 this._shader.def = cloudMaterialDef;
113 this._shader.init();
114
115 // set up the material node
116 this._materialNode = createMaterialNode("cloudMaterial" + "_" + world.generateUniqueNodeID());
117 this._materialNode.setShader(this._shader);
118
119 this._time = 0;
120 if (this._shader && this._shader['default']) {
121 this._shader['default'].u_time.set( [this._time] );
122 this._shader['default'].u_DiffuseColor.set( this._diffuseColor );
123 }
124
125 // set the shader values in the shader
126 this.updateTexture();
127 this.update( 0 );
128 };
129
130 this.updateColor = function()
131 {
132 var material = this._materialNode;
133 if (material)
134 {