aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/uber-material.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-14 15:17:01 -0700
committerJose Antonio Marquez2012-03-14 15:17:01 -0700
commite7e18f02870a0cfe06e550acf8ffef6eab945231 (patch)
treec940a63fd47e60f121c42b1823194522c8c2820f /js/lib/rdge/materials/uber-material.js
parentef601b13a2529c207eb782942e918212e5a0805e (diff)
parent089534a80c64226bf7d124ab9147afce386fdb5c (diff)
downloadninja-e7e18f02870a0cfe06e550acf8ffef6eab945231.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into Document
Diffstat (limited to 'js/lib/rdge/materials/uber-material.js')
-rwxr-xr-xjs/lib/rdge/materials/uber-material.js46
1 files changed, 42 insertions, 4 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js
index 0964c9c4..655d8e2a 100755
--- a/js/lib/rdge/materials/uber-material.js
+++ b/js/lib/rdge/materials/uber-material.js
@@ -33,6 +33,8 @@ var UberMaterial = function UberMaterial() {
33 this._useEnvironmentMap = true; 33 this._useEnvironmentMap = true;
34 this._useLights = [true, true, true, true]; 34 this._useLights = [true, true, true, true];
35 35
36 this._MAX_LIGHTS = 4;
37
36 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
37 // Material Property Accessors 39 // Material Property Accessors
38 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
@@ -374,6 +376,18 @@ var UberMaterial = function UberMaterial() {
374 var index = importStr.indexOf( endKey ); 376 var index = importStr.indexOf( endKey );
375 index += endKey.length; 377 index += endKey.length;
376 importStr = importStr.substr( index ); 378 importStr = importStr.substr( index );
379 var pu = new MaterialParser( importStr );
380
381 var matProps = pu.nextValue( "materialProps: " );
382 if (matProps)
383 {
384 var ambientColor = Number( pu.nextValue( "ambientColor: " )); this.setProperty( "ambientColor", ambientColor );
385 var diffuseColor = Number( pu.nextValue( "diffuseColor: " )); this.setProperty( "diffuseColor", diffuseColor );
386 var specularColor = Number( pu.nextValue( "specularColor: " )); this.setProperty( "specularColor", specularColor );
387 var specularPower = Number( pu.nextValue( "specularPower: " )); this.setProperty( "specularPower", specularPower );
388 }
389
390 var lightProps = pu.nextValue( "theLights" );
377 } 391 }
378 392
379 this.export = function() 393 this.export = function()
@@ -387,7 +401,7 @@ var UberMaterial = function UberMaterial() {
387 // export the material properties 401 // export the material properties
388 if (typeof caps.material != 'undefined') 402 if (typeof caps.material != 'undefined')
389 { 403 {
390 exportStr += "material: true\n"; 404 exportStr += "materialProps: true\n";
391 exportStr += "ambientColor: " + caps.material.ambientColor + "\n"; 405 exportStr += "ambientColor: " + caps.material.ambientColor + "\n";
392 exportStr += "diffuseColor: " + caps.material.diffuseColor + "\n"; 406 exportStr += "diffuseColor: " + caps.material.diffuseColor + "\n";
393 exportStr += "specularColor: " + caps.material.specularColor + "\n"; 407 exportStr += "specularColor: " + caps.material.specularColor + "\n";
@@ -396,8 +410,9 @@ var UberMaterial = function UberMaterial() {
396 410
397 if (typeof caps.lighting != 'undefined') 411 if (typeof caps.lighting != 'undefined')
398 { 412 {
413 exportStr += "lightProps: true\n";
414
399 var light = caps.lighting['light' + i]; 415 var light = caps.lighting['light' + i];
400 var t;
401 for (var i=0; i<this._MAX_LIGHTS; i++) 416 for (var i=0; i<this._MAX_LIGHTS; i++)
402 { 417 {
403 var light = caps.lighting["light" + i]; 418 var light = caps.lighting["light" + i];
@@ -405,6 +420,7 @@ var UberMaterial = function UberMaterial() {
405 { 420 {
406 exportStr += "light" + i + ': ' + light.type + "\n"; 421 exportStr += "light" + i + ': ' + light.type + "\n";
407 422
423 // output the light secific data
408 if (light.type === 'directional') 424 if (light.type === 'directional')
409 { 425 {
410 exportStr += 'light' + i + 'Dir: ' + light['direction'] + '\n'; 426 exportStr += 'light' + i + 'Dir: ' + light['direction'] + '\n';
@@ -419,9 +435,11 @@ var UberMaterial = function UberMaterial() {
419 } 435 }
420 else // light.type === 'point' 436 else // light.type === 'point'
421 { 437 {
422 technique['u_light'+i+'Pos'].set(light['position'] || [ 0, 0, 0 ]); 438 exportStr += 'light' + i + 'Pos: ' + (light['position'] || [ 0, 0, 0 ]) ;
423 technique['u_light'+i+'Atten'].set(light['attenuation'] || [ 1,0,0 ]); 439 exportStr += 'light' + i + 'Attenuation: ' + (light['attenuation'] || [ 1, 0, 0 ]) ;
424 } 440 }
441
442 // common to all lights
425 exportStr += 'light' + i + 'Color: ' + light['diffuseColor'] || [ 1,1,1,1 ] + '\n'; 443 exportStr += 'light' + i + 'Color: ' + light['diffuseColor'] || [ 1,1,1,1 ] + '\n';
426 exportStr += 'light' + i + 'SpecularColor: ' + light['specularColor'] || [ 1, 1, 1, 1 ] + '\n'; 444 exportStr += 'light' + i + 'SpecularColor: ' + light['specularColor'] || [ 1, 1, 1, 1 ] + '\n';
427 445
@@ -429,6 +447,26 @@ var UberMaterial = function UberMaterial() {
429 } 447 }
430 } 448 }
431 } 449 }
450
451// this._diffuseMapOb = { 'texture' : 'assets/images/rocky-diffuse.jpg', 'wrap' : 'REPEAT' };
452// this._normalMapOb = { 'texture' : 'assets/images/rocky-normal.jpg', 'wrap' : 'REPEAT' };
453// this._specularMapOb = { 'texture' : 'assets/images/rocky-spec.jpg', 'wrap' : 'REPEAT' };
454// this._environmentMapOb = { 'texture' : 'assets/images/silver.png', 'wrap' : 'CLAMP', 'envReflection' : this._environmentAmount };
455 var world = this.getWorld();
456 if (!world)
457 throw new Error( "no world in material.export, " + this.getName() );
458
459 if(typeof caps.diffuseMap != 'undefined')
460 exportStr += "diffuseMap: " + caps.diffuseMap.texture + "\n";
461
462 if(typeof caps.normalMap != 'undefined')
463 exportStr += "normalMap: " + caps.normalMap.texture + "\n";
464
465 if(typeof caps.specularMap != 'undefined')
466 exportStr += "specularMap: " + caps.specularMap.texture + "\n";
467
468 if(typeof caps.environmentMap != 'undefined')
469 exportStr += "environmentMap: " + caps.environmentMap.texture + "\n";
432 470
433 // every material needs to terminate like this 471 // every material needs to terminate like this
434 exportStr += "endMaterial\n"; 472 exportStr += "endMaterial\n";