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 049145ce..4b117242 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js | |||
@@ -729,6 +729,57 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { | |||
729 | } | 729 | } |
730 | }; | 730 | }; |
731 | 731 | ||
732 | World.prototype.exportJSON = function() | ||
733 | { | ||
734 | // world properties | ||
735 | var worldObj = | ||
736 | { | ||
737 | 'version' : 1.1, | ||
738 | 'id' : this.getCanvas().getAttribute( "data-RDGE-id" ), | ||
739 | 'fov' : this._fov, | ||
740 | 'zNear' : this._zNear, | ||
741 | 'zFar' : this._zFar, | ||
742 | 'viewDist' : this._viewDist, | ||
743 | 'webGL' : this._useWebGL | ||
744 | }; | ||
745 | |||
746 | // RDGE scenegraph | ||
747 | if (this._useWebGL) | ||
748 | worldObj.scenedata = this.myScene.exportJSON(); | ||
749 | |||
750 | // object data | ||
751 | var strArray = []; | ||
752 | this.exportObjectsJSON( this._geomRoot, worldObj ); | ||
753 | |||
754 | // convert the object to a string | ||
755 | var jStr = JSON.stringify( worldObj ); | ||
756 | |||
757 | // the RDGE export function corrupts the data. | ||
758 | // rebuild the tree | ||
759 | var root = this._rootNode; | ||
760 | root.children = new Array(); | ||
761 | if (worldObj.children && (worldObj.children.length === 1)) | ||
762 | this.importObjectsJSON( worldObj.children[0] ); | ||
763 | |||
764 | return jStr; | ||
765 | } | ||
766 | |||
767 | World.prototype.exportObjectsJSON = function( obj, parentObj ) | ||
768 | { | ||
769 | if (!obj) return; | ||
770 | |||
771 | var jObj = obj.exportJSON(); | ||
772 | if (!parentObj.children) parentObj.children = []; | ||
773 | parentObj.children.push( jObj ); | ||
774 | |||
775 | if (obj.getChild()) { | ||
776 | this.exportObjects( obj.getChild (), jObj ); | ||
777 | } | ||
778 | |||
779 | if (obj.getNext()) | ||
780 | this.exportObjects( obj.getNext(), parentObj ); | ||
781 | } | ||
782 | |||
732 | World.prototype.export = function() | 783 | World.prototype.export = function() |
733 | { | 784 | { |
734 | var exportStr = "GLWorld 1.0\n"; | 785 | var exportStr = "GLWorld 1.0\n"; |
@@ -810,6 +861,83 @@ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) | |||
810 | return rtnNode; | 861 | return rtnNode; |
811 | }; | 862 | }; |
812 | 863 | ||
864 | World.prototype.importJSON = function( jObj ) | ||
865 | { | ||
866 | if (jObj.webGL) | ||
867 | { | ||
868 | // start RDGE | ||
869 | rdgeStarted = true; | ||
870 | var id = this._canvas.getAttribute( "data-RDGE-id" ); | ||
871 | this._canvas.rdgeid = id; | ||
872 | g_Engine.registerCanvas(this._canvas, this); | ||
873 | RDGEStart( this._canvas ); | ||
874 | this._canvas.task.stop() | ||
875 | } | ||
876 | |||
877 | // import the objects | ||
878 | // there should be exactly one child of the parent object | ||
879 | if (jObj.children && (jObj.children.length === 1)) | ||
880 | this.importObjectsJSON( jObj.children[0] ); | ||
881 | else | ||
882 | throw new Error ("unrecoverable canvas import error - inconsistent root object: " + jObj.children ); | ||
883 | |||
884 | if (!this._useWebGL) | ||
885 | { | ||
886 | // render using canvas 2D | ||
887 | this.render(); | ||
888 | } | ||
889 | } | ||
890 | |||
891 | World.prototype.importObjectsJSON = function( jObj, parentGeomObj ) | ||
892 | { | ||
893 | // read the next object | ||
894 | var gObj = this.importObjectJSON( jObj, parentGeomObj ); | ||
895 | |||
896 | // determine if we have children | ||
897 | if (jObj.children) | ||
898 | { | ||
899 | var nKids = ojObjbj.chilodren.length; | ||
900 | for (var i=0; i<nKids; i++) | ||
901 | { | ||
902 | var child = jObj.children[i]; | ||
903 | this.importObjectsJSON( child, gObj ); | ||
904 | } | ||
905 | } | ||
906 | } | ||
907 | |||
908 | World.prototype.importObjectJSON = function( jObj, parentGeomObj ) | ||
909 | { | ||
910 | var type = jObj.type; | ||
911 | |||
912 | var obj; | ||
913 | switch (type) | ||
914 | { | ||
915 | case 1: | ||
916 | obj = new Rectangle(); | ||
917 | obj.importJSON( jObj ); | ||
918 | break; | ||
919 | |||
920 | case 2: // circle | ||
921 | obj = new Circle(); | ||
922 | obj.importJSON( jObj ); | ||
923 | break; | ||
924 | |||
925 | case 3: // line | ||
926 | obj = new Line(); | ||
927 | obj.importJSON( jObj ); | ||
928 | break; | ||
929 | |||
930 | default: | ||
931 | throw new Error( "Unrecognized object type: " + type ); | ||
932 | break; | ||
933 | } | ||
934 | |||
935 | if (obj) | ||
936 | this.addObject( obj, parentGeomObj ); | ||
937 | |||
938 | return obj; | ||
939 | }; | ||
940 | |||
813 | World.prototype.import = function( importStr ) { | 941 | World.prototype.import = function( importStr ) { |
814 | // import the worldattributes - not currently used | 942 | // import the worldattributes - not currently used |
815 | 943 | ||
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 4b155b4c..fec62308 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,65 @@ var Circle = function GLCircle() { | |||
598 | } | 598 | } |
599 | }; | 599 | }; |
600 | 600 | ||
601 | this.export = function() { | 601 | this.exportJSON = function() |
602 | { | ||
603 | var jObj = | ||
604 | { | ||
605 | 'type' : this.geomType(), | ||
606 | 'xoff' : this._xOffset, | ||
607 | 'yoff' : this._yOffset, | ||
608 | 'width' : this._width, | ||
609 | 'height' : this._height, | ||
610 | 'strokeWidth' : this._strokeWidth, | ||
611 | 'strokeColor' : this._strokeColor, | ||
612 | 'fillColor' : this._fillColor, | ||
613 | 'innerRadius' : this._innerRadius, | ||
614 | 'strokeStyle' : this._strokeStyle, | ||
615 | 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), | ||
616 | 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), | ||
617 | 'materials' : this.exportMaterialsJSON() | ||
618 | }; | ||
619 | |||
620 | return jObj; | ||
621 | }; | ||
622 | |||
623 | this.importJSON = function( jObj ) | ||
624 | { | ||
625 | this._xOffset = jObj.xoff; | ||
626 | this._yOffset = jObj.yoff; | ||
627 | this._width = jObj.width; | ||
628 | this._height = jObj.height; | ||
629 | this._strokeWidth = jObj.strokeWidth; | ||
630 | this._strokeColor = jObj.strokeColor; | ||
631 | this._fillColor = jObj.fillColor; | ||
632 | this._innerRadius = jObj.innerRadius; | ||
633 | this._strokeStyle = jObj.strokeStyle; | ||
634 | var strokeMaterialName = jObj.strokeMat; | ||
635 | var fillMaterialName = jObj.fillMat; | ||
636 | this.importMaterialsJSON( jObj.materials ); | ||
637 | |||
638 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
639 | if (!strokeMat) { | ||
640 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
641 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
642 | } | ||