OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 * This function is very specific to our sample importer. It expects that if | 106 * This function is very specific to our sample importer. It expects that if |
107 * no Effect exists on a material that certain extra Params have been created | 107 * no Effect exists on a material that certain extra Params have been created |
108 * on the Material to give us instructions on what to Effects to create. | 108 * on the Material to give us instructions on what to Effects to create. |
109 * | 109 * |
110 * @param {!o3d.Pack} pack Pack to manage created objects. | 110 * @param {!o3d.Pack} pack Pack to manage created objects. |
111 * @param {!o3djs.rendergraph.ViewInfo} viewInfo as returned from | 111 * @param {!o3djs.rendergraph.ViewInfo} viewInfo as returned from |
112 * o3djs.rendergraph.createView. | 112 * o3djs.rendergraph.createView. |
113 * @param {!o3d.Material} material to prepare. | 113 * @param {!o3d.Material} material to prepare. |
114 * @param {string} opt_effectType type of effect to create ('phong', | 114 * @param {string} opt_effectType type of effect to create ('phong', |
115 * 'lambert', 'constant'). | 115 * 'lambert', 'constant'). |
| 116 * @param {Object} opt_options Extra options for effect.getStandardShader |
116 * | 117 * |
117 * @see o3djs.material.attachStandardEffect | 118 * @see o3djs.material.attachStandardEffect |
118 */ | 119 */ |
119 o3djs.material.prepareMaterial = function(pack, | 120 o3djs.material.prepareMaterial = function(pack, |
120 viewInfo, | 121 viewInfo, |
121 material, | 122 material, |
122 opt_effectType) { | 123 opt_effectType, |
| 124 opt_options) { |
123 // Assume we want the performance list | 125 // Assume we want the performance list |
124 var drawList = viewInfo.performanceDrawList; | 126 var drawList = viewInfo.performanceDrawList; |
125 // First check if we have a tag telling us that it is or is not | 127 // First check if we have a tag telling us that it is or is not |
126 // transparent | 128 // transparent |
127 if (!material.drawList) { | 129 if (!material.drawList) { |
128 var param = material.getParam('collada.transparent'); | 130 var param = material.getParam('collada.transparent'); |
129 if (param && param.className == 'o3d.ParamBoolean') { | 131 if (param && param.className == 'o3d.ParamBoolean') { |
130 material.drawList = param.value ? viewInfo.zOrderedDrawList : | 132 material.drawList = param.value ? viewInfo.zOrderedDrawList : |
131 viewInfo.performanceDrawList; | 133 viewInfo.performanceDrawList; |
132 } | 134 } |
133 } | 135 } |
134 // If the material has no effect, try to build shaders for it. | 136 // If the material has no effect, try to build shaders for it. |
135 if (!material.effect) { | 137 if (!material.effect) { |
136 // If the user didn't pass an effect type in see if one was stored there | 138 // If the user didn't pass an effect type in see if one was stored there |
137 // by our importer. | 139 // by our importer. |
138 if (!opt_effectType) { | 140 if (!opt_effectType) { |
139 // Retrieve the lightingType parameter from the material, if any. | 141 // Retrieve the lightingType parameter from the material, if any. |
140 var lightingType = o3djs.effect.getColladaLightingType(material); | 142 var lightingType = o3djs.effect.getColladaLightingType(material); |
141 if (lightingType) { | 143 if (lightingType) { |
142 opt_effectType = lightingType; | 144 opt_effectType = lightingType; |
143 } | 145 } |
144 } | 146 } |
145 if (opt_effectType) { | 147 if (opt_effectType) { |
146 o3djs.material.attachStandardEffect(pack, | 148 o3djs.material.attachStandardEffect(pack, |
147 material, | 149 material, |
148 viewInfo, | 150 viewInfo, |
149 opt_effectType); | 151 opt_effectType, |
| 152 opt_options); |
150 // For collada common profile stuff guess what drawList to use. Note: We | 153 // For collada common profile stuff guess what drawList to use. Note: We |
151 // can only do this for collada common profile stuff because we supply | 154 // can only do this for collada common profile stuff because we supply |
152 // the shaders and therefore now the inputs and how they are used. | 155 // the shaders and therefore now the inputs and how they are used. |
153 // For other shaders you've got to do this stuff yourself. On top of | 156 // For other shaders you've got to do this stuff yourself. On top of |
154 // that this is a total guess. Just because a texture has no alpha | 157 // that this is a total guess. Just because a texture has no alpha |
155 // it does not follow that you don't want it in the zOrderedDrawList. | 158 // it does not follow that you don't want it in the zOrderedDrawList. |
156 // That is application specific. Here we are just making a guess and | 159 // That is application specific. Here we are just making a guess and |
157 // hoping that it covers most cases. | 160 // hoping that it covers most cases. |
158 if (material.drawList == null) { | 161 if (material.drawList == null) { |
159 // Check the common profile params. | 162 // Check the common profile params. |
(...skipping 18 matching lines...) Expand all Loading... |
178 * | 181 * |
179 * This function is very specific to our sample importer. It expects that if | 182 * This function is very specific to our sample importer. It expects that if |
180 * no Effect exists on a material that certain extra Params have been created | 183 * no Effect exists on a material that certain extra Params have been created |
181 * on the Material to give us instructions on what to Effects to create. | 184 * on the Material to give us instructions on what to Effects to create. |
182 * | 185 * |
183 * @param {!o3d.Pack} pack Pack to prepare. | 186 * @param {!o3d.Pack} pack Pack to prepare. |
184 * @param {!o3djs.rendergraph.ViewInfo} viewInfo as returned from | 187 * @param {!o3djs.rendergraph.ViewInfo} viewInfo as returned from |
185 * o3djs.rendergraph.createView. | 188 * o3djs.rendergraph.createView. |
186 * @param {!o3d.Pack} opt_effectPack Pack to create effects in. If this | 189 * @param {!o3d.Pack} opt_effectPack Pack to create effects in. If this |
187 * is not specifed the pack to prepare above will be used. | 190 * is not specifed the pack to prepare above will be used. |
| 191 * @param {Object} opt_options Extra options for effect.getStandardShader |
188 * | 192 * |
189 * @see o3djs.material.prepareMaterial | 193 * @see o3djs.material.prepareMaterial |
190 */ | 194 */ |
191 o3djs.material.prepareMaterials = function(pack, | 195 o3djs.material.prepareMaterials = function(pack, |
192 viewInfo, | 196 viewInfo, |
193 opt_effectPack) { | 197 opt_effectPack, |
| 198 opt_options) { |
194 var materials = pack.getObjectsByClassName('o3d.Material'); | 199 var materials = pack.getObjectsByClassName('o3d.Material'); |
195 for (var mm = 0; mm < materials.length; mm++) { | 200 for (var mm = 0; mm < materials.length; mm++) { |
196 o3djs.material.prepareMaterial(opt_effectPack || pack, | 201 o3djs.material.prepareMaterial(opt_effectPack || pack, |
197 viewInfo, | 202 viewInfo, |
198 materials[mm]); | 203 materials[mm], |
| 204 opt_options); |
199 } | 205 } |
200 }; | 206 }; |
201 | 207 |
202 /** | 208 /** |
203 * Builds a standard effect for a given material. | 209 * Builds a standard effect for a given material. |
204 * If the material already has an effect, none is created. | 210 * If the material already has an effect, none is created. |
205 * @param {!o3d.Pack} pack Pack to manage created objects. | 211 * @param {!o3d.Pack} pack Pack to manage created objects. |
206 * @param {!o3d.Material} material The material for which to create an | 212 * @param {!o3d.Material} material The material for which to create an |
207 * effect. | 213 * effect. |
208 * @param {string} effectType Type of effect to create ('phong', 'lambert', | 214 * @param {string} effectType Type of effect to create ('phong', 'lambert', |
209 * 'constant'). | 215 * 'constant'). |
| 216 * @param {Object} opt_options Extra options for effect.getStandardShader |
210 * | 217 * |
211 * @see o3djs.effect.attachStandardShader | 218 * @see o3djs.effect.attachStandardShader |
212 */ | 219 */ |
213 o3djs.material.attachStandardEffectEx = function(pack, | 220 o3djs.material.attachStandardEffectEx = function(pack, |
214 material, | 221 material, |
215 effectType) { | 222 effectType, |
| 223 opt_options) { |
216 if (!material.effect) { | 224 if (!material.effect) { |
217 if (!o3djs.effect.attachStandardShader(pack, | 225 if (!o3djs.effect.attachStandardShader(pack, |
218 material, | 226 material, |
219 [0, 0, 0], | 227 [0, 0, 0], |
220 effectType)) { | 228 effectType, |
| 229 opt_options)) { |
221 throw 'Could not attach a standard effect'; | 230 throw 'Could not attach a standard effect'; |
222 } | 231 } |
223 } | 232 } |
224 }; | 233 }; |
225 | 234 |
226 /** | 235 /** |
227 * Builds a standard effect for a given material. The position of the | 236 * Builds a standard effect for a given material. The position of the |
228 * default light is set to the view position. If the material already has | 237 * default light is set to the view position. If the material already has |
229 * an effect, none is created. | 238 * an effect, none is created. |
230 * @param {!o3d.Pack} pack Pack to manage created objects. | 239 * @param {!o3d.Pack} pack Pack to manage created objects. |
231 * @param {!o3d.Material} material The material for which to create an | 240 * @param {!o3d.Material} material The material for which to create an |
232 * effect. | 241 * effect. |
233 * @param {!o3djs.rendergraph.ViewInfo} viewInfo as returned from | 242 * @param {!o3djs.rendergraph.ViewInfo} viewInfo as returned from |
234 * o3djs.rendergraph.createView. | 243 * o3djs.rendergraph.createView. |
235 * @param {string} effectType Type of effect to create ('phong', 'lambert', | 244 * @param {string} effectType Type of effect to create ('phong', 'lambert', |
236 * 'constant'). | 245 * 'constant'). |
| 246 * @param {Object} opt_options Extra options for effect.getStandardShader |
237 * | 247 * |
238 * @see o3djs.effect.attachStandardShader | 248 * @see o3djs.effect.attachStandardShader |
239 */ | 249 */ |
240 o3djs.material.attachStandardEffect = function(pack, | 250 o3djs.material.attachStandardEffect = function(pack, |
241 material, | 251 material, |
242 viewInfo, | 252 viewInfo, |
243 effectType) { | 253 effectType, |
| 254 opt_options) { |
244 if (!material.effect) { | 255 if (!material.effect) { |
245 var lightPos = | 256 var lightPos = |
246 o3djs.math.matrix4.getTranslation( | 257 o3djs.math.matrix4.getTranslation( |
247 o3djs.math.inverse(viewInfo.drawContext.view)); | 258 o3djs.math.inverse(viewInfo.drawContext.view)); |
248 if (!o3djs.effect.attachStandardShader(pack, | 259 if (!o3djs.effect.attachStandardShader(pack, |
249 material, | 260 material, |
250 lightPos, // TODO(gman): remove this | 261 lightPos, // TODO(gman): remove this |
251 effectType)) { | 262 effectType, |
| 263 opt_options)) { |
252 throw 'Could not attach a standard effect'; | 264 throw 'Could not attach a standard effect'; |
253 } | 265 } |
254 } | 266 } |
255 }; | 267 }; |
256 | 268 |
257 /** | 269 /** |
258 * Prepares all the materials in the given pack by setting their | 270 * Prepares all the materials in the given pack by setting their |
259 * drawList. | 271 * drawList. |
260 * @param {!o3d.Pack} pack Pack to manage created objects. | 272 * @param {!o3d.Pack} pack Pack to manage created objects. |
261 * @param {!o3d.DrawList} drawList DrawList to assign to materials. | 273 * @param {!o3d.DrawList} drawList DrawList to assign to materials. |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 * @param {!o3d.Pack} pack Pack to create params in. | 583 * @param {!o3d.Pack} pack Pack to create params in. |
572 * @return {!Object} params A object where each property is the name of a param | 584 * @return {!Object} params A object where each property is the name of a param |
573 * and its value is that param. | 585 * and its value is that param. |
574 */ | 586 */ |
575 o3djs.material.createAndBindStandardParams = function(pack) { | 587 o3djs.material.createAndBindStandardParams = function(pack) { |
576 var params = o3djs.material.createStandardParams(pack); | 588 var params = o3djs.material.createStandardParams(pack); |
577 o3djs.material.bindParams(pack, params); | 589 o3djs.material.bindParams(pack, params); |
578 return params; | 590 return params; |
579 }; | 591 }; |
580 | 592 |
OLD | NEW |