diff options
Diffstat (limited to 'js/lib/rdge/materials/uber-material.js')
-rwxr-xr-x | js/lib/rdge/materials/uber-material.js | 187 |
1 files changed, 0 insertions, 187 deletions
diff --git a/js/lib/rdge/materials/uber-material.js b/js/lib/rdge/materials/uber-material.js index da6ea9f4..e94458cc 100755 --- a/js/lib/rdge/materials/uber-material.js +++ b/js/lib/rdge/materials/uber-material.js | |||
@@ -367,115 +367,6 @@ var UberMaterial = function UberMaterial() { | |||
367 | this._materialNode.setShader(this._shader); | 367 | this._materialNode.setShader(this._shader); |
368 | }; | 368 | }; |
369 | 369 | ||
370 | this.import = function (importStr) { | ||
371 | // limit the key searches to this material | ||
372 | var endKey = "endMaterial\n"; | ||
373 | var index = importStr.indexOf(endKey); | ||
374 | index += endKey.length; | ||
375 | importStr = importStr.slice(0, index); | ||
376 | var pu = new MaterialParser(importStr); | ||
377 | |||
378 | var matProps = pu.nextValue("materialProps: "); | ||
379 | if (matProps) { | ||
380 | var ambientColor = eval("[" + pu.nextValue("ambientColor: ") + ']'); this.setProperty("ambientColor", ambientColor); | ||
381 | var diffuseColor = eval("[" + pu.nextValue("diffuseColor: ") + ']'); this.setProperty("diffuseColor", diffuseColor); | ||
382 | var specularColor = eval("[" + pu.nextValue("specularColor: ") + ']'); this.setProperty("specularColor", specularColor); | ||
383 | var specularPower = eval("[" + pu.nextValue("specularPower: ") + ']'); this.setProperty("specularPower", specularPower); | ||
384 | } | ||
385 | |||
386 | var lightProps = pu.nextValue("lightProps: "); | ||
387 | if (lightProps) { | ||
388 | this._lights = []; | ||
389 | var lightStr; | ||
390 | for (var i = 0; i < this._MAX_LIGHTS; i++) { | ||
391 | var type = pu.nextValue("light" + i + ": "); | ||
392 | if (type) { | ||
393 | var light = new Object; | ||
394 | switch (type) { | ||
395 | case "directional": | ||
396 | lightStr = pu.nextValue('light' + i + 'Dir: '); | ||
397 | light.direction = eval("[" + lightStr + "]"); | ||
398 | break; | ||
399 | |||
400 | case "spot": | ||
401 | lightStr = pu.nextValue('light' + i + 'Pos: '); | ||
402 | light.position = eval("[" + lightStr + "]"); | ||
403 | |||
404 | lightStr = pu.nextValue('light' + i + 'OuterSpotCutoff: '); | ||
405 | light['spotInnerCutoff'] = Number(lightStr); | ||
406 | |||
407 | lightStr = pu.nextValue('light' + i + 'InnerSpotCutoff: '); | ||
408 | light['spotOuterCutoff'] = Number(lightStr); | ||
409 | break; | ||
410 | |||
411 | case "point": | ||
412 | lightStr = pu.nextValue('light' + i + 'Pos: '); | ||
413 | light.position = eval("[" + lightStr + "]"); | ||
414 | |||
415 | lightStr = pu.nextValue('light' + i + 'Attenuation: '); | ||
416 | light.attenuation = eval("[" + lightStr + "]"); | ||
417 | break; | ||
418 | |||
419 | default: | ||
420 | throw new Error("unrecognized light type on import: " + type); | ||
421 | break; | ||
422 | } | ||
423 | |||
424 | // common to all lights | ||
425 | light.diffuseColor = eval("[" + pu.nextValue('light' + i + 'Color: ') + "]"); | ||
426 | light.specularColor = eval("[" + pu.nextValue('light' + i + 'SpecularColor: ') + "]"); | ||
427 | |||
428 | // push the light | ||
429 | this._lights.push(light); | ||
430 | } | ||
431 | else { | ||
432 | this._lights[i] = 'undefined'; | ||
433 | } | ||
434 | |||
435 | // advance to the next light | ||
436 | var endLightKey = "endMaterial\n"; | ||
437 | index = importStr.indexOf(endLightKey); | ||
438 | if (index < 0) throw new Error("ill-formed light encountered in import"); | ||
439 | index += endLightKey.length; | ||
440 | importStr = importStr.slice(0, index); | ||
441 | |||
442 | } | ||
443 | |||
444 | if (this._lights.length > 0) { | ||
445 | this._ubershaderCaps.lighting = | ||
446 | { | ||
447 | 'light0': this._lights[0], | ||
448 | 'light1': this._lights[1], | ||
449 | 'light2': this._lights[2], | ||
450 | 'light3': this._lights[3] | ||
451 | } | ||
452 | } | ||
453 | } | ||
454 | |||
455 | var diffuseMap = pu.nextValue("diffuseMap: ") | ||
456 | if (diffuseMap) { | ||
457 | this.setProperty("diffuseMap", diffuseMap); | ||
458 | } | ||
459 | |||
460 | var normalMap = pu.nextValue("normalMap: "); | ||
461 | if (normalMap) { | ||
462 | this.setProperty("normalMap", normalMap); | ||
463 | } | ||
464 | |||
465 | var specularMap = pu.nextValue("specularMap: "); | ||
466 | if (specularMap) { | ||
467 | this.setProperty("specularMap", specularMap); | ||
468 | } | ||
469 | |||
470 | var environmentMap = pu.nextValue("environmentMap: "); | ||
471 | if (environmentMap) { | ||
472 | this.setProperty("environmentMap", environmentMap); | ||
473 | this.setProperty("environmentAmount", Number(pu.nextValue("environmentAmount"))); | ||
474 | } | ||
475 | |||
476 | this.rebuildShader(); | ||
477 | }; | ||
478 | |||
479 | this.importJSON = function (jObj) { | 370 | this.importJSON = function (jObj) { |
480 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); | 371 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); |
481 | this.setName(jObj.name); | 372 | this.setName(jObj.name); |
@@ -640,84 +531,6 @@ var UberMaterial = function UberMaterial() { | |||
640 | return jObj; | 531 | return jObj; |
641 | }; | 532 | }; |
642 | 533 | ||
643 | |||
644 | this.export = function () { | ||
645 | // every material needs the base type and instance name | ||
646 | var exportStr = "material: " + this.getShaderName() + "\n"; | ||
647 | exportStr += "name: " + this.getName() + "\n"; | ||
648 | |||
649 | var caps = this._ubershaderCaps; | ||
650 | |||
651 | // export the material properties | ||
652 | if (typeof caps.material != 'undefined') { | ||
653 | exportStr += "materialProps: true\n"; | ||
654 | exportStr += "ambientColor: " + this._ambientColor + "\n"; | ||
655 | exportStr += "diffuseColor: " + this._diffuseColor + "\n"; | ||
656 | exportStr += "specularColor: " + this._specularColor + "\n"; | ||
657 | exportStr += "specularPower: " + this._specularPower + "\n"; | ||
658 | } | ||
659 | |||
660 | if (typeof caps.lighting != 'undefined') { | ||
661 | exportStr += "lightProps: true\n"; | ||
662 | |||
663 | var light = caps.lighting['light' + i]; | ||
664 | for (var i = 0; i < this._MAX_LIGHTS; i++) { | ||
665 | var light = caps.lighting["light" + i]; | ||
666 | if (typeof light != "undefined") { | ||
667 | exportStr += "light" + i + ': ' + light.type + "\n"; | ||
668 | |||
669 | // output the light secific data | ||
670 | if (light.type === 'directional') { | ||
671 | exportStr += 'light' + i + 'Dir: ' + light['direction'] + '\n'; | ||
672 | } | ||
673 | else if (light.type === 'spot') { | ||
674 | exportStr += 'light' + i + 'Pos: ' + light['position'] + '\n'; | ||
675 | exportStr += 'light' + i + 'SpotInnerCutoff: ' + light['spotInnerCutoff'] + '\n'; | ||
676 | exportStr += 'light' + i + 'SpotOuterCutoff: ' + light['spotOuterCutoff'] + '\n'; | ||
677 | } | ||
678 | else // light.type === 'point' | ||
679 | { | ||
680 | exportStr += 'light' + i + 'Pos: ' + (light['position'] || [0, 0, 0]) + '\n'; | ||
681 | exportStr += 'light' + i + 'Attenuation: ' + (light['attenuation'] || [1, 0, 0]) + '\n'; | ||
682 | } | ||
683 | |||
684 | // common to all lights | ||
685 | exportStr += 'light' + i + 'Color: ' + (light['diffuseColor'] || [1, 1, 1, 1]) + '\n'; | ||
686 | exportStr += 'light' + i + 'SpecularColor: ' + (light['specularColor'] || [1, 1, 1, 1]) + '\n'; | ||
687 | |||
688 | exportStr += "endlight\n"; | ||
689 | } | ||
690 | } | ||
691 | } | ||
692 | |||
693 | var world = this.getWorld(); | ||
694 | if (!world) { | ||
695 | throw new Error("no world in material.export, " + this.getName()); | ||
696 | } | ||
697 | |||
698 | if (typeof caps.diffuseMap != 'undefined') { | ||
699 | exportStr += "diffuseMap: " + caps.diffuseMap.texture + "\n"; | ||
700 | } | ||
701 | |||
702 | if (typeof caps.normalMap != 'undefined') { | ||
703 | exportStr += "normalMap: " + caps.normalMap.texture + "\n"; | ||
704 | } | ||
705 | |||
706 | if (typeof caps.specularMap != 'undefined') { | ||
707 | exportStr += "specularMap: " + caps.specularMap.texture + "\n"; | ||
708 | } | ||
709 | |||
710 | if (typeof caps.environmentMap != 'undefined') { | ||
711 | exportStr += "environmentMap: " + caps.environmentMap.texture + "\n"; | ||
712 | exportStr += "environmentAmount: " + caps.environmentMap.envReflection + "\n"; | ||
713 | } | ||
714 | |||
715 | // every material needs to terminate like this | ||
716 | exportStr += "endMaterial\n"; | ||
717 | |||
718 | return exportStr; | ||
719 | }; | ||
720 | |||
721 | this.buildUberShader = function (caps) { | 534 | this.buildUberShader = function (caps) { |
722 | var preproc = ""; | 535 | var preproc = ""; |
723 | var paramBlock = {}; | 536 | var paramBlock = {}; |