actionManager.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. module BABYLON {
  2. /**
  3. * ActionEvent is the event being sent when an action is triggered.
  4. */
  5. export class ActionEvent {
  6. /**
  7. * Creates a new ActionEvent
  8. * @param source The mesh or sprite that triggered the action
  9. * @param pointerX The X mouse cursor position at the time of the event
  10. * @param pointerY The Y mouse cursor position at the time of the event
  11. * @param meshUnderPointer The mesh that is currently pointed at (can be null)
  12. * @param sourceEvent the original (browser) event that triggered the ActionEvent
  13. * @param additionalData additional data for the event
  14. */
  15. constructor(
  16. /** The mesh or sprite that triggered the action */
  17. public source: any,
  18. /** The X mouse cursor position at the time of the event */
  19. public pointerX: number,
  20. /** The Y mouse cursor position at the time of the event */
  21. public pointerY: number,
  22. /** The mesh that is currently pointed at (can be null) */
  23. public meshUnderPointer: Nullable<AbstractMesh>,
  24. /** the original (browser) event that triggered the ActionEvent */
  25. public sourceEvent?: any,
  26. /** additional data for the event */
  27. public additionalData?: any) {
  28. }
  29. /**
  30. * Helper function to auto-create an ActionEvent from a source mesh.
  31. * @param source The source mesh that triggered the event
  32. * @param evt The original (browser) event
  33. * @param additionalData additional data for the event
  34. * @returns the new ActionEvent
  35. */
  36. public static CreateNew(source: AbstractMesh, evt?: Event, additionalData?: any): ActionEvent {
  37. var scene = source.getScene();
  38. return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt, additionalData);
  39. }
  40. /**
  41. * Helper function to auto-create an ActionEvent from a source sprite
  42. * @param source The source sprite that triggered the event
  43. * @param scene Scene associated with the sprite
  44. * @param evt The original (browser) event
  45. * @param additionalData additional data for the event
  46. * @returns the new ActionEvent
  47. */
  48. public static CreateNewFromSprite(source: Sprite, scene: Scene, evt?: Event, additionalData?: any): ActionEvent {
  49. return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt, additionalData);
  50. }
  51. /**
  52. * Helper function to auto-create an ActionEvent from a scene. If triggered by a mesh use ActionEvent.CreateNew
  53. * @param scene the scene where the event occurred
  54. * @param evt The original (browser) event
  55. * @returns the new ActionEvent
  56. */
  57. public static CreateNewFromScene(scene: Scene, evt: Event): ActionEvent {
  58. return new ActionEvent(null, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
  59. }
  60. /**
  61. * Helper function to auto-create an ActionEvent from a primitive
  62. * @param prim defines the target primitive
  63. * @param pointerPos defines the pointer position
  64. * @param evt The original (browser) event
  65. * @param additionalData additional data for the event
  66. * @returns the new ActionEvent
  67. */
  68. public static CreateNewFromPrimitive(prim: any, pointerPos: Vector2, evt?: Event, additionalData?: any): ActionEvent {
  69. return new ActionEvent(prim, pointerPos.x, pointerPos.y, null, evt, additionalData);
  70. }
  71. }
  72. /**
  73. * Action Manager manages all events to be triggered on a given mesh or the global scene.
  74. * A single scene can have many Action Managers to handle predefined actions on specific meshes.
  75. * @see http://doc.babylonjs.com/how_to/how_to_use_actions
  76. */
  77. export class ActionManager {
  78. /**
  79. * Nothing
  80. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  81. */
  82. public static readonly NothingTrigger = 0;
  83. /**
  84. * On pick
  85. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  86. */
  87. public static readonly OnPickTrigger = 1;
  88. /**
  89. * On left pick
  90. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  91. */
  92. public static readonly OnLeftPickTrigger = 2;
  93. /**
  94. * On right pick
  95. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  96. */
  97. public static readonly OnRightPickTrigger = 3;
  98. /**
  99. * On center pick
  100. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  101. */
  102. public static readonly OnCenterPickTrigger = 4;
  103. /**
  104. * On pick down
  105. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  106. */
  107. public static readonly OnPickDownTrigger = 5;
  108. /**
  109. * On double pick
  110. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  111. */
  112. public static readonly OnDoublePickTrigger = 6;
  113. /**
  114. * On pick up
  115. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  116. */
  117. public static readonly OnPickUpTrigger = 7;
  118. /**
  119. * On pick out.
  120. * This trigger will only be raised if you also declared a OnPickDown
  121. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  122. */
  123. public static readonly OnPickOutTrigger = 16;
  124. /**
  125. * On long press
  126. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  127. */
  128. public static readonly OnLongPressTrigger = 8;
  129. /**
  130. * On pointer over
  131. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  132. */
  133. public static readonly OnPointerOverTrigger = 9;
  134. /**
  135. * On pointer out
  136. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  137. */
  138. public static readonly OnPointerOutTrigger = 10;
  139. /**
  140. * On every frame
  141. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  142. */
  143. public static readonly OnEveryFrameTrigger = 11;
  144. /**
  145. * On intersection enter
  146. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  147. */
  148. public static readonly OnIntersectionEnterTrigger = 12;
  149. /**
  150. * On intersection exit
  151. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  152. */
  153. public static readonly OnIntersectionExitTrigger = 13;
  154. /**
  155. * On key down
  156. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  157. */
  158. public static readonly OnKeyDownTrigger = 14;
  159. /**
  160. * On key up
  161. * @see http://doc.babylonjs.com/how_to/how_to_use_actions#triggers
  162. */
  163. public static readonly OnKeyUpTrigger = 15;
  164. /** Gets the list of active triggers */
  165. public static Triggers: { [key: string]: number } = {};
  166. // Members
  167. /** Gets the list of actions */
  168. public actions = new Array<Action>();
  169. /** Gets the cursor to use when hovering items */
  170. public hoverCursor: string = '';
  171. private _scene: Scene;
  172. /**
  173. * Creates a new action manager
  174. * @param scene defines the hosting scene
  175. */
  176. constructor(scene: Scene) {
  177. this._scene = scene || Engine.LastCreatedScene;
  178. scene.actionManagers.push(this);
  179. }
  180. // Methods
  181. /**
  182. * Releases all associated resources
  183. */
  184. public dispose(): void {
  185. var index = this._scene.actionManagers.indexOf(this);
  186. for (var i = 0; i < this.actions.length; i++) {
  187. var action = this.actions[i];
  188. ActionManager.Triggers[action.trigger]--;
  189. if (ActionManager.Triggers[action.trigger] === 0) {
  190. delete ActionManager.Triggers[action.trigger];
  191. }
  192. }
  193. if (index > -1) {
  194. this._scene.actionManagers.splice(index, 1);
  195. }
  196. }
  197. /**
  198. * Gets hosting scene
  199. * @returns the hosting scene
  200. */
  201. public getScene(): Scene {
  202. return this._scene;
  203. }
  204. /**
  205. * Does this action manager handles actions of any of the given triggers
  206. * @param triggers defines the triggers to be tested
  207. * @return a boolean indicating whether one (or more) of the triggers is handled
  208. */
  209. public hasSpecificTriggers(triggers: number[]): boolean {
  210. for (var index = 0; index < this.actions.length; index++) {
  211. var action = this.actions[index];
  212. if (triggers.indexOf(action.trigger) > -1) {
  213. return true;
  214. }
  215. }
  216. return false;
  217. }
  218. /**
  219. * Does this action manager handles actions of any of the given triggers. This function takes two arguments for
  220. * speed.
  221. * @param triggerA defines the trigger to be tested
  222. * @param triggerB defines the trigger to be tested
  223. * @return a boolean indicating whether one (or more) of the triggers is handled
  224. */
  225. public hasSpecificTriggers2(triggerA: number, triggerB: number): boolean {
  226. for (var index = 0; index < this.actions.length; index++) {
  227. var action = this.actions[index];
  228. if (triggerA == action.trigger || triggerB == action.trigger) {
  229. return true;
  230. }
  231. }
  232. return false;
  233. }
  234. /**
  235. * Does this action manager handles actions of a given trigger
  236. * @param trigger defines the trigger to be tested
  237. * @param parameterPredicate defines an optional predicate to filter triggers by parameter
  238. * @return whether the trigger is handled
  239. */
  240. public hasSpecificTrigger(trigger: number, parameterPredicate?: (parameter: any) => boolean): boolean {
  241. for (var index = 0; index < this.actions.length; index++) {
  242. var action = this.actions[index];
  243. if (action.trigger === trigger) {
  244. if (parameterPredicate) {
  245. if (parameterPredicate(action.getTriggerParameter())) {
  246. return true;
  247. }
  248. } else {
  249. return true;
  250. }
  251. }
  252. }
  253. return false;
  254. }
  255. /**
  256. * Does this action manager has pointer triggers
  257. */
  258. public get hasPointerTriggers(): boolean {
  259. for (var index = 0; index < this.actions.length; index++) {
  260. var action = this.actions[index];
  261. if (action.trigger >= ActionManager.OnPickTrigger && action.trigger <= ActionManager.OnPointerOutTrigger) {
  262. return true;
  263. }
  264. }
  265. return false;
  266. }
  267. /**
  268. * Does this action manager has pick triggers
  269. */
  270. public get hasPickTriggers(): boolean {
  271. for (var index = 0; index < this.actions.length; index++) {
  272. var action = this.actions[index];
  273. if (action.trigger >= ActionManager.OnPickTrigger && action.trigger <= ActionManager.OnPickUpTrigger) {
  274. return true;
  275. }
  276. }
  277. return false;
  278. }
  279. /**
  280. * Does exist one action manager with at least one trigger
  281. **/
  282. public static get HasTriggers(): boolean {
  283. for (var t in ActionManager.Triggers) {
  284. if (ActionManager.Triggers.hasOwnProperty(t)) {
  285. return true;
  286. }
  287. }
  288. return false;
  289. }
  290. /**
  291. * Does exist one action manager with at least one pick trigger
  292. **/
  293. public static get HasPickTriggers(): boolean {
  294. for (var t in ActionManager.Triggers) {
  295. if (ActionManager.Triggers.hasOwnProperty(t)) {
  296. let t_int = parseInt(t);
  297. if (t_int >= ActionManager.OnPickTrigger && t_int <= ActionManager.OnPickUpTrigger) {
  298. return true;
  299. }
  300. }
  301. }
  302. return false;
  303. }
  304. /**
  305. * Does exist one action manager that handles actions of a given trigger
  306. * @param trigger defines the trigger to be tested
  307. * @return a boolean indicating whether the trigger is handeled by at least one action manager
  308. **/
  309. public static HasSpecificTrigger(trigger: number): boolean {
  310. for (var t in ActionManager.Triggers) {
  311. if (ActionManager.Triggers.hasOwnProperty(t)) {
  312. let t_int = parseInt(t);
  313. if (t_int === trigger) {
  314. return true;
  315. }
  316. }
  317. }
  318. return false;
  319. }
  320. /**
  321. * Registers an action to this action manager
  322. * @param action defines the action to be registered
  323. * @return the action amended (prepared) after registration
  324. */
  325. public registerAction(action: Action): Nullable<Action> {
  326. if (action.trigger === ActionManager.OnEveryFrameTrigger) {
  327. if (this.getScene().actionManager !== this) {
  328. Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
  329. return null;
  330. }
  331. }
  332. this.actions.push(action);
  333. if (ActionManager.Triggers[action.trigger]) {
  334. ActionManager.Triggers[action.trigger]++;
  335. }
  336. else {
  337. ActionManager.Triggers[action.trigger] = 1;
  338. }
  339. action._actionManager = this;
  340. action._prepare();
  341. return action;
  342. }
  343. /**
  344. * Unregisters an action to this action manager
  345. * @param action defines the action to be unregistered
  346. * @return a boolean indicating whether the action has been unregistered
  347. */
  348. public unregisterAction(action: Action): Boolean {
  349. var index = this.actions.indexOf(action);
  350. if (index !== -1) {
  351. this.actions.splice(index, 1);
  352. ActionManager.Triggers[action.trigger] -= 1;
  353. if (ActionManager.Triggers[action.trigger] === 0) {
  354. delete ActionManager.Triggers[action.trigger];
  355. }
  356. delete action._actionManager;
  357. return true;
  358. }
  359. return false;
  360. }
  361. /**
  362. * Process a specific trigger
  363. * @param trigger defines the trigger to process
  364. * @param evt defines the event details to be processed
  365. */
  366. public processTrigger(trigger: number, evt?: ActionEvent): void {
  367. for (var index = 0; index < this.actions.length; index++) {
  368. var action = this.actions[index];
  369. if (action.trigger === trigger) {
  370. if (evt) {
  371. if (trigger === ActionManager.OnKeyUpTrigger
  372. || trigger === ActionManager.OnKeyDownTrigger) {
  373. var parameter = action.getTriggerParameter();
  374. if (parameter && parameter !== evt.sourceEvent.keyCode) {
  375. if (!parameter.toLowerCase) {
  376. continue;
  377. }
  378. var lowerCase = parameter.toLowerCase();
  379. if (lowerCase !== evt.sourceEvent.key) {
  380. var unicode = evt.sourceEvent.charCode ? evt.sourceEvent.charCode : evt.sourceEvent.keyCode;
  381. var actualkey = String.fromCharCode(unicode).toLowerCase();
  382. if (actualkey !== lowerCase) {
  383. continue;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. action._executeCurrent(evt);
  390. }
  391. }
  392. }
  393. /** @hidden */
  394. public _getEffectiveTarget(target: any, propertyPath: string): any {
  395. var properties = propertyPath.split(".");
  396. for (var index = 0; index < properties.length - 1; index++) {
  397. target = target[properties[index]];
  398. }
  399. return target;
  400. }
  401. /** @hidden */
  402. public _getProperty(propertyPath: string): string {
  403. var properties = propertyPath.split(".");
  404. return properties[properties.length - 1];
  405. }
  406. /**
  407. * Serialize this manager to a JSON object
  408. * @param name defines the property name to store this manager
  409. * @returns a JSON representation of this manager
  410. */
  411. public serialize(name: string): any {
  412. var root = {
  413. children: new Array(),
  414. name: name,
  415. type: 3, // Root node
  416. properties: new Array() // Empty for root but required
  417. };
  418. for (var i = 0; i < this.actions.length; i++) {
  419. var triggerObject = {
  420. type: 0, // Trigger
  421. children: new Array(),
  422. name: ActionManager.GetTriggerName(this.actions[i].trigger),
  423. properties: new Array()
  424. };
  425. var triggerOptions = this.actions[i].triggerOptions;
  426. if (triggerOptions && typeof triggerOptions !== "number") {
  427. if (triggerOptions.parameter instanceof Node) {
  428. triggerObject.properties.push(Action._GetTargetProperty(triggerOptions.parameter));
  429. }
  430. else {
  431. var parameter = <any>{};
  432. Tools.DeepCopy(triggerOptions.parameter, parameter, ["mesh"]);
  433. if (triggerOptions.parameter && triggerOptions.parameter.mesh) {
  434. parameter._meshId = triggerOptions.parameter.mesh.id;
  435. }
  436. triggerObject.properties.push({ name: "parameter", targetType: null, value: parameter });
  437. }
  438. }
  439. // Serialize child action, recursively
  440. this.actions[i].serialize(triggerObject);
  441. // Add serialized trigger
  442. root.children.push(triggerObject);
  443. }
  444. return root;
  445. }
  446. /**
  447. * Creates a new ActionManager from a JSON data
  448. * @param parsedActions defines the JSON data to read from
  449. * @param object defines the hosting mesh
  450. * @param scene defines the hosting scene
  451. */
  452. public static Parse(parsedActions: any, object: Nullable<AbstractMesh>, scene: Scene): void {
  453. var actionManager = new ActionManager(scene);
  454. if (object === null) {
  455. scene.actionManager = actionManager;
  456. }
  457. else {
  458. object.actionManager = actionManager;
  459. }
  460. // instanciate a new object
  461. var instanciate = (name: string, params: Array<any>): any => {
  462. // TODO: We will need to find a solution for the next line when using commonjs / es6 .
  463. var newInstance: Object = Object.create(Tools.Instantiate("BABYLON." + name).prototype);
  464. newInstance.constructor.apply(newInstance, params);
  465. return newInstance;
  466. };
  467. var parseParameter = (name: string, value: string, target: any, propertyPath: Nullable<string>): any => {
  468. if (propertyPath === null) {
  469. // String, boolean or float
  470. var floatValue = parseFloat(value);
  471. if (value === "true" || value === "false") {
  472. return value === "true";
  473. }
  474. else {
  475. return isNaN(floatValue) ? value : floatValue;
  476. }
  477. }
  478. var effectiveTarget = propertyPath.split(".");
  479. var values = value.split(",");
  480. // Get effective Target
  481. for (var i = 0; i < effectiveTarget.length; i++) {
  482. target = target[effectiveTarget[i]];
  483. }
  484. // Return appropriate value with its type
  485. if (typeof (target) === "boolean") {
  486. return values[0] === "true";
  487. }
  488. if (typeof (target) === "string") {
  489. return values[0];
  490. }
  491. // Parameters with multiple values such as Vector3 etc.
  492. var split = new Array<number>();
  493. for (var i = 0; i < values.length; i++) {
  494. split.push(parseFloat(values[i]));
  495. }
  496. if (target instanceof Vector3) {
  497. return Vector3.FromArray(split);
  498. }
  499. if (target instanceof Vector4) {
  500. return Vector4.FromArray(split);
  501. }
  502. if (target instanceof Color3) {
  503. return Color3.FromArray(split);
  504. }
  505. if (target instanceof Color4) {
  506. return Color4.FromArray(split);
  507. }
  508. return parseFloat(values[0]);
  509. };
  510. // traverse graph per trigger
  511. var traverse = (parsedAction: any, trigger: any, condition: Nullable<Condition>, action: Nullable<Action>, combineArray: Nullable<Array<Action>> = null) => {
  512. if (parsedAction.detached) {
  513. return;
  514. }
  515. var parameters = new Array<any>();
  516. var target: any = null;
  517. var propertyPath: Nullable<string> = null;
  518. var combine = parsedAction.combine && parsedAction.combine.length > 0;
  519. // Parameters
  520. if (parsedAction.type === 2) {
  521. parameters.push(actionManager);
  522. }
  523. else {
  524. parameters.push(trigger);
  525. }
  526. if (combine) {
  527. var actions = new Array<Action>();
  528. for (var j = 0; j < parsedAction.combine.length; j++) {
  529. traverse(parsedAction.combine[j], ActionManager.NothingTrigger, condition, action, actions);
  530. }
  531. parameters.push(actions);
  532. }
  533. else {
  534. for (var i = 0; i < parsedAction.properties.length; i++) {
  535. var value = parsedAction.properties[i].value;
  536. var name = parsedAction.properties[i].name;
  537. var targetType = parsedAction.properties[i].targetType;
  538. if (name === "target") {
  539. if (targetType !== null && targetType === "SceneProperties") {
  540. value = target = scene;
  541. }
  542. else {
  543. value = target = scene.getNodeByName(value);
  544. }
  545. }
  546. else if (name === "parent") {
  547. value = scene.getNodeByName(value);
  548. }
  549. else if (name === "sound") {
  550. // Can not externalize to component, so only checks for the presence off the API.
  551. if (scene.getSoundByName) {
  552. value = scene.getSoundByName(value);
  553. }
  554. }
  555. else if (name !== "propertyPath") {
  556. if (parsedAction.type === 2 && name === "operator") {
  557. value = (<any>ValueCondition)[value];
  558. }
  559. else {
  560. value = parseParameter(name, value, target, name === "value" ? propertyPath : null);
  561. }
  562. } else {
  563. propertyPath = value;
  564. }
  565. parameters.push(value);
  566. }
  567. }
  568. if (combineArray === null) {
  569. parameters.push(condition);
  570. }
  571. else {
  572. parameters.push(null);
  573. }
  574. // If interpolate value action
  575. if (parsedAction.name === "InterpolateValueAction") {
  576. var param = parameters[parameters.length - 2];
  577. parameters[parameters.length - 1] = param;
  578. parameters[parameters.length - 2] = condition;
  579. }
  580. // Action or condition(s) and not CombineAction
  581. var newAction = instanciate(parsedAction.name, parameters);
  582. if (newAction instanceof Condition && condition !== null) {
  583. var nothing = new DoNothingAction(trigger, condition);
  584. if (action) {
  585. action.then(nothing);
  586. }
  587. else {
  588. actionManager.registerAction(nothing);
  589. }
  590. action = nothing;
  591. }
  592. if (combineArray === null) {
  593. if (newAction instanceof Condition) {
  594. condition = newAction;
  595. newAction = action;
  596. } else {
  597. condition = null;
  598. if (action) {
  599. action.then(newAction);
  600. }
  601. else {
  602. actionManager.registerAction(newAction);
  603. }
  604. }
  605. }
  606. else {
  607. combineArray.push(newAction);
  608. }
  609. for (var i = 0; i < parsedAction.children.length; i++) {
  610. traverse(parsedAction.children[i], trigger, condition, newAction, null);
  611. }
  612. };
  613. // triggers
  614. for (var i = 0; i < parsedActions.children.length; i++) {
  615. var triggerParams: any;
  616. var trigger = parsedActions.children[i];
  617. if (trigger.properties.length > 0) {
  618. var param = trigger.properties[0].value;
  619. var value = trigger.properties[0].targetType === null ? param : scene.getMeshByName(param);
  620. if (value._meshId) {
  621. value.mesh = scene.getMeshByID(value._meshId);
  622. }
  623. triggerParams = { trigger: (<any>ActionManager)[trigger.name], parameter: value };
  624. }
  625. else {
  626. triggerParams = (<any>ActionManager)[trigger.name];
  627. }
  628. for (var j = 0; j < trigger.children.length; j++) {
  629. if (!trigger.detached) {
  630. traverse(trigger.children[j], triggerParams, null, null);
  631. }
  632. }
  633. }
  634. }
  635. /**
  636. * Get a trigger name by index
  637. * @param trigger defines the trigger index
  638. * @returns a trigger name
  639. */
  640. public static GetTriggerName(trigger: number): string {
  641. switch (trigger) {
  642. case 0: return "NothingTrigger";
  643. case 1: return "OnPickTrigger";
  644. case 2: return "OnLeftPickTrigger";
  645. case 3: return "OnRightPickTrigger";
  646. case 4: return "OnCenterPickTrigger";
  647. case 5: return "OnPickDownTrigger";
  648. case 6: return "OnPickUpTrigger";
  649. case 7: return "OnLongPressTrigger";
  650. case 8: return "OnPointerOverTrigger";
  651. case 9: return "OnPointerOutTrigger";
  652. case 10: return "OnEveryFrameTrigger";
  653. case 11: return "OnIntersectionEnterTrigger";
  654. case 12: return "OnIntersectionExitTrigger";
  655. case 13: return "OnKeyDownTrigger";
  656. case 14: return "OnKeyUpTrigger";
  657. case 15: return "OnPickOutTrigger";
  658. default: return "";
  659. }
  660. }
  661. }
  662. }