diff options
Diffstat (limited to 'js/lib/rdge/materials/material.js')
-rwxr-xr-x | js/lib/rdge/materials/material.js | 534 |
1 files changed, 267 insertions, 267 deletions
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index a7183187..6cfc4eb4 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js | |||
@@ -39,156 +39,156 @@ var Material = function GLMaterial( world ) { | |||
39 | /////////////////////////////////////////////////////////////////////// | 39 | /////////////////////////////////////////////////////////////////////// |
40 | // Instance variables | 40 | // Instance variables |
41 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
42 | this._name = "GLMaterial"; | 42 | this._name = "GLMaterial"; |
43 | this._shaderName = "undefined"; | 43 | this._shaderName = "undefined"; |
44 | 44 | ||
45 | this._time = 0.0; | 45 | this._time = 0.0; |
46 | this._dTime = 0.01; | 46 | this._dTime = 0.01; |
47 | 47 | ||
48 | // keep a reference to the owning GLWorld | 48 | // keep a reference to the owning GLWorld |
49 | this._world = null; | 49 | this._world = null; |
50 | if(world) { | 50 | if(world) { |
51 | this._world = world; | 51 | this._world = world; |
52 | } | 52 | } |
53 | 53 | ||
54 | this._glTextures = []; // indexed by uniform name | 54 | this._glTextures = []; // indexed by uniform name |
55 | 55 | ||
56 | // vertex deformation variables | 56 | // vertex deformation variables |
57 | this._hasVertexDeformation = false; | 57 | this._hasVertexDeformation = false; |
58 | this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) | 58 | this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) |
59 | this._vertexDeformationTolerance = 0.02; | 59 | this._vertexDeformationTolerance = 0.02; |
60 | 60 | ||
61 | // RDGE variables | 61 | // RDGE variables |
62 | this._shader = null; | 62 | this._shader = null; |
63 | this._materialNode = null; | 63 | this._materialNode = null; |
64 | 64 | ||
65 | 65 | ||
66 | /////////////////////////////////////////////////////////////////////// | 66 | /////////////////////////////////////////////////////////////////////// |
67 | // Property Accessors | 67 | // Property Accessors |
68 | /////////////////////////////////////////////////////////////////////// | 68 | /////////////////////////////////////////////////////////////////////// |
69 | 69 | ||
70 | this.setName = function(n) { | 70 | this.setName = function(n) { |
71 | this._name = n; | 71 | this._name = n; |
72 | }; | 72 | }; |
73 | 73 | ||
74 | this.getName = function() { | 74 | this.getName = function() { |
75 | return this._name; | 75 | return this._name; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | this.setShaderName = function(n) { | 78 | this.setShaderName = function(n) { |
79 | this._shaderName = n; | 79 | this._shaderName = n; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | this.getShaderName = function() { | 82 | this.getShaderName = function() { |
83 | return this._shaderName; | 83 | return this._shaderName; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | this.setWorld = function(world) { | 86 | this.setWorld = function(world) { |
87 | this._world = world; | 87 | this._world = world; |
88 | }; | 88 | }; |
89 | 89 | ||
90 | this.getWorld = function() { | 90 | this.getWorld = function() { |
91 | return this._world; | 91 | return this._world; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | this.getShader = function() { | 94 | this.getShader = function() { |
95 | return this._shader; | 95 | return this._shader; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | this.getMaterialNode = function() { | 98 | this.getMaterialNode = function() { |
99 | return this._materialNode; | 99 | return this._materialNode; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | // a material can be animated or not. default is not. | 102 | // a material can be animated or not. default is not. |
103 | // Any material needing continuous rendering should override this method | 103 | // Any material needing continuous rendering should override this method |
104 | this.isAnimated = function() { | 104 | this.isAnimated = function() { |
105 | return false; | 105 | return false; |
106 | }; | 106 | }; |
107 | 107 | ||
108 | this.getTechniqueName = function() { | 108 | this.getTechniqueName = function() { |
109 | return 'default' | 109 | return 'default' |
110 | }; | 110 | }; |
111 | 111 | ||
112 | // the vertex shader can apply deformations requiring refinement in | 112 | // the vertex shader can apply deformations requiring refinement in |
113 | // certain areas. | 113 | // certain areas. |
114 | this.hasVertexDeformation = function() { | 114 | this.hasVertexDeformation = function() { |
115 | return this._hasVertexDeformation; | 115 | return this._hasVertexDeformation; |
116 | }; | 116 | }; |
117 | 117 | ||
118 | this.getVertexDeformationRange = function() { | 118 | this.getVertexDeformationRange = function() { |
119 | return this._vertexDeformationRange.slice(); | 119 | return this._vertexDeformationRange.slice(); |
120 | }; | 120 | }; |
121 | 121 | ||
122 | this.getVertexDeformationTolerance = function() { | 122 | this.getVertexDeformationTolerance = function() { |
123 | return this._vertexDeformationTolerance; | 123 | return this._vertexDeformationTolerance; |
124 | }; | 124 | }; |
125 | 125 | ||
126 | /////////////////////////////////////////////////////////////////////// | 126 | /////////////////////////////////////////////////////////////////////// |
127 | // Common Material Methods | 127 | // Common Material Methods |
128 | /////////////////////////////////////////////////////////////////////// | 128 | /////////////////////////////////////////////////////////////////////// |
129 | this.getProperty = function( propName ) { | 129 | this.getProperty = function( propName ) { |
130 | return this._propValues[propName]; | 130 | return this._propValues[propName]; |
131 | }; | 131 | }; |
132 | 132 | ||
133 | this.getPropertyCount = function() { | 133 | this.getPropertyCount = function() { |
134 | return this._propNames.length; | 134 | return this._propNames.length; |
135 | }; | 135 | }; |
136 | 136 | ||
137 | this.getPropertyAtIndex = function( index ) { | 137 | this.getPropertyAtIndex = function( index ) { |
138 | var rtnArr = []; | 138 | var rtnArr = []; |
139 | if ((index < 0) || (index >= this.getPropertyCount())) { | 139 | if ((index < 0) || (index >= this.getPropertyCount())) { |
140 | throw new Error( "property index " + index + " is out of range for material" ); | 140 | throw new Error( "property index " + index + " is out of range for material" ); |
141 | } | 141 | } |
142 | 142 | ||
143 | return [ this._propNames[index], this._propLabels[index], this._propTypes[index], this._propValues[index] ]; | 143 | return [ this._propNames[index], this._propLabels[index], this._propTypes[index], this._propValues[index] ]; |
144 | }; | 144 | }; |
145 | 145 | ||
146 | this.getAllProperties = function( propNames, propValues, propTypes, propLabels) { | 146 | this.getAllProperties = function( propNames, propValues, propTypes, propLabels) { |
147 | // clear all the input arrays if there is junk in them | 147 | // clear all the input arrays if there is junk in them |
148 | propNames.length = 0; | 148 | propNames.length = 0; |
149 | propValues.length = 0; | 149 | propValues.length = 0; |
150 | propTypes.length = 0; | 150 | propTypes.length = 0; |
151 | propLabels.length = 0; | 151 | propLabels.length = 0; |
152 | 152 | ||
153 | var nProps = this._propNames.length; | 153 | var nProps = this._propNames.length; |
154 | for (var i=0; i<nProps; i++) { | 154 | for (var i=0; i<nProps; i++) { |
155 | propNames[i] = this._propNames[i]; | 155 | propNames[i] = this._propNames[i]; |
156 | propValues[i] = this._propValues[this._propNames[i]]; | 156 | propValues[i] = this._propValues[this._propNames[i]]; |
157 | propTypes[i] = this._propTypes[i]; | 157 | propTypes[i] = this._propTypes[i]; |
158 | propLabels[i] = this._propLabels[i]; | 158 | propLabels[i] = this._propLabels[i]; |
159 | } | 159 | } |
160 | }; | 160 | }; |
161 | 161 | ||
162 | this.hasProperty = function( prop ) | 162 | this.hasProperty = function( prop ) |
163 | { | 163 | { |
164 | var propNames = [], dummy = []; | 164 | var propNames = [], dummy = []; |
165 | this.getAllProperties( propNames, dummy, dummy, dummy ) | 165 | this.getAllProperties( propNames, dummy, dummy, dummy ) |
166 | for (var i=0; i<propNames.length; i++) | 166 | for (var i=0; i<propNames.length; i++) |
167 | { | 167 | { |
168 | if (prop === propNames[i]) return true; | 168 | if (prop === propNames[i]) return true; |
169 | } | 169 | } |
170 | }; | 170 | }; |
171 | 171 | ||
172 | this.getPropertyType = function( prop ) | 172 | this.getPropertyType = function( prop ) |
173 | { | 173 | { |
174 | var n = this.getPropertyCount(); | 174 | var n = this.getPropertyCount(); |
175 | for (var i=0; i<n; i++) | 175 | for (var i=0; i<n; i++) |
176 | { | 176 | { |
177 | if (prop === this._propNames[i]) return this._propTypes[i]; | 177 | if (prop === this._propNames[i]) return this._propTypes[i]; |
178 | } | 178 | } |
179 | }; | 179 | }; |
180 | 180 | ||
181 | this.dup = function () | 181 | this.dup = function () |
182 | { | 182 | { |
183 | // get the current values; | 183 | // get the current values; |
184 | var propNames = [], propValues = [], propTypes = [], propLabels = []; | 184 | var propNames = [], propValues = [], propTypes = [], propLabels = []; |
185 |