diff options
author | Jose Antonio Marquez | 2012-04-04 15:54:33 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-04-04 15:54:33 -0700 |
commit | a9bcc403df76ad2cb7c31ff7fdd42a85c35cf424 (patch) | |
tree | 9415f5ba25ad643df678e561719d2708fd3ead5a /js/lib/rdge/materials/cloud-material.js | |
parent | 0a469a14757b8cea262c21f652e75c85c9903f4b (diff) | |
parent | e721a7c1009f298a1bd8fea583da14535e039880 (diff) | |
download | ninja-a9bcc403df76ad2cb7c31ff7fdd42a85c35cf424.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into FileIO
Diffstat (limited to 'js/lib/rdge/materials/cloud-material.js')
-rw-r--r-- | js/lib/rdge/materials/cloud-material.js | 377 |
1 files changed, 162 insertions, 215 deletions
diff --git a/js/lib/rdge/materials/cloud-material.js b/js/lib/rdge/materials/cloud-material.js index 85088f91..bde42ac3 100644 --- a/js/lib/rdge/materials/cloud-material.js +++ b/js/lib/rdge/materials/cloud-material.js | |||
@@ -1,8 +1,8 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | 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/> | 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. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
@@ -14,275 +14,222 @@ var CloudMaterial = function CloudMaterial() { | |||
14 | /////////////////////////////////////////////////////////////////////// | 14 | /////////////////////////////////////////////////////////////////////// |
15 | // Instance variables | 15 | // Instance variables |
16 | /////////////////////////////////////////////////////////////////////// | 16 | /////////////////////////////////////////////////////////////////////// |
17 | this._name = "CloudMaterial"; | 17 | this._name = "CloudMaterial"; |
18 | this._shaderName = "cloud"; | 18 | this._shaderName = "cloud"; |
19 | 19 | ||
20 | this._texMap = 'assets/images/cloud2.jpg'; | 20 | this._texMap = 'assets/images/cloud2.jpg'; |
21 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; | 21 | this._diffuseColor = [0.5, 0.5, 0.5, 0.5]; |
22 | 22 | ||
23 | this._time = 0.0; | 23 | this._time = 0.0; |
24 | this._dTime = 0.01; | 24 | this._dTime = 0.01; |
25 | 25 | ||
26 | /////////////////////////////////////////////////////////////////////// | 26 | /////////////////////////////////////////////////////////////////////// |
27 | // Property Accessors | 27 | // Property Accessors |
28 | /////////////////////////////////////////////////////////////////////// | 28 | /////////////////////////////////////////////////////////////////////// |
29 | this.getName = function() { return this._name; }; | 29 | this.getName = function () { return this._name; }; |
30 | this.getShaderName = function() { return this._shaderName; }; | 30 | this.getShaderName = function () { return this._shaderName; }; |
31 | 31 | ||
32 | this.getTextureMap = function() { return this._propValues[this._propNames[0]] ? this._propValues[this._propNames[0]].slice() : null }; | 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(); }; | 33 | this.setTextureMap = function (m) { this._propValues[this._propNames[0]] = m ? m.slice(0) : null; this.updateTexture(); }; |
34 | 34 | ||
35 | this.setDiffuseColor = function(c) { this._propValues[this._propNames[1]] = c.slice(0); this.updateColor(); }; | 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; }; | 36 | this.getDiffuseColor = function () { return this._propValues[this._propNames[1]] ? this._propValues[this._propNames[1]].slice() : null; }; |
37 | 37 | ||
38 | this.isAnimated = function() { return true; }; | 38 | this.isAnimated = function () { return true; }; |
39 | 39 | ||
40 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
41 | // Material Property Accessors | 41 | // Material Property Accessors |
42 | /////////////////////////////////////////////////////////////////////// | 42 | /////////////////////////////////////////////////////////////////////// |
43 | this._propNames = ["texmap", "diffusecolor"]; | 43 | this._propNames = ["texmap", "diffusecolor"]; |
44 | this._propLabels = ["Texture map", "Diffuse Color"]; | 44 | this._propLabels = ["Texture map", "Diffuse Color"]; |
45 | this._propTypes = ["file", "color"]; | 45 | this._propTypes = ["file", "color"]; |
46 | this._propValues = []; | 46 | this._propValues = []; |
47 | 47 | ||
48 | this._propValues[ this._propNames[0] ] = this._texMap.slice(0); | 48 | this._propValues[this._propNames[0]] = this._texMap.slice(0); |
49 | this._propValues[ this._propNames[1] ] = this._diffuseColor.slice(); | 49 | this._propValues[this._propNames[1]] = this._diffuseColor.slice(); |
50 | 50 | ||
51 | this.setProperty = function( prop, value ) | 51 | this.setProperty = function (prop, value) { |
52 | { | 52 | if (prop === 'color') prop = 'diffusecolor'; |
53 | if (prop === 'color') prop = 'diffusecolor'; | ||
54 | 53 | ||
55 | // make sure we have legitimate imput | 54 | // make sure we have legitimate imput |
56 | var ok = this.validateProperty( prop, value ); | 55 | var ok = this.validateProperty(prop, value); |
57 | if (!ok) { | 56 | if (!ok) { |
58 | console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value ); | 57 | console.log("invalid property in Radial Gradient Material:" + prop + " : " + value); |
59 | } | 58 | } |
60 | 59 | ||
61 | switch (prop) | 60 | switch (prop) { |
62 | { | 61 | case "texmap": |
63 | case "texmap": | 62 | this.setTextureMap(value); |
64 | this.setTextureMap(value); | 63 | break; |
65 | break; | 64 | |
66 | 65 | case "diffusecolor": | |
67 | case "diffusecolor": | 66 | this.setDiffuseColor(value); |
68 | this.setDiffuseColor( value ); | 67 | break; |
69 | break; | 68 | |
70 | 69 | case "color": | |
71 | case "color": | 70 | break; |
72 | break; | 71 | } |
73 | } | 72 | }; |
74 | }; | ||
75 | /////////////////////////////////////////////////////////////////////// | 73 | /////////////////////////////////////////////////////////////////////// |
76 | 74 | ||
77 | 75 | ||
78 | /////////////////////////////////////////////////////////////////////// | 76 | /////////////////////////////////////////////////////////////////////// |
79 | // Methods | 77 | // Methods |
80 | /////////////////////////////////////////////////////////////////////// | 78 | /////////////////////////////////////////////////////////////////////// |
81 | // duplcate method requirde | 79 | // duplicate method required |
82 | this.dup = function( world ) | 80 | this.dup = function (world) { |
83 | { | 81 | // save the world |
84 | // save the world | 82 | if (world) this.setWorld(world); |
85 | if (world) this.setWorld( world ); | 83 | |
86 | 84 | // allocate a new uber material | |
87 | // allocate a new uber material | 85 | var newMat = new CloudMaterial(); |
88 | var newMat = new CloudMaterial(); | 86 | |
89 | 87 | // copy over the current values; | |
90 | // copy over the current values; | 88 | var propNames = [], propValues = [], propTypes = [], propLabels = []; |
91 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | 89 | this.getAllProperties(propNames, propValues, propTypes, propLabels); |
92 | this.getAllProperties( propNames, propValues, propTypes, propLabels); | 90 | var n = propNames.length; |
93 | var n = propNames.length; | 91 | for (var i = 0; i < n; i++) { |
94 | for (var i=0; i<n; i++) { | 92 | newMat.setProperty(propNames[i], propValues[i]); |
95 | newMat.setProperty( propNames[i], propValues[i] ); | ||
96 | } | 93 | } |
97 | 94 | ||
98 | return newMat; | 95 | return newMat; |
99 | }; | 96 | }; |
100 | 97 | ||
101 | this.init = function( world ) | 98 | this.init = function (world) { |
102 | { | 99 | // save the world |
103 | // save the world | 100 | if (world) this.setWorld(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 | 101 | ||
125 | // set the shader values in the shader | 102 | // this variable declared above is inherited set to a smaller delta. |
126 | this.updateTexture(); | 103 | // the cloud material runs a little faster |
127 | this.update( 0 ); | 104 | this._dTime = 0.01; |
128 | }; | ||
129 | 105 | ||
130 | this.updateColor = function() | 106 | // set up the shader |
131 | { | 107 | this._shader = new RDGE.jshader(); |
132 | var material = this._materialNode; | 108 | this._shader.def = cloudMaterialDef; |
133 | if (material) | 109 | this._shader.init(); |
134 | { | ||
135 | var technique = material.shaderProgram['default']; | ||
136 | var renderer = g_Engine.getContext().renderer; | ||
137 | if (renderer && technique) { | ||
138 | var color = this._propValues[this._propNames[1]]; | ||
139 | technique.u_DiffuseColor.set( this._diffuseColor ); | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
144 | this.updateTexture = function() { | ||
145 | var material = this._materialNode; | ||
146 | if (material) { | ||
147 | var technique = material.shaderProgram['default']; | ||
148 | var renderer = g_Engine.getContext().renderer; | ||
149 | if (renderer && technique) { | ||
150 | var texMapName = this._propValues[this._propNames[0]]; | ||
151 | var wrap = 'REPEAT', mips = true; | ||
152 | var tex = this.loadTexture( texMapName, wrap, mips ); |