actionsbuilder.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. var ActionsBuilder;
  2. (function (ActionsBuilder) {
  3. /**
  4. * Defines static types
  5. */
  6. var Type = (function () {
  7. function Type() {
  8. }
  9. Object.defineProperty(Type, "TRIGGER", {
  10. get: function () {
  11. return Type._TRIGGER;
  12. },
  13. enumerable: true,
  14. configurable: true
  15. });
  16. Object.defineProperty(Type, "ACTION", {
  17. get: function () {
  18. return Type._ACTION;
  19. },
  20. enumerable: true,
  21. configurable: true
  22. });
  23. Object.defineProperty(Type, "FLOW_CONTROL", {
  24. get: function () {
  25. return Type._FLOW_CONTROL;
  26. },
  27. enumerable: true,
  28. configurable: true
  29. });
  30. Object.defineProperty(Type, "OBJECT", {
  31. get: function () {
  32. return Type._OBJECT;
  33. },
  34. enumerable: true,
  35. configurable: true
  36. });
  37. Object.defineProperty(Type, "SCENE", {
  38. get: function () {
  39. return Type._SCENE;
  40. },
  41. enumerable: true,
  42. configurable: true
  43. });
  44. Type._TRIGGER = 0;
  45. Type._ACTION = 1;
  46. Type._FLOW_CONTROL = 2;
  47. Type._OBJECT = 3;
  48. Type._SCENE = 4;
  49. return Type;
  50. })();
  51. ActionsBuilder.Type = Type;
  52. /*
  53. * Defines the BABYLON.JS elements
  54. */
  55. var SceneElements = (function () {
  56. function SceneElements() {
  57. }
  58. Object.defineProperty(SceneElements, "ENGINE", {
  59. get: function () {
  60. return SceneElements._ENGINE;
  61. },
  62. enumerable: true,
  63. configurable: true
  64. });
  65. Object.defineProperty(SceneElements, "SCENE", {
  66. get: function () {
  67. return SceneElements._SCENE;
  68. },
  69. enumerable: true,
  70. configurable: true
  71. });
  72. Object.defineProperty(SceneElements, "MESH", {
  73. get: function () {
  74. return SceneElements._MESH;
  75. },
  76. enumerable: true,
  77. configurable: true
  78. });
  79. Object.defineProperty(SceneElements, "LIGHT", {
  80. get: function () {
  81. return SceneElements._LIGHT;
  82. },
  83. enumerable: true,
  84. configurable: true
  85. });
  86. Object.defineProperty(SceneElements, "CAMERA", {
  87. get: function () {
  88. return SceneElements._CAMERA;
  89. },
  90. enumerable: true,
  91. configurable: true
  92. });
  93. Object.defineProperty(SceneElements, "MESHES", {
  94. get: function () {
  95. return SceneElements._MESHES;
  96. },
  97. enumerable: true,
  98. configurable: true
  99. });
  100. Object.defineProperty(SceneElements, "LIGHTS", {
  101. get: function () {
  102. return SceneElements._LIGHTS;
  103. },
  104. enumerable: true,
  105. configurable: true
  106. });
  107. Object.defineProperty(SceneElements, "CAMERAS", {
  108. get: function () {
  109. return SceneElements._CAMERAS;
  110. },
  111. enumerable: true,
  112. configurable: true
  113. });
  114. Object.defineProperty(SceneElements, "SOUNDS", {
  115. get: function () {
  116. return SceneElements._SOUNDS;
  117. },
  118. enumerable: true,
  119. configurable: true
  120. });
  121. Object.defineProperty(SceneElements, "MESH_PROPERTIES", {
  122. get: function () {
  123. return SceneElements._MESH_PROPERTIES;
  124. },
  125. enumerable: true,
  126. configurable: true
  127. });
  128. Object.defineProperty(SceneElements, "LIGHT_PROPERTIES", {
  129. get: function () {
  130. return SceneElements._LIGHT_PROPERTIES;
  131. },
  132. enumerable: true,
  133. configurable: true
  134. });
  135. Object.defineProperty(SceneElements, "CAMERA_PROPERTIES", {
  136. get: function () {
  137. return SceneElements._CAMERA_PROPERTIES;
  138. },
  139. enumerable: true,
  140. configurable: true
  141. });
  142. Object.defineProperty(SceneElements, "SCENE_PROPERTIES", {
  143. get: function () {
  144. return SceneElements._SCENE_PROPERTIES;
  145. },
  146. enumerable: true,
  147. configurable: true
  148. });
  149. Object.defineProperty(SceneElements, "TYPES", {
  150. get: function () {
  151. return SceneElements._TYPES;
  152. },
  153. enumerable: true,
  154. configurable: true
  155. });
  156. Object.defineProperty(SceneElements, "OPERATORS", {
  157. get: function () {
  158. return SceneElements._OPERATORS;
  159. },
  160. enumerable: true,
  161. configurable: true
  162. });
  163. /*
  164. * Methods
  165. */
  166. SceneElements.GetInstanceOf = function (object) {
  167. if (object === null || object === undefined) {
  168. return "";
  169. }
  170. return object.constructor.toString().match(/function (\w*)/)[1];
  171. };
  172. SceneElements.TestInstanceOf = function (object, propertyName) {
  173. if (object === null || object.constructor === null) {
  174. return false;
  175. }
  176. if (propertyName.length > 0 && propertyName[0] === "_")
  177. return false;
  178. var name = SceneElements.GetInstanceOf(object);
  179. for (var i = 0; i < SceneElements.TYPES.length; i++) {
  180. if (name === SceneElements.TYPES[i]) {
  181. return true;
  182. }
  183. }
  184. return false;
  185. };
  186. /*
  187. * BabylonJS objects
  188. */
  189. SceneElements._ENGINE = new BABYLON.Engine(document.getElementById("RenderCanvasID"));
  190. SceneElements._SCENE = new BABYLON.Scene(SceneElements.ENGINE);
  191. SceneElements._MESH = new BABYLON.Mesh("mesh", SceneElements._SCENE);
  192. SceneElements._LIGHT = new BABYLON.Light("light", SceneElements._SCENE);
  193. SceneElements._CAMERA = new BABYLON.Camera("camera", BABYLON.Vector3.Zero(), SceneElements._SCENE);
  194. /*
  195. * Objects names
  196. */
  197. SceneElements._MESHES = new Array();
  198. SceneElements._LIGHTS = new Array();
  199. SceneElements._CAMERAS = new Array();
  200. SceneElements._SOUNDS = new Array();
  201. /*
  202. * Properties
  203. */
  204. SceneElements._MESH_PROPERTIES = new Array();
  205. SceneElements._LIGHT_PROPERTIES = new Array();
  206. SceneElements._CAMERA_PROPERTIES = new Array();
  207. SceneElements._SCENE_PROPERTIES = new Array();
  208. /*
  209. * Types
  210. */
  211. SceneElements._TYPES = new Array();
  212. /*
  213. * Operators
  214. */
  215. SceneElements._OPERATORS = new Array();
  216. return SceneElements;
  217. })();
  218. ActionsBuilder.SceneElements = SceneElements;
  219. // Functions
  220. var specialTypes = [
  221. "StandardMaterial"
  222. ];
  223. SceneElements.MESH.material = new BABYLON.StandardMaterial("material", SceneElements.SCENE);
  224. var addSpecialType = function (object, properties, thing) {
  225. for (var specialThing in object[thing]) {
  226. if (object[thing].hasOwnProperty(specialThing) && SceneElements.TestInstanceOf(object[thing][specialThing], specialThing)) {
  227. properties.push(thing + "." + specialThing);
  228. }
  229. }
  230. };
  231. // Configure types
  232. SceneElements.TYPES.push("Color3");
  233. SceneElements.TYPES.push("Boolean");
  234. SceneElements.TYPES.push("Number");
  235. SceneElements.TYPES.push("Vector2");
  236. SceneElements.TYPES.push("Vector3");
  237. SceneElements.TYPES.push("String");
  238. // Configure operators
  239. SceneElements.OPERATORS.push("IsEqual");
  240. SceneElements.OPERATORS.push("IsDifferent");
  241. SceneElements.OPERATORS.push("IsGreater");
  242. SceneElements.OPERATORS.push("IsLesser");
  243. // Configure properties
  244. for (var thing in SceneElements.MESH) {
  245. var instance = SceneElements.GetInstanceOf(SceneElements.MESH[thing]);
  246. if (SceneElements.MESH.hasOwnProperty(thing)) {
  247. if (specialTypes.indexOf(instance) !== -1) {
  248. addSpecialType(SceneElements.MESH, SceneElements.MESH_PROPERTIES, thing);
  249. }
  250. else if (SceneElements.TestInstanceOf(SceneElements.MESH[thing], thing)) {
  251. SceneElements.MESH_PROPERTIES.push(thing);
  252. }
  253. }
  254. }
  255. for (var thing in SceneElements.LIGHT) {
  256. if (SceneElements.LIGHT.hasOwnProperty(thing) && SceneElements.TestInstanceOf(SceneElements.LIGHT[thing], thing)) {
  257. SceneElements.LIGHT_PROPERTIES.push(thing);
  258. }
  259. }
  260. for (var thing in SceneElements.CAMERA) {
  261. if (SceneElements.CAMERA.hasOwnProperty(thing) && SceneElements.TestInstanceOf(SceneElements.CAMERA[thing], thing)) {
  262. SceneElements.CAMERA_PROPERTIES.push(thing);
  263. }
  264. }
  265. for (var thing in SceneElements.SCENE) {
  266. if (SceneElements.SCENE.hasOwnProperty(thing) && SceneElements.TestInstanceOf(SceneElements.SCENE[thing], thing)) {
  267. SceneElements.SCENE_PROPERTIES.push(thing);
  268. }
  269. }
  270. /**
  271. * Actions Builder elements (triggers, actions & flow controls) that are
  272. * arrays of Element
  273. */
  274. var Elements = (function () {
  275. function Elements() {
  276. }
  277. Object.defineProperty(Elements, "TRIGGERS", {
  278. get: function () {
  279. return Elements._TRIGGERS;
  280. },
  281. enumerable: true,
  282. configurable: true
  283. });
  284. Object.defineProperty(Elements, "ACTIONS", {
  285. get: function () {
  286. return Elements._ACTIONS;
  287. },
  288. enumerable: true,
  289. configurable: true
  290. });
  291. Object.defineProperty(Elements, "FLOW_CONTROLS", {
  292. get: function () {
  293. return Elements._FLOW_CONTROLS;
  294. },
  295. enumerable: true,
  296. configurable: true
  297. });
  298. Elements.GetElementFromName = function (name) {
  299. for (var i = 0; i < Elements.TRIGGERS.length; i++) {
  300. if (Elements.TRIGGERS[i].name === name) {
  301. return Elements._TRIGGERS[i];
  302. }
  303. }
  304. for (var i = 0; i < Elements.ACTIONS.length; i++) {
  305. if (Elements.ACTIONS[i].name === name) {
  306. return Elements._ACTIONS[i];
  307. }
  308. }
  309. for (var i = 0; i < Elements.FLOW_CONTROLS.length; i++) {
  310. if (Elements.FLOW_CONTROLS[i].name === name) {
  311. return Elements._FLOW_CONTROLS[i];
  312. }
  313. }
  314. return null;
  315. };
  316. Elements._TRIGGERS = new Array();
  317. Elements._ACTIONS = new Array();
  318. Elements._FLOW_CONTROLS = new Array();
  319. return Elements;
  320. })();
  321. ActionsBuilder.Elements = Elements;
  322. // Configure triggers
  323. Elements.TRIGGERS.push({ name: "OnPickTrigger", text: "pick", properties: [], description: "When the user picks the edited mesh" });
  324. Elements.TRIGGERS.push({ name: "OnLeftPickTrigger", text: "left pick", properties: [], description: "When the user picks the edited mesh using the left click" });
  325. Elements.TRIGGERS.push({ name: "OnRightPickTrigger", text: "right pick", properties: [], description: "When the user picks the edited mesh using the right click" });
  326. Elements.TRIGGERS.push({ name: "OnCenterPickTrigger", text: "center pick", properties: [], description: "When the user picks the edited mesh using the click of the mouse wheel" });
  327. Elements.TRIGGERS.push({ name: "OnPointerOverTrigger", text: "pointer over", properties: [], description: "When the user's mouse is over the edited mesh" });
  328. Elements.TRIGGERS.push({ name: "OnPointerOutTrigger", text: "pointer out", properties: [], description: "When the user's mouse is out of the edited mesh" });
  329. Elements.TRIGGERS.push({ name: "OnEveryFrameTrigger", text: "every frame", properties: [], description: "This trigger is called each frame (only on scene)" });
  330. Elements.TRIGGERS.push({ name: "OnIntersectionEnterTrigger", text: "intersection enter", properties: [{ targetType: "MeshProperties", text: "parameter", value: "Object name?" }], description: "When the edited mesh intersects the another mesh predefined in the options" });
  331. Elements.TRIGGERS.push({ name: "OnIntersectionExitTrigger", text: "intersection exit", properties: [{ targetType: "MeshProperties", text: "parameter", value: "Object name?" }], description: "When the edited mesh exits intersection with the another mesh predefined in the options" });
  332. Elements.TRIGGERS.push({ name: "OnKeyDownTrigger", text: "key down", properties: [{ targetType: null, text: "parameter:", value: "a" }], description: "When the user pressed a key (enter the key character, example: \"r\")" });
  333. Elements.TRIGGERS.push({ name: "OnKeyUpTrigger", text: "key up", properties: [{ targetType: null, text: "parameter:", value: "a" }], description: "When the user unpressed a key (enter the key character, example: \"p\")" });
  334. // Configure actions
  335. Elements.ACTIONS.push({ name: "SwitchBooleanAction", text: "switch boolean", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "propertyPath", value: "" }], description: "Switches the boolean value of a given parameter of the target object: true to false, or false to true" });
  336. Elements.ACTIONS.push({ name: "SetStateAction", text: "set state", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "value", value: "" }], description: "Sets a new state value for the target object (example: \"off\" or \"on\")" });
  337. Elements.ACTIONS.push({ name: "SetValueAction", text: "set value", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "propertyPath", value: "" }, { text: "value", value: "" }], description: "Sets a new value to the specified parameter of the target object (example: position.x to 0.0)" });
  338. Elements.ACTIONS.push({ name: "SetParentAction", text: "set parent", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "parent", value: "" }], description: "Sets the new parent of the target object (example: a mesh or a light)" });
  339. Elements.ACTIONS.push({ name: "IncrementValueAction", text: "increment value", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "propertyPath", value: "" }, { text: "value", value: "" }], description: "Increments the value of the given parameter of the target object. The value can be negative. (example: increment position.x of 5.0)" });
  340. Elements.ACTIONS.push({ name: "PlayAnimationAction", text: "play animation", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "from", value: "0" }, { text: "to", value: "150" }, { text: "loop", value: "false" }], description: "Plays an animation of the target object. Specify the start frame, the end frame and if the animation should loop." });
  341. Elements.ACTIONS.push({ name: "StopAnimationAction", text: "stop animation", properties: [{ targetType: "MeshProperties", text: "target", value: "" }], description: "Stops the animations of the target object." });
  342. Elements.ACTIONS.push({ name: "DoNothingAction", text: "do nothing", properties: [], description: "Does nothing, can be used to balance/equilibrate the actions graph." });
  343. Elements.ACTIONS.push({ name: "InterpolateValueAction", text: "interpolate value", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "propertyPath", value: "" }, { text: "value", value: "0" }, { text: "duration", value: "1000" }, { text: "stopOtherAnimations", value: "false" }], description: "Creates an animation (key frames) that animates the target object by interpolating the given parameter of the target value." });
  344. Elements.ACTIONS.push({ name: "PlaySoundAction", text: "play sound", properties: [{ text: "sound", value: "" }], description: "Plays the specified sound." });
  345. Elements.ACTIONS.push({ name: "StopSoundAction", text: "stop sound", properties: [{ text: "sound", value: "" }], description: "Stops the specified sound." });
  346. Elements.ACTIONS.push({ name: "CombineAction", text: "combine", properties: [], description: "Special action that combines multiple actions. The combined actions are executed at the same time. Drag'n'drop the new actions inside to combine actions." });
  347. // Configure flow control
  348. Elements.FLOW_CONTROLS.push({ name: "ValueCondition", text: "value condition", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "propertyPath", value: "" }, { text: "value", value: "" }, { text: "operator", value: SceneElements.OPERATORS[0] }], description: "A condition checking if a given value is equal, different, lesser or greater than the given parameter of the target object" });
  349. Elements.FLOW_CONTROLS.push({ name: "StateCondition", text: "state condition", properties: [{ targetType: "MeshProperties", text: "target", value: "" }, { text: "value", value: "" }], description: "A condition checking if the target object's state is equal to the given state. See \"set state\" action to set a state to an object." });
  350. Elements.FLOW_CONTROLS.push({ name: "Hub", text: "hub", properties: [], description: "The hub is internally used by the Combine Action. It allows to add children to the Combine Action" });
  351. })(ActionsBuilder || (ActionsBuilder = {}));
  352. //# sourceMappingURL=actionsbuilder.js.map