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