jax 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (473) hide show
  1. data/.gitignore +4 -0
  2. data/.rvmrc +2 -3
  3. data/.travis.yml +8 -22
  4. data/README.md +2 -2
  5. data/Rakefile +128 -96
  6. data/app/assets/javascripts/jax/controller-list.js.coffee +22 -0
  7. data/app/assets/javascripts/jax/dom-helpers.js.coffee +17 -0
  8. data/app/assets/javascripts/jax/jasmine_runner.js +177 -0
  9. data/app/assets/javascripts/jax/runtime.js +6 -0
  10. data/app/assets/javascripts/jax/shader_editor.js.coffee +33 -0
  11. data/app/assets/stylesheets/jax/controller-list.css +5 -0
  12. data/app/assets/stylesheets/jax/jasmine.css +16 -0
  13. data/app/assets/stylesheets/jax/nav.css +41 -0
  14. data/app/assets/stylesheets/jax/runtime.css +47 -0
  15. data/app/assets/stylesheets/jax/shader_editor.css +3 -0
  16. data/app/assets/stylesheets/jax/suite.css +82 -0
  17. data/app/controllers/jax/suite_controller.rb +48 -0
  18. data/app/views/jax/suite/jasmine.html.erb +38 -0
  19. data/app/views/jax/suite/run_webgl.html.erb +49 -0
  20. data/app/views/jax/suite/shader_editor.html.erb +24 -0
  21. data/app/views/layouts/jax.html.erb +40 -0
  22. data/bin/jax +8 -4
  23. data/config/routes.rb +2 -0
  24. data/config.ru +5 -0
  25. data/features/rails/resources.feature +45 -0
  26. data/features/rails/shaders.feature +13 -0
  27. data/features/rails/specs.feature +24 -0
  28. data/features/runtime.feature +15 -0
  29. data/features/step_definitions/environment_steps.rb +15 -0
  30. data/features/step_definitions/response_steps.rb +13 -0
  31. data/features/step_definitions/runtime.rb +11 -0
  32. data/features/step_definitions/web_steps.rb +223 -0
  33. data/features/support/env.rb +75 -0
  34. data/features/support/paths.rb +30 -0
  35. data/features/support/rails_environment.rb +3 -0
  36. data/features/support/selectors.rb +39 -0
  37. data/features/support/setup.rb +17 -0
  38. data/jax.gemspec +22 -16
  39. data/lib/assets/javascripts/jax/anim_frame.js +64 -0
  40. data/lib/assets/javascripts/jax/application.js +16 -0
  41. data/lib/assets/javascripts/jax/builtin/all.js +21 -0
  42. data/lib/assets/javascripts/jax/builtin/meshes/cube.js +83 -0
  43. data/lib/assets/javascripts/jax/builtin/meshes/plane.js +67 -0
  44. data/lib/assets/javascripts/jax/builtin/meshes/quad.js +89 -0
  45. data/lib/assets/javascripts/jax/builtin/meshes/sphere.js +65 -0
  46. data/lib/assets/javascripts/jax/builtin/meshes/teapot.js +48 -0
  47. data/lib/assets/javascripts/jax/builtin/meshes/torus.js +64 -0
  48. data/lib/assets/javascripts/jax/compatibility.js +312 -0
  49. data/lib/assets/javascripts/jax/context.js +741 -0
  50. data/lib/assets/javascripts/jax/core/base.js +69 -0
  51. data/lib/assets/javascripts/jax/core/glMatrix_ext/mat3.js +20 -0
  52. data/lib/assets/javascripts/jax/core/glMatrix_ext/mat4.js +10 -0
  53. data/lib/assets/javascripts/jax/core/glMatrix_ext/quat4.js +148 -0
  54. data/lib/assets/javascripts/jax/core/glMatrix_ext/vec2.js +25 -0
  55. data/lib/assets/javascripts/jax/core/glMatrix_ext/vec3.js +86 -0
  56. data/lib/assets/javascripts/jax/core/glMatrix_ext/vec4.js +28 -0
  57. data/lib/assets/javascripts/jax/core/helper.js +44 -0
  58. data/lib/assets/javascripts/jax/core/math.js +61 -0
  59. data/lib/assets/javascripts/jax/core/matrix_stack.js +310 -0
  60. data/lib/assets/javascripts/jax/core/util.js +271 -0
  61. data/lib/assets/javascripts/jax/core.js +43 -0
  62. data/lib/assets/javascripts/jax/events.js +304 -0
  63. data/lib/assets/javascripts/jax/geometry/line.js +185 -0
  64. data/lib/assets/javascripts/jax/geometry/plane.js +371 -0
  65. data/lib/assets/javascripts/jax/geometry/triangle/inliner.rb +94 -0
  66. data/lib/assets/javascripts/jax/geometry/triangle/slow_tri_tri_intersect.js +20 -0
  67. data/lib/assets/javascripts/jax/geometry/triangle/tri_tri_intersect.js +281 -0
  68. data/lib/assets/javascripts/jax/geometry/triangle/tri_tri_intersect_optimized.js +564 -0
  69. data/lib/assets/javascripts/jax/geometry/triangle.js +311 -0
  70. data/lib/assets/javascripts/jax/geometry.js +14 -0
  71. data/lib/assets/javascripts/jax/mvc/controller.js +188 -0
  72. data/lib/assets/javascripts/jax/mvc/model.js +302 -0
  73. data/lib/assets/javascripts/jax/mvc/route_set.js +148 -0
  74. data/lib/assets/javascripts/jax/mvc/view.js +43 -0
  75. data/lib/assets/javascripts/jax/mvc/view_manager.js +65 -0
  76. data/lib/assets/javascripts/jax/noise.js +251 -0
  77. data/lib/assets/javascripts/jax/prototype/class.js +81 -0
  78. data/lib/assets/javascripts/jax/prototype/core.js +112 -0
  79. data/lib/assets/javascripts/jax/prototype/extensions.js +142 -0
  80. data/lib/assets/javascripts/jax/vendor/ejs.js +1 -0
  81. data/lib/assets/javascripts/jax/vendor/glMatrix.js +7 -0
  82. data/lib/assets/javascripts/jax/webgl/camera.js +697 -0
  83. data/lib/assets/javascripts/jax/webgl/cleanup.js +1 -0
  84. data/lib/assets/javascripts/jax/webgl/core/buffer.js +292 -0
  85. data/lib/assets/javascripts/jax/webgl/core/data_region.js +184 -0
  86. data/lib/assets/javascripts/jax/webgl/core/data_segment.js +255 -0
  87. data/lib/assets/javascripts/jax/webgl/core/events.js +99 -0
  88. data/lib/assets/javascripts/jax/webgl/core/framebuffer.js +316 -0
  89. data/lib/assets/javascripts/jax/webgl/core.js +6 -0
  90. data/lib/assets/javascripts/jax/webgl/material.js +381 -0
  91. data/lib/assets/javascripts/jax/webgl/mesh/normals.js +37 -0
  92. data/lib/assets/javascripts/jax/webgl/mesh/support.js +104 -0
  93. data/lib/assets/javascripts/jax/webgl/mesh/tangent_space.js +111 -0
  94. data/lib/assets/javascripts/jax/webgl/mesh.js +440 -0
  95. data/lib/assets/javascripts/jax/webgl/scene/frustum.js +422 -0
  96. data/lib/assets/javascripts/jax/webgl/scene/light_manager.js +141 -0
  97. data/lib/assets/javascripts/jax/webgl/scene/light_source.js +300 -0
  98. data/lib/assets/javascripts/jax/webgl/scene.js +16 -0
  99. data/lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js +53 -0
  100. data/lib/assets/javascripts/jax/webgl/shader/delegator/uniform.js +71 -0
  101. data/lib/assets/javascripts/jax/webgl/shader/delegator.js +13 -0
  102. data/lib/assets/javascripts/jax/webgl/shader/manifest.js +70 -0
  103. data/lib/assets/javascripts/jax/webgl/shader/program.js +138 -0
  104. data/lib/assets/javascripts/jax/webgl/shader.js +299 -0
  105. data/lib/assets/javascripts/jax/webgl/shader_chain.js +267 -0
  106. data/lib/assets/javascripts/jax/webgl/texture.js +506 -0
  107. data/lib/assets/javascripts/jax/webgl/world.js +279 -0
  108. data/lib/assets/javascripts/jax/webgl.js +109 -0
  109. data/lib/assets/javascripts/jax.js +136 -0
  110. data/{builtin/app/shaders/basic/common.ejs → lib/assets/javascripts/shaders/basic/common.glsl} +0 -0
  111. data/{builtin/app/shaders/basic/fragment.ejs → lib/assets/javascripts/shaders/basic/fragment.glsl} +0 -0
  112. data/{builtin/app/shaders/basic/vertex.ejs → lib/assets/javascripts/shaders/basic/vertex.glsl} +1 -1
  113. data/{builtin/app/shaders/depthmap/common.ejs → lib/assets/javascripts/shaders/depthmap/common.glsl} +0 -0
  114. data/{builtin/app/shaders/depthmap/fragment.ejs → lib/assets/javascripts/shaders/depthmap/fragment.glsl} +1 -1
  115. data/{builtin/app → lib/assets/javascripts}/shaders/depthmap/material.js +0 -0
  116. data/{builtin/app/shaders/depthmap/vertex.ejs → lib/assets/javascripts/shaders/depthmap/vertex.glsl} +0 -0
  117. data/{builtin/app/shaders/fog/common.ejs → lib/assets/javascripts/shaders/fog/common.glsl} +0 -0
  118. data/{builtin/app/shaders/fog/fragment.ejs → lib/assets/javascripts/shaders/fog/fragment.glsl} +0 -0
  119. data/{builtin/app → lib/assets/javascripts}/shaders/fog/manifest.yml +0 -0
  120. data/{builtin/app → lib/assets/javascripts}/shaders/fog/material.js +6 -8
  121. data/{builtin/app/shaders/fog/vertex.ejs → lib/assets/javascripts/shaders/fog/vertex.glsl} +0 -0
  122. data/{builtin/app/shaders/functions/depth_map.ejs → lib/assets/javascripts/shaders/functions/depth_map.glsl} +0 -0
  123. data/{builtin/app/shaders/functions/lights.ejs → lib/assets/javascripts/shaders/functions/lights.glsl} +0 -0
  124. data/{builtin/app/shaders/functions/noise.ejs → lib/assets/javascripts/shaders/functions/noise.glsl} +0 -0
  125. data/lib/assets/javascripts/shaders/lighting/common.glsl +5 -0
  126. data/{builtin/app/shaders/lighting/fragment.ejs → lib/assets/javascripts/shaders/lighting/fragment.glsl} +0 -0
  127. data/{builtin/app → lib/assets/javascripts}/shaders/lighting/manifest.yml +0 -0
  128. data/{builtin/app → lib/assets/javascripts}/shaders/lighting/material.js +2 -4
  129. data/{builtin/app/shaders/lighting/vertex.ejs → lib/assets/javascripts/shaders/lighting/vertex.glsl} +0 -0
  130. data/{builtin/app/shaders/normal_map/common.ejs → lib/assets/javascripts/shaders/normal_map/common.glsl} +1 -1
  131. data/{builtin/app/shaders/normal_map/fragment.ejs → lib/assets/javascripts/shaders/normal_map/fragment.glsl} +0 -0
  132. data/{builtin/app → lib/assets/javascripts}/shaders/normal_map/manifest.yml +0 -0
  133. data/lib/assets/javascripts/shaders/normal_map/material.js +11 -0
  134. data/{builtin/app/shaders/normal_map/vertex.ejs → lib/assets/javascripts/shaders/normal_map/vertex.glsl} +0 -0
  135. data/{builtin/app/shaders/paraboloid/common.ejs → lib/assets/javascripts/shaders/paraboloid/common.glsl} +0 -0
  136. data/{builtin/app/shaders/paraboloid/fragment.ejs → lib/assets/javascripts/shaders/paraboloid/fragment.glsl} +0 -0
  137. data/{builtin/app → lib/assets/javascripts}/shaders/paraboloid/manifest.yml +0 -0
  138. data/{builtin/app → lib/assets/javascripts}/shaders/paraboloid/material.js +2 -4
  139. data/{builtin/app/shaders/paraboloid/vertex.ejs → lib/assets/javascripts/shaders/paraboloid/vertex.glsl} +0 -0
  140. data/{builtin/app/shaders/picking/common.ejs → lib/assets/javascripts/shaders/picking/common.glsl} +0 -0
  141. data/{builtin/app/shaders/picking/fragment.ejs → lib/assets/javascripts/shaders/picking/fragment.glsl} +0 -0
  142. data/{builtin/app → lib/assets/javascripts}/shaders/picking/material.js +2 -4
  143. data/{builtin/app/shaders/picking/vertex.ejs → lib/assets/javascripts/shaders/picking/vertex.glsl} +0 -0
  144. data/{builtin/app/shaders/shadow_map/common.ejs → lib/assets/javascripts/shaders/shadow_map/common.glsl} +2 -1
  145. data/{builtin/app/shaders/shadow_map/fragment.ejs → lib/assets/javascripts/shaders/shadow_map/fragment.glsl} +1 -1
  146. data/{builtin/app → lib/assets/javascripts}/shaders/shadow_map/manifest.yml +0 -0
  147. data/{builtin/app → lib/assets/javascripts}/shaders/shadow_map/material.js +4 -6
  148. data/{builtin/app/shaders/shadow_map/vertex.ejs → lib/assets/javascripts/shaders/shadow_map/vertex.glsl} +0 -0
  149. data/{builtin/app/shaders/texture/common.ejs → lib/assets/javascripts/shaders/texture/common.glsl} +0 -0
  150. data/{builtin/app/shaders/texture/fragment.ejs → lib/assets/javascripts/shaders/texture/fragment.glsl} +0 -0
  151. data/{builtin/app → lib/assets/javascripts}/shaders/texture/manifest.yml +0 -0
  152. data/lib/assets/javascripts/shaders/texture/material.js +17 -0
  153. data/{builtin/app/shaders/texture/vertex.ejs → lib/assets/javascripts/shaders/texture/vertex.glsl} +0 -0
  154. data/lib/generators/jax/all.rb +16 -0
  155. data/lib/generators/jax/application/application_generator.rb +48 -0
  156. data/lib/generators/jax/base/actions.rb +52 -0
  157. data/lib/generators/jax/base/coffee_generator.rb +30 -0
  158. data/lib/generators/jax/base/named_base.rb +17 -0
  159. data/lib/generators/jax/base/plugin_base.rb +108 -0
  160. data/lib/generators/jax/base/plugin_credentials.rb +99 -0
  161. data/lib/generators/jax/base/plugin_manifest.rb +75 -0
  162. data/lib/generators/jax/base/rails_base.rb +30 -0
  163. data/lib/generators/jax/base/source_root.rb +5 -0
  164. data/lib/generators/jax/controller/controller_generator.rb +37 -0
  165. data/lib/generators/jax/helper/helper_generator.rb +30 -0
  166. data/lib/generators/jax/install/install_generator.rb +27 -0
  167. data/lib/generators/jax/jax_generator.rb +13 -0
  168. data/lib/generators/jax/light/light_generator.rb +23 -0
  169. data/lib/{jax/generators → generators/jax}/material/USAGE +4 -8
  170. data/lib/generators/jax/material/material_generator.rb +112 -0
  171. data/lib/generators/jax/model/model_generator.rb +24 -0
  172. data/lib/generators/jax/plugin/plugin_generator.rb +72 -0
  173. data/lib/generators/jax/scaffold/scaffold_generator.rb +35 -0
  174. data/lib/generators/jax/shader/shader_generator.rb +38 -0
  175. data/lib/jax/commands/plugin_manager.rb +240 -0
  176. data/lib/jax/commands.rb +69 -0
  177. data/lib/jax/configuration.rb +64 -0
  178. data/lib/jax/directive_processor.rb +53 -0
  179. data/lib/jax/engine.rb +38 -54
  180. data/lib/jax/helper_methods.rb +3 -0
  181. data/lib/jax/rails/application.rb +34 -0
  182. data/lib/jax/resource_file.rb +29 -0
  183. data/lib/jax/script_loader.rb +68 -0
  184. data/lib/jax/server.rb +87 -0
  185. data/lib/jax/shader.rb +70 -172
  186. data/lib/jax/testing/rails_environment.rb +94 -0
  187. data/lib/jax/util/tar.rb +75 -0
  188. data/lib/jax/util.rb +3 -0
  189. data/lib/jax/version.rb +7 -8
  190. data/lib/jax.rb +23 -41
  191. data/spec/bin/jax_spec.rb +149 -0
  192. data/{lib/jax/generators/app/templates/app/models/.empty_directory → spec/fixtures/public/favicon.ico} +0 -0
  193. data/spec/fixtures/public/textures/brickwall.jpg +0 -0
  194. data/spec/fixtures/public/textures/jacks.jpg +0 -0
  195. data/spec/fixtures/public/textures/normal_map.jpg +0 -0
  196. data/spec/fixtures/public/textures/rock.png +0 -0
  197. data/spec/fixtures/public/textures/rock_normal.png +0 -0
  198. data/spec/fixtures/public/textures/rss.png +0 -0
  199. data/spec/generators/jax/application_generator_spec.rb +18 -0
  200. data/spec/generators/jax/controller_generator_spec.rb +102 -0
  201. data/spec/generators/jax/helper_generator_spec.rb +55 -0
  202. data/spec/generators/jax/install_generator_spec.rb +30 -0
  203. data/spec/generators/jax/jax_generator_spec.rb +21 -0
  204. data/spec/generators/jax/light_generator_spec.rb +27 -0
  205. data/spec/generators/jax/material_generator_spec.rb +62 -0
  206. data/spec/generators/jax/model_generator_spec.rb +72 -0
  207. data/spec/generators/jax/plugin_generator_spec.rb +143 -0
  208. data/spec/generators/jax/scaffold_generator_spec.rb +35 -0
  209. data/spec/generators/jax/shader_generator_spec.rb +37 -0
  210. data/spec/javascripts/helpers/jasmine_webgl_helper.js +13 -0
  211. data/{lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers → spec/javascripts/helpers}/jax_spec_environment_helper.js +7 -2
  212. data/{lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers → spec/javascripts/helpers}/jax_spec_helper.js +0 -0
  213. data/spec/javascripts/jax/builtin/meshes/cube_spec.js +10 -0
  214. data/spec/javascripts/jax/builtin/meshes/plane_spec.js +8 -0
  215. data/spec/javascripts/jax/builtin/meshes/quad_spec.js +8 -0
  216. data/spec/javascripts/jax/builtin/meshes/sphere_spec.js +8 -0
  217. data/spec/javascripts/jax/builtin/meshes/teapot_spec.js +8 -0
  218. data/spec/javascripts/jax/builtin/meshes/torus_spec.js +8 -0
  219. data/spec/javascripts/jax/compatibility_spec.js +46 -0
  220. data/spec/javascripts/jax/context_events_spec.js +212 -0
  221. data/spec/javascripts/jax/context_spec.js +305 -0
  222. data/spec/javascripts/jax/core/data_region_spec.js +118 -0
  223. data/spec/javascripts/jax/core/data_segment_spec.js +96 -0
  224. data/spec/javascripts/jax/core/delegation_spec.js +48 -0
  225. data/spec/javascripts/jax/core/events_spec.js +17 -0
  226. data/spec/javascripts/jax/core/glMatrix_extensions_spec.js +8 -0
  227. data/spec/javascripts/jax/core/helper_spec.js +61 -0
  228. data/spec/javascripts/jax/core/matrix_stack_spec.js +28 -0
  229. data/spec/javascripts/jax/core/utils_spec.js +275 -0
  230. data/spec/javascripts/jax/geometry/line_spec.js +20 -0
  231. data/spec/javascripts/jax/geometry/plane_spec.js +181 -0
  232. data/spec/javascripts/jax/geometry/triangle_spec.js +105 -0
  233. data/spec/javascripts/jax/mvc/controller_spec.js +156 -0
  234. data/spec/javascripts/jax/mvc/model_spec.js +93 -0
  235. data/spec/javascripts/jax/mvc/route_set_spec.js +49 -0
  236. data/spec/javascripts/jax/mvc/view_manager_spec.js +17 -0
  237. data/spec/javascripts/jax/noise_spec.js +50 -0
  238. data/spec/javascripts/jax/optimizations/material_limitations_spec.js +85 -0
  239. data/spec/javascripts/jax/optimizations/shaders/basic_spec.js +65 -0
  240. data/spec/javascripts/jax/prototype/extensions_spec.js +34 -0
  241. data/spec/javascripts/jax/webgl/camera_spec.js +237 -0
  242. data/spec/javascripts/jax/webgl/core/events_spec.js +47 -0
  243. data/spec/javascripts/jax/webgl/framebuffer_spec.js +44 -0
  244. data/spec/javascripts/jax/webgl/lighting_spec.js +108 -0
  245. data/spec/javascripts/jax/webgl/material_spec.js +117 -0
  246. data/spec/javascripts/jax/webgl/mesh_spec.js +228 -0
  247. data/spec/javascripts/jax/webgl/shader/manifest_spec.js +57 -0
  248. data/spec/javascripts/jax/webgl/shader_chain_spec.js +211 -0
  249. data/spec/javascripts/jax/webgl/shader_spec.js +276 -0
  250. data/spec/javascripts/jax/webgl/tangent_space_spec.js +142 -0
  251. data/spec/javascripts/jax/webgl/texture_spec.js +159 -0
  252. data/spec/javascripts/jax/webgl_spec.js +5 -0
  253. data/spec/javascripts/jax/world_spec.js +175 -0
  254. data/spec/javascripts/jax_spec.js +14 -0
  255. data/spec/javascripts/node/mocks/webgl.js +159 -0
  256. data/spec/javascripts/node_helper.js +51 -0
  257. data/spec/javascripts/shaders/core_materials_spec.js +38 -0
  258. data/spec/javascripts/shaders/fog_spec.js +15 -0
  259. data/spec/javascripts/shaders/lighting_spec.js +15 -0
  260. data/spec/javascripts/shaders/normal_map_spec.js +15 -0
  261. data/spec/javascripts/shaders/paraboloid_spec.js +33 -0
  262. data/spec/javascripts/shaders/preprocessor_spec.js +45 -0
  263. data/spec/javascripts/shaders/shadow_map_spec.js +15 -0
  264. data/spec/javascripts/shaders/texture_spec.js +37 -0
  265. data/spec/javascripts/suite/controller_select_spec.js.coffee +24 -0
  266. data/spec/lib/jax/commands/plugin_manager/credentials_spec.rb +56 -0
  267. data/spec/lib/jax/commands/plugin_manager/push_spec.rb +62 -0
  268. data/spec/lib/jax/commands/plugin_manager_spec.rb +204 -0
  269. data/spec/lib/jax/rails/application_spec.rb +23 -0
  270. data/spec/lib/jax/shader_spec.rb +67 -0
  271. data/spec/lib/jax/util/tar_spec.rb +26 -0
  272. data/spec/{test_helper.rb → spec_helper.rb} +37 -28
  273. data/spec/support/test_model_generator.rb +14 -0
  274. data/templates/app/Gemfile.tt +17 -0
  275. data/templates/app/Rakefile +4 -0
  276. data/templates/app/config/application.rb +16 -0
  277. data/{lib/jax/generators/app/templates → templates/app}/config/boot.rb +0 -0
  278. data/templates/app/config/environment.rb +5 -0
  279. data/templates/app/config/environments/production.rb +4 -0
  280. data/templates/app/config.ru +6 -0
  281. data/{lib/jax/generators/app/templates/app/resources → templates/app/public}/.empty_directory +0 -0
  282. data/templates/app/script/jax +8 -0
  283. data/{lib/jax/generators/app/templates/app/views → templates/app/spec}/.empty_directory +0 -0
  284. data/templates/application_controller.js.coffee.erb +3 -0
  285. data/templates/application_controller.js.erb +6 -0
  286. data/templates/application_helper.js.coffee.erb +3 -0
  287. data/templates/application_helper.js.erb +3 -0
  288. data/templates/controller.js.coffee.erb +9 -0
  289. data/templates/controller.js.erb +15 -0
  290. data/templates/controller_spec.js.coffee.erb +9 -0
  291. data/templates/controller_spec.js.erb +12 -0
  292. data/templates/helper.js.coffee.erb +2 -0
  293. data/templates/helper.js.erb +3 -0
  294. data/templates/helper_spec.js.coffee.erb +8 -0
  295. data/templates/helper_spec.js.erb +12 -0
  296. data/{lib/jax/generators/light_source/templates/light.yml.tt → templates/light_source.resource.erb} +3 -3
  297. data/{lib/jax/generators/material/templates/material.yml.tt → templates/material.resource.erb} +0 -9
  298. data/templates/model.js.coffee.erb +3 -0
  299. data/templates/model.js.erb +5 -0
  300. data/templates/model_defaults.resource.erb +5 -0
  301. data/templates/model_spec.js.coffee.erb +16 -0
  302. data/templates/model_spec.js.erb +18 -0
  303. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/controllers/.empty_directory +0 -0
  304. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/helpers/.empty_directory +0 -0
  305. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/models/.empty_directory +0 -0
  306. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/resources/.empty_directory +0 -0
  307. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/views/.empty_directory +0 -0
  308. data/{lib/jax/generators/plugin/templates → templates}/new_plugin/init.rb +0 -0
  309. data/{lib/jax/generators/plugin/templates → templates}/new_plugin/install.rb +0 -0
  310. data/{lib/jax/generators/plugin/templates/new_plugin/public → templates/new_plugin/spec}/.empty_directory +0 -0
  311. data/{lib/jax/generators/plugin/templates → templates}/new_plugin/uninstall.rb +0 -0
  312. data/{lib/jax/generators/shader/templates/common.ejs.tt → templates/shader_common.glsl.erb} +0 -0
  313. data/{lib/jax/generators/shader/templates/fragment.ejs.tt → templates/shader_fragment.glsl.erb} +0 -0
  314. data/{lib/jax/generators/shader/templates/manifest.yml.tt → templates/shader_manifest.yml.erb} +0 -0
  315. data/templates/shader_material.js.coffee.erb +22 -0
  316. data/{lib/jax/generators/shader/templates/material.js.tt → templates/shader_material.js.erb} +0 -0
  317. data/templates/shader_spec.js.coffee.erb +16 -0
  318. data/{lib/jax/generators/shader/templates/spec.js.tt → templates/shader_spec.js.erb} +1 -1
  319. data/{lib/jax/generators/shader/templates/vertex.ejs.tt → templates/shader_vertex.glsl.erb} +0 -0
  320. data/templates/view.js.coffee.erb +3 -0
  321. data/{lib/jax/generators/controller/templates/view.js.tt → templates/view.js.erb} +1 -1
  322. data/vendor/assets/javascripts/ejs.js +505 -0
  323. data/vendor/assets/javascripts/glMatrix.js +1772 -0
  324. data/vendor/assets/javascripts/jasmine.js +2476 -0
  325. data/vendor/assets/stylesheets/jasmine.css +166 -0
  326. data/vendor/pdoc_template/html/assets/images/pdoc/alias.png +0 -0
  327. data/vendor/pdoc_template/html/assets/images/pdoc/class.png +0 -0
  328. data/vendor/pdoc_template/html/assets/images/pdoc/class_deprecated.png +0 -0
  329. data/vendor/pdoc_template/html/assets/images/pdoc/class_method.png +0 -0
  330. data/vendor/pdoc_template/html/assets/images/pdoc/class_property.png +0 -0
  331. data/vendor/pdoc_template/html/assets/images/pdoc/constant.png +0 -0
  332. data/vendor/pdoc_template/html/assets/images/pdoc/constructor.png +0 -0
  333. data/vendor/pdoc_template/html/assets/images/pdoc/deprecated.png +0 -0
  334. data/vendor/pdoc_template/html/assets/images/pdoc/description.png +0 -0
  335. data/vendor/pdoc_template/html/assets/images/pdoc/information.png +0 -0
  336. data/vendor/pdoc_template/html/assets/images/pdoc/instance_method.png +0 -0
  337. data/vendor/pdoc_template/html/assets/images/pdoc/instance_property.png +0 -0
  338. data/vendor/pdoc_template/html/assets/images/pdoc/method.png +0 -0
  339. data/vendor/pdoc_template/html/assets/images/pdoc/method_deprecated.png +0 -0
  340. data/vendor/pdoc_template/html/assets/images/pdoc/mixin.png +0 -0
  341. data/vendor/pdoc_template/html/assets/images/pdoc/namespace.png +0 -0
  342. data/vendor/pdoc_template/html/assets/images/pdoc/property.png +0 -0
  343. data/vendor/pdoc_template/html/assets/images/pdoc/related_to.png +0 -0
  344. data/vendor/pdoc_template/html/assets/images/pdoc/search-background.png +0 -0
  345. data/vendor/pdoc_template/html/assets/images/pdoc/section-background.png +0 -0
  346. data/vendor/pdoc_template/html/assets/images/pdoc/section.png +0 -0
  347. data/vendor/pdoc_template/html/assets/images/pdoc/selected-section-background.png +0 -0
  348. data/vendor/pdoc_template/html/assets/images/pdoc/subclass.png +0 -0
  349. data/vendor/pdoc_template/html/assets/images/pdoc/superclass.png +0 -0
  350. data/vendor/pdoc_template/html/assets/images/pdoc/utility.png +0 -0
  351. data/vendor/pdoc_template/html/assets/javascripts/pdoc/application.js +478 -0
  352. data/vendor/pdoc_template/html/assets/javascripts/pdoc/prototype.js +4874 -0
  353. data/vendor/pdoc_template/html/assets/javascripts/pdoc/tabs.js +506 -0
  354. data/vendor/pdoc_template/html/assets/stylesheets/jax.css +30 -0
  355. data/vendor/pdoc_template/html/assets/stylesheets/pdoc/api.css +681 -0
  356. data/vendor/pdoc_template/html/assets/stylesheets/pdoc/pygments.css +62 -0
  357. data/vendor/pdoc_template/html/helpers.rb +35 -0
  358. data/vendor/pdoc_template/html/index.erb +18 -0
  359. data/vendor/pdoc_template/html/item_index.js.erb +6 -0
  360. data/vendor/pdoc_template/html/layout.erb +67 -0
  361. data/vendor/pdoc_template/html/leaf.erb +22 -0
  362. data/vendor/pdoc_template/html/node.erb +30 -0
  363. data/vendor/pdoc_template/html/partials/class_relationships.erb +19 -0
  364. data/vendor/pdoc_template/html/partials/classes.erb +7 -0
  365. data/vendor/pdoc_template/html/partials/constructor.erb +5 -0
  366. data/vendor/pdoc_template/html/partials/description.erb +5 -0
  367. data/vendor/pdoc_template/html/partials/link_list.erb +1 -0
  368. data/vendor/pdoc_template/html/partials/method_signatures.erb +14 -0
  369. data/vendor/pdoc_template/html/partials/methodized_note.erb +9 -0
  370. data/vendor/pdoc_template/html/partials/mixins.erb +7 -0
  371. data/vendor/pdoc_template/html/partials/namespaces.erb +7 -0
  372. data/vendor/pdoc_template/html/partials/related_utilities.erb +5 -0
  373. data/vendor/pdoc_template/html/partials/relationships.erb +11 -0
  374. data/vendor/pdoc_template/html/partials/short_description_list.erb +7 -0
  375. data/vendor/pdoc_template/html/partials/title.erb +24 -0
  376. data/vendor/pdoc_template/html/section.erb +18 -0
  377. metadata +635 -332
  378. data/builtin/app/shaders/lighting/common.ejs +0 -5
  379. data/builtin/app/shaders/normal_map/material.js +0 -16
  380. data/builtin/app/shaders/texture/material.js +0 -18
  381. data/jax.gems +0 -1
  382. data/lib/jax/application/builtin/configurable.rb +0 -5
  383. data/lib/jax/application/builtin/configuration.rb +0 -5
  384. data/lib/jax/application/builtin.rb +0 -12
  385. data/lib/jax/application/configurable.rb +0 -19
  386. data/lib/jax/application/configuration.rb +0 -60
  387. data/lib/jax/application/railties.rb +0 -26
  388. data/lib/jax/application.rb +0 -149
  389. data/lib/jax/core_ext/kernel.rb +0 -7
  390. data/lib/jax/engine/configurable.rb +0 -19
  391. data/lib/jax/engine/configuration.rb +0 -49
  392. data/lib/jax/generators/app/app_generator.rb +0 -96
  393. data/lib/jax/generators/app/templates/Gemfile.tt +0 -3
  394. data/lib/jax/generators/app/templates/Rakefile +0 -6
  395. data/lib/jax/generators/app/templates/app/controllers/application_controller.js.tt +0 -5
  396. data/lib/jax/generators/app/templates/app/helpers/application_helper.js.tt +0 -3
  397. data/lib/jax/generators/app/templates/config/application.rb.tt +0 -6
  398. data/lib/jax/generators/app/templates/config/environment.rb.tt +0 -5
  399. data/lib/jax/generators/app/templates/config/routes.rb.tt +0 -5
  400. data/lib/jax/generators/app/templates/public/index.html.tt +0 -26
  401. data/lib/jax/generators/app/templates/public/javascripts/jax.js +0 -9462
  402. data/lib/jax/generators/app/templates/public/stylesheets/%file_name%.css.tt +0 -11
  403. data/lib/jax/generators/app/templates/public/webgl_not_supported.html +0 -26
  404. data/lib/jax/generators/app/templates/script/jax +0 -7
  405. data/lib/jax/generators/app/templates/spec/javascripts/controllers/application_controller_spec.js +0 -11
  406. data/lib/jax/generators/app/templates/spec/javascripts/helpers/application_helper_spec.js +0 -12
  407. data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine.yml +0 -91
  408. data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine_config.rb +0 -23
  409. data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine_runner.rb +0 -32
  410. data/lib/jax/generators/app/templates/spec/javascripts/support/spec_layout.html.erb +0 -104
  411. data/lib/jax/generators/app.rb +0 -18
  412. data/lib/jax/generators/commands.rb +0 -220
  413. data/lib/jax/generators/controller/USAGE +0 -9
  414. data/lib/jax/generators/controller/controller_generator.rb +0 -66
  415. data/lib/jax/generators/controller/templates/controller_source.js.tt +0 -16
  416. data/lib/jax/generators/controller/templates/controller_test.js.tt +0 -11
  417. data/lib/jax/generators/controller/templates/helper.js.tt +0 -3
  418. data/lib/jax/generators/controller/templates/helper_test.js.tt +0 -12
  419. data/lib/jax/generators/interactions.rb +0 -56
  420. data/lib/jax/generators/light_source/USAGE +0 -14
  421. data/lib/jax/generators/light_source/light_source_generator.rb +0 -46
  422. data/lib/jax/generators/material/material_generator.rb +0 -80
  423. data/lib/jax/generators/material/templates/append.yml.tt +0 -7
  424. data/lib/jax/generators/model/USAGE +0 -5
  425. data/lib/jax/generators/model/model_generator.rb +0 -40
  426. data/lib/jax/generators/model/templates/model.js.tt +0 -11
  427. data/lib/jax/generators/model/templates/test.js.tt +0 -11
  428. data/lib/jax/generators/packager/package_generator.rb +0 -32
  429. data/lib/jax/generators/plugin/USAGE +0 -4
  430. data/lib/jax/generators/plugin/all.rb +0 -113
  431. data/lib/jax/generators/plugin/credentials.rb +0 -108
  432. data/lib/jax/generators/plugin/plugin_generator.rb +0 -72
  433. data/lib/jax/generators/plugin/plugin_manager.rb +0 -254
  434. data/lib/jax/generators/plugin/templates/new_plugin/config/routes.rb +0 -3
  435. data/lib/jax/generators/plugin/templates/new_plugin/spec/.empty_directory +0 -0
  436. data/lib/jax/generators/script_jax_loader.rb +0 -49
  437. data/lib/jax/generators/shader/USAGE +0 -4
  438. data/lib/jax/generators/shader/shader_generator.rb +0 -70
  439. data/lib/jax/monkeypatch/jasmine/config.rb +0 -45
  440. data/lib/jax/monkeypatch/jasmine/server.rb +0 -50
  441. data/lib/jax/monkeypatch/jasmine.rb +0 -3
  442. data/lib/jax/packager/sprockets_template.rb +0 -77
  443. data/lib/jax/packager.rb +0 -59
  444. data/lib/jax/plugin/manifest.rb +0 -71
  445. data/lib/jax/plugin.rb +0 -49
  446. data/lib/jax/resource_compiler.rb +0 -60
  447. data/lib/jax/routes.rb +0 -62
  448. data/lib/jax/tasks/rake.rb +0 -38
  449. data/spec/benchmark.htm +0 -93
  450. data/spec/generators/app_generator_test.rb +0 -42
  451. data/spec/generators/controller_generator_test.rb +0 -47
  452. data/spec/generators/light_generator_test.rb +0 -37
  453. data/spec/generators/material_generator_test.rb +0 -22
  454. data/spec/generators/model_generator_test.rb +0 -26
  455. data/spec/generators/plugin_generator_test.rb +0 -114
  456. data/spec/generators/plugin_manager/push_test.rb +0 -59
  457. data/spec/generators/plugin_manager_test.rb +0 -192
  458. data/spec/generators/shader_generator_test.rb +0 -38
  459. data/spec/javascripts/support/jasmine.yml +0 -85
  460. data/spec/javascripts/support/jasmine_runner.rb +0 -32
  461. data/spec/lib/jax/application_test.rb +0 -18
  462. data/spec/lib/jax/generators/plugin/credentials_test.rb +0 -72
  463. data/spec/lib/jax/packager_test.rb +0 -87
  464. data/spec/lib/jax/plugin_test.rb +0 -27
  465. data/spec/lib/jax/reloading_test.rb +0 -23
  466. data/spec/lib/jax/routes_test.rb +0 -28
  467. data/spec/lib/jax/shader_test.rb +0 -29
  468. data/spec/lib/jax/tasks/jax_rake_test.rb +0 -85
  469. data/spec/support/bases/generator_test_case.rb +0 -108
  470. data/spec/support/bases/isolated_test_case.rb +0 -148
  471. data/spec/support/file_exist_matcher.rb +0 -23
  472. data/spec/support/spec_shell.rb +0 -110
  473. data/spec/test_app.rb +0 -3
