actionsbuilder.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. var ActionsBuilder;
  2. (function (ActionsBuilder) {
  3. var Type = (function () {
  4. function Type() {
  5. }
  6. Object.defineProperty(Type, "TRIGGER", {
  7. get: function () {
  8. return Type._TRIGGER;
  9. },
  10. enumerable: true,
  11. configurable: true
  12. });
  13. Object.defineProperty(Type, "ACTION", {
  14. get: function () {
  15. return Type._ACTION;
  16. },
  17. enumerable: true,
  18. configurable: true
  19. });
  20. Object.defineProperty(Type, "FLOW_CONTROL", {
  21. get: function () {
  22. return Type._FLOW_CONTROL;
  23. },
  24. enumerable: true,
  25. configurable: true
  26. });
  27. Object.defineProperty(Type, "OBJECT", {
  28. get: function () {
  29. return Type._OBJECT;
  30. },
  31. enumerable: true,
  32. configurable: true
  33. });
  34. Object.defineProperty(Type, "SCENE", {
  35. get: function () {
  36. return Type._SCENE;
  37. },
  38. enumerable: true,
  39. configurable: true
  40. });
  41. Type._TRIGGER = 0;
  42. Type._ACTION = 1;
  43. Type._FLOW_CONTROL = 2;
  44. Type._OBJECT = 3;
  45. Type._SCENE = 4;
  46. return Type;
  47. })();
  48. ActionsBuilder.Type = Type;
  49. var SceneElements = (function () {
  50. function SceneElements() {
  51. }
  52. Object.defineProperty(SceneElements, "ENGINE", {
  53. get: function () {
  54. return SceneElements._ENGINE;
  55. },
  56. enumerable: true,
  57. configurable: true
  58. });
  59. Object.defineProperty(SceneElements, "SCENE", {
  60. get: function () {
  61. return SceneElements._SCENE;
  62. },
  63. enumerable: true,
  64. configurable: true
  65. });
  66. Object.defineProperty(SceneElements, "MESH", {
  67. get: function () {
  68. return SceneElements._MESH;
  69. },
  70. enumerable: true,
  71. configurable: true
  72. });
  73. Object.defineProperty(SceneElements, "LIGHT", {
  74. get: function () {
  75. return SceneElements._LIGHT;
  76. },
  77. enumerable: true,
  78. configurable: true
  79. });
  80. Object.defineProperty(SceneElements, "CAMERA", {
  81. get: function () {
  82. return SceneElements._CAMERA;
  83. },
  84. enumerable: true,
  85. configurable: true
  86. });
  87. Object.defineProperty(SceneElements, "MESHES", {
  88. get: function () {
  89. return SceneElements._MESHES;
  90. },
  91. enumerable: true,
  92. configurable: true
  93. });
  94. Object.defineProperty(SceneElements, "LIGHTS", {
  95. get: function () {
  96. return SceneElements._LIGHTS;
  97. },
  98. enumerable: true,
  99. configurable: true
  100. });
  101. Object.defineProperty(SceneElements, "CAMERAS", {
  102. get: function () {
  103. return SceneElements._CAMERAS;
  104. },
  105. enumerable: true,
  106. configurable: true
  107. });
  108. Object.defineProperty(SceneElements, "SOUNDS", {
  109. get: function () {
  110. return SceneElements._SOUNDS;
  111. },
  112. enumerable: true,
  113. configurable: true
  114. });
  115. Object.defineProperty(SceneElements, "MESH_PROPERTIES", {
  116. get: function () {
  117. return SceneElements._MESH_PROPERTIES;
  118. },
  119. enumerable: true,
  120. configurable: true
  121. });
  122. Object.defineProperty(SceneElements, "LIGHT_PROPERTIES", {
  123. get: function () {
  124. return SceneElements._LIGHT_PROPERTIES;
  125. },
  126. enumerable: true,
  127. configurable: true
  128. });
  129. Object.defineProperty(SceneElements, "CAMERA_PROPERTIES", {
  130. get: function () {
  131. return SceneElements._CAMERA_PROPERTIES;
  132. },
  133. enumerable: true,
  134. configurable: true
  135. });
  136. Object.defineProperty(SceneElements, "SCENE_PROPERTIES", {
  137. get: function () {
  138. return SceneElements._SCENE_PROPERTIES;
  139. },
  140. enumerable: true,
  141. configurable: true
  142. });
  143. Object.defineProperty(SceneElements, "TYPES", {
  144. get: function () {
  145. return SceneElements._TYPES;
  146. },
  147. enumerable: true,
  148. configurable: true
  149. });
  150. Object.defineProperty(SceneElements, "OPERATORS", {
  151. get: function () {
  152. return SceneElements._OPERATORS;
  153. },
  154. enumerable: true,
  155. configurable: true
  156. });
  157. SceneElements.GetInstanceOf = function (object) {
  158. if (object === null || object === undefined) {
  159. return "";
  160. }
  161. return object.constructor.toString().match(/function (\w*)/)[1];
  162. };
  163. SceneElements.TestInstanceOf = function (object, propertyName) {
  164. if (object === null || object.constructor === null) {
  165. return false;
  166. }
  167. if (propertyName.length > 0 && propertyName[0] === "_")
  168. return false;
  169. var name = SceneElements.GetInstanceOf(object);
  170. for (var i = 0; i < SceneElements.TYPES.length; i++) {
  171. if (name === SceneElements.TYPES[i]) {
  172. return true;
  173. }
  174. }
  175. return false;
  176. };
  177. SceneElements._ENGINE = new BABYLON.Engine(document.getElementById("RenderCanvasID"));
  178. SceneElements._SCENE = new BABYLON.Scene(SceneElements.ENGINE);
  179. SceneElements._MESH = new BABYLON.Mesh("mesh", SceneElements._SCENE);
  180. SceneElements._LIGHT = new BABYLON.Light("light", SceneElements._SCENE);
  181. SceneElements._CAMERA = new BABYLON.Camera("camera", BABYLON.Vector3.Zero(), SceneElements._SCENE);
  182. SceneElements._MESHES = new Array();
  183. SceneElements._LIGHTS = new Array();
  184. SceneElements._CAMERAS = new Array();
  185. SceneElements._SOUNDS = new Array();
  186. SceneElements._MESH_PROPERTIES = new Array();
  187. SceneElements._LIGHT_PROPERTIES = new Array();
  188. SceneElements._CAMERA_PROPERTIES = new Array();
  189. SceneElements._SCENE_PROPERTIES = new Array();
  190. SceneElements._TYPES = new Array();
  191. SceneElements._OPERATORS = new Array();
  192. return SceneElements;
  193. })();
  194. ActionsBuilder.SceneElements = SceneElements;
  195. var specialTypes = [
  196. "StandardMaterial"
  197. ];
  198. SceneElements.MESH.material = new BABYLON.StandardMaterial("material", SceneElements.SCENE);
  199. var addSpecialType = function (object, properties, thing) {
  200. for (var specialThing in object[thing]) {
  201. if (object[thing].hasOwnProperty(specialThing) && SceneElements.TestInstanceOf(object[thing][specialThing], specialThing)) {
  202. properties.push(thing + "." + specialThing);
  203. }
  204. }
  205. };
  206. SceneElements.TYPES.push("Color3");
  207. SceneElements.TYPES.push("Boolean");
  208. SceneElements.TYPES.push("Number");
  209. SceneElements.TYPES.push("Vector2");
  210. SceneElements.TYPES.push("Vector3");
  211. SceneElements.TYPES.push("String");
  212. SceneElements.OPERATORS.push("IsEqual");
  213. SceneElements.OPERATORS.push("IsDifferent");
  214. SceneElements.OPERATORS.push("IsGreater");
  215. SceneElements.OPERATORS.push("IsLesser");
  216. for (var thing in SceneElements.MESH) {
  217. var instance = SceneElements.GetInstanceOf(SceneElements.MESH[thing]);
  218. if (SceneElements.MESH.hasOwnProperty(thing)) {
  219. if (specialTypes.indexOf(instance) !== -1) {
  220. addSpecialType(SceneElements.MESH, SceneElements.MESH_PROPERTIES, thing);
  221. }
  222. else if (SceneElements.TestInstanceOf(SceneElements.MESH[thing], thing)) {
  223. SceneElements.MESH_PROPERTIES.push(thing);
  224. }
  225. }
  226. }
  227. for (var thing in SceneElements.LIGHT) {
  228. if (SceneElements.LIGHT.hasOwnProperty(thing) && SceneElements.TestInstanceOf(SceneElements.LIGHT[thing], thing)) {
  229. SceneElements.LIGHT_PROPERTIES.push(thing);
  230. }
  231. }
  232. for (var thing in SceneElements.CAMERA) {
  233. if (SceneElements.CAMERA.hasOwnProperty(thing) && SceneElements.TestInstanceOf(SceneElements.CAMERA[thing], thing)) {
  234. SceneElements.CAMERA_PROPERTIES.push(thing);
  235. }
  236. }
  237. for (var thing in SceneElements.SCENE) {
  238. if (SceneElements.SCENE.hasOwnProperty(thing) && SceneElements.TestInstanceOf(SceneElements.SCENE[thing], thing)) {
  239. SceneElements.SCENE_PROPERTIES.push(thing);
  240. }
  241. }
  242. var Elements = (function () {
  243. function Elements() {
  244. }
  245. Object.defineProperty(Elements, "TRIGGERS", {
  246. get: function () {
  247. return Elements._TRIGGERS;
  248. },
  249. enumerable: true,
  250. configurable: true
  251. });
  252. Object.defineProperty(Elements, "ACTIONS", {
  253. get: function () {
  254. return Elements._ACTIONS;
  255. },
  256. enumerable: true,
  257. configurable: true
  258. });
  259. Object.defineProperty(Elements, "FLOW_CONTROLS", {
  260. get: function () {
  261. return Elements._FLOW_CONTROLS;
  262. },
  263. enumerable: true,
  264. configurable: true
  265. });
  266. Elements.GetElementFromName = function (name) {
  267. for (var i = 0; i < Elements.TRIGGERS.length; i++) {
  268. if (Elements.TRIGGERS[i].name === name) {
  269. return Elements._TRIGGERS[i];
  270. }
  271. }
  272. for (var i = 0; i < Elements.ACTIONS.length; i++) {
  273. if (Elements.ACTIONS[i].name === name) {
  274. return Elements._ACTIONS[i];
  275. }
  276. }
  277. for (var i = 0; i < Elements.FLOW_CONTROLS.length; i++) {
  278. if (Elements.FLOW_CONTROLS[i].name === name) {
  279. return Elements._FLOW_CONTROLS[i];
  280. }
  281. }
  282. return null;
  283. };
  284. Elements._TRIGGERS = new Array();
  285. Elements._ACTIONS = new Array();
  286. Elements._FLOW_CONTROLS = new Array();
  287. return Elements;
  288. })();
  289. ActionsBuilder.Elements = Elements;
  290. Elements.TRIGGERS.push({ name: "OnPickTrigger", text: "pick", properties: [], description: "When the user picks the edited mesh" });
  291. Elements.TRIGGERS.push({ name: "OnLeftPickTrigger", text: "left pick", properties: [], description: "When the user picks the edited mesh using the left click" });
  292. Elements.TRIGGERS.push({ name: "OnRightPickTrigger", text: "right pick", properties: [], description: "When the user picks the edited mesh using the right click" });
  293. Elements.TRIGGERS.push({ name: "OnCenterPickTrigger", text: "center pick", properties: [], description: "When the user picks the edited mesh using the click of the mouse wheel" });
  294. Elements.TRIGGERS.push({ name: "OnPointerOverTrigger", text: "pointer over", properties: [], description: "When the user's mouse is over the edited mesh" });
  295. Elements.TRIGGERS.push({ name: "OnPointerOutTrigger", text: "pointer out", properties: [], description: "When the user's mouse is out of the edited mesh" });
  296. Elements.TRIGGERS.push({ name: "OnEveryFrameTrigger", text: "every frame", properties: [], description: "This trigger is called each frame (only on scene)" });
  297. 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" });
  298. 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" });
  299. 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\")" });
  300. 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\")" });
  301. 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" });
  302. 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\")" });
  303. 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)" });
  304. 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)" });
  305. 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)" });
  306. 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." });
  307. Elements.ACTIONS.push({ name: "StopAnimationAction", text: "stop animation", properties: [{ targetType: "MeshProperties", text: "target", value: "" }], description: "Stops the animations of the target object." });
  308. Elements.ACTIONS.push({ name: "DoNothingAction", text: "do nothing", properties: [], description: "Does nothing, can be used to balance/equilibrate the actions graph." });
  309. 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." });
  310. Elements.ACTIONS.push({ name: "PlaySoundAction", text: "play sound", properties: [{ text: "sound", value: "" }], description: "Plays the specified sound." });
  311. Elements.ACTIONS.push({ name: "StopSoundAction", text: "stop sound", properties: [{ text: "sound", value: "" }], description: "Stops the specified sound." });
  312. 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." });
  313. 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" });
  314. 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." });
  315. 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" });
  316. })(ActionsBuilder || (ActionsBuilder = {}));