diff options
Diffstat (limited to 'js/lib')
-rwxr-xr-x | js/lib/drawing/world.js | 128 | ||||
-rwxr-xr-x | js/lib/geom/circle.js | 72 | ||||
-rwxr-xr-x | js/lib/geom/geom-obj.js | 79 | ||||
-rwxr-xr-x | js/lib/geom/line.js | 53 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 87 | ||||
-rwxr-xr-x | js/lib/rdge/materials/bump-metal-material.js | 44 | ||||
-rwxr-xr-x | js/lib/rdge/materials/flat-material.js | 21 | ||||
-rwxr-xr-x | js/lib/rdge/materials/linear-gradient-material.js | 53 | ||||
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 32 | ||||
-rw-r--r-- | js/lib/rdge/materials/radial-blur-material.js | 36 | ||||
-rwxr-xr-x | js/lib/rdge/materials/radial-gradient-material.js | 54 | ||||
-rw-r--r-- | js/lib/rdge/materials/taper-material.js | 27 | ||||
-rw-r--r-- | js/lib/rdge/materials/twist-vert-material.js | 28 | ||||
-rwxr-xr-x | js/lib/rdge/materials/uber-material.js | 185 |
14 files changed, 872 insertions, 27 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 44c9e37d..9e502c3e 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js | |||
@@ -727,6 +727,57 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { | |||
727 | } | 727 | } |
728 | }; | 728 | }; |
729 | 729 | ||
730 | World.prototype.exportJSON = function() | ||
731 | { | ||
732 | // world properties | ||
733 | var worldObj = | ||
734 | { | ||
735 | 'version' : 1.1, | ||
736 | 'id' : this.getCanvas().getAttribute( "data-RDGE-id" ), | ||
737 | 'fov' : this._fov, | ||
738 | 'zNear' : this._zNear, | ||
739 | 'zFar' : this._zFar, | ||
740 | 'viewDist' : this._viewDist, | ||
741 | 'webGL' : this._useWebGL | ||
742 | }; | ||
743 | |||
744 | // RDGE scenegraph | ||
745 | if (this._useWebGL) | ||
746 | worldObj.scenedata = this.myScene.exportJSON(); | ||
747 | |||
748 | // object data | ||
749 | var strArray = []; | ||
750 | this.exportObjectsJSON( this._geomRoot, worldObj ); | ||
751 | |||
752 | // convert the object to a string | ||
753 | var jStr = JSON.stringify( worldObj ); | ||
754 | |||
755 | // the RDGE export function corrupts the data. | ||
756 | // rebuild the tree | ||
757 | var root = this._rootNode; | ||
758 | root.children = new Array(); | ||
759 | if (worldObj.children && (worldObj.children.length === 1)) | ||
760 | this.importObjectsJSON( worldObj.children[0] ); | ||
761 | |||
762 | return jStr; | ||
763 | } | ||
764 | |||
765 | World.prototype.exportObjectsJSON = function( obj, parentObj ) | ||
766 | { | ||
767 | if (!obj) return; | ||
768 | |||
769 | var jObj = obj.exportJSON(); | ||
770 | if (!parentObj.children) parentObj.children = []; | ||
771 | parentObj.children.push( jObj ); | ||
772 | |||
773 | if (obj.getChild()) { | ||
774 | this.exportObjects( obj.getChild (), jObj ); | ||
775 | } | ||
776 | |||
777 | if (obj.getNext()) | ||
778 | this.exportObjects( obj.getNext(), parentObj ); | ||
779 | } | ||
780 | |||
730 | World.prototype.export = function() | 781 | World.prototype.export = function() |
731 | { | 782 | { |
732 | var exportStr = "GLWorld 1.0\n"; | 783 | var exportStr = "GLWorld 1.0\n"; |
@@ -808,6 +859,83 @@ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) | |||
808 | return rtnNode; | 859 | return rtnNode; |
809 | }; | 860 | }; |
810 | 861 | ||
862 | World.prototype.importJSON = function( jObj ) | ||
863 | { | ||
864 | if (jObj.webGL) | ||
865 | { | ||
866 | // start RDGE | ||
867 | rdgeStarted = true; | ||
868 | var id = this._canvas.getAttribute( "data-RDGE-id" ); | ||
869 | this._canvas.rdgeid = id; | ||
870 | g_Engine.registerCanvas(this._canvas, this); | ||
871 | RDGEStart( this._canvas ); | ||
872 | this._canvas.task.stop() | ||
873 | } | ||
874 | |||
875 | // import the objects | ||
876 | // there should be exactly one child of the parent object | ||
877 | if (jObj.children && (jObj.children.length === 1)) | ||
878 | this.importObjectsJSON( jObj.children[0] ); | ||
879 | else | ||
880 | throw new Error ("unrecoverable canvas import error - inconsistent root object: " + jObj.children ); | ||
881 | |||
882 | if (!this._useWebGL) | ||
883 | { | ||
884 | // render using canvas 2D | ||
885 | this.render(); | ||
886 | } | ||
887 | } | ||
888 | |||
889 | World.prototype.importObjectsJSON = function( jObj, parentGeomObj ) | ||
890 | { | ||
891 | // read the next object | ||
892 | var gObj = this.importObjectJSON( jObj, parentGeomObj ); | ||
893 | |||
894 | // determine if we have children | ||
895 | if (jObj.children) | ||
896 | { | ||
897 | var nKids = ojObjbj.chilodren.length; | ||
898 | for (var i=0; i<nKids; i++) | ||
899 | { | ||
900 | var child = jObj.children[i]; | ||
901 | this.importObjectsJSON( child, gObj ); | ||
902 | } | ||
903 | } | ||
904 | } | ||
905 | |||
906 | World.prototype.importObjectJSON = function( jObj, parentGeomObj ) | ||
907 | { | ||
908 | var type = jObj.type; | ||
909 | |||
910 | var obj; | ||
911 | switch (type) | ||
912 | { | ||
913 | case 1: | ||
914 | obj = new Rectangle(); | ||
915 | obj.importJSON( jObj ); | ||
916 | break; | ||
917 | |||
918 | case 2: // circle | ||
919 | obj = new Circle(); | ||
920 | obj.importJSON( jObj ); | ||
921 | break; | ||
922 | |||
923 | case 3: // line | ||
924 | obj = new Line(); | ||
925 | obj.importJSON( jObj ); | ||
926 | break; | ||
927 | |||
928 | default: | ||
929 | throw new Error( "Unrecognized object type: " + type ); | ||
930 | break; | ||
931 | } | ||
932 | |||
933 | if (obj) | ||
934 | this.addObject( obj, parentGeomObj ); | ||
935 | |||
936 | return obj; | ||
937 | }; | ||
938 | |||
811 | World.prototype.import = function( importStr ) { | 939 | World.prototype.import = function( importStr ) { |
812 | // import the worldattributes - not currently used | 940 | // import the worldattributes - not currently used |
813 | 941 | ||
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index f94d4e6b..7d1a3452 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(); |
@@ -551,7 +551,65 @@ var Circle = function GLCircle() { | |||
551 | } | 551 | } |
552 | }; | 552 | }; |
553 | 553 | ||
554 | this.export = function() { | 554 | this.exportJSON = function() |
555 | { | ||
556 | var jObj = | ||
557 | { | ||
558 | 'type' : this.geomType(), | ||
559 | 'xoff' : this._xOffset, | ||
560 | 'yoff' : this._yOffset, | ||
561 | 'width' : this._width, | ||
562 | 'height' : this._height, | ||
563 | 'strokeWidth' : this._strokeWidth, | ||
564 | 'strokeColor' : this._strokeColor, | ||
565 | 'fillColor' : this._fillColor, | ||
566 | 'innerRadius' : this._innerRadius, | ||
567 | 'strokeStyle' : this._strokeStyle, | ||
568 | 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), | ||
569 | 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), | ||
570 | 'materials' : this.exportMaterialsJSON() | ||
571 | }; | ||
572 | |||
573 | return jObj; | ||
574 | }; | ||
575 | |||
576 | this.importJSON = function( jObj ) | ||
577 | { | ||
578 | this._xOffset = jObj.xoff; | ||
579 | this._yOffset = jObj.yoff; | ||
580 | this._width = jObj.width; | ||
581 | this._height = jObj.height; | ||
582 | this._strokeWidth = jObj.strokeWidth; | ||
583 | this._strokeColor = jObj.strokeColor; | ||
584 | this._fillColor = jObj.fillColor; | ||
585 | this._innerRadius = jObj.innerRadius; | ||
586 | this._strokeStyle = jObj.strokeStyle; | ||
587 | var strokeMaterialName = jObj.strokeMat; | ||
588 | var fillMaterialName = jObj.fillMat; | ||
589 | this.importMaterialsJSON( jObj.materials ); | ||
590 | |||
591 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
592 | if (!strokeMat) { | ||
593 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
594 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
595 |