aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/html-document.js43
-rwxr-xr-xjs/lib/drawing/world.js128
-rwxr-xr-xjs/lib/geom/circle.js72
-rwxr-xr-xjs/lib/geom/geom-obj.js79
-rwxr-xr-xjs/lib/geom/line.js53
-rwxr-xr-xjs/lib/geom/rectangle.js87
-rwxr-xr-xjs/lib/rdge/materials/bump-metal-material.js44
-rwxr-xr-xjs/lib/rdge/materials/flat-material.js21
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js53
-rw-r--r--js/lib/rdge/materials/pulse-material.js32
-rw-r--r--js/lib/rdge/materials/radial-blur-material.js36
-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.js185
-rwxr-xr-xjs/models/materials-model.js32
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 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
732World.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
767World.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
732World.prototype.export = function() 783World.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
864World.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
891World.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
908World.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 }