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