aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorhwc4872012-03-22 15:47:11 -0700
committerhwc4872012-03-22 15:47:11 -0700
commite927e4702d7dbd4a878f6979b3f56b46758f93de (patch)
treee6bb8951374a6504bd6c745ce7233da5cd4869dc /js/lib
parent00cd98e49c959906d7c44bb6adcdef1f3d5148ae (diff)
parent31e924e1b8b8da8342b3ff2341c8284915486c0b (diff)
downloadninja-e927e4702d7dbd4a878f6979b3f56b46758f93de.tar.gz
Merge branch 'integration' of github.com:ericmueller/ninja-internal into Textures
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/drawing/world.js147
-rwxr-xr-xjs/lib/geom/circle.js54
-rwxr-xr-xjs/lib/geom/geom-obj.js154
-rwxr-xr-xjs/lib/geom/line.js44
-rwxr-xr-xjs/lib/geom/rectangle.js63
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js40
-rw-r--r--js/lib/rdge/materials/cloud-material.js300
-rwxr-xr-xjs/lib/rdge/materials/flat-material.js21
-rw-r--r--js/lib/rdge/materials/julia-material.js6
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js53
-rw-r--r--js/lib/rdge/materials/mandel-material.js6
-rw-r--r--js/lib/rdge/materials/plasma-material.js18
-rw-r--r--js/lib/rdge/materials/pulse-material.js44
-rw-r--r--js/lib/rdge/materials/radial-blur-material.js57
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js54
-rw-r--r--js/lib/rdge/materials/taper-material.js27
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js28
-rwxr-xr-xjs/lib/rdge/materials/uber-material.js180
-rw-r--r--js/lib/rdge/materials/water-material.js103
19 files changed, 1310 insertions, 89 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 049145ce..07a2c3ae 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -363,6 +363,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
363 if (this._useWebGL) { 363 if (this._useWebGL) {
364 rdgeStarted = true; 364 rdgeStarted = true;
365 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); 365 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" );
366 g_Engine.unregisterCanvas( this._canvas )
366 g_Engine.registerCanvas(this._canvas, this); 367 g_Engine.registerCanvas(this._canvas, this);
367 RDGEStart( this._canvas ); 368 RDGEStart( this._canvas );
368 this._canvas.task.stop() 369 this._canvas.task.stop()
@@ -729,6 +730,72 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) {
729 } 730 }
730}; 731};
731 732
733World.prototype.exportJSON = function()
734{
735 // world properties
736 var worldObj =
737 {
738 'version' : 1.1,
739 'id' : this.getCanvas().getAttribute( "data-RDGE-id" ),
740 'fov' : this._fov,
741 'zNear' : this._zNear,
742 'zFar' : this._zFar,
743 'viewDist' : this._viewDist,
744 'webGL' : this._useWebGL
745 };
746
747 // RDGE scenegraph
748 if (this._useWebGL)
749 worldObj.scenedata = this.myScene.exportJSON();
750
751 // object data
752 var strArray = [];
753 this.exportObjectsJSON( this._geomRoot, worldObj );
754
755 // You would think that the RDGE export function
756 // would not be destructive of the data. You would be wrong...
757 // We need to rebuild everything
758 if (this._useWebGL)
759 {
760 var root = this._rootNode;
761 root.children = new Array();
762 if (worldObj.children && (worldObj.children.length === 1))
763 {
764 this.init();
765 this._geomRoot = undefined;
766 this.importObjectsJSON( worldObj.children[0] );
767 }
768 }
769
770 // convert the object to a string
771 var jStr = JSON.stringify( worldObj );
772
773 // prepend some version information to the string.
774 // this string is also used to differentiate between JSON
775 // and pre-JSON versions of fileIO.
776 // the ending ';' in the version string is necessary
777 jStr = "v1.0;" + jStr;
778
779 return jStr;
780}
781
782World.prototype.exportObjectsJSON = function( obj, parentObj )
783{
784 if (!obj) return;
785
786 var jObj = obj.exportJSON();
787 if (!parentObj.children) parentObj.children = [];
788 parentObj.children.push( jObj );
789
790 if (obj.getChild()) {
791 this.exportObjectsJSON( obj.getChild (), jObj );
792 }
793
794 if (obj.getNext())
795 this.exportObjectsJSON( obj.getNext(), parentObj );
796}
797
798/*
732World.prototype.export = function() 799World.prototype.export = function()
733{ 800{
734 var exportStr = "GLWorld 1.0\n"; 801 var exportStr = "GLWorld 1.0\n";
@@ -791,6 +858,7 @@ World.prototype.exportObjects = function( obj ) {
791 858
792 return rtnStr; 859 return rtnStr;
793}; 860};
861*/
794 862
795World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) { 863World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) {
796 //if (trNode == null) trNode = this._ctrNode; 864 //if (trNode == null) trNode = this._ctrNode;
@@ -810,6 +878,85 @@ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode )
810 return rtnNode; 878 return rtnNode;
811}; 879};
812 880
881World.prototype.importJSON = function( jObj )
882{
883 if (jObj.webGL)
884 {
885 // start RDGE
886 rdgeStarted = true;
887 var id = this._canvas.getAttribute( "data-RDGE-id" );
888 this._canvas.rdgeid = id;
889 g_Engine.registerCanvas(this._canvas, this);
890 RDGEStart( this._canvas );
891 this._canvas.task.stop()
892 }
893
894 // import the objects
895 // there should be exactly one child of the parent object
896 if (jObj.children && (jObj.children.length === 1))
897 this.importObjectsJSON( jObj.children[0] );
898 else
899 throw new Error ("unrecoverable canvas import error - inconsistent root object: " + jObj.children );
900
901 if (!this._useWebGL)
902 {
903 // render using canvas 2D
904 this.render();
905 }
906 else
907 this.restartRenderLoop();
908}
909
910World.prototype.importObjectsJSON = function( jObj, parentGeomObj )
911{
912 // read the next object
913 var gObj = this.importObjectJSON( jObj, parentGeomObj );
914
915 // determine if we have children
916 if (jObj.children)
917 {
918 var nKids = ojObjbj.chilodren.length;
919 for (var i=0; i<nKids; i++)
920 {
921 var child = jObj.children[i];
922 this.importObjectsJSON( child, gObj );
923 }
924 }
925}
926
927World.prototype.importObjectJSON = function( jObj, parentGeomObj )
928{
929 var type = jObj.type;
930
931 var obj;
932 switch (type)
933 {
934 case 1:
935 obj = new Rectangle();
936 obj.importJSON( jObj );
937 break;
938
939 case 2: // circle
940 obj = new Circle();
941 obj.importJSON( jObj );
942 break;
943
944 case 3: // line
945 obj = new Line();
946 obj.importJSON( jObj );
947 break;
948
949 default:
950 throw new Error( "Unrecognized object type: " + type );
951 break;
952 }
953
954 if (obj)
955 this.addObject( obj, parentGeomObj );
956
957 return obj;
958};
959
813World.prototype.import = function( importStr ) { 960World.prototype.import = function( importStr ) {
814 // import the worldattributes - not currently used 961 // import the worldattributes - not currently used
815 962
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index 4b155b4c..d48bf98b 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -53,13 +53,13 @@ var Circle = function GLCircle() {
53 if(strokeMaterial){ 53 if(strokeMaterial){
54 this._strokeMaterial = strokeMaterial; 54 this._strokeMaterial = strokeMaterial;
55 } else { 55 } else {
56 this._strokeMaterial = MaterialsModel.exportFlatMaterial(); 56 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
57 } 57 }
58 58
59 if(fillMaterial) { 59 if(fillMaterial) {
60 this._fillMaterial = fillMaterial; 60 this._fillMaterial = fillMaterial;
61 } else { 61 } else {
62 this._fillMaterial = MaterialsModel.exportFlatMaterial(); 62 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
63 } 63 }
64 64
65 this.exportMaterials(); 65 this.exportMaterials();
@@ -598,7 +598,47 @@ var Circle = function GLCircle() {
598 } 598 }
599 }; 599 };