@@ -0,0 +1,300 @@
1
+ Jax.POINT_LIGHT = 1;
2
+ Jax.SPOT_LIGHT = 2;
3
+ Jax.DIRECTIONAL_LIGHT = 3;
4
+
5
+ Jax.Scene.LightSource = (function() {
6
+ function setupProjection(self) {
7
+ if (self.camera.projection) return;
8
+
9
+ switch(self.type) {
10
+ case Jax.DIRECTIONAL_LIGHT:
11
+ self.camera.ortho({left:-1,right:1, top:1,bottom:-1, near:-1,far:1 });
12
+ self.camera.setPosition(0,0,0);
13
+ break;
14
+ case Jax.POINT_LIGHT:
15
+ self.camera.perspective({fov:45,near:0.01,far:500,width:2048,height:2048});
16
+ break;
17
+ case Jax.SPOT_LIGHT:
18
+ self.camera.perspective({near:0.1,far:500,fov:60,width:2048,height:2048});
19
+ break;
20
+ default:
21
+ throw new Error("Unexpected light type: "+self.type);
22
+ }
23
+ }
24
+
25
+ return Jax.Model.create({
26
+ initialize: function($super, data) {
27
+ data = Jax.Util.normalizeOptions(data, {
28
+ enabled: true,
29
+ type: Jax.POINT_LIGHT,
30
+ color: {
31
+ ambient: [0,0,0,1],
32
+ diffuse: [1,1,1,1],
33
+ specular: [1,1,1,1]
34
+ },
35
+ position: [0,0,0],
36
+ direction: [0,0,-1],
37
+ angle: Math.PI/6,
38
+ attenuation: {
39
+ constant: 0,
40
+ linear: 0.02,
41
+ quadratic: 0
42
+ },
43
+ spot_exponent: 0,
44
+ shadowcaster: true
45
+ });
46
+
47
+ if (typeof(data.type) == "string") data.type = Jax[data.type] || data.type;
48
+ data.color.ambient = Jax.Util.colorize(data.color.ambient);
49
+ data.color.diffuse = Jax.Util.colorize(data.color.diffuse);
50
+ data.color.specular= Jax.Util.colorize(data.color.specular);
51
+ $super(data);
52
+
53
+ var self = this;
54
+ this.camera.addEventListener('updated', function() { self.invalidate(); });
55
+
56
+ this.spotExponent = this.spot_exponent;
57
+ delete this.spot_exponent;
58
+
59
+ this.shadowMatrix = mat4.create();
60
+
61
+ this.framebuffers = [new Jax.Framebuffer({width:1024,height:1024,depth:true,color:GL_RGBA}),
62
+ new Jax.Framebuffer({width:1024,height:1024,depth:true,color:GL_RGBA})];
63
+
64
+ setupProjection(this);
65
+ },
66
+
67
+ format: function() {
68
+ this._format = this._format || new glMatrixArrayType(Jax.Scene.LightSource.STRUCT_SIZE);
69
+ var i, j, len = 0, self = this;
70
+ function push() { for (j = 0; j < arguments.length; j++) self._format[len++] = arguments[j]; }
71
+ for (i = 0; i < arguments.length; i++) {
72
+ switch(arguments[i]) {
73
+ case Jax.Scene.LightSource.POSITION: push.apply(this, this.getPosition()); break;
74
+ case Jax.Scene.LightSource.DIRECTION: push.apply(this, this.getDirection()); break;
75
+ case Jax.Scene.LightSource.AMBIENT: push.apply(this, this.getAmbientColor()); break;
76
+ case Jax.Scene.LightSource.DIFFUSE: push.apply(this, this.getDiffuseColor()); break;
77
+ case Jax.Scene.LightSource.SPECULAR: push.apply(this, this.getSpecularColor()); break;
78
+ case Jax.Scene.LightSource.CONSTANT_ATTENUATION: push(this.getConstantAttenuation()); break;
79
+ case Jax.Scene.LightSource.LINEAR_ATTENUATION: push(this.getLinearAttenuation()); break;
80
+ case Jax.Scene.LightSource.QUADRATIC_ATTENUATION: push(this.getQuadraticAttenuation()); break;
81
+ case Jax.Scene.LightSource.SPOTLIGHT_EXPONENT: push(this.getSpotExponent()); break;
82
+ case Jax.Scene.LightSource.SPOTLIGHT_COS_CUTOFF: push(this.getSpotCosCutoff()); break;
83
+ default: throw new Error("Unexpected light source format descriptor: "+arguments[i]);
84
+ }
85
+ }
86
+ return this._format;
87
+ },
88
+
89
+ getPosition: function() { setupProjection(this); return this.camera.getPosition(); },
90
+ getDirection: function() { setupProjection(this); return this.camera.getViewVector(); },
91
+
92
+ setEnabled: function(b) { this.enabled = b; },
93
+ enable: function() { this.setEnabled(true); },
94
+ disable: function() { this.setEnabled(false); },
95
+
96
+ isEnabled: function() { return this.enabled; },
97
+ getType: function() { return this.type; },
98
+
99
+ getDiffuseColor: function() { return this.color.diffuse; },
100
+ getAmbientColor: function() { return this.color.ambient; },
101
+ getSpecularColor: function() { return this.color.specular; },
102
+ getConstantAttenuation: function() { return this.attenuation.constant; },
103
+ getQuadraticAttenuation: function() { return this.attenuation.quadratic; },
104
+ getLinearAttenuation: function() { return this.attenuation.linear; },
105
+ getAngle: function() { return this.angle; },
106
+ getSpotExponent: function() { return this.spotExponent; },
107
+ getSpotCosCutoff: function() { return Math.cos(this.angle); },
108
+
109
+ getShadowMapTexture: function(context) {
110
+ setupProjection(this);
111
+ return this.framebuffers[0].getTexture(context, 0);
112
+ },
113
+
114
+ getShadowMapTextures: function(context) {
115
+ setupProjection(this);
116
+ return [this.framebuffers[0].getTexture(context, 0),
117
+ this.framebuffers[1].getTexture(context, 0)];
118
+ },
119
+
120
+ isShadowMapEnabled: function() {
121
+ return !!(this.framebuffers && this.isShadowcaster());
122
+ },
123
+
124
+ getShadowMatrix: function() {
125
+ return this.shadowMatrix;
126
+ },
127
+
128
+ registerCaster: function(object) {
129
+ var self = this;
130
+ function updated() { self.invalidate(); }
131
+ object.camera.addEventListener('updated', updated);
132
+ this.invalidate();
133
+ },
134
+
135
+ unregisterCaster: function(object) {
136
+ /* FIXME remove the shadowmap event listener from object's camera matrix */
137
+ },
138
+
139
+ isShadowcaster: function() { return this.shadowcaster; },
140
+
141
+ getDPShadowNear: function() { setupProjection(this); return this.camera.projection.near; },
142
+
143
+ getDPShadowFar: function() { setupProjection(this); return this.camera.projection.far; },
144
+
145
+ invalidate: function() { this.valid = false; },
146
+
147
+ render: function(context, objects, options) {
148
+ if (!this.valid) {
149
+ var real_pass = context.current_pass;
150
+ /* shadowgen pass */
151
+ context.current_pass = Jax.Scene.SHADOWMAP_PASS;
152
+ // Look for errors while rendering the shadow map; if any occur, log them, but then
153
+ // disable shadowmap generation so Jax can continue without shadow support.
154
+ try {
155
+ if (this.shadowcaster)
156
+ this.updateShadowMap(context, this.boundingRadius, objects, options);
157
+ this.valid = true;
158
+ } catch(e) {
159
+ if (Jax.getGlobal().console && Jax.getGlobal().console.log)
160
+ Jax.getGlobal().console.log(e.toString());
161
+ this.shadowcaster = false;
162
+ }
163
+ context.current_pass = real_pass;
164
+ }
165
+
166
+ for (var j = 0; j < objects.length; j++) {
167
+ options.model_index = j;
168
+
169
+ /* TODO optimization: see if objects[j] is even affected by this light (based on attenuation) */
170
+ if (objects[j].isLit()) // it could be unlit but still in array if it casts a shadow
171
+ objects[j].render(context, options);
172
+ }
173
+ },
174
+
175
+ updateShadowMap: function(context, sceneBoundingRadius, objects, render_options) {
176
+ // we can't afford to taint the original options
177
+ render_options = Jax.Util.normalizeOptions(render_options, {});
178
+
179
+ setupProjection(this);
180
+
181
+ var self = this;
182
+ var sm = this.shadowMatrix;
183
+ var lightToSceneDistance = vec3.length(this.camera.getPosition());
184
+ var nearPlane = lightToSceneDistance - sceneBoundingRadius;
185
+ if (nearPlane < 0.01) nearPlane = 0.01;
186
+
187
+ if (this.type == Jax.DIRECTIONAL_LIGHT) {
188
+ this.camera.ortho({left:-sceneBoundingRadius,right:sceneBoundingRadius,
189
+ top:sceneBoundingRadius,bottom:-sceneBoundingRadius,
190
+ near:-sceneBoundingRadius,far:sceneBoundingRadius
191
+ });
192
+ this.camera.setPosition(0,0,0);
193
+ } else if (this.type == Jax.SPOT_LIGHT) {
194
+ // Save the depth precision for where it's useful
195
+ var fieldOfView = Math.radToDeg(2.0 * Math.atan(sceneBoundingRadius / lightToSceneDistance));
196
+
197
+ // fieldOfView = Math.radToDeg(this.getAngle());
198
+ fieldOfView = 60;
199
+ this.camera.perspective({near:nearPlane,far:nearPlane+(2.0*sceneBoundingRadius),fov:fieldOfView,width:2048,height:2048});
200
+ } else if (this.type == Jax.POINT_LIGHT) {
201
+ var paraboloid_depthmap = Jax.Material.find("paraboloid-depthmap");
202
+
203
+ context.glDisable(GL_BLEND);
204
+ context.glEnable(GL_CULL_FACE);
205
+ context.glCullFace(GL_FRONT);
206
+ context.glEnable(GL_POLYGON_OFFSET_FILL);
207
+ context.glPolygonOffset(2.0, 2.0);
208
+
209
+ context.pushMatrix(function() {
210
+ render_options.direction = 1;
211
+ render_options.material = paraboloid_depthmap;
212
+
213
+ self.framebuffers[0].bind(context, function() {
214
+ // front paraboloid
215
+ self.framebuffers[0].viewport(context);
216
+ context.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
217
+ context.loadViewMatrix(self.camera.getTransformationMatrix());
218
+ mat4.set(context.getInverseViewMatrix(), sm);
219
+
220
+ for (var i = 0; i < objects.length; i++) {
221
+ objects[i].render(context, render_options);
222
+ }
223
+ });
224
+
225
+ render_options.direction = -1;
226
+
227
+ self.framebuffers[1].bind(context, function() {
228
+ // back paraboloid
229
+ self.framebuffers[1].viewport(context);
230
+ context.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
231
+ context.loadViewMatrix(self.camera.getTransformationMatrix());
232
+ for (var i = 0; i < objects.length; i++) {
233
+ objects[i].render(context, render_options);
234
+ }
235
+ });
236
+
237
+ context.glDisable(GL_POLYGON_OFFSET_FILL);
238
+ context.glEnable(GL_BLEND);
239
+ context.glCullFace(GL_BACK);
240
+ context.glDisable(GL_CULL_FACE);
241
+
242
+ // restore the original context viewport
243
+ context.glViewport(0, 0, context.canvas.width, context.canvas.height);
244
+ });
245
+
246
+ return;
247
+ }
248
+
249
+ render_options.material = "depthmap";
250
+
251
+ this.framebuffers[0].bind(context, function() {
252
+ self.framebuffers[0].viewport(context);
253
+ context.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
254
+ context.pushMatrix(function() {
255
+ self.framebuffers[0].viewport(context);
256
+ context.matrix_stack.loadProjectionMatrix(self.camera.getProjectionMatrix());
257
+ context.matrix_stack.loadViewMatrix(self.camera.getTransformationMatrix());
258
+ mat4.identity(sm);
259
+ sm[0] = sm[5] = sm[10] = sm[12] = sm[13] = sm[14] = 0.5;
260
+ mat4.multiply(sm, context.getModelViewProjectionMatrix());
261
+
262
+ context.glEnable(GL_CULL_FACE);
263
+ context.glCullFace(GL_FRONT);
264
+ context.glDisable(GL_BLEND);
265
+ context.glEnable(GL_POLYGON_OFFSET_FILL);
266
+ context.glPolygonOffset(2.0, 2.0);
267
+ for (var i = 0; i < objects.length; i++) {
268
+ objects[i].render(context, render_options);
269
+ }
270
+ context.glDisable(GL_POLYGON_OFFSET_FILL);
271
+ context.glEnable(GL_BLEND);
272
+ context.glCullFace(GL_BACK);
273
+ context.glDisable(GL_CULL_FACE);
274
+ });
275
+ // restore the original context viewport
276
+ context.glViewport(0, 0, context.canvas.width, context.canvas.height);
277
+ });
278
+ }
279
+ });
280
+ })();
281
+
282
+ /*
283
+ Constants used internally when constructing the flat-array format for a light source.
284
+ This is so we don't need to make redundant glUniform() calls to specify the attributes of a single
285
+ light source.
286
+ */
287
+ Jax.Scene.LightSource.POSITION = 1;
288
+ Jax.Scene.LightSource.DIRECTION = 2;
289
+ Jax.Scene.LightSource.AMBIENT = 3;
290
+ Jax.Scene.LightSource.DIFFUSE = 4;
291
+ Jax.Scene.LightSource.SPECULAR = 5;
292
+ Jax.Scene.LightSource.CONSTANT_ATTENUATION = 6;
293
+ Jax.Scene.LightSource.LINEAR_ATTENUATION = 7;
294
+ Jax.Scene.LightSource.QUADRATIC_ATTENUATION = 8;
295
+ Jax.Scene.LightSource.SPOTLIGHT_EXPONENT = 9;
296
+ Jax.Scene.LightSource.SPOTLIGHT_COS_CUTOFF = 10;
297
+
298
+ /* The size of the light source structure, in float elements */
299
+ Jax.Scene.LightSource.STRUCT_SIZE = 23;
300
+
@@ -0,0 +1,16 @@
1
+ //= require_self
2
+ //= require "jax/webgl/scene/frustum"
3
+ //= require "jax/webgl/scene/light_manager"
4
+
5
+ /**
6
+ * Jax.Scene
7
+ *
8
+ **/
9
+ Jax.Scene = {};
10
+
11
+ /* used by some shaders to determine what kind of shading is to be done.
12
+ * This is stored in context.world.current_pass.
13
+ */
14
+ Jax.Scene.ILLUMINATION_PASS = 1;
15
+ Jax.Scene.AMBIENT_PASS = 2;
16
+ Jax.Scene.SHADOWMAP_PASS = 3;
@@ -0,0 +1,53 @@
1
+ //= require "../delegator"
2
+
3
+ Jax.Shader.AttributeDelegator = (function() {
4
+ return Jax.Class.create(Jax.Shader.Delegator, {
5
+ initialize: function($super, context, program) {
6
+ var numAttributes = context.glGetProgramParameter(program, GL_ACTIVE_ATTRIBUTES);
7
+ var attributes = {};
8
+ for (var i = 0; i < numAttributes; i++)
9
+ {
10
+ var attrib = context.glGetActiveAttrib(program, i);
11
+ attributes[attrib.name] = {
12
+ length:attrib.length,
13
+ size:attrib.size,
14
+ type:attrib.type,
15
+ type_str:Jax.Util.enumName(attrib.type),
16
+ location: context.glGetAttribLocation(program, attrib.name)
17
+ };
18
+ }
19
+ $super(context, program, attributes);
20
+ },
21
+
22
+ set: function(name, value) {
23
+ var v, c = this.context, i, variables = this.variables;
24
+
25
+ function _set(name, value) {
26
+ if (value == undefined) return;
27
+ // if (value == undefined) throw new Error("Value is undefined for shader attribute "+JSON.stringify(name));
28
+
29
+ if (v = variables[name]) {
30
+ value.bind(c);
31
+ c.glEnableVertexAttribArray(v.location);
32
+ c.glVertexAttribPointer(v.location, value.itemSize, GL_FLOAT, false, 0, 0);
33
+ // } else {
34
+ // console.warn("skipping assignment of attribute %s (variables: %s)", name, JSON.stringify(variables));
35
+ }
36
+ }
37
+
38
+ if (arguments.length == 1 && typeof(arguments[0]) == "object")
39
+ for (i in arguments[0])
40
+ _set(i, arguments[0][i]);
41
+ else
42
+ for (i = 0; i < arguments.length; i += 2)
43
+ _set(arguments[i], arguments[i+1]);
44
+ },
45
+
46
+ disableAll: function() {
47
+ for (var v in this.variables) {
48
+ v = this.variables[v];
49
+ this.context.glDisableVertexAttribArray(v.location);
50
+ }
51
+ }
52
+ });
53
+ })();
@@ -0,0 +1,71 @@
1
+ //= require "../delegator"
2
+
3
+ Jax.Shader.UniformDelegator = (function() {
4
+ return Jax.Class.create(Jax.Shader.Delegator, {
5
+ initialize: function($super, context, program) {
6
+ var numUniforms = context.glGetProgramParameter(program, GL_ACTIVE_UNIFORMS);
7
+ var uniforms = {};
8
+ for (var i = 0; i < numUniforms; i++)
9
+ {
10
+ var unif = context.glGetActiveUniform(program, i);
11
+ uniforms[unif.name] = {
12
+ length:unif.length,
13
+ size:unif.size,
14
+ type:unif.type,
15
+ type_str:Jax.Util.enumName(unif.type),
16
+ location: context.glGetUniformLocation(program, unif.name)
17
+ };
18
+ }
19
+ $super(context, program, uniforms);
20
+ },
21
+
22
+ set: function(name, value) {
23
+ var self = this;
24
+ var variables = this.variables, v, c = this.context, i;
25
+
26
+ function _set(name, value) {
27
+ if (value == undefined) throw new Error("Value is undefined for shader uniform "+JSON.stringify(name));
28
+
29
+ if (v = variables[name]) {
30
+ try {
31
+ switch(v.type) {
32
+ case GL_FLOAT:
33
+ value.length != undefined ? c.glUniform1fv(v.location, value) : c.glUniform1f(v.location, value);
34
+ break;
35
+ case GL_BOOL: // same as int
36
+ case GL_INT:
37
+ value.length != undefined ? c.glUniform1iv(v.location, value) : c.glUniform1i(v.location, value);
38
+ break;
39
+ case GL_FLOAT_VEC2: c.glUniform2fv(v.location, value); break;
40
+ case GL_FLOAT_VEC3: c.glUniform3fv(v.location, value); break;
41
+ case GL_FLOAT_VEC4: c.glUniform4fv(v.location, value); break;
42
+ case GL_FLOAT_MAT2: c.glUniformMatrix2fv(v.location, false, value); break;
43
+ case GL_FLOAT_MAT3: c.glUniformMatrix3fv(v.location, false, value); break;
44
+ case GL_FLOAT_MAT4: c.glUniformMatrix4fv(v.location, false, value); break;
45
+ case GL_BOOL_VEC2: // same as int
46
+ case GL_INT_VEC2: c.glUniform2iv(v.location, value); break;
47
+ case GL_BOOL_VEC3: // same as int
48
+ case GL_INT_VEC3: c.glUniform3iv(v.location, value); break;
49
+ case GL_BOOL_VEC4: // same as int
50
+ case GL_INT_VEC4: c.glUniform4iv(v.location, value); break;
51
+ case GL_SAMPLER_2D: c.glUniform1i(v.location, value); break;
52
+ case GL_SAMPLER_CUBE: c.glUniform1i(v.location, value); break;
53
+ default:
54
+ throw new Error("Unexpected attribute type: "+v.type+" ("+JSON.stringify(v)+")");
55
+ }
56
+ } catch(e) {
57
+ var error = new Error("Failed to set uniform for "+name+' ('+value+") in shader program:\n\n"+e);
58
+ Jax.reraise(e, error);
59
+ }
60
+ }
61
+ }
62
+
63
+ if (arguments.length == 1 && typeof(arguments[0]) == "object")
64
+ for (i in arguments[0])
65
+ _set(i, arguments[0][i]);
66
+ else
67
+ for (i = 0; i < arguments.length; i += 2)
68
+ _set(arguments[i], arguments[i+1]);
69
+ }
70
+ });
71
+ })();
@@ -0,0 +1,13 @@
1
+ Jax.Shader.Delegator = (function() {
2
+ return Jax.Class.create({
3
+ initialize: function(context, program, variables) {
4
+ this.context = context;
5
+ this.program = program;
6
+ this.variables = variables;
7
+ },
8
+
9
+ doesExist: function(key) {
10
+ return this.variables[key] != undefined;
11
+ }
12
+ });
13
+ })();
@@ -0,0 +1,70 @@
1
+ /**
2
+ * class Jax.Shader.Manifest
3
+ *
4
+ * Used to track variable assignments. After all assignments have been made just prior to committing a render phase,
5
+ * the manifest will be used to actually pass variable values into the shader. This keeps from specifying shader
6
+ * values more than once. Manifest can also be used to cache values between render passes, because its values are
7
+ * never reset.
8
+ **/
9
+ Jax.Shader.Manifest = Jax.Class.create({
10
+ initialize: function(existing) {
11
+ this.values = {};
12
+ this.texture_tracker = 0;
13
+ this.variable_prefix = "";
14
+ this.existing = existing || [];
15
+ },
16
+
17
+ set: function(name, value) {
18
+ var i;
19
+ if (value === undefined)
20
+ if (typeof(name) == "object")
21
+ for (i in name)
22
+ this.set(i, name[i]);
23
+ else throw new Error("Invalid argument (or the value given is undefined): "+
24
+ JSON.stringify(name)+"\n\n"+new Error().stack);
25
+ else
26
+ for (i = 0; i < arguments.length; i += 2) {
27
+ if (this.existing.indexOf(arguments[i]) != -1)
28
+ this.values[arguments[i]] = arguments[i+1];
29
+ else
30
+ this.values[this.variable_prefix+arguments[i]] = arguments[i+1];
31
+ }
32
+ },
33
+
34
+ getValue: function(name) {
35
+ if (this.existing.indexOf(name) != -1)
36
+ return this.values[name];
37
+ else return this.values[this.variable_prefix+name];
38
+ },
39
+
40
+ texture: function(name, tex, context) {
41
+ if (!context) throw new Error("Can't bind texture without a context");
42
+ if (this.texture_tracker == GL_MAX_ACTIVE_TEXTURES-1) {
43
+ /* FIXME add a callback for Materials to enter compatibility mode and recompile their shaders
44
+ before throwing a hard error. Until this is implemented, the hard error itself is disabled
45
+ because it causes unnecessary barfing on machines that are otherwise capable of running the
46
+ scene. Using too many textures doesn't seem to have any catastrophic results on tested
47
+ hardware, except some visual anomolies, so there's no reason to crash out catastrophically.
48
+ */
49
+ // throw new Error("Maximum number of textures ("+GL_MAX_ACTIVE_TEXTURES+") has been reached!");
50
+ }
51
+
52
+ if (typeof(this.getValue(name)) != "number")
53
+ this.set(name, this.texture_tracker++);
54
+
55
+ if (tex.loaded) {
56
+ context.glActiveTexture(GL_TEXTURES[this.getValue(name)]);
57
+ tex.bind(context, this.getValue(name));
58
+ }
59
+ },
60
+
61
+ apply: function(uniforms, attributes) {
62
+ attributes.disableAll();
63
+ for (var name in this.values) {
64
+ if (uniforms.doesExist(name))
65
+ uniforms.set(name, this.values[name]);
66
+ else if (attributes.doesExist(name))
67
+ attributes.set(name, this.values[name]);
68
+ }
69
+ }
70
+ });
@@ -0,0 +1,138 @@
1
+ //= require "jax/webgl/shader/delegator/attribute"
2
+ //= require "jax/webgl/shader/delegator/uniform"
3
+ //= require "jax/webgl/shader/manifest"
4
+
5
+ Jax.Shader.Program = (function() {
6
+ function buildShaderSources(self, context, material) {
7
+ for (var i = 0; i < self.shaders.length; i++) {
8
+ self.shaders[i].build(context, material);
9
+ }
10
+ }
11
+
12
+ function getShaderProgram(self, context) {
13
+ if (self.programs[context.id]) return self.programs[context.id];
14
+ return self.programs[context.id] = context.glCreateProgram();
15
+ }
16
+
17
+ function addToVariableList(self, delegator) {
18
+ for (var name in delegator.variables) {
19
+ self.variable_names.push(name);
20
+ }
21
+ }
22
+
23
+ function updateVariableList(self, context) {
24
+ while (self.variable_names.length > 0) self.variable_names.pop();
25
+ addToVariableList(self, self.getAttributeDelegator(context));
26
+ addToVariableList(self, self.getUniformDelegator(context));
27
+ }
28
+
29
+ function linkProgram(self, context, material, program) {
30
+ /* really attach those shaders that we've pretended to have attached already */
31
+ for (var i = 0; i < self.shaders.length; i++) {
32
+ var shader = self.shaders[i];
33
+ var vert = shader.getVertexShader(context),
34
+ frag = shader.getFragmentShader(context);
35
+
36
+ if (vert) {
37
+ program.vertex = vert;
38
+ program.vertex_shader = vert;
39
+ context.glAttachShader(program, vert);
40
+ }
41
+ if (frag) {
42
+ program.fragment = true;
43
+ program.fragment_shader = frag;
44
+ context.glAttachShader(program, frag);
45
+ }
46
+ }
47
+
48
+ if (!program.vertex || !program.fragment)
49
+ throw new Error("Attempted to link program missing either a vertex or fragment shader! " +
50
+ "(WebGL requires at least 1 of each.)");
51
+
52
+ buildShaderSources(self, context, material);
53
+ context.glLinkProgram(program);
54
+
55
+ if (!context.glGetProgramParameter(program, GL_LINK_STATUS))
56
+ throw new Error("Could not initialize shader!\n\n"+context.glGetProgramInfoLog(program));
57
+ else program.linked = true;
58
+
59
+ context.glUseProgram(program);
60
+
61
+ self.attribute_delegator[context.id] = new Jax.Shader.AttributeDelegator(context, program);
62
+ self.uniform_delegator[context.id] = new Jax.Shader.UniformDelegator(context, program);
63
+ }
64
+
65
+ return Jax.Class.create({
66
+ initialize: function() {
67
+ this.shaders = [];
68
+ this.programs = {};
69
+ this.attribute_delegator = {};
70
+ this.uniform_delegator = {};
71
+ this.variable_names = [];
72
+ this.manifest = new Jax.Shader.Manifest(this.variable_names);
73
+ },
74
+
75
+ attach: function(shaderName, context) {
76
+ if (!context) throw new Error("No context!");
77
+ var shader = Jax.shaders[shaderName];
78
+ if (!shader)
79
+ throw new Error("Could not find shader named '"+shaderName+"'! " +
80
+ "Does it exist in Jax.shaders?");
81
+ this.shaders.push(shader);
82
+ },
83
+
84
+ invalidate: function() {
85
+ for (var i in this.programs)
86
+ this.programs[i].linked = false;
87
+ },
88
+
89
+ link: function(context, material) {
90
+ var program = this.getGLProgram(context);
91
+
92
+ if (!program.linked)
93
+ linkProgram(this, context, material, program);
94
+
95
+ // update list of variable names
96
+ updateVariableList(this, context);
97
+
98
+ return program;
99
+ },
100
+
101
+ setShaderVariables: function(context, mesh, material, options) {
102
+ material.setShaderVariables(context, mesh, options, this.manifest);
103
+ this.manifest.apply(this.getUniformDelegator(context), this.getAttributeDelegator(context));
104
+ },
105
+
106
+ render: function(context, mesh, material, options) {
107
+ var program = this.link(context, material);
108
+
109
+ context.glUseProgram(program);
110
+
111
+ this.setShaderVariables(context, mesh, material, options);
112
+
113
+ try {
114
+ var buffer;
115
+ if ((buffer = mesh.getIndexBuffer()) && buffer.length > 0) {
116
+ buffer.bind(context);
117
+ context.glDrawElements(options.draw_mode, buffer.length, GL_UNSIGNED_SHORT, 0);
118
+ }
119
+ else if ((buffer = mesh.getVertexBuffer()) && buffer.length > 0) {
120
+ context.glDrawArrays(options.draw_mode, 0, buffer.length);
121
+ }
122
+ } catch(e) {
123
+ var error = new Error("Fatal error encountered while drawing mesh:\n\n"+e+"\n\nShaders: "+this.getShaderNames());
124
+ Jax.reraise(e, error);
125
+ }
126
+ },
127
+
128
+ getShaderNames: function() {
129
+ var shaderNames = [];
130
+ for (var i = 0; i < this.shaders.length; i++) shaderNames[i] = this.shaders[i].getName();
131
+ return shaderNames;
132
+ },
133
+
134
+ getGLProgram: function(context) { return getShaderProgram(this, context); },
135
+ getAttributeDelegator: function(context) { return this.attribute_delegator[context.id]; },
136
+ getUniformDelegator: function(context) { return this.uniform_delegator[context.id]; }
137
+ });
138
+ })();