2
0

Object2D.js.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: Object2D.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: Object2D.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>import {Vector2} from "./math/Vector2.js";
  20. import {Matrix} from "./math/Matrix.js";
  21. import {UUID} from "./math/UUID.js";
  22. /**
  23. * Base object class, implements all the object positioning and scaling features.
  24. *
  25. * Stores all the base properties shared between all objects as the position, transformation properties, children etc.
  26. *
  27. * Object2D object can be used as a group to the other objects drawn.
  28. *
  29. * @class
  30. */
  31. function Object2D()
  32. {
  33. /**
  34. * UUID of the object.
  35. *
  36. * @type {string}
  37. */
  38. this.uuid = UUID.generate();
  39. /**
  40. * List of children objects attached to the object.
  41. *
  42. * @type {Object2D[]}
  43. */
  44. this.children = [];
  45. /**
  46. * Parent object, the object position is affected by its parent position.
  47. *
  48. * @type {Object2D}
  49. */
  50. this.parent = null;
  51. /**
  52. * Depth level in the object tree, objects with higher depth are drawn on top.
  53. *
  54. * The layer value is considered first.
  55. *
  56. * @type {number}
  57. */
  58. this.level = 0;
  59. /**
  60. * Position of the object.
  61. *
  62. * The world position of the object is affected by its parent transform.
  63. *
  64. * @type {Vector2}
  65. */
  66. this.position = new Vector2(0, 0);
  67. /**
  68. * Origin of the object used as point of rotation.
  69. *
  70. * @type {Vector2}
  71. */
  72. this.origin = new Vector2(0, 0);
  73. /**
  74. * Scale of the object.
  75. *
  76. * The world scale of the object is affected by the parent transform.
  77. *
  78. * @type {Vector2}
  79. */
  80. this.scale = new Vector2(1, 1);
  81. /**
  82. * Rotation of the object relative to its center.
  83. *
  84. * The world rotation of the object is affected by the parent transform.
  85. *
  86. * @type {number}
  87. */
  88. this.rotation = 0.0;
  89. /**
  90. * Indicates if the object is visible.
  91. *
  92. * @type {boolean}
  93. */
  94. this.visible = true;
  95. /**
  96. * Layer of this object, objects are sorted by layer value.
  97. *
  98. * Lower layer value is draw first, higher layer value is drawn on top.
  99. *
  100. * @type {number}
  101. */
  102. this.layer = 0;
  103. /**
  104. * Local transformation matrix applied to the object.
  105. *
  106. * @type {Matrix}
  107. */
  108. this.matrix = new Matrix();
  109. /**
  110. * Global transformation matrix multiplied by the parent matrix.
  111. *
  112. * Used to transform the object before projecting into screen coordinates.
  113. *
  114. * @type {Matrix}
  115. */
  116. this.globalMatrix = new Matrix();
  117. /**
  118. * Inverse of the global (world) transform matrix.
  119. *
  120. * Used to convert pointer input points (viewport space) into object coordinates.
  121. *
  122. * @type {Matrix}
  123. */
  124. this.inverseGlobalMatrix = new Matrix();
  125. /**
  126. * Mask objects being applied to this object. Used to mask/subtract portions of this object when rendering.
  127. *
  128. * Multiple masks can be used simultaneously. Same mask might be reused for multiple objects.
  129. *
  130. * @type {Mask[]}
  131. */
  132. this.masks = [];
  133. /**
  134. * Indicates if the transform matrix should be automatically updated every frame.
  135. *
  136. * Set this false for better performance. But if you do so dont forget to set matrixNeedsUpdate every time that a transform attribute is changed.
  137. *
  138. * @type {boolean}
  139. */
  140. this.matrixAutoUpdate = true;
  141. /**
  142. * Indicates if the matrix needs to be updated, should be set true after changes to the object position, scale or rotation.
  143. *
  144. * The matrix is updated before rendering the object, after the matrix is updated this attribute is automatically reset to false.
  145. *
  146. * @type {boolean}
  147. */
  148. this.matrixNeedsUpdate = true;
  149. /**
  150. * Draggable controls if its possible to drag the object around. Set this true to enable dragging events on this object.
  151. *
  152. * The onPointerDrag callback is used to update the state of the object while being dragged, by default it just updates the object position.
  153. *
  154. * @type {boolean}
  155. */
  156. this.draggable = false;
  157. /**
  158. * Indicates if this object uses pointer events.
  159. *
  160. * Can be set false to skip the pointer interaction events, better performance if pointer events are not required.
  161. *
  162. * @type {boolean}
  163. */
  164. this.pointerEvents = true;
  165. /**
  166. * Flag to indicate whether this object ignores the viewport transformation.
  167. *
  168. * @type {boolean}
  169. */
  170. this.ignoreViewport = false;
  171. /**
  172. * Flag to indicate if the context of canvas should be saved before render.
  173. *
  174. * @type {boolean}
  175. */
  176. this.saveContextState = true;
  177. /**
  178. * Flag to indicate if the context of canvas should be restored after render.
  179. *
  180. * @type {boolean}
  181. */
  182. this.restoreContextState = true;
  183. /**
  184. * Flag indicating if the pointer is inside of the element.
  185. *
  186. * Used to control object event.
  187. *
  188. * @type {boolean}
  189. */
  190. this.pointerInside = false;
  191. /**
  192. * Flag to indicate if the object is currently being dragged.
  193. *
  194. * @type {boolean}
  195. */
  196. this.beingDragged = false;
  197. /**
  198. * Indicates if the object should be serialized or not as a child of another object.
  199. *
  200. * Used to prevent duplicate serialization data on custom objects. Should be set false for objects added on constructor.
  201. *
  202. * @type {boolean}
  203. */
  204. this.serializable = true;
  205. }
  206. Object2D.prototype.constructor = Object2D;
  207. /**
  208. * Type of the object, used for data serialization and/or checking the object type.
  209. *
  210. * The name used should match the object constructor name. But it is not required.
  211. *
  212. * If this type is from an external library you can add the library name to the object type name to prevent collisions.
  213. *
  214. * @type {string}
  215. */
  216. Object2D.prototype.type = "Object2D";
  217. /**
  218. * List of available object types known by the application. Stores the object constructor by object type.
  219. *
  220. * Newly created types should be introduced in this map for data serialization support.
  221. *
  222. * New object types should be added using the Object2D.register() method.
  223. *
  224. * @static
  225. * @type {Map&lt;string, Function>}
  226. */
  227. Object2D.types = new Map([[Object2D.prototype.type, Object2D]]);
  228. /**
  229. * Register a object type into the application. Associates the type string to the object constructor.
  230. *
  231. * Should be called for every new object class implemented if you want to be able to serialize and parse data.
  232. *
  233. * @static
  234. * @param {Function} constructor Object constructor.
  235. * @param {string} type Object type name.
  236. */
  237. Object2D.register = function(constructor, type)
  238. {
  239. Object2D.types.set(type, constructor);
  240. };
  241. /**
  242. * Check if a point in world coordinates intersects this object or its children and get a list of the objects intersected.
  243. *
  244. * @param {Vector2} point Point in world coordinates.
  245. * @param {Object2D[]} list List of objects intersected passed to children objects recursively.
  246. * @return {Object2D[]} List of object intersected by this point.
  247. */
  248. Object2D.prototype.getWorldPointIntersections = function(point, list)
  249. {
  250. if(list === undefined)
  251. {
  252. list = [];
  253. }
  254. // Calculate the pointer position in the object coordinates
  255. var localPoint = this.inverseGlobalMatrix.transformPoint(point);
  256. if(this.isInside(localPoint))
  257. {
  258. list.push(this);
  259. }
  260. // Iterate trough the children
  261. for(var i = 0; i &lt; this.children.length; i++)
  262. {
  263. this.children[i].getWorldPointIntersections(point, list);
  264. }
  265. return list;
  266. };
  267. /**
  268. * Check if a point in world coordinates intersects this object or some of its children.
  269. *
  270. * @param {Vector2} point Point in world coordinates.
  271. * @param {boolean} recursive If set to true it will also check intersections with the object children.
  272. * @return {boolean} Returns true if the point in inside of the object.
  273. */
  274. Object2D.prototype.isWorldPointInside = function(point, recursive)
  275. {
  276. // Calculate the pointer position in the object coordinates
  277. var localPoint = this.inverseGlobalMatrix.transformPoint(point);
  278. if(this.isInside(localPoint))
  279. {
  280. return true;
  281. }
  282. // Iterate trough the children
  283. if(recursive)
  284. {
  285. for(var i = 0; i &lt; this.children.length; i++)
  286. {
  287. if(this.children[i].isWorldPointInside(point, true))
  288. {
  289. return true;
  290. }
  291. }
  292. }
  293. return false;
  294. };
  295. /**
  296. * Destroy the object, removes it from the parent object.
  297. */
  298. Object2D.prototype.destroy = function()
  299. {
  300. if(this.parent !== null)
  301. {
  302. this.parent.remove(this);
  303. }
  304. };
  305. /**
  306. * Traverse the object tree and run a function for all objects.
  307. *
  308. * @param {Function} callback Callback function that receives the object as parameter.
  309. */
  310. Object2D.prototype.traverse = function(callback)
  311. {
  312. callback(this);
  313. for(var i = 0; i &lt; this.children.length; i++)
  314. {
  315. this.children[i].traverse(callback);
  316. }
  317. };
  318. /**
  319. * Get a object from its children list by its UUID.
  320. *
  321. * @param {string} uuid UUID of the object to get.
  322. * @return {Object2D} The object that has the UUID specified, null if the object was not found.
  323. */
  324. Object2D.prototype.getChildByUUID = function(uuid)
  325. {
  326. var object = null;
  327. this.traverse(function(child)
  328. {
  329. if(child.uuid === uuid)
  330. {
  331. object = child;
  332. }
  333. });
  334. return object;
  335. };
  336. /**
  337. * Attach a children to this object.
  338. *
  339. * The object is set as children of this object and the transformations applied to this object are traversed to its children.
  340. *
  341. * @param {Object2D} object Object to attach to this object.
  342. */
  343. Object2D.prototype.add = function(object)
  344. {
  345. object.parent = this;
  346. object.level = this.level + 1;
  347. object.traverse(function(child)
  348. {
  349. if(child.onAdd !== null)
  350. {
  351. child.onAdd(this);
  352. }
  353. });
  354. this.children.push(object);
  355. };
  356. /**
  357. * Remove object from the children list.
  358. *
  359. * Resets the parent of the object to null and resets its level.
  360. *
  361. * @param {Object2D} children Object to be removed.
  362. */
  363. Object2D.prototype.remove = function(children)
  364. {
  365. var index = this.children.indexOf(children);
  366. if(index !== -1)
  367. {
  368. var object = this.children[index];
  369. object.parent = null;
  370. object.level = 0;
  371. object.traverse(function(child)
  372. {
  373. if(child.onRemove !== null)
  374. {
  375. child.onRemove(this);
  376. }
  377. });
  378. this.children.splice(index, 1)
  379. }
  380. };
  381. /**
  382. * Check if a point is inside of the object. Used by the renderer check for pointer collision (required for the object to properly process pointer events).
  383. *
  384. * Point should be in local object coordinates.
  385. *
  386. * To check if a point in world coordinates intersects the object the inverseGlobalMatrix should be applied to that point before calling this method.
  387. *
  388. * @param {Vector2} point Point in local object coordinates.
  389. * @return {boolean} True if the point is inside of the object.
  390. */
  391. Object2D.prototype.isInside = function(point)
  392. {
  393. return false;
  394. };
  395. /**
  396. * Update the transformation matrix of the object.
  397. *
  398. * @param {CanvasRenderingContext2D} context Canvas 2d drawing context.
  399. */
  400. Object2D.prototype.updateMatrix = function(context)
  401. {
  402. if(this.matrixAutoUpdate || this.matrixNeedsUpdate)
  403. {
  404. this.matrix.compose(this.position.x, this.position.y, this.scale.x, this.scale.y, this.origin.x, this.origin.y, this.rotation);
  405. this.globalMatrix.copy(this.matrix);
  406. if(this.parent !== null)
  407. {
  408. this.globalMatrix.premultiply(this.parent.globalMatrix);
  409. }
  410. this.inverseGlobalMatrix = this.globalMatrix.getInverse()
  411. this.matrixNeedsUpdate = false;
  412. }
  413. };
  414. /**
  415. * Apply the transform to the rendering context, it is assumed that the viewport transform is pre-applied to the context.
  416. *
  417. * This is called before style() and draw(). It can also be used for some pre-rendering logic.
  418. *
  419. * @param {CanvasRenderingContext2D} context Canvas 2d drawing context.
  420. * @param {Viewport} viewport Viewport applied to the canvas.
  421. * @param {Element} canvas DOM canvas element where the content is being drawn.
  422. * @param {Renderer} renderer Renderer object being used to draw the object into the canvas.
  423. */
  424. Object2D.prototype.transform = function(context, viewport, canvas, renderer)
  425. {
  426. this.globalMatrix.tranformContext(context);
  427. };
  428. /**
  429. * Style is called right before draw() it should not draw any content into the canvas, all context styling should be applied here (colors, fonts, etc).
  430. *
  431. * The draw() and style() methods can be useful for objects that share the same styling attributes but are drawing differently.
  432. *
  433. * Should be implemented by underlying classes.
  434. *
  435. * @param {CanvasRenderingContext2D} context Canvas 2d drawing context.
  436. * @param {Viewport} viewport Viewport used to view the canvas content.
  437. * @param {Element} canvas DOM canvas element where the content is being drawn.
  438. */
  439. Object2D.prototype.style = null; // function(context, viewport, canvas){};
  440. /**
  441. * Draw the object into the canvas, this is called transform() and style(), should be where the content is actually drawn into the canvas.
  442. *
  443. * Should be implemented by underlying classes.
  444. *
  445. * @param {CanvasRenderingContext2D} context Canvas 2d drawing context.
  446. * @param {Viewport} viewport Viewport used to view the canvas content.
  447. * @param {Element} canvas DOM canvas element where the content is being drawn.
  448. */
  449. Object2D.prototype.draw = null; // function(context, viewport, canvas){};
  450. /**
  451. * Callback method while the object is being dragged across the screen.
  452. *
  453. * By default is adds the delta value to the object position (making it follow the mouse movement).
  454. *
  455. * Delta is the movement of the pointer already translated into local object coordinates.
  456. *
  457. * To detect when the object drag stops the onPointerDragEnd() method can be used.
  458. *
  459. * @param {Pointer} pointer Pointer object that receives the user input.
  460. * @param {Viewport} viewport Viewport where the object is drawn.
  461. * @param {Vector2} delta Pointer movement diff in world space since the last frame.
  462. * @param {Vector2} positionWorld Position of the dragging pointer in world coordinates.
  463. */
  464. Object2D.prototype.onPointerDrag = function(pointer, viewport, delta, positionWorld)
  465. {
  466. this.position.add(delta);
  467. };
  468. /**
  469. * Callback method called when the pointer drag start after the button was pressed
  470. *
  471. * @param {Pointer} pointer Pointer object that receives the user input.
  472. * @param {Viewport} viewport Viewport where the object is drawn.
  473. */
  474. Object2D.prototype.onPointerDragStart = null;
  475. /**
  476. * Callback method called when the pointer drag ends after the button has been released.
  477. *
  478. * @param {Pointer} pointer Pointer object that receives the user input.
  479. * @param {Viewport} viewport Viewport where the object is drawn.
  480. */
  481. Object2D.prototype.onPointerDragEnd = null;
  482. /**
  483. * Method called when the object its added to a parent.
  484. *
  485. * @param {Object2D} parent Parent object were it was added.
  486. */
  487. Object2D.prototype.onAdd = null;
  488. /**
  489. * Method called when the object gets removed from its parent
  490. *
  491. * @param {Object2D} parent Parent object from were the object is being removed.
  492. */
  493. Object2D.prototype.onRemove = null;
  494. /**
  495. * Callback method called every time before the object is draw into the canvas.
  496. *
  497. * Should be used to run object logic, any preparation code, move the object, etc.
  498. *
  499. * This method is called for every object before rendering.
  500. */
  501. Object2D.prototype.onUpdate = null;
  502. /**
  503. * Callback method called when the pointer enters the object.
  504. *
  505. * It is not called while the pointer is inside of the object, just on the first time that the pointer enters the object for that use onPointerOver()
  506. *
  507. * @param {Pointer} pointer Pointer object that receives the user input.
  508. * @param {Viewport} viewport Viewport where the object is drawn.
  509. */
  510. Object2D.prototype.onPointerEnter = null;
  511. /**
  512. * Method called when the was inside of the object and leaves the object.
  513. *
  514. * @param {Pointer} pointer Pointer object that receives the user input.
  515. * @param {Viewport} viewport Viewport where the object is drawn.
  516. */
  517. Object2D.prototype.onPointerLeave = null;
  518. /**
  519. * Method while the pointer is over (inside) of the object.
  520. *
  521. * @param {Pointer} pointer Pointer object that receives the user input.
  522. * @param {Viewport} viewport Viewport where the object is drawn.
  523. */
  524. Object2D.prototype.onPointerOver = null;
  525. /**
  526. * Method called while the pointer button is pressed.
  527. *
  528. * @param {Pointer} pointer Pointer object that receives the user input.
  529. * @param {Viewport} viewport Viewport where the object is drawn.
  530. */
  531. Object2D.prototype.onButtonPressed = null;
  532. /**
  533. * Method called while the pointer button is double clicked.
  534. *
  535. * @param {Pointer} pointer Pointer object that receives the user input.
  536. * @param {Viewport} viewport Viewport where the object is drawn.
  537. */
  538. Object2D.prototype.onDoubleClick = null;
  539. /**
  540. * Callback method called when the pointer button is pressed down (single time).
  541. *
  542. * @param {Pointer} pointer Pointer object that receives the user input.
  543. * @param {Viewport} viewport Viewport where the object is drawn.
  544. */
  545. Object2D.prototype.onButtonDown = null;
  546. /**
  547. * Method called when the pointer button is released (single time).
  548. *
  549. * @param {Pointer} pointer Pointer object that receives the user input.
  550. * @param {Viewport} viewport Viewport where the object is drawn.
  551. */
  552. Object2D.prototype.onButtonUp = null;
  553. /**
  554. * Serialize the object data into a JSON object. That can be written into a file, sent using HTTP request etc.
  555. *
  556. * All required attributes to recreate the object in its current state should be stored. Relations between children should be stored by their UUID only.
  557. *
  558. * Data has to be parsed back into a usable object.
  559. *
  560. * @param {boolean} recursive If set false the children list is not serialized, otherwise all children are serialized.
  561. * @return {Object} Serialized object data.
  562. */
  563. Object2D.prototype.serialize = function(recursive)
  564. {
  565. var data = {
  566. uuid: this.uuid,
  567. type: this.type,
  568. position: this.position.toArray(),
  569. origin: this.origin.toArray(),
  570. scale: this.scale.toArray(),
  571. rotation: this.rotation,
  572. visible: this.visible,
  573. layer: this.layer,
  574. matrix: this.matrix.m,
  575. globalMatrix: this.globalMatrix.m,
  576. inverseGlobalMatrix: this.inverseGlobalMatrix.m,
  577. matrixAutoUpdate: this.matrixAutoUpdate,
  578. draggable: this.draggable,
  579. pointerEvents: this.pointerEvents,
  580. ignoreViewport: this.ignoreViewport,
  581. saveContextState: this.saveContextState,
  582. restoreContextState: this.restoreContextState,
  583. children: [],
  584. masks: []
  585. };
  586. if(recursive !== false)
  587. {
  588. for(var i = 0; i &lt; this.children.length; i++)
  589. {
  590. if(this.children[i].serializable)
  591. {
  592. data.children.push(this.children[i].serialize());
  593. }
  594. }
  595. }
  596. for(var i = 0; i &lt; this.masks.length; i++)
  597. {
  598. data.masks.push(this.masks[i].uuid);
  599. }
  600. return data;
  601. };
  602. /**
  603. * Parse serialized object data and fill the object attributes.
  604. *
  605. * Implementations of this method should only load the attributes added to the structure, the based method already loads common attributes.
  606. *
  607. * Dont forget to register object types using the Object2D.register() method.
  608. *
  609. * @param {Object} data Object data loaded from JSON.
  610. * @param {Object2D} root Root object being loaded can be used to get references to other objects.
  611. */
  612. Object2D.prototype.parse = function(data, root)
  613. {
  614. this.uuid = data.uuid;
  615. this.position.fromArray(data.position);
  616. this.origin.fromArray(data.origin);
  617. this.scale.fromArray(data.scale);
  618. this.rotation = data.rotation;
  619. this.visible = data.visible;
  620. this.layer = data.layer;
  621. this.matrix = new Matrix(data.matrix);
  622. this.globalMatrix = new Matrix(data.globalMatrix);
  623. this.inverseGlobalMatrix = new Matrix(data.inverseGlobalMatrix);
  624. this.matrixAutoUpdate = data.matrixAutoUpdate;
  625. this.draggable = data.draggable;
  626. this.pointerEvents = data.pointerEvents;
  627. this.ignoreViewport = data.ignoreViewport;
  628. this.saveContextState = data.saveContextState;
  629. this.restoreContextState = data.restoreContextState;
  630. for(var i = 0; i &lt; this.masks.length; i++)
  631. {
  632. data.masks.push(root.getChildByUUID(data.masks[i]));
  633. }
  634. };
  635. /**
  636. * Create objects from serialized object data into the proper data structures.
  637. *
  638. * All objects should implement serialization methods to serialize and load data properly.
  639. *
  640. * First all objects instances are created to ensure that object trying to get references to other object can have the data accessible, only then the parse method is called.
  641. *
  642. * @static
  643. * @param {Object} data Object data loaded from JSON.
  644. * @return {Object2D} Parsed object data.
  645. */
  646. Object2D.parse = function(data)
  647. {
  648. // List of objects created stored as pairs of object, data to be later parsed.
  649. var objects = [];
  650. // Parse all objects from the data object recursively and create the correct instances.
  651. function createObjectInstances(data)
  652. {
  653. if(!Object2D.types.has(data.type))
  654. {
  655. throw new Error("Object type " + data.type + " unknown. Cannot parse data.");
  656. }
  657. var Constructor = Object2D.types.get(data.type);
  658. var object = new Constructor();
  659. object.uuid = data.uuid;
  660. objects.push({object: object, data: data});
  661. for(var i = 0; i &lt; data.children.length; i++)
  662. {
  663. object.add(createObjectInstances(data.children[i]));
  664. }
  665. return object;
  666. }
  667. var root = createObjectInstances(data);
  668. // Parse objects data
  669. for(var i = 0; i &lt; objects.length; i++)
  670. {
  671. objects[i].object.parse(objects[i].data, root);
  672. }
  673. return root;
  674. };
  675. export {Object2D};
  676. </code></pre>
  677. </article>
  678. </section>
  679. </div>
  680. <nav>
  681. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnimationTimer.html">AnimationTimer</a></li><li><a href="BarGraph.html">BarGraph</a></li><li><a href="BezierCurve.html">BezierCurve</a></li><li><a href="Box.html">Box</a></li><li><a href="Box2.html">Box2</a></li><li><a href="BoxMask.html">BoxMask</a></li><li><a href="Circle.html">Circle</a></li><li><a href="ColorStyle.html">ColorStyle</a></li><li><a href="DOM.html">DOM</a></li><li><a href="EventManager.html">EventManager</a></li><li><a href="FileUtils.html">FileUtils</a></li><li><a href="Gauge.html">Gauge</a></li><li><a href="GradientColorStop.html">GradientColorStop</a></li><li><a href="GradientStyle.html">GradientStyle</a></li><li><a href="Graph.html">Graph</a></li><li><a href="Helpers.html">Helpers</a></li><li><a href="Image.html">Image</a></li><li><a href="Key.html">Key</a></li><li><a href="Line.html">Line</a></li><li><a href="LinearGradientStyle.html">LinearGradientStyle</a></li><li><a href="Mask.html">Mask</a></li><li><a href="Matrix.html">Matrix</a></li><li><a href="MultiLineText.html">MultiLineText</a></li><li><a href="Node.html">Node</a></li><li><a href="NodeConnector.html">NodeConnector</a></li><li><a href="NodeGraph.html">NodeGraph</a></li><li><a href="NodeSocket.html">NodeSocket</a></li><li><a href="Object2D.html">Object2D</a></li><li><a href="Path.html">Path</a></li><li><a href="Pattern.html">Pattern</a></li><li><a href="PatternStyle.html">PatternStyle</a></li><li><a href="PieChart.html">PieChart</a></li><li><a href="Pointer.html">Pointer</a></li><li><a href="QuadraticCurve.html">QuadraticCurve</a></li><li><a href="RadialGradientStyle.html">RadialGradientStyle</a></li><li><a href="Renderer.html">Renderer</a></li><li><a href="RoundedBox.html">RoundedBox</a></li><li><a href="ScatterGraph.html">ScatterGraph</a></li><li><a href="Style.html">Style</a></li><li><a href="Text.html">Text</a></li><li><a href="UUID.html">UUID</a></li><li><a href="Vector2.html">Vector2</a></li><li><a href="Viewport.html">Viewport</a></li><li><a href="ViewportControls.html">ViewportControls</a></li></ul><h3>Global</h3><ul><li><a href="global.html#writeFile">writeFile</a></li></ul>
  682. </nav>
  683. <br class="clear">
  684. <footer>
  685. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Sep 17 2022 14:24:36 GMT+0100 (Hora de verão da Europa Ocidental)
  686. </footer>
  687. <script> prettyPrint(); </script>
  688. <script src="scripts/linenumber.js"> </script>
  689. </body>
  690. </html>