node.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. import { Scene } from "./scene";
  2. import { Nullable } from "./types";
  3. import { Matrix } from "./Maths/math";
  4. import { Engine } from "./Engines/engine";
  5. import { IBehaviorAware, Behavior } from "./Behaviors/behavior";
  6. import { serialize } from "./Misc/decorators";
  7. import { Observable, Observer } from "./Misc/observable";
  8. import { EngineStore } from "./Engines/engineStore";
  9. declare type Animatable = import("./Animations/animatable").Animatable;
  10. declare type AnimationPropertiesOverride = import("./Animations/animationPropertiesOverride").AnimationPropertiesOverride;
  11. declare type Animation = import("./Animations/animation").Animation;
  12. declare type AnimationRange = import("./Animations/animation").AnimationRange;
  13. declare type AbstractMesh = import("./Meshes/abstractMesh").AbstractMesh;
  14. /**
  15. * Defines how a node can be built from a string name.
  16. */
  17. export type NodeConstructor = (name: string, scene: Scene, options?: any) => () => Node;
  18. /**
  19. * Node is the basic class for all scene objects (Mesh, Light, Camera.)
  20. */
  21. export class Node implements IBehaviorAware<Node> {
  22. /** @hidden */
  23. public static _AnimationRangeFactory = (name: string, from: number, to: number): AnimationRange => {
  24. throw "AnimationRange needs to be imported from animation before being created.";
  25. }
  26. private static _NodeConstructors: { [key: string]: any } = {};
  27. /**
  28. * Add a new node constructor
  29. * @param type defines the type name of the node to construct
  30. * @param constructorFunc defines the constructor function
  31. */
  32. public static AddNodeConstructor(type: string, constructorFunc: NodeConstructor) {
  33. this._NodeConstructors[type] = constructorFunc;
  34. }
  35. /**
  36. * Returns a node constructor based on type name
  37. * @param type defines the type name
  38. * @param name defines the new node name
  39. * @param scene defines the hosting scene
  40. * @param options defines optional options to transmit to constructors
  41. * @returns the new constructor or null
  42. */
  43. public static Construct(type: string, name: string, scene: Scene, options?: any): Nullable<() => Node> {
  44. let constructorFunc = this._NodeConstructors[type];
  45. if (!constructorFunc) {
  46. return null;
  47. }
  48. return constructorFunc(name, scene, options);
  49. }
  50. /**
  51. * Gets or sets the name of the node
  52. */
  53. @serialize()
  54. public name: string;
  55. /**
  56. * Gets or sets the id of the node
  57. */
  58. @serialize()
  59. public id: string;
  60. /**
  61. * Gets or sets the unique id of the node
  62. */
  63. @serialize()
  64. public uniqueId: number;
  65. /**
  66. * Gets or sets a string used to store user defined state for the node
  67. */
  68. @serialize()
  69. public state = "";
  70. /**
  71. * Gets or sets an object used to store user defined information for the node
  72. */
  73. @serialize()
  74. public metadata: any = null;
  75. /**
  76. * For internal use only. Please do not use.
  77. */
  78. public reservedDataStore: any = null;
  79. /**
  80. * Gets or sets a boolean used to define if the node must be serialized
  81. */
  82. public doNotSerialize = false;
  83. /** @hidden */
  84. public _isDisposed = false;
  85. /**
  86. * Gets a list of Animations associated with the node
  87. */
  88. public animations = new Array<Animation>();
  89. protected _ranges: { [name: string]: Nullable<AnimationRange> } = {};
  90. /**
  91. * Callback raised when the node is ready to be used
  92. */
  93. public onReady: (node: Node) => void;
  94. private _isEnabled = true;
  95. private _isParentEnabled = true;
  96. private _isReady = true;
  97. /** @hidden */
  98. public _currentRenderId = -1;
  99. private _parentRenderId = -1;
  100. protected _childRenderId = -1;
  101. /** @hidden */
  102. public _waitingParentId: Nullable<string>;
  103. /** @hidden */
  104. public _scene: Scene;
  105. /** @hidden */
  106. public _cache: any;
  107. private _parentNode: Nullable<Node>;
  108. private _children: Node[];
  109. /** @hidden */
  110. public _worldMatrix = Matrix.Identity();
  111. /** @hidden */
  112. public _worldMatrixDeterminant = 0;
  113. /** @hidden */
  114. private _sceneRootNodesIndex = -1;
  115. /**
  116. * Gets a boolean indicating if the node has been disposed
  117. * @returns true if the node was disposed
  118. */
  119. public isDisposed(): boolean {
  120. return this._isDisposed;
  121. }
  122. /**
  123. * Gets or sets the parent of the node
  124. */
  125. public set parent(parent: Nullable<Node>) {
  126. if (this._parentNode === parent) {
  127. return;
  128. }
  129. const previousParentNode = this._parentNode;
  130. // Remove self from list of children of parent
  131. if (this._parentNode && this._parentNode._children !== undefined && this._parentNode._children !== null) {
  132. var index = this._parentNode._children.indexOf(this);
  133. if (index !== -1) {
  134. this._parentNode._children.splice(index, 1);
  135. }
  136. if (!parent && !this._isDisposed) {
  137. this.addToSceneRootNodes();
  138. }
  139. }
  140. // Store new parent
  141. this._parentNode = parent;
  142. // Add as child to new parent
  143. if (this._parentNode) {
  144. if (this._parentNode._children === undefined || this._parentNode._children === null) {
  145. this._parentNode._children = new Array<Node>();
  146. }
  147. this._parentNode._children.push(this);
  148. if (!previousParentNode) {
  149. this.removeFromSceneRootNodes();
  150. }
  151. }
  152. // Enabled state
  153. this._syncParentEnabledState();
  154. }
  155. public get parent(): Nullable<Node> {
  156. return this._parentNode;
  157. }
  158. private addToSceneRootNodes() {
  159. if (this._sceneRootNodesIndex === -1) {
  160. this._sceneRootNodesIndex = this._scene.rootNodes.length;
  161. this._scene.rootNodes.push(this);
  162. }
  163. }
  164. private removeFromSceneRootNodes() {
  165. if (this._sceneRootNodesIndex !== -1) {
  166. const rootNodes = this._scene.rootNodes;
  167. const lastIdx = rootNodes.length - 1;
  168. rootNodes[this._sceneRootNodesIndex] = rootNodes[lastIdx];
  169. rootNodes[this._sceneRootNodesIndex]._sceneRootNodesIndex = this._sceneRootNodesIndex;
  170. this._scene.rootNodes.pop();
  171. this._sceneRootNodesIndex = -1;
  172. }
  173. }
  174. private _animationPropertiesOverride: Nullable<AnimationPropertiesOverride> = null;
  175. /**
  176. * Gets or sets the animation properties override
  177. */
  178. public get animationPropertiesOverride(): Nullable<AnimationPropertiesOverride> {
  179. if (!this._animationPropertiesOverride) {
  180. return this._scene.animationPropertiesOverride;
  181. }
  182. return this._animationPropertiesOverride;
  183. }
  184. public set animationPropertiesOverride(value: Nullable<AnimationPropertiesOverride>) {
  185. this._animationPropertiesOverride = value;
  186. }
  187. /**
  188. * Gets a string idenfifying the name of the class
  189. * @returns "Node" string
  190. */
  191. public getClassName(): string {
  192. return "Node";
  193. }
  194. /** @hidden */
  195. public readonly _isNode = true;
  196. /**
  197. * An event triggered when the mesh is disposed
  198. */
  199. public onDisposeObservable = new Observable<Node>();
  200. private _onDisposeObserver: Nullable<Observer<Node>>;
  201. /**
  202. * Sets a callback that will be raised when the node will be disposed
  203. */
  204. public set onDispose(callback: () => void) {
  205. if (this._onDisposeObserver) {
  206. this.onDisposeObservable.remove(this._onDisposeObserver);
  207. }
  208. this._onDisposeObserver = this.onDisposeObservable.add(callback);
  209. }
  210. /**
  211. * Creates a new Node
  212. * @param name the name and id to be given to this node
  213. * @param scene the scene this node will be added to
  214. * @param addToRootNodes the node will be added to scene.rootNodes
  215. */
  216. constructor(name: string, scene: Nullable<Scene> = null, addToRootNodes = true) {
  217. this.name = name;
  218. this.id = name;
  219. this._scene = <Scene>(scene || EngineStore.LastCreatedScene);
  220. this.uniqueId = this._scene.getUniqueId();
  221. this._initCache();
  222. if (addToRootNodes) {
  223. this.addToSceneRootNodes();
  224. }
  225. }
  226. /**
  227. * Gets the scene of the node
  228. * @returns a scene
  229. */
  230. public getScene(): Scene {
  231. return this._scene;
  232. }
  233. /**
  234. * Gets the engine of the node
  235. * @returns a Engine
  236. */
  237. public getEngine(): Engine {
  238. return this._scene.getEngine();
  239. }
  240. // Behaviors
  241. private _behaviors = new Array<Behavior<Node>>();
  242. /**
  243. * Attach a behavior to the node
  244. * @see http://doc.babylonjs.com/features/behaviour
  245. * @param behavior defines the behavior to attach
  246. * @param attachImmediately defines that the behavior must be attached even if the scene is still loading
  247. * @returns the current Node
  248. */
  249. public addBehavior(behavior: Behavior<Node>, attachImmediately = false): Node {
  250. var index = this._behaviors.indexOf(behavior);
  251. if (index !== -1) {
  252. return this;
  253. }
  254. behavior.init();
  255. if (this._scene.isLoading && !attachImmediately) {
  256. // We defer the attach when the scene will be loaded
  257. this._scene.onDataLoadedObservable.addOnce(() => {
  258. behavior.attach(this);
  259. });
  260. } else {
  261. behavior.attach(this);
  262. }
  263. this._behaviors.push(behavior);
  264. return this;
  265. }
  266. /**
  267. * Remove an attached behavior
  268. * @see http://doc.babylonjs.com/features/behaviour
  269. * @param behavior defines the behavior to attach
  270. * @returns the current Node
  271. */
  272. public removeBehavior(behavior: Behavior<Node>): Node {
  273. var index = this._behaviors.indexOf(behavior);
  274. if (index === -1) {
  275. return this;
  276. }
  277. this._behaviors[index].detach();
  278. this._behaviors.splice(index, 1);
  279. return this;
  280. }
  281. /**
  282. * Gets the list of attached behaviors
  283. * @see http://doc.babylonjs.com/features/behaviour
  284. */
  285. public get behaviors(): Behavior<Node>[] {
  286. return this._behaviors;
  287. }
  288. /**
  289. * Gets an attached behavior by name
  290. * @param name defines the name of the behavior to look for
  291. * @see http://doc.babylonjs.com/features/behaviour
  292. * @returns null if behavior was not found else the requested behavior
  293. */
  294. public getBehaviorByName(name: string): Nullable<Behavior<Node>> {
  295. for (var behavior of this._behaviors) {
  296. if (behavior.name === name) {
  297. return behavior;
  298. }
  299. }
  300. return null;
  301. }
  302. /**
  303. * Returns the latest update of the World matrix
  304. * @returns a Matrix
  305. */
  306. public getWorldMatrix(): Matrix {
  307. if (this._currentRenderId !== this._scene.getRenderId()) {
  308. this.computeWorldMatrix();
  309. }
  310. return this._worldMatrix;
  311. }
  312. /** @hidden */
  313. public _getWorldMatrixDeterminant(): number {
  314. return this._worldMatrixDeterminant;
  315. }
  316. /**
  317. * Returns directly the latest state of the mesh World matrix.
  318. * A Matrix is returned.
  319. */
  320. public get worldMatrixFromCache(): Matrix {
  321. return this._worldMatrix;
  322. }
  323. // override it in derived class if you add new variables to the cache
  324. // and call the parent class method
  325. /** @hidden */
  326. public _initCache() {
  327. this._cache = {};
  328. this._cache.parent = undefined;
  329. }
  330. /** @hidden */
  331. public updateCache(force?: boolean): void {
  332. if (!force && this.isSynchronized()) {
  333. return;
  334. }
  335. this._cache.parent = this.parent;
  336. this._updateCache();
  337. }
  338. // override it in derived class if you add new variables to the cache
  339. // and call the parent class method if !ignoreParentClass
  340. /** @hidden */
  341. public _updateCache(ignoreParentClass?: boolean): void {
  342. }
  343. // override it in derived class if you add new variables to the cache
  344. /** @hidden */
  345. public _isSynchronized(): boolean {
  346. return true;
  347. }
  348. /** @hidden */
  349. public _markSyncedWithParent() {
  350. if (this._parentNode) {
  351. this._parentRenderId = this._parentNode._childRenderId;
  352. }
  353. }
  354. /** @hidden */
  355. public isSynchronizedWithParent(): boolean {
  356. if (!this._parentNode) {
  357. return true;
  358. }
  359. if (this._parentRenderId !== this._parentNode._childRenderId) {
  360. return false;
  361. }
  362. return this._parentNode.isSynchronized();
  363. }
  364. /** @hidden */
  365. public isSynchronized(): boolean {
  366. if (this._cache.parent != this._parentNode) {
  367. this._cache.parent = this._parentNode;
  368. return false;
  369. }
  370. if (this._parentNode && !this.isSynchronizedWithParent()) {
  371. return false;
  372. }
  373. return this._isSynchronized();
  374. }
  375. /**
  376. * Is this node ready to be used/rendered
  377. * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)
  378. * @return true if the node is ready
  379. */
  380. public isReady(completeCheck = false): boolean {
  381. return this._isReady;
  382. }
  383. /**
  384. * Is this node enabled?
  385. * If the node has a parent, all ancestors will be checked and false will be returned if any are false (not enabled), otherwise will return true
  386. * @param checkAncestors indicates if this method should check the ancestors. The default is to check the ancestors. If set to false, the method will return the value of this node without checking ancestors
  387. * @return whether this node (and its parent) is enabled
  388. */
  389. public isEnabled(checkAncestors: boolean = true): boolean {
  390. if (checkAncestors === false) {
  391. return this._isEnabled;
  392. }
  393. if (!this._isEnabled) {
  394. return false;
  395. }
  396. return this._isParentEnabled;
  397. }
  398. /** @hidden */
  399. protected _syncParentEnabledState() {
  400. this._isParentEnabled = this._parentNode ? this._parentNode.isEnabled() : true;
  401. if (this._children) {
  402. this._children.forEach((c) => {
  403. c._syncParentEnabledState(); // Force children to update accordingly
  404. });
  405. }
  406. }
  407. /**
  408. * Set the enabled state of this node
  409. * @param value defines the new enabled state
  410. */
  411. public setEnabled(value: boolean): void {
  412. this._isEnabled = value;
  413. this._syncParentEnabledState();
  414. }
  415. /**
  416. * Is this node a descendant of the given node?
  417. * The function will iterate up the hierarchy until the ancestor was found or no more parents defined
  418. * @param ancestor defines the parent node to inspect
  419. * @returns a boolean indicating if this node is a descendant of the given node
  420. */
  421. public isDescendantOf(ancestor: Node): boolean {
  422. if (this.parent) {
  423. if (this.parent === ancestor) {
  424. return true;
  425. }
  426. return this.parent.isDescendantOf(ancestor);
  427. }
  428. return false;
  429. }
  430. /** @hidden */
  431. public _getDescendants(results: Node[], directDescendantsOnly: boolean = false, predicate?: (node: Node) => boolean): void {
  432. if (!this._children) {
  433. return;
  434. }
  435. for (var index = 0; index < this._children.length; index++) {
  436. var item = this._children[index];
  437. if (!predicate || predicate(item)) {
  438. results.push(item);
  439. }
  440. if (!directDescendantsOnly) {
  441. item._getDescendants(results, false, predicate);
  442. }
  443. }
  444. }
  445. /**
  446. * Will return all nodes that have this node as ascendant
  447. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
  448. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  449. * @return all children nodes of all types
  450. */
  451. public getDescendants(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): Node[] {
  452. var results = new Array<Node>();
  453. this._getDescendants(results, directDescendantsOnly, predicate);
  454. return results;
  455. }
  456. /**
  457. * Get all child-meshes of this node
  458. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
  459. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  460. * @returns an array of AbstractMesh
  461. */
  462. public getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): AbstractMesh[] {
  463. var results: Array<AbstractMesh> = [];
  464. this._getDescendants(results, directDescendantsOnly, (node: Node) => {
  465. return ((!predicate || predicate(node)) && ((<AbstractMesh>node).cullingStrategy !== undefined));
  466. });
  467. return results;
  468. }
  469. /**
  470. * Get all direct children of this node
  471. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  472. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: true)
  473. * @returns an array of Node
  474. */
  475. public getChildren(predicate?: (node: Node) => boolean, directDescendantsOnly = true): Node[] {
  476. return this.getDescendants(directDescendantsOnly, predicate);
  477. }
  478. /** @hidden */
  479. public _setReady(state: boolean): void {
  480. if (state === this._isReady) {
  481. return;
  482. }
  483. if (!state) {
  484. this._isReady = false;
  485. return;
  486. }
  487. if (this.onReady) {
  488. this.onReady(this);
  489. }
  490. this._isReady = true;
  491. }
  492. /**
  493. * Get an animation by name
  494. * @param name defines the name of the animation to look for
  495. * @returns null if not found else the requested animation
  496. */
  497. public getAnimationByName(name: string): Nullable<Animation> {
  498. for (var i = 0; i < this.animations.length; i++) {
  499. var animation = this.animations[i];
  500. if (animation.name === name) {
  501. return animation;
  502. }
  503. }
  504. return null;
  505. }
  506. /**
  507. * Creates an animation range for this node
  508. * @param name defines the name of the range
  509. * @param from defines the starting key
  510. * @param to defines the end key
  511. */
  512. public createAnimationRange(name: string, from: number, to: number): void {
  513. // check name not already in use
  514. if (!this._ranges[name]) {
  515. this._ranges[name] = Node._AnimationRangeFactory(name, from, to);
  516. for (var i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {
  517. if (this.animations[i]) {
  518. this.animations[i].createRange(name, from, to);
  519. }
  520. }
  521. }
  522. }
  523. /**
  524. * Delete a specific animation range
  525. * @param name defines the name of the range to delete
  526. * @param deleteFrames defines if animation frames from the range must be deleted as well
  527. */
  528. public deleteAnimationRange(name: string, deleteFrames = true): void {
  529. for (var i = 0, nAnimations = this.animations.length; i < nAnimations; i++) {
  530. if (this.animations[i]) {
  531. this.animations[i].deleteRange(name, deleteFrames);
  532. }
  533. }
  534. this._ranges[name] = null; // said much faster than 'delete this._range[name]'
  535. }
  536. /**
  537. * Get an animation range by name
  538. * @param name defines the name of the animation range to look for
  539. * @returns null if not found else the requested animation range
  540. */
  541. public getAnimationRange(name: string): Nullable<AnimationRange> {
  542. return this._ranges[name];
  543. }
  544. /**
  545. * Will start the animation sequence
  546. * @param name defines the range frames for animation sequence
  547. * @param loop defines if the animation should loop (false by default)
  548. * @param speedRatio defines the speed factor in which to run the animation (1 by default)
  549. * @param onAnimationEnd defines a function to be executed when the animation ended (undefined by default)
  550. * @returns the object created for this animation. If range does not exist, it will return null
  551. */
  552. public beginAnimation(name: string, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): Nullable<Animatable> {
  553. var range = this.getAnimationRange(name);
  554. if (!range) {
  555. return null;
  556. }
  557. return this._scene.beginAnimation(this, range.from, range.to, loop, speedRatio, onAnimationEnd);
  558. }
  559. /**
  560. * Serialize animation ranges into a JSON compatible object
  561. * @returns serialization object
  562. */
  563. public serializeAnimationRanges(): any {
  564. var serializationRanges = [];
  565. for (var name in this._ranges) {
  566. var localRange = this._ranges[name];
  567. if (!localRange) {
  568. continue;
  569. }
  570. var range: any = {};
  571. range.name = name;
  572. range.from = localRange.from;
  573. range.to = localRange.to;
  574. serializationRanges.push(range);
  575. }
  576. return serializationRanges;
  577. }
  578. /**
  579. * Computes the world matrix of the node
  580. * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch
  581. * @returns the world matrix
  582. */
  583. public computeWorldMatrix(force?: boolean): Matrix {
  584. if (!this._worldMatrix) {
  585. this._worldMatrix = Matrix.Identity();
  586. }
  587. return this._worldMatrix;
  588. }
  589. /**
  590. * Releases resources associated with this node.
  591. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  592. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  593. */
  594. public dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false): void {
  595. this._isDisposed = true;
  596. if (!doNotRecurse) {
  597. const nodes = this.getDescendants(true);
  598. for (const node of nodes) {
  599. node.dispose(doNotRecurse, disposeMaterialAndTextures);
  600. }
  601. }
  602. if (!this.parent) {
  603. this.removeFromSceneRootNodes();
  604. } else {
  605. this.parent = null;
  606. }
  607. // Callback
  608. this.onDisposeObservable.notifyObservers(this);
  609. this.onDisposeObservable.clear();
  610. // Behaviors
  611. for (var behavior of this._behaviors) {
  612. behavior.detach();
  613. }
  614. this._behaviors = [];
  615. }
  616. /**
  617. * Parse animation range data from a serialization object and store them into a given node
  618. * @param node defines where to store the animation ranges
  619. * @param parsedNode defines the serialization object to read data from
  620. * @param scene defines the hosting scene
  621. */
  622. public static ParseAnimationRanges(node: Node, parsedNode: any, scene: Scene): void {
  623. if (parsedNode.ranges) {
  624. for (var index = 0; index < parsedNode.ranges.length; index++) {
  625. var data = parsedNode.ranges[index];
  626. node.createAnimationRange(data.name, data.from, data.to);
  627. }
  628. }
  629. }
  630. }