@@ -189,6 +189,122 @@ let Graph = class Graph
189189 ME . Device2D . strokeStyle = '#000000' ;
190190 }
191191 }
192+ ToJson ( )
193+ {
194+ let js = { } ;
195+ js [ "nodes" ] = [ ] ;
196+ for ( let i = 0 ; i < this . Nodes . length ; i ++ )
197+ {
198+ let child = {
199+ "name" : this . Nodes [ i ] . Name ,
200+ "id" : this . Nodes [ i ] . ID ,
201+ "location" : {
202+ "x" : this . Nodes [ i ] . Location . X ,
203+ "y" : this . Nodes [ i ] . Location . Y ,
204+ "z" : this . Nodes [ i ] . Location . Z
205+ } ,
206+ "enabled" : this . Nodes [ i ] . Enabled ,
207+ "neighbors" : [ ]
208+ } ;
209+ for ( let j = 0 ; j < this . Nodes [ i ] . Neighbors . length ; j ++ )
210+ {
211+ child [ "neighbors" ] . push ( {
212+ "distance" : this . Nodes [ i ] . Neighbors [ j ] . Distance ,
213+ "end" : this . Nodes [ i ] . Neighbors [ j ] . EndNode . ID ,
214+ } ) ;
215+ }
216+ js [ "nodes" ] . push ( child ) ;
217+ }
218+ js [ "elements" ] = [ ] ;
219+ for ( let i = 0 ; i < this . Elements . length ; i ++ )
220+ {
221+ let id = null ;
222+ if ( this . Elements [ i ] . Node )
223+ {
224+ id = this . Elements [ i ] . Node . ID ;
225+ }
226+ let child = {
227+ "name" : this . Elements [ i ] . Name ,
228+ "type" : this . Elements [ i ] . Type ,
229+ "node" : id ,
230+ "vertices" : [ ] ,
231+ "indices" : [ ]
232+ }
233+ for ( let j = 0 ; j < this . Elements [ i ] . Object . Vertices . length ; j ++ )
234+ {
235+ child [ "vertices" ] . push ( [
236+ this . Elements [ i ] . Object . Vertices [ j ] . X ,
237+ this . Elements [ i ] . Object . Vertices [ j ] . Y ,
238+ this . Elements [ i ] . Object . Vertices [ j ] . Z ,
239+ this . Elements [ i ] . Object . Vertices [ j ] . R ,
240+ this . Elements [ i ] . Object . Vertices [ j ] . G ,
241+ this . Elements [ i ] . Object . Vertices [ j ] . B ,
242+ this . Elements [ i ] . Object . Vertices [ j ] . A ,
243+ ] ) ;
244+ }
245+ for ( let j = 0 ; j < this . Elements [ i ] . Object . Indices . length ; j ++ )
246+ {
247+ child [ "indices" ] . push ( this . Elements [ i ] . Object . Indices [ j ] . indices ) ;
248+ }
249+ js [ "elements" ] . push ( child ) ;
250+ }
251+ console . log ( JSON . stringify ( js ) ) ;
252+ return js ;
253+ }
254+ FromJson ( ME , js )
255+ {
256+ console . log ( js ) ;
257+ for ( let i = 0 ; i < js [ "nodes" ] . length ; i ++ )
258+ {
259+ let n = new Node ( js [ "nodes" ] [ i ] [ "name" ] , new Vertex ( js [ "nodes" ] [ i ] [ "location" ] [ "x" ] , js [ "nodes" ] [ i ] [ "location" ] [ "y" ] , js [ "nodes" ] [ i ] [ "location" ] [ "z" ] ) ) ;
260+ n . ID = js [ "nodes" ] [ i ] [ "id" ] ;
261+ n . Enabled = js [ "nodes" ] [ i ] [ "enabled" ] ;
262+ this . Nodes . push ( n ) ;
263+ }
264+ for ( let i = 0 ; i < this . Nodes . length ; i ++ )
265+ {
266+ let n = this . Nodes [ i ] ;
267+ for ( let j = 0 ; j < js [ "nodes" ] [ i ] [ "neighbors" ] . length ; j ++ )
268+ {
269+ for ( let k = 0 ; k < this . Nodes . length ; k ++ )
270+ {
271+ if ( this . Nodes [ k ] . ID === js [ "nodes" ] [ i ] [ "neighbors" ] [ j ] [ "end" ] )
272+ {
273+ n . Neighbors . push ( new Neighbor ( this . Nodes [ k ] , js [ "nodes" ] [ i ] [ "neighbors" ] [ j ] [ "distance" ] ) ) ;
274+ break ;
275+ }
276+ }
277+ }
278+ }
279+ for ( let i = 0 ; i < js [ "elements" ] . length ; i ++ )
280+ {
281+ let v = [ ] ;
282+ for ( let j = 0 ; j < js [ "elements" ] [ i ] [ "vertices" ] . length ; j ++ )
283+ {
284+ let c = js [ "elements" ] [ i ] [ "vertices" ] [ j ] ;
285+ v . push ( new GraphicsVertex ( c [ 0 ] , c [ 1 ] , c [ 2 ] , c [ 3 ] , c [ 4 ] , c [ 5 ] , c [ 6 ] ) ) ;
286+ }
287+ let ind = [ ] ;
288+ for ( let j = 0 ; j < js [ "elements" ] [ i ] [ "indices" ] . length ; j ++ )
289+ {
290+ let c = js [ "elements" ] [ i ] [ "indices" ] [ j ] ;
291+ ind . push ( new Index ( c [ 0 ] , c [ 1 ] , c [ 2 ] ) ) ;
292+ }
293+ console . log ( v ) ;
294+ let n = new Element ( new Object3D ( ME , v , ind , "New Object" ) , js [ "elements" ] [ i ] [ "name" ] , js [ "elements" ] [ i ] [ "type" ] ) ;
295+ if ( js [ "elements" ] [ i ] [ "node" ] != null )
296+ {
297+ for ( let k = 0 ; k < this . Nodes . length ; k ++ )
298+ {
299+ if ( this . Nodes [ k ] . ID === js [ "elements" ] [ i ] [ "node" ] )
300+ {
301+ n . BindToNode ( this . Nodes [ k ] ) ;
302+ }
303+ }
304+ }
305+ this . Elements . push ( n ) ;
306+ }
307+ }
192308}
193309let nID = 0 ;
194310let Node = class Node
0 commit comments