diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/document/html-document.js | 43 | ||||
-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 | ||||
-rwxr-xr-x | js/models/materials-model.js | 32 |
16 files changed, 923 insertions, 51 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index d4db6e2f..bf03e38b 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -194,11 +194,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
194 | // | 194 | // |
195 | if (elt) { | 195 | if (elt) { |
196 | this._glData = []; | 196 | this._glData = []; |
197 | //if (path) { | 197 | this.collectGLData(elt, this._glData ); |
198 | //this.collectGLData(elt, this._glData, path); | ||
199 | //} else { | ||
200 | this.collectGLData(elt, this._glData ); | ||
201 | //} | ||
202 | } else { | 198 | } else { |
203 | this._glData = null | 199 | this._glData = null |
204 | } | 200 | } |
@@ -220,25 +216,26 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
220 | 216 | ||
221 | // /* | 217 | // /* |
222 | var importStr = value[i]; | 218 | var importStr = value[i]; |
223 | var startIndex = importStr.indexOf( "id: " ); | 219 | var jObj = JSON.parse( importStr ); |
224 | if (startIndex >= 0) { | 220 | if (jObj) |
225 | var endIndex = importStr.indexOf( "\n", startIndex ); | 221 | { |
226 | if (endIndex > 0) { | 222 | var id = jObj.id; |
227 | var id = importStr.substring( startIndex+4, endIndex ); | 223 | if (id) |
228 | if (id) { | 224 | { |
229 | var canvas = this.findCanvasWithID( id, elt ); | 225 | var canvas = this.findCanvasWithID( id, elt ); |
230 | if (canvas) { | 226 | if (canvas) { |
231 | if (!canvas.elementModel) { | 227 | if (!canvas.elementModel) { |
232 | NJUtils.makeElementModel(canvas, "Canvas", "shape", true); | 228 | NJUtils.makeElementModel(canvas, "Canvas", "shape", true); |
229 | } | ||
230 | if (canvas.elementModel) { | ||
231 | if (canvas.elementModel.shapeModel.GLWorld) { | ||
232 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | ||
233 | } | 233 | } |
234 | if (canvas.elementModel) { | 234 | if (jObj) |
235 | if (canvas.elementModel.shapeModel.GLWorld) { | 235 | { |
236 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | 236 | var useWebGL = jObj.webGL; |
237 | } | ||
238 | var index = importStr.indexOf( "webGL: " ); | ||
239 | var useWebGL = (index >= 0) | ||
240 | var world = new GLWorld( canvas, useWebGL ); | 237 | var world = new GLWorld( canvas, useWebGL ); |
241 | world.import( importStr ); | 238 | world.importJSON( jObj ); |
242 | this.buildShapeModel( canvas.elementModel, world ); | 239 | this.buildShapeModel( canvas.elementModel, world ); |
243 | } | 240 | } |
244 | } | 241 | } |
@@ -382,7 +379,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
382 | { | 379 | { |
383 | if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) | 380 | if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) |
384 | { | 381 | { |
385 | var data = elt.elementModel.shapeModel.GLWorld.export(); | 382 | var data = elt.elementModel.shapeModel.GLWorld.exportJSON(); |
386 | dataArray.push( data ); | 383 | dataArray.push( data ); |
387 | } | 384 | } |
388 | 385 | ||
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; | ||