diff options
Diffstat (limited to 'js/lib/rdge/materials/uber-material.js')
-rwxr-xr-x | js/lib/rdge/materials/uber-material.js | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index 6bc35d51..0964c9c4 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js | |||
@@ -363,10 +363,79 @@ var UberMaterial = function UberMaterial() { | |||
363 | this._shader = this.buildUberShader( this._ubershaderCaps ); | 363 | this._shader = this.buildUberShader( this._ubershaderCaps ); |
364 | 364 | ||
365 | // set up the material node | 365 | // set up the material node |
366 | this._materialNode = createMaterialNode("uberMaterial"); | 366 | this._materialNode = createMaterialNode("uberMaterial" + "_" + world.generateUniqueNodeID()); |
367 | this._materialNode.setShader(this._shader); | 367 | this._materialNode.setShader(this._shader); |
368 | }; | 368 | }; |
369 | 369 | ||
370 | this.import = function( importStr ) | ||
371 | { | ||
372 | // limit the key searches to this material | ||
373 | var endKey = "endMaterial\n"; | ||
374 | var index = importStr.indexOf( endKey ); | ||
375 | index += endKey.length; | ||
376 | importStr = importStr.substr( index ); | ||
377 | } | ||
378 | |||
379 | this.export = function() | ||
380 | { | ||
381 | // every material needs the base type and instance name | ||
382 | var exportStr = "material: " + this.getShaderName() + "\n"; | ||
383 | exportStr += "name: " + this.getName() + "\n"; | ||
384 | |||
385 | var caps = this._ubershaderCaps; | ||
386 | |||
387 | // export the material properties | ||
388 | if (typeof caps.material != 'undefined') | ||
389 | { | ||
390 | exportStr += "material: true\n"; | ||
391 | exportStr += "ambientColor: " + caps.material.ambientColor + "\n"; | ||
392 | exportStr += "diffuseColor: " + caps.material.diffuseColor + "\n"; | ||
393 | exportStr += "specularColor: " + caps.material.specularColor + "\n"; | ||
394 | exportStr += "specularPower: " + caps.material.specularPower + "\n"; | ||
395 | } | ||
396 | |||
397 | if (typeof caps.lighting != 'undefined') | ||
398 | { | ||
399 | var light = caps.lighting['light' + i]; | ||
400 | var t; | ||
401 | for (var i=0; i<this._MAX_LIGHTS; i++) | ||
402 | { | ||
403 | var light = caps.lighting["light" + i]; | ||
404 | if( typeof light != "undefined") | ||
405 | { | ||
406 | exportStr += "light" + i + ': ' + light.type + "\n"; | ||
407 | |||
408 | if (light.type === 'directional') | ||
409 | { | ||
410 | exportStr += 'light' + i + 'Dir: ' + light['direction'] + '\n'; | ||
411 | } | ||
412 | else if (light.type === 'spot') | ||
413 | { | ||
414 | exportStr += 'light' + i + 'Pos: ' + light['position'] + '\n'; | ||
415 | |||
416 | var deg2Rad = Math.PI / 180; | ||
417 | exportStr += 'light' + i + 'Spot: ' + [ Math.cos( ( light['spotInnerCutoff'] || 45.0 ) * deg2Rad ), | ||
418 | Math.cos( ( light['spotOuterCutoff'] || 90.0 ) * deg2Rad )] + '\n'; | ||
419 | } | ||
420 | else // light.type === 'point' | ||
421 | { | ||
422 | technique['u_light'+i+'Pos'].set(light['position'] || [ 0, 0, 0 ]); | ||
423 | technique['u_light'+i+'Atten'].set(light['attenuation'] || [ 1,0,0 ]); | ||
424 | } | ||
425 | exportStr += 'light' + i + 'Color: ' + light['diffuseColor'] || [ 1,1,1,1 ] + '\n'; | ||
426 | exportStr += 'light' + i + 'SpecularColor: ' + light['specularColor'] || [ 1, 1, 1, 1 ] + '\n'; | ||
427 | |||
428 | exportStr += "endlight\n"; | ||
429 | } | ||
430 | } | ||
431 | } | ||
432 | |||
433 | // every material needs to terminate like this | ||
434 | exportStr += "endMaterial\n"; | ||
435 | |||
436 | return exportStr; | ||
437 | } | ||
438 | |||
370 | this.buildUberShader = function(caps) | 439 | this.buildUberShader = function(caps) |
371 | { | 440 | { |
372 | var preproc = ""; | 441 | var preproc = ""; |