aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
Diffstat (limited to 'assets')
-rw-r--r--assets/canvas-runtime.js185
1 files changed, 168 insertions, 17 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index 51c1de1f..fd823f35 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -504,20 +504,7 @@ function RuntimeGeomObj()
504 504
505 /////////////////////////////////////////////////////////////////////// 505 ///////////////////////////////////////////////////////////////////////
506 // Methods 506 // Methods
507 /////////////////////////////////////////////////////////////////////// 507 ///////////////////////////////////////////////////////////////////////
508 this.makeStrokeMaterial = function()
509 {
510 }
511
512 this.makeFillMaterial = function()
513 {
514 }
515
516
517 this.render = function()
518 {
519 }
520
521 this.addChild = function( child ) 508 this.addChild = function( child )
522 { 509 {
523 if (!this._children) this._children = []; 510 if (!this._children) this._children = [];
@@ -573,9 +560,10 @@ function RuntimeGeomObj()
573 this._materials.push( mat ); 560 this._materials.push( mat );
574 } 561 }
575 562
576 var endIndex = importStr.indexOf( "endMaterial\n" ); 563 var endKey = "endMaterial\n";
564 var endIndex = importStr.indexOf( endKey );
577 if (endIndex < 0) break; 565 if (endIndex < 0) break;
578 importStr = importStr.substr( endIndex ); 566 importStr = importStr.substr( endIndex + endKey.length );
579 } 567 }
580 } 568 }
581 569
@@ -1369,8 +1357,88 @@ function RuntimeUberMaterial()
1369 this.inheritedFrom = RuntimeMaterial; 1357 this.inheritedFrom = RuntimeMaterial;
1370 this.inheritedFrom(); 1358 this.inheritedFrom();
1371 1359
1360 this._MAX_LIGHTS = 4;
1361
1372 this.init = function( ) 1362 this.init = function( )
1373 { 1363 {
1364 var material = this._materialNode;
1365 if (material)
1366 {
1367 var technique = material.shaderProgram.defaultTechnique;
1368 var renderer = g_Engine.getContext().renderer;
1369 if (renderer && technique)
1370 {
1371 if (this._shader && this._shader.defaultTechnique)
1372 {
1373 if (this._ambientColor && technique.u_ambientColor) technique.u_ambientColor.set(this._ambientColor );
1374 if (this._diffuseColor && technique.u_diffuseColor ) technique.u_diffuseColor.set(this._diffuseColor );
1375 if (this._specularColor && technique.u_specularColor) technique.u_specularColor.set(this._specularColor);
1376 if (this._specularPower && technique.u_specularPower) technique.u_specularPower.set([this._specularPower]);
1377
1378 if (this._lights)
1379 {
1380 for(var i = 0; i < 4; ++i)
1381 {
1382 var light = this._lights[i];
1383 if (light)
1384 {
1385 if(light.type == 'directional')
1386 {
1387 technique['u_light'+i+'Dir'].set( light.direction || [ 0, 0, 1 ]);
1388 }
1389 else if(light.type == 'spot')
1390 {
1391 technique['u_light'+i+'Atten'].set(light.attenuation || [ 1,0,0 ]);
1392 technique['u_light'+i+'Pos'].set(light.position || [ 0, 0, 0 ]);
1393 technique['u_light'+i+'Spot'].set([ Math.cos( ( light.spotInnerCutoff || 45.0 ) * deg2Rad ),
1394 Math.cos( ( light.spotOuterCutoff || 90.0 ) * deg2Rad )]);
1395 }
1396 else
1397 {
1398 technique['u_light'+i+'Pos'].set(light.position || [ 0, 0, 0 ]);
1399 technique['u_light'+i+'Atten'].set(light.attenuation || [ 1,0,0 ]);
1400 }
1401
1402 // set the common light properties
1403 technique['u_light'+i+'Color'].set(light.diffuseColor || [ 1,1,1,1 ]);
1404 technique['u_light'+i+'Specular'].set(light.specularColor || [ 1, 1, 1, 1 ]);
1405 }
1406 }
1407 }
1408
1409 // currently not exported
1410 var uvTransform = [ 2.0, 0, 0, 0, 0, 2.0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1];
1411 technique.u_uvMatrix.set(uvTransform);
1412
1413 var renderer = g_Engine.getContext().renderer;
1414 if (this._diffuseMap)
1415 {
1416 var tex = renderer.getTextureByName(this._diffuseMap, 'REPEAT');
1417 technique.s_diffuseMap.set( tex );
1418 }
1419
1420 if (this._normalMap)
1421 {
1422 var tex = renderer.getTextureByName(this._normalMap, 'REPEAT');
1423 technique.s_normalMap.set( tex );
1424 }
1425
1426 if (this._specularMap)
1427 {
1428 var tex = renderer.getTextureByName(this._specularMap, 'REPEAT');
1429 technique.s_specMap.set( tex );
1430 }
1431
1432 if(this._environmentMap)
1433 {
1434 var tex = renderer.getTextureByName(this._environmentMap, 'CLAMP');
1435 technique.s_envMap.set( tex );
1436 if (this._environmentAmount)
1437 technique.u_envReflection.set([ this._environmentAmount ] );
1438 }
1439 }
1440 }
1441 }
1374 } 1442 }
1375 1443
1376 this.update = function( time ) 1444 this.update = function( time )
@@ -1379,6 +1447,89 @@ function RuntimeUberMaterial()
1379 1447
1380 this.import = function( importStr ) 1448 this.import = function( importStr )
1381 { 1449 {
1450 // limit the key searches to this material
1451 var endKey = "endMaterial\n";
1452 var index = importStr.indexOf( endKey );
1453 index += endKey.length;
1454 importStr = importStr.slice( 0, index );
1455
1456 var matProps = getPropertyFromString( "materialProps: ", importStr );
1457 if (matProps)
1458 {
1459 this._ambientColor = eval( "[" + getPropertyFromString("ambientColor: ", importStr) + ']' );
1460 this._diffuseColor = eval( "[" + getPropertyFromString( "diffuseColor: ", importStr) + ']' );
1461 this._specularColor = eval( "[" + getPropertyFromString( "specularColor: ", importStr) + ']' );
1462 this._specularPower = Number( getPropertyFromString( "specularPower: ", importStr) );
1463 }
1464
1465 var lightProps = getPropertyFromString( "lightProps: ", importStr );
1466 if (lightProps)
1467 {
1468 this._lights = [];
1469 var lightStr;
1470 for (var i=0; i<this._MAX_LIGHTS; i++)
1471 {
1472 var type = getPropertyFromString( "light" + i + ": ", importStr );
1473 if (type)
1474 {
1475 var light = new Object;
1476 light.type = type;
1477 switch (type)
1478 {
1479 case "directional":
1480 lightStr = getPropertyFromString( 'light' + i + 'Dir: ', importStr);
1481 light.direction = eval( "[" + lightStr + "]" );
1482 break;
1483
1484 case "spot":
1485 lightStr = getPropertyFromString( 'light' + i + 'Pos: ', importStr );
1486 light.position = eval( "[" + lightStr + "]" );
1487
1488 lightStr = getPropertyFromString( 'light' + i + 'OuterSpotCutoff: ', importStr );
1489 light['spotInnerCutoff'] = Number( lightStr );
1490
1491 lightStr = getPropertyFromString( 'light' + i + 'InnerSpotCutoff: ', importStr );
1492 light['spotOuterCutoff'] = Number( lightStr );
1493 break;
1494
1495 case "point":
1496 lightStr = getPropertyFromString( 'light' + i + 'Pos: ', importStr );
1497 light.position = eval( "[" + lightStr + "]" );
1498
1499 lightStr = getPropertyFromString( 'light' + i + 'Attenuation: ', importStr );
1500 light.attenuation = eval( "[" + lightStr + "]" );
1501 break;
1502
1503 default:
1504 throw new Error( "unrecognized light type on import: " + type );
1505 break;
1506 }
1507
1508 // common to all lights
1509 light.diffuseColor = eval( "[" + getPropertyFromString( 'light' + i + 'Color: ', importStr) + "]" );
1510 light.specularColor = eval( "[" + getPropertyFromString( 'light' + i + 'SpecularColor: ', importStr) + "]" );
1511
1512 // push the light
1513 this._lights.push( light );
1514 }
1515 else
1516 this._lights[i] = 'undefined';
1517
1518 // advance to the next light
1519 var endLightKey = "endMaterial\n";
1520 index = importStr.indexOf( endLightKey );
1521 if (index < 0) throw new Error( "ill-formed light encountered in import" );
1522 index += endLightKey.length;
1523 importStr = importStr.slice( 0, index );
1524 }
1525 }
1526
1527 this._diffuseMap = getPropertyFromString( "diffuseMap: ", importStr )
1528 this._normalMap = getPropertyFromString( "normalMap: ", importStr );
1529 this._specularMap = getPropertyFromString( "specularMap: ", importStr );
1530 this._environmentMap = getPropertyFromString( "environmentMap: ", importStr );
1531 if (this._environmentMap)
1532 this._environmentAmount = Number( getPropertyFromString( "environmentAmount", importStr ) );
1382 } 1533 }
1383} 1534}