actionkinds.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /// <reference path="raphael.js" />
  2. /// <reference path="viewer.js" />
  3. /// <reference path="action.js" />
  4. /// <reference path="babylon.max.js" />
  5. var AB;
  6. (function (AB) {
  7. var directActionTemplate = function (parameters, secondArgument) {
  8. var template = [
  9. { text: "target", value: "Object name?", targetType: "SceneProperties" }
  10. ];
  11. if (secondArgument)
  12. template.push({text: secondArgument, value: "value..."});
  13. if (parameters)
  14. template.push.apply(template, parameters);
  15. return template;
  16. }
  17. var directActionWidthPropertyPath = function (parameters) {
  18. return directActionTemplate(parameters, "propertyPath");
  19. }
  20. var ActionsBuilder = (function () {
  21. function ActionsBuilder()
  22. { }
  23. var engine = new BABYLON.Engine(document.getElementById("renderCanvas"), false);
  24. var scene = new BABYLON.Scene(engine);
  25. var camera = new BABYLON.Camera("empty_camera", BABYLON.Vector3.Zero(), scene);
  26. var light = new BABYLON.PointLight("empty_light", BABYLON.Vector3.Zero(), scene);
  27. var mesh = new BABYLON.Mesh("empty_mesh", scene);
  28. ActionsBuilder.Engine = function () {
  29. return engine;
  30. }
  31. ActionsBuilder.Scene = function () {
  32. return scene;
  33. }
  34. ActionsBuilder.Camera = function () {
  35. return camera;
  36. }
  37. ActionsBuilder.Light = function () {
  38. return light;
  39. }
  40. ActionsBuilder.Mesh = function () {
  41. return mesh;
  42. }
  43. //
  44. // Types
  45. //
  46. ActionsBuilder.Type = ActionsBuilder.Type || {};
  47. ActionsBuilder.Type.TRIGGER = 0;
  48. ActionsBuilder.Type.ACTION = 1;
  49. ActionsBuilder.Type.FLOW_CONTROL = 2;
  50. ActionsBuilder.Type.OBJECT = 3;
  51. ActionsBuilder.Type.SCENE = 4;
  52. //
  53. // Data types names
  54. //
  55. ActionsBuilder.DataTypesNames = ActionsBuilder.DataTypesNames || new Array();
  56. ActionsBuilder.DataTypesNames.push({ name: "Scene", data: "SceneProperties" });
  57. ActionsBuilder.DataTypesNames.push({ name: "Camera", data: "CameraProperties" });
  58. ActionsBuilder.DataTypesNames.push({ name: "Light", data: "LightProperties" });
  59. ActionsBuilder.DataTypesNames.push({ name: "Mesh", data: "MeshProperties" });
  60. //
  61. // Autorized data types
  62. //
  63. ActionsBuilder.Types = ActionsBuilder.Types || new Array();
  64. ActionsBuilder.Types.push("Boolean");
  65. ActionsBuilder.Types.push("Number");
  66. ActionsBuilder.Types.push("Vector2");
  67. ActionsBuilder.Types.push("Vector3");
  68. ActionsBuilder.Types.push("String");
  69. // Tests if the property type is in ActionsBuilder.Types
  70. var testInstanceOf = function (object, propertyName) {
  71. if (object == null || object.constructor == null)
  72. return false;
  73. if (propertyName.length > 0 && propertyName[0] == "_")
  74. return false;
  75. var name = object.constructor.toString().match(/function (\w*)/)[1];
  76. for (var i = 0; i < ActionsBuilder.Types.length; i++) {
  77. if (name == ActionsBuilder.Types[i])
  78. return true;
  79. }
  80. return false;
  81. }
  82. //
  83. // Scene properties
  84. //
  85. ActionsBuilder.SceneProperties = ActionsBuilder.SceneProperties || new Array();
  86. for (var thing in scene) {
  87. if (testInstanceOf(scene[thing], thing)) {
  88. ActionsBuilder.SceneProperties.push({ name: thing, type: typeof (scene[thing]) });
  89. }
  90. }
  91. //
  92. // Camera properties
  93. //
  94. ActionsBuilder.CameraProperties = ActionsBuilder.CameraProperties || new Array();
  95. for (var thing in camera) {
  96. if (testInstanceOf(camera[thing], thing)) {
  97. ActionsBuilder.CameraProperties.push({ name: thing, type: typeof (camera[thing]) });
  98. }
  99. }
  100. //
  101. // Light properties
  102. //
  103. ActionsBuilder.LightProperties = ActionsBuilder.LightProperties || new Array();
  104. for (var thing in light) {
  105. if (testInstanceOf(light[thing], thing)) {
  106. ActionsBuilder.LightProperties.push({ name: thing, type: typeof (light[thing]) });
  107. }
  108. }
  109. //
  110. // Mesh properties
  111. //
  112. ActionsBuilder.MeshProperties = ActionsBuilder.MeshProperties || new Array();
  113. for (var thing in mesh) {
  114. if (testInstanceOf(mesh[thing], thing)) {
  115. ActionsBuilder.MeshProperties.push({ name: thing, type: typeof (mesh[thing]) });
  116. }
  117. }
  118. //
  119. // Scene properties (meshes, lights, etc)
  120. //
  121. ActionsBuilder.MeshesList = ActionsBuilder.MeshesList || new Array();
  122. ActionsBuilder.LightsList = ActionsBuilder.LightsList || new Array();
  123. ActionsBuilder.CamerasList = ActionsBuilder.CamerasList || new Array();
  124. ActionsBuilder.SoundsList = ActionsBuilder.SoundsList || new Array();
  125. //
  126. // Triggers
  127. //
  128. ActionsBuilder.Trigger = ActionsBuilder.Trigger || {};
  129. ActionsBuilder.Trigger[0] = { name: "NothingTrigger", properties: [] };
  130. ActionsBuilder.Trigger[1] = { name: "OnPickTrigger", properties: [], description: "When the user clicks" };
  131. ActionsBuilder.Trigger[2] = { name: "OnLeftPickTrigger", properties: [], description: "When the user left clicks" };
  132. ActionsBuilder.Trigger[3] = { name: "OnRightPickTrigger", properties: [], description: "When the user right clicks" };
  133. ActionsBuilder.Trigger[4] = { name: "OnCenterPickTrigger", properties: [], description: "When the user center clicks (mouse wheel)" };
  134. ActionsBuilder.Trigger[5] = { name: "OnPointerOverTrigger", properties: [], description: "When the user's mouse is on the object" };
  135. ActionsBuilder.Trigger[6] = { name: "OnPointerOutTrigger", properties: [], description: "When the user's mouse is out of the object" };
  136. ActionsBuilder.Trigger[7] = { name: "OnEveryFrameTrigger", properties: [], description: "Called each frame (only on scene)" };
  137. ActionsBuilder.Trigger[8] = { name: "OnIntersectionEnterTrigger", properties: [{ text: "parameter", value: "Object name?" }], description: "When the object intersects an other object" };
  138. ActionsBuilder.Trigger[9] = { name: "OnIntersectionExitTrigger", properties: [{ text: "parameter", value: "Object name?" }], descripton: "When the object exists intersection with an other object" };
  139. ActionsBuilder.Trigger[10] = { name: "OnKeyDownTrigger", properties: [{ text: "parameter:", value: "" }], description: "When the user push a key" };
  140. ActionsBuilder.Trigger[11] = { name: "OnKeyUpTrigger", properties: [{ text: "parameter:", value: "" }], description: "When the user pushed a key" };
  141. ActionsBuilder.Trigger.COUNT = 12;
  142. //
  143. // Actions (direct & interpolate)
  144. //
  145. ActionsBuilder.Action = ActionsBuilder.Action || {};
  146. ActionsBuilder.Action[0] = { name: "SwitchBooleanAction", properties: directActionWidthPropertyPath(), description: "Switches a boolean value for a given parameter of the target object : true to false, or false to true" };
  147. ActionsBuilder.Action[1] = { name: "SetStateAction", properties: directActionTemplate(null, "value"), description: "Sets a new state value of the target object (i.e \"off\" or \"on\")" };
  148. ActionsBuilder.Action[2] = { name: "SetValueAction", properties: directActionWidthPropertyPath([{ text: "value", value: "value?" }]), description: "Sets a new value to the specified parameter of the object" };
  149. ActionsBuilder.Action[3] = { name: "SetParentAction", properties: directActionTemplate([{ text: "parent", value: "object name?" }]), description: "Sets a new parent for the target object" };
  150. ActionsBuilder.Action[4] = { name: "IncrementValueAction", properties: directActionWidthPropertyPath([{ text: "value", value: "value?" }]), description: "Increments the value of the given parameter for the target object. The value can be negative" };
  151. ActionsBuilder.Action[5] = { name: "PlayAnimationAction", properties: directActionTemplate([{ text: "from", value: "0" }, { text: "to", value: "150" }, { text: "loop", value: "false" }]), description: "Plays the animation of the target object" };
  152. ActionsBuilder.Action[6] = { name: "StopAnimationAction", properties: directActionTemplate(), description: "Stops the animation of the target object" };
  153. ActionsBuilder.Action[7] = { name: "DoNothingAction", properties: [], description: "Does nothing, can be used to balance the actions graph" };
  154. ActionsBuilder.Action[8] = {
  155. name: "InterpolateValueAction", properties: directActionWidthPropertyPath([
  156. { text: "value", value: "value" },
  157. { text: "duration", value: "1000" },
  158. { text: "stopOtherAnimations", value: "false" }]),
  159. description: "Creates an animation (key frames) that animates the target object by modifying the given parameter to the target value"
  160. };
  161. ActionsBuilder.Action[9] = { name: "PlaySoundAction", properties: [{ text: "sound", value: "path to sound..." }], description: "Plays a sound giving it's path (name)" };
  162. ActionsBuilder.Action[10] = { name: "StopSoundAction", properties: [{ text: "sound", value: "path to sound..." }], description: "Stops a sound giving it's path (name)" };
  163. ActionsBuilder.Action[11] = { name: "CombineAction", properties: [], description: "Special action that combines multiple actions" };
  164. ActionsBuilder.Action.COUNT = 12;
  165. //
  166. // Flow Control
  167. //
  168. ActionsBuilder.FlowActionOperators = ActionsBuilder.FlowActionOperators || new Array();
  169. ActionsBuilder.FlowActionOperators.push("IsEqual");
  170. ActionsBuilder.FlowActionOperators.push("IsDifferent");
  171. ActionsBuilder.FlowActionOperators.push("IsGreater");
  172. ActionsBuilder.FlowActionOperators.push("IsLesser");
  173. ActionsBuilder.FlowAction = ActionsBuilder.FlowAction || {};
  174. ActionsBuilder.FlowAction[0] = { name: "ValueCondition", properties: directActionWidthPropertyPath([{ text: "value", value: "value?" }, { text: "operator", value: ActionsBuilder.FlowActionOperators[0] }]), description: "A condition" };
  175. ActionsBuilder.FlowAction[1] = { name: "StateCondition", properties: directActionTemplate([{ text: "value", value: "value?" }]), description: "A condition, true if the target object state equals the given state" };
  176. ActionsBuilder.FlowAction.COUNT = 2;
  177. ActionsBuilder.FlowAction.Hub = { name: "Hub", properties: [], description: "" };
  178. //
  179. // Utils
  180. //
  181. ActionsBuilder.GetDescriptionFromActionName = function (name) {
  182. for (var i = 0; i < ActionsBuilder.Trigger.COUNT; i++) {
  183. if (ActionsBuilder.Trigger[i].name == name)
  184. return ActionsBuilder.Trigger[i].description;
  185. }
  186. for (var i = 0; i < ActionsBuilder.Action.COUNT; i++) {
  187. if (ActionsBuilder.Action[i].name == name)
  188. return ActionsBuilder.Action[i].description;
  189. }
  190. for (var i = 0; i < ActionsBuilder.FlowAction.COUNT; i++) {
  191. if (ActionsBuilder.FlowAction[i].name == name)
  192. return ActionsBuilder.FlowAction[i].description;
  193. }
  194. };
  195. return ActionsBuilder;
  196. })();
  197. AB.ActionsBuilder = ActionsBuilder;
  198. })(AB || (AB = {}));