jax 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +2 -3
- data/.travis.yml +8 -22
- data/README.md +2 -2
- data/Rakefile +128 -96
- data/app/assets/javascripts/jax/controller-list.js.coffee +22 -0
- data/app/assets/javascripts/jax/dom-helpers.js.coffee +17 -0
- data/app/assets/javascripts/jax/jasmine_runner.js +177 -0
- data/app/assets/javascripts/jax/runtime.js +6 -0
- data/app/assets/javascripts/jax/shader_editor.js.coffee +33 -0
- data/app/assets/stylesheets/jax/controller-list.css +5 -0
- data/app/assets/stylesheets/jax/jasmine.css +16 -0
- data/app/assets/stylesheets/jax/nav.css +41 -0
- data/app/assets/stylesheets/jax/runtime.css +47 -0
- data/app/assets/stylesheets/jax/shader_editor.css +3 -0
- data/app/assets/stylesheets/jax/suite.css +82 -0
- data/app/controllers/jax/suite_controller.rb +48 -0
- data/app/views/jax/suite/jasmine.html.erb +38 -0
- data/app/views/jax/suite/run_webgl.html.erb +49 -0
- data/app/views/jax/suite/shader_editor.html.erb +24 -0
- data/app/views/layouts/jax.html.erb +40 -0
- data/bin/jax +8 -4
- data/config/routes.rb +2 -0
- data/config.ru +5 -0
- data/features/rails/resources.feature +45 -0
- data/features/rails/shaders.feature +13 -0
- data/features/rails/specs.feature +24 -0
- data/features/runtime.feature +15 -0
- data/features/step_definitions/environment_steps.rb +15 -0
- data/features/step_definitions/response_steps.rb +13 -0
- data/features/step_definitions/runtime.rb +11 -0
- data/features/step_definitions/web_steps.rb +223 -0
- data/features/support/env.rb +75 -0
- data/features/support/paths.rb +30 -0
- data/features/support/rails_environment.rb +3 -0
- data/features/support/selectors.rb +39 -0
- data/features/support/setup.rb +17 -0
- data/jax.gemspec +22 -16
- data/lib/assets/javascripts/jax/anim_frame.js +64 -0
- data/lib/assets/javascripts/jax/application.js +16 -0
- data/lib/assets/javascripts/jax/builtin/all.js +21 -0
- data/lib/assets/javascripts/jax/builtin/meshes/cube.js +83 -0
- data/lib/assets/javascripts/jax/builtin/meshes/plane.js +67 -0
- data/lib/assets/javascripts/jax/builtin/meshes/quad.js +89 -0
- data/lib/assets/javascripts/jax/builtin/meshes/sphere.js +65 -0
- data/lib/assets/javascripts/jax/builtin/meshes/teapot.js +48 -0
- data/lib/assets/javascripts/jax/builtin/meshes/torus.js +64 -0
- data/lib/assets/javascripts/jax/compatibility.js +312 -0
- data/lib/assets/javascripts/jax/context.js +741 -0
- data/lib/assets/javascripts/jax/core/base.js +69 -0
- data/lib/assets/javascripts/jax/core/glMatrix_ext/mat3.js +20 -0
- data/lib/assets/javascripts/jax/core/glMatrix_ext/mat4.js +10 -0
- data/lib/assets/javascripts/jax/core/glMatrix_ext/quat4.js +148 -0
- data/lib/assets/javascripts/jax/core/glMatrix_ext/vec2.js +25 -0
- data/lib/assets/javascripts/jax/core/glMatrix_ext/vec3.js +86 -0
- data/lib/assets/javascripts/jax/core/glMatrix_ext/vec4.js +28 -0
- data/lib/assets/javascripts/jax/core/helper.js +44 -0
- data/lib/assets/javascripts/jax/core/math.js +61 -0
- data/lib/assets/javascripts/jax/core/matrix_stack.js +310 -0
- data/lib/assets/javascripts/jax/core/util.js +271 -0
- data/lib/assets/javascripts/jax/core.js +43 -0
- data/lib/assets/javascripts/jax/events.js +304 -0
- data/lib/assets/javascripts/jax/geometry/line.js +185 -0
- data/lib/assets/javascripts/jax/geometry/plane.js +371 -0
- data/lib/assets/javascripts/jax/geometry/triangle/inliner.rb +94 -0
- data/lib/assets/javascripts/jax/geometry/triangle/slow_tri_tri_intersect.js +20 -0
- data/lib/assets/javascripts/jax/geometry/triangle/tri_tri_intersect.js +281 -0
- data/lib/assets/javascripts/jax/geometry/triangle/tri_tri_intersect_optimized.js +564 -0
- data/lib/assets/javascripts/jax/geometry/triangle.js +311 -0
- data/lib/assets/javascripts/jax/geometry.js +14 -0
- data/lib/assets/javascripts/jax/mvc/controller.js +188 -0
- data/lib/assets/javascripts/jax/mvc/model.js +302 -0
- data/lib/assets/javascripts/jax/mvc/route_set.js +148 -0
- data/lib/assets/javascripts/jax/mvc/view.js +43 -0
- data/lib/assets/javascripts/jax/mvc/view_manager.js +65 -0
- data/lib/assets/javascripts/jax/noise.js +251 -0
- data/lib/assets/javascripts/jax/prototype/class.js +81 -0
- data/lib/assets/javascripts/jax/prototype/core.js +112 -0
- data/lib/assets/javascripts/jax/prototype/extensions.js +142 -0
- data/lib/assets/javascripts/jax/vendor/ejs.js +1 -0
- data/lib/assets/javascripts/jax/vendor/glMatrix.js +7 -0
- data/lib/assets/javascripts/jax/webgl/camera.js +697 -0
- data/lib/assets/javascripts/jax/webgl/cleanup.js +1 -0
- data/lib/assets/javascripts/jax/webgl/core/buffer.js +292 -0
- data/lib/assets/javascripts/jax/webgl/core/data_region.js +184 -0
- data/lib/assets/javascripts/jax/webgl/core/data_segment.js +255 -0
- data/lib/assets/javascripts/jax/webgl/core/events.js +99 -0
- data/lib/assets/javascripts/jax/webgl/core/framebuffer.js +316 -0
- data/lib/assets/javascripts/jax/webgl/core.js +6 -0
- data/lib/assets/javascripts/jax/webgl/material.js +381 -0
- data/lib/assets/javascripts/jax/webgl/mesh/normals.js +37 -0
- data/lib/assets/javascripts/jax/webgl/mesh/support.js +104 -0
- data/lib/assets/javascripts/jax/webgl/mesh/tangent_space.js +111 -0
- data/lib/assets/javascripts/jax/webgl/mesh.js +440 -0
- data/lib/assets/javascripts/jax/webgl/scene/frustum.js +422 -0
- data/lib/assets/javascripts/jax/webgl/scene/light_manager.js +141 -0
- data/lib/assets/javascripts/jax/webgl/scene/light_source.js +300 -0
- data/lib/assets/javascripts/jax/webgl/scene.js +16 -0
- data/lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js +53 -0
- data/lib/assets/javascripts/jax/webgl/shader/delegator/uniform.js +71 -0
- data/lib/assets/javascripts/jax/webgl/shader/delegator.js +13 -0
- data/lib/assets/javascripts/jax/webgl/shader/manifest.js +70 -0
- data/lib/assets/javascripts/jax/webgl/shader/program.js +138 -0
- data/lib/assets/javascripts/jax/webgl/shader.js +299 -0
- data/lib/assets/javascripts/jax/webgl/shader_chain.js +267 -0
- data/lib/assets/javascripts/jax/webgl/texture.js +506 -0
- data/lib/assets/javascripts/jax/webgl/world.js +279 -0
- data/lib/assets/javascripts/jax/webgl.js +109 -0
- data/lib/assets/javascripts/jax.js +136 -0
- data/{builtin/app/shaders/basic/common.ejs → lib/assets/javascripts/shaders/basic/common.glsl} +0 -0
- data/{builtin/app/shaders/basic/fragment.ejs → lib/assets/javascripts/shaders/basic/fragment.glsl} +0 -0
- data/{builtin/app/shaders/basic/vertex.ejs → lib/assets/javascripts/shaders/basic/vertex.glsl} +1 -1
- data/{builtin/app/shaders/depthmap/common.ejs → lib/assets/javascripts/shaders/depthmap/common.glsl} +0 -0
- data/{builtin/app/shaders/depthmap/fragment.ejs → lib/assets/javascripts/shaders/depthmap/fragment.glsl} +1 -1
- data/{builtin/app → lib/assets/javascripts}/shaders/depthmap/material.js +0 -0
- data/{builtin/app/shaders/depthmap/vertex.ejs → lib/assets/javascripts/shaders/depthmap/vertex.glsl} +0 -0
- data/{builtin/app/shaders/fog/common.ejs → lib/assets/javascripts/shaders/fog/common.glsl} +0 -0
- data/{builtin/app/shaders/fog/fragment.ejs → lib/assets/javascripts/shaders/fog/fragment.glsl} +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/fog/manifest.yml +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/fog/material.js +6 -8
- data/{builtin/app/shaders/fog/vertex.ejs → lib/assets/javascripts/shaders/fog/vertex.glsl} +0 -0
- data/{builtin/app/shaders/functions/depth_map.ejs → lib/assets/javascripts/shaders/functions/depth_map.glsl} +0 -0
- data/{builtin/app/shaders/functions/lights.ejs → lib/assets/javascripts/shaders/functions/lights.glsl} +0 -0
- data/{builtin/app/shaders/functions/noise.ejs → lib/assets/javascripts/shaders/functions/noise.glsl} +0 -0
- data/lib/assets/javascripts/shaders/lighting/common.glsl +5 -0
- data/{builtin/app/shaders/lighting/fragment.ejs → lib/assets/javascripts/shaders/lighting/fragment.glsl} +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/lighting/manifest.yml +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/lighting/material.js +2 -4
- data/{builtin/app/shaders/lighting/vertex.ejs → lib/assets/javascripts/shaders/lighting/vertex.glsl} +0 -0
- data/{builtin/app/shaders/normal_map/common.ejs → lib/assets/javascripts/shaders/normal_map/common.glsl} +1 -1
- data/{builtin/app/shaders/normal_map/fragment.ejs → lib/assets/javascripts/shaders/normal_map/fragment.glsl} +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/normal_map/manifest.yml +0 -0
- data/lib/assets/javascripts/shaders/normal_map/material.js +11 -0
- data/{builtin/app/shaders/normal_map/vertex.ejs → lib/assets/javascripts/shaders/normal_map/vertex.glsl} +0 -0
- data/{builtin/app/shaders/paraboloid/common.ejs → lib/assets/javascripts/shaders/paraboloid/common.glsl} +0 -0
- data/{builtin/app/shaders/paraboloid/fragment.ejs → lib/assets/javascripts/shaders/paraboloid/fragment.glsl} +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/paraboloid/manifest.yml +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/paraboloid/material.js +2 -4
- data/{builtin/app/shaders/paraboloid/vertex.ejs → lib/assets/javascripts/shaders/paraboloid/vertex.glsl} +0 -0
- data/{builtin/app/shaders/picking/common.ejs → lib/assets/javascripts/shaders/picking/common.glsl} +0 -0
- data/{builtin/app/shaders/picking/fragment.ejs → lib/assets/javascripts/shaders/picking/fragment.glsl} +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/picking/material.js +2 -4
- data/{builtin/app/shaders/picking/vertex.ejs → lib/assets/javascripts/shaders/picking/vertex.glsl} +0 -0
- data/{builtin/app/shaders/shadow_map/common.ejs → lib/assets/javascripts/shaders/shadow_map/common.glsl} +2 -1
- data/{builtin/app/shaders/shadow_map/fragment.ejs → lib/assets/javascripts/shaders/shadow_map/fragment.glsl} +1 -1
- data/{builtin/app → lib/assets/javascripts}/shaders/shadow_map/manifest.yml +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/shadow_map/material.js +4 -6
- data/{builtin/app/shaders/shadow_map/vertex.ejs → lib/assets/javascripts/shaders/shadow_map/vertex.glsl} +0 -0
- data/{builtin/app/shaders/texture/common.ejs → lib/assets/javascripts/shaders/texture/common.glsl} +0 -0
- data/{builtin/app/shaders/texture/fragment.ejs → lib/assets/javascripts/shaders/texture/fragment.glsl} +0 -0
- data/{builtin/app → lib/assets/javascripts}/shaders/texture/manifest.yml +0 -0
- data/lib/assets/javascripts/shaders/texture/material.js +17 -0
- data/{builtin/app/shaders/texture/vertex.ejs → lib/assets/javascripts/shaders/texture/vertex.glsl} +0 -0
- data/lib/generators/jax/all.rb +16 -0
- data/lib/generators/jax/application/application_generator.rb +48 -0
- data/lib/generators/jax/base/actions.rb +52 -0
- data/lib/generators/jax/base/coffee_generator.rb +30 -0
- data/lib/generators/jax/base/named_base.rb +17 -0
- data/lib/generators/jax/base/plugin_base.rb +108 -0
- data/lib/generators/jax/base/plugin_credentials.rb +99 -0
- data/lib/generators/jax/base/plugin_manifest.rb +75 -0
- data/lib/generators/jax/base/rails_base.rb +30 -0
- data/lib/generators/jax/base/source_root.rb +5 -0
- data/lib/generators/jax/controller/controller_generator.rb +37 -0
- data/lib/generators/jax/helper/helper_generator.rb +30 -0
- data/lib/generators/jax/install/install_generator.rb +27 -0
- data/lib/generators/jax/jax_generator.rb +13 -0
- data/lib/generators/jax/light/light_generator.rb +23 -0
- data/lib/{jax/generators → generators/jax}/material/USAGE +4 -8
- data/lib/generators/jax/material/material_generator.rb +112 -0
- data/lib/generators/jax/model/model_generator.rb +24 -0
- data/lib/generators/jax/plugin/plugin_generator.rb +72 -0
- data/lib/generators/jax/scaffold/scaffold_generator.rb +35 -0
- data/lib/generators/jax/shader/shader_generator.rb +38 -0
- data/lib/jax/commands/plugin_manager.rb +240 -0
- data/lib/jax/commands.rb +69 -0
- data/lib/jax/configuration.rb +64 -0
- data/lib/jax/directive_processor.rb +53 -0
- data/lib/jax/engine.rb +38 -54
- data/lib/jax/helper_methods.rb +3 -0
- data/lib/jax/rails/application.rb +34 -0
- data/lib/jax/resource_file.rb +29 -0
- data/lib/jax/script_loader.rb +68 -0
- data/lib/jax/server.rb +87 -0
- data/lib/jax/shader.rb +70 -172
- data/lib/jax/testing/rails_environment.rb +94 -0
- data/lib/jax/util/tar.rb +75 -0
- data/lib/jax/util.rb +3 -0
- data/lib/jax/version.rb +7 -8
- data/lib/jax.rb +23 -41
- data/spec/bin/jax_spec.rb +149 -0
- data/{lib/jax/generators/app/templates/app/models/.empty_directory → spec/fixtures/public/favicon.ico} +0 -0
- data/spec/fixtures/public/textures/brickwall.jpg +0 -0
- data/spec/fixtures/public/textures/jacks.jpg +0 -0
- data/spec/fixtures/public/textures/normal_map.jpg +0 -0
- data/spec/fixtures/public/textures/rock.png +0 -0
- data/spec/fixtures/public/textures/rock_normal.png +0 -0
- data/spec/fixtures/public/textures/rss.png +0 -0
- data/spec/generators/jax/application_generator_spec.rb +18 -0
- data/spec/generators/jax/controller_generator_spec.rb +102 -0
- data/spec/generators/jax/helper_generator_spec.rb +55 -0
- data/spec/generators/jax/install_generator_spec.rb +30 -0
- data/spec/generators/jax/jax_generator_spec.rb +21 -0
- data/spec/generators/jax/light_generator_spec.rb +27 -0
- data/spec/generators/jax/material_generator_spec.rb +62 -0
- data/spec/generators/jax/model_generator_spec.rb +72 -0
- data/spec/generators/jax/plugin_generator_spec.rb +143 -0
- data/spec/generators/jax/scaffold_generator_spec.rb +35 -0
- data/spec/generators/jax/shader_generator_spec.rb +37 -0
- data/spec/javascripts/helpers/jasmine_webgl_helper.js +13 -0
- data/{lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers → spec/javascripts/helpers}/jax_spec_environment_helper.js +7 -2
- data/{lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers → spec/javascripts/helpers}/jax_spec_helper.js +0 -0
- data/spec/javascripts/jax/builtin/meshes/cube_spec.js +10 -0
- data/spec/javascripts/jax/builtin/meshes/plane_spec.js +8 -0
- data/spec/javascripts/jax/builtin/meshes/quad_spec.js +8 -0
- data/spec/javascripts/jax/builtin/meshes/sphere_spec.js +8 -0
- data/spec/javascripts/jax/builtin/meshes/teapot_spec.js +8 -0
- data/spec/javascripts/jax/builtin/meshes/torus_spec.js +8 -0
- data/spec/javascripts/jax/compatibility_spec.js +46 -0
- data/spec/javascripts/jax/context_events_spec.js +212 -0
- data/spec/javascripts/jax/context_spec.js +305 -0
- data/spec/javascripts/jax/core/data_region_spec.js +118 -0
- data/spec/javascripts/jax/core/data_segment_spec.js +96 -0
- data/spec/javascripts/jax/core/delegation_spec.js +48 -0
- data/spec/javascripts/jax/core/events_spec.js +17 -0
- data/spec/javascripts/jax/core/glMatrix_extensions_spec.js +8 -0
- data/spec/javascripts/jax/core/helper_spec.js +61 -0
- data/spec/javascripts/jax/core/matrix_stack_spec.js +28 -0
- data/spec/javascripts/jax/core/utils_spec.js +275 -0
- data/spec/javascripts/jax/geometry/line_spec.js +20 -0
- data/spec/javascripts/jax/geometry/plane_spec.js +181 -0
- data/spec/javascripts/jax/geometry/triangle_spec.js +105 -0
- data/spec/javascripts/jax/mvc/controller_spec.js +156 -0
- data/spec/javascripts/jax/mvc/model_spec.js +93 -0
- data/spec/javascripts/jax/mvc/route_set_spec.js +49 -0
- data/spec/javascripts/jax/mvc/view_manager_spec.js +17 -0
- data/spec/javascripts/jax/noise_spec.js +50 -0
- data/spec/javascripts/jax/optimizations/material_limitations_spec.js +85 -0
- data/spec/javascripts/jax/optimizations/shaders/basic_spec.js +65 -0
- data/spec/javascripts/jax/prototype/extensions_spec.js +34 -0
- data/spec/javascripts/jax/webgl/camera_spec.js +237 -0
- data/spec/javascripts/jax/webgl/core/events_spec.js +47 -0
- data/spec/javascripts/jax/webgl/framebuffer_spec.js +44 -0
- data/spec/javascripts/jax/webgl/lighting_spec.js +108 -0
- data/spec/javascripts/jax/webgl/material_spec.js +117 -0
- data/spec/javascripts/jax/webgl/mesh_spec.js +228 -0
- data/spec/javascripts/jax/webgl/shader/manifest_spec.js +57 -0
- data/spec/javascripts/jax/webgl/shader_chain_spec.js +211 -0
- data/spec/javascripts/jax/webgl/shader_spec.js +276 -0
- data/spec/javascripts/jax/webgl/tangent_space_spec.js +142 -0
- data/spec/javascripts/jax/webgl/texture_spec.js +159 -0
- data/spec/javascripts/jax/webgl_spec.js +5 -0
- data/spec/javascripts/jax/world_spec.js +175 -0
- data/spec/javascripts/jax_spec.js +14 -0
- data/spec/javascripts/node/mocks/webgl.js +159 -0
- data/spec/javascripts/node_helper.js +51 -0
- data/spec/javascripts/shaders/core_materials_spec.js +38 -0
- data/spec/javascripts/shaders/fog_spec.js +15 -0
- data/spec/javascripts/shaders/lighting_spec.js +15 -0
- data/spec/javascripts/shaders/normal_map_spec.js +15 -0
- data/spec/javascripts/shaders/paraboloid_spec.js +33 -0
- data/spec/javascripts/shaders/preprocessor_spec.js +45 -0
- data/spec/javascripts/shaders/shadow_map_spec.js +15 -0
- data/spec/javascripts/shaders/texture_spec.js +37 -0
- data/spec/javascripts/suite/controller_select_spec.js.coffee +24 -0
- data/spec/lib/jax/commands/plugin_manager/credentials_spec.rb +56 -0
- data/spec/lib/jax/commands/plugin_manager/push_spec.rb +62 -0
- data/spec/lib/jax/commands/plugin_manager_spec.rb +204 -0
- data/spec/lib/jax/rails/application_spec.rb +23 -0
- data/spec/lib/jax/shader_spec.rb +67 -0
- data/spec/lib/jax/util/tar_spec.rb +26 -0
- data/spec/{test_helper.rb → spec_helper.rb} +37 -28
- data/spec/support/test_model_generator.rb +14 -0
- data/templates/app/Gemfile.tt +17 -0
- data/templates/app/Rakefile +4 -0
- data/templates/app/config/application.rb +16 -0
- data/{lib/jax/generators/app/templates → templates/app}/config/boot.rb +0 -0
- data/templates/app/config/environment.rb +5 -0
- data/templates/app/config/environments/production.rb +4 -0
- data/templates/app/config.ru +6 -0
- data/{lib/jax/generators/app/templates/app/resources → templates/app/public}/.empty_directory +0 -0
- data/templates/app/script/jax +8 -0
- data/{lib/jax/generators/app/templates/app/views → templates/app/spec}/.empty_directory +0 -0
- data/templates/application_controller.js.coffee.erb +3 -0
- data/templates/application_controller.js.erb +6 -0
- data/templates/application_helper.js.coffee.erb +3 -0
- data/templates/application_helper.js.erb +3 -0
- data/templates/controller.js.coffee.erb +9 -0
- data/templates/controller.js.erb +15 -0
- data/templates/controller_spec.js.coffee.erb +9 -0
- data/templates/controller_spec.js.erb +12 -0
- data/templates/helper.js.coffee.erb +2 -0
- data/templates/helper.js.erb +3 -0
- data/templates/helper_spec.js.coffee.erb +8 -0
- data/templates/helper_spec.js.erb +12 -0
- data/{lib/jax/generators/light_source/templates/light.yml.tt → templates/light_source.resource.erb} +3 -3
- data/{lib/jax/generators/material/templates/material.yml.tt → templates/material.resource.erb} +0 -9
- data/templates/model.js.coffee.erb +3 -0
- data/templates/model.js.erb +5 -0
- data/templates/model_defaults.resource.erb +5 -0
- data/templates/model_spec.js.coffee.erb +16 -0
- data/templates/model_spec.js.erb +18 -0
- data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/controllers/.empty_directory +0 -0
- data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/helpers/.empty_directory +0 -0
- data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/models/.empty_directory +0 -0
- data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/resources/.empty_directory +0 -0
- data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/views/.empty_directory +0 -0
- data/{lib/jax/generators/plugin/templates → templates}/new_plugin/init.rb +0 -0
- data/{lib/jax/generators/plugin/templates → templates}/new_plugin/install.rb +0 -0
- data/{lib/jax/generators/plugin/templates/new_plugin/public → templates/new_plugin/spec}/.empty_directory +0 -0
- data/{lib/jax/generators/plugin/templates → templates}/new_plugin/uninstall.rb +0 -0
- data/{lib/jax/generators/shader/templates/common.ejs.tt → templates/shader_common.glsl.erb} +0 -0
- data/{lib/jax/generators/shader/templates/fragment.ejs.tt → templates/shader_fragment.glsl.erb} +0 -0
- data/{lib/jax/generators/shader/templates/manifest.yml.tt → templates/shader_manifest.yml.erb} +0 -0
- data/templates/shader_material.js.coffee.erb +22 -0
- data/{lib/jax/generators/shader/templates/material.js.tt → templates/shader_material.js.erb} +0 -0
- data/templates/shader_spec.js.coffee.erb +16 -0
- data/{lib/jax/generators/shader/templates/spec.js.tt → templates/shader_spec.js.erb} +1 -1
- data/{lib/jax/generators/shader/templates/vertex.ejs.tt → templates/shader_vertex.glsl.erb} +0 -0
- data/templates/view.js.coffee.erb +3 -0
- data/{lib/jax/generators/controller/templates/view.js.tt → templates/view.js.erb} +1 -1
- data/vendor/assets/javascripts/ejs.js +505 -0
- data/vendor/assets/javascripts/glMatrix.js +1772 -0
- data/vendor/assets/javascripts/jasmine.js +2476 -0
- data/vendor/assets/stylesheets/jasmine.css +166 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/alias.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/class.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/class_deprecated.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/class_method.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/class_property.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/constant.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/constructor.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/deprecated.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/description.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/information.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/instance_method.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/instance_property.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/method.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/method_deprecated.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/mixin.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/namespace.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/property.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/related_to.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/search-background.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/section-background.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/section.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/selected-section-background.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/subclass.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/superclass.png +0 -0
- data/vendor/pdoc_template/html/assets/images/pdoc/utility.png +0 -0
- data/vendor/pdoc_template/html/assets/javascripts/pdoc/application.js +478 -0
- data/vendor/pdoc_template/html/assets/javascripts/pdoc/prototype.js +4874 -0
- data/vendor/pdoc_template/html/assets/javascripts/pdoc/tabs.js +506 -0
- data/vendor/pdoc_template/html/assets/stylesheets/jax.css +30 -0
- data/vendor/pdoc_template/html/assets/stylesheets/pdoc/api.css +681 -0
- data/vendor/pdoc_template/html/assets/stylesheets/pdoc/pygments.css +62 -0
- data/vendor/pdoc_template/html/helpers.rb +35 -0
- data/vendor/pdoc_template/html/index.erb +18 -0
- data/vendor/pdoc_template/html/item_index.js.erb +6 -0
- data/vendor/pdoc_template/html/layout.erb +67 -0
- data/vendor/pdoc_template/html/leaf.erb +22 -0
- data/vendor/pdoc_template/html/node.erb +30 -0
- data/vendor/pdoc_template/html/partials/class_relationships.erb +19 -0
- data/vendor/pdoc_template/html/partials/classes.erb +7 -0
- data/vendor/pdoc_template/html/partials/constructor.erb +5 -0
- data/vendor/pdoc_template/html/partials/description.erb +5 -0
- data/vendor/pdoc_template/html/partials/link_list.erb +1 -0
- data/vendor/pdoc_template/html/partials/method_signatures.erb +14 -0
- data/vendor/pdoc_template/html/partials/methodized_note.erb +9 -0
- data/vendor/pdoc_template/html/partials/mixins.erb +7 -0
- data/vendor/pdoc_template/html/partials/namespaces.erb +7 -0
- data/vendor/pdoc_template/html/partials/related_utilities.erb +5 -0
- data/vendor/pdoc_template/html/partials/relationships.erb +11 -0
- data/vendor/pdoc_template/html/partials/short_description_list.erb +7 -0
- data/vendor/pdoc_template/html/partials/title.erb +24 -0
- data/vendor/pdoc_template/html/section.erb +18 -0
- metadata +635 -332
- data/builtin/app/shaders/lighting/common.ejs +0 -5
- data/builtin/app/shaders/normal_map/material.js +0 -16
- data/builtin/app/shaders/texture/material.js +0 -18
- data/jax.gems +0 -1
- data/lib/jax/application/builtin/configurable.rb +0 -5
- data/lib/jax/application/builtin/configuration.rb +0 -5
- data/lib/jax/application/builtin.rb +0 -12
- data/lib/jax/application/configurable.rb +0 -19
- data/lib/jax/application/configuration.rb +0 -60
- data/lib/jax/application/railties.rb +0 -26
- data/lib/jax/application.rb +0 -149
- data/lib/jax/core_ext/kernel.rb +0 -7
- data/lib/jax/engine/configurable.rb +0 -19
- data/lib/jax/engine/configuration.rb +0 -49
- data/lib/jax/generators/app/app_generator.rb +0 -96
- data/lib/jax/generators/app/templates/Gemfile.tt +0 -3
- data/lib/jax/generators/app/templates/Rakefile +0 -6
- data/lib/jax/generators/app/templates/app/controllers/application_controller.js.tt +0 -5
- data/lib/jax/generators/app/templates/app/helpers/application_helper.js.tt +0 -3
- data/lib/jax/generators/app/templates/config/application.rb.tt +0 -6
- data/lib/jax/generators/app/templates/config/environment.rb.tt +0 -5
- data/lib/jax/generators/app/templates/config/routes.rb.tt +0 -5
- data/lib/jax/generators/app/templates/public/index.html.tt +0 -26
- data/lib/jax/generators/app/templates/public/javascripts/jax.js +0 -9462
- data/lib/jax/generators/app/templates/public/stylesheets/%file_name%.css.tt +0 -11
- data/lib/jax/generators/app/templates/public/webgl_not_supported.html +0 -26
- data/lib/jax/generators/app/templates/script/jax +0 -7
- data/lib/jax/generators/app/templates/spec/javascripts/controllers/application_controller_spec.js +0 -11
- data/lib/jax/generators/app/templates/spec/javascripts/helpers/application_helper_spec.js +0 -12
- data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine.yml +0 -91
- data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine_config.rb +0 -23
- data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine_runner.rb +0 -32
- data/lib/jax/generators/app/templates/spec/javascripts/support/spec_layout.html.erb +0 -104
- data/lib/jax/generators/app.rb +0 -18
- data/lib/jax/generators/commands.rb +0 -220
- data/lib/jax/generators/controller/USAGE +0 -9
- data/lib/jax/generators/controller/controller_generator.rb +0 -66
- data/lib/jax/generators/controller/templates/controller_source.js.tt +0 -16
- data/lib/jax/generators/controller/templates/controller_test.js.tt +0 -11
- data/lib/jax/generators/controller/templates/helper.js.tt +0 -3
- data/lib/jax/generators/controller/templates/helper_test.js.tt +0 -12
- data/lib/jax/generators/interactions.rb +0 -56
- data/lib/jax/generators/light_source/USAGE +0 -14
- data/lib/jax/generators/light_source/light_source_generator.rb +0 -46
- data/lib/jax/generators/material/material_generator.rb +0 -80
- data/lib/jax/generators/material/templates/append.yml.tt +0 -7
- data/lib/jax/generators/model/USAGE +0 -5
- data/lib/jax/generators/model/model_generator.rb +0 -40
- data/lib/jax/generators/model/templates/model.js.tt +0 -11
- data/lib/jax/generators/model/templates/test.js.tt +0 -11
- data/lib/jax/generators/packager/package_generator.rb +0 -32
- data/lib/jax/generators/plugin/USAGE +0 -4
- data/lib/jax/generators/plugin/all.rb +0 -113
- data/lib/jax/generators/plugin/credentials.rb +0 -108
- data/lib/jax/generators/plugin/plugin_generator.rb +0 -72
- data/lib/jax/generators/plugin/plugin_manager.rb +0 -254
- data/lib/jax/generators/plugin/templates/new_plugin/config/routes.rb +0 -3
- data/lib/jax/generators/plugin/templates/new_plugin/spec/.empty_directory +0 -0
- data/lib/jax/generators/script_jax_loader.rb +0 -49
- data/lib/jax/generators/shader/USAGE +0 -4
- data/lib/jax/generators/shader/shader_generator.rb +0 -70
- data/lib/jax/monkeypatch/jasmine/config.rb +0 -45
- data/lib/jax/monkeypatch/jasmine/server.rb +0 -50
- data/lib/jax/monkeypatch/jasmine.rb +0 -3
- data/lib/jax/packager/sprockets_template.rb +0 -77
- data/lib/jax/packager.rb +0 -59
- data/lib/jax/plugin/manifest.rb +0 -71
- data/lib/jax/plugin.rb +0 -49
- data/lib/jax/resource_compiler.rb +0 -60
- data/lib/jax/routes.rb +0 -62
- data/lib/jax/tasks/rake.rb +0 -38
- data/spec/benchmark.htm +0 -93
- data/spec/generators/app_generator_test.rb +0 -42
- data/spec/generators/controller_generator_test.rb +0 -47
- data/spec/generators/light_generator_test.rb +0 -37
- data/spec/generators/material_generator_test.rb +0 -22
- data/spec/generators/model_generator_test.rb +0 -26
- data/spec/generators/plugin_generator_test.rb +0 -114
- data/spec/generators/plugin_manager/push_test.rb +0 -59
- data/spec/generators/plugin_manager_test.rb +0 -192
- data/spec/generators/shader_generator_test.rb +0 -38
- data/spec/javascripts/support/jasmine.yml +0 -85
- data/spec/javascripts/support/jasmine_runner.rb +0 -32
- data/spec/lib/jax/application_test.rb +0 -18
- data/spec/lib/jax/generators/plugin/credentials_test.rb +0 -72
- data/spec/lib/jax/packager_test.rb +0 -87
- data/spec/lib/jax/plugin_test.rb +0 -27
- data/spec/lib/jax/reloading_test.rb +0 -23
- data/spec/lib/jax/routes_test.rb +0 -28
- data/spec/lib/jax/shader_test.rb +0 -29
- data/spec/lib/jax/tasks/jax_rake_test.rb +0 -85
- data/spec/support/bases/generator_test_case.rb +0 -108
- data/spec/support/bases/isolated_test_case.rb +0 -148
- data/spec/support/file_exist_matcher.rb +0 -23
- data/spec/support/spec_shell.rb +0 -110
- data/spec/test_app.rb +0 -3
@@ -0,0 +1,741 @@
|
|
1
|
+
//= require "jax/webgl"
|
2
|
+
//= require "jax/events"
|
3
|
+
|
4
|
+
/**
|
5
|
+
* class Jax.Context
|
6
|
+
* includes Jax.Events.Methods
|
7
|
+
*
|
8
|
+
* The highest level of operation in Jax. Initialization is simple:
|
9
|
+
*
|
10
|
+
* var context = new Jax.Context(canvas);
|
11
|
+
*
|
12
|
+
* where _canvas_ is a reference to an HTML5 Canvas element.
|
13
|
+
*
|
14
|
+
* If there is a root route set up, then at this point you are done.
|
15
|
+
* If not, there's an additional step:
|
16
|
+
*
|
17
|
+
* context.redirectTo("controller_name/action_name");
|
18
|
+
*
|
19
|
+
* where *controller_name* is the short name of the controller to start at,
|
20
|
+
* and *action_name* is the action to fire within that controller.
|
21
|
+
*
|
22
|
+
* Note that the specified redirect path must be registered in the route set.
|
23
|
+
*
|
24
|
+
* Jax will automatically initialize and maintain a WebGL rendering bridge,
|
25
|
+
* and WebGL methods can be called directly on this context by prefixing
|
26
|
+
* the name of the method with "gl". For example:
|
27
|
+
*
|
28
|
+
* context.glClear(GL_COLOR_BIT | GL_DEPTH_BUFFER_BIT);
|
29
|
+
*
|
30
|
+
* ### Error Reporting
|
31
|
+
*
|
32
|
+
* Contexts emit an 'error' event that you can hook into in order to perform
|
33
|
+
* error handling. By default, when an error is encountered in either the
|
34
|
+
* 'render' or 'update' phase, Jax will log the error to the console, if
|
35
|
+
* available, and in development mode will raise the error in the form of an
|
36
|
+
* +alert()+ message. You can disable both of these by setting the +silence+
|
37
|
+
* property of the error itself. Example:
|
38
|
+
*
|
39
|
+
* context.addEventListener('error', function(err) {
|
40
|
+
* // do something with the error, then prevent it from logging
|
41
|
+
* error.silence = true;
|
42
|
+
* });
|
43
|
+
*
|
44
|
+
* You can also see which phase the error was encountered under by checking
|
45
|
+
* the +phase+ property on the error.
|
46
|
+
*
|
47
|
+
* Note that if an error is encountered, the phase it is encountered upon is
|
48
|
+
* immediately halted. That is, if an error is encountered during the 'render'
|
49
|
+
* phase, all rendering will be stopped, and the same goes for 'update' phases.
|
50
|
+
*
|
51
|
+
* You can restart rendering or updating after recovering from an error
|
52
|
+
* by calling Jax.Context#startRendering or Jax.Context#startUpdating,
|
53
|
+
* respectively.
|
54
|
+
*
|
55
|
+
* #### MVC Error Handling
|
56
|
+
*
|
57
|
+
* Your controllers can have an +error+ function which will be automatically
|
58
|
+
* called whenever an error occurs. If the +error+ function returns any value
|
59
|
+
* that evaluates to +true+, the error will be considered non-fatal and
|
60
|
+
* no further error handling will be performed. Event handlers listening for
|
61
|
+
* error events will still be called, but the error will not be processed
|
62
|
+
* in any other way.
|
63
|
+
*
|
64
|
+
* Example:
|
65
|
+
*
|
66
|
+
* var ApplicationController = Jax.Controller.create("application", {
|
67
|
+
* error: function(error) {
|
68
|
+
* // handle the error, then return true
|
69
|
+
* // to indicate that it is non-fatal.
|
70
|
+
* return true;
|
71
|
+
* }
|
72
|
+
* });
|
73
|
+
*
|
74
|
+
* Returning a +false+ value will cause rendering and updating to be halted,
|
75
|
+
* and will also invoke the default error handling behavior unless the error
|
76
|
+
* is silenced.
|
77
|
+
*
|
78
|
+
* Error functions are inherited when a base controller is inherited. Since
|
79
|
+
* the +ApplicationController+ is the base for all controllers, defining an
|
80
|
+
* +error+ function on +ApplicationController+ will define the same error
|
81
|
+
* function on all controllers. This provides a nice, DRY way to implement
|
82
|
+
* consistent error handling across all controllers.
|
83
|
+
*
|
84
|
+
* When a Jax context is first being initialized, an error may occur if the
|
85
|
+
* client does not support a WebGL context. This is a special case because
|
86
|
+
* there are no controllers registered during context initialization. In
|
87
|
+
* this event, the +ApplicationController+ prototype's +error+ function
|
88
|
+
* will be called if it exists. In practice, this is identical to any other
|
89
|
+
* controller-based error handling with the following exception:
|
90
|
+
*
|
91
|
+
* If the +error+ function returns a falsy value when given an error which
|
92
|
+
* occurred during context initialization, Jax will redirect the user to
|
93
|
+
* +Jax.webgl_not_supported_path+, which defaults to +/webgl_not_supported.html+.
|
94
|
+
* If the function returns a truthy value, Jax will assume that the error
|
95
|
+
* has been handled appropriately and will silence the error and then return
|
96
|
+
* without further ado.
|
97
|
+
*
|
98
|
+
* In all cases, if an error occurs, rendering and updating are halted (even
|
99
|
+
* for non-fatal errors); it is up to the error handler to restart rendering
|
100
|
+
* and/or updating as necessary.
|
101
|
+
*
|
102
|
+
**/
|
103
|
+
Jax.Context = (function() {
|
104
|
+
function setupContext(self) {
|
105
|
+
if (!self.canvas.eventListeners) {
|
106
|
+
/* TODO merge this with jax/webgl/core/events.js and use for all Jax event handling */
|
107
|
+
self.canvas.eventListeners = {};
|
108
|
+
var _add = self.canvas.addEventListener, _remove = self.canvas.removeEventListener;
|
109
|
+
|
110
|
+
self.canvas.getEventListeners = function(type) {
|
111
|
+
if (type) return (this.eventListeners[type] = this.eventListeners[type] || []);
|
112
|
+
else {
|
113
|
+
var ret = [];
|
114
|
+
for (var i in this.eventListeners) ret = ret.concat(this.eventListeners[i]);
|
115
|
+
return ret;
|
116
|
+
}
|
117
|
+
};
|
118
|
+
|
119
|
+
self.canvas.addEventListener = function(type, listener, capture) {
|
120
|
+
this.getEventListeners(type).push(listener);
|
121
|
+
_add.call(this, type, listener, capture || false);
|
122
|
+
}
|
123
|
+
|
124
|
+
self.canvas.removeEventListener = function(type, listener, capture) {
|
125
|
+
if (typeof(type) == "string") {
|
126
|
+
var listeners = this.getEventListeners(type);
|
127
|
+
var index = listeners.indexOf(listener);
|
128
|
+
if (index != -1) {
|
129
|
+
listeners.splice(index, 1);
|
130
|
+
_remove.call(this, type, listener, capture || false);
|
131
|
+
}
|
132
|
+
} else if (!listener) {
|
133
|
+
// type *is* the listener, remove it from all listener types
|
134
|
+
for (var i in this.eventListeners)
|
135
|
+
this.removeEventListener(i, type, false);
|
136
|
+
}
|
137
|
+
};
|
138
|
+
}
|
139
|
+
|
140
|
+
try { self.gl = self.canvas.getContext(WEBGL_CONTEXT_NAME, WEBGL_CONTEXT_OPTIONS); } catch(e) { }
|
141
|
+
if (!self.gl) throw new Error("WebGL could not be initialized!");
|
142
|
+
}
|
143
|
+
|
144
|
+
function updateFramerate(self) {
|
145
|
+
var current_render_start = Jax.uptime;
|
146
|
+
if (!self.last_render_start) self.last_render_start = Jax.uptime;
|
147
|
+
var time_to_render_this_frame = current_render_start - self.last_render_start;
|
148
|
+
|
149
|
+
self.time_to_render = (self.time_to_render || 0) * self.framerate_sample_ratio
|
150
|
+
+ time_to_render_this_frame * (1 - self.framerate_sample_ratio);
|
151
|
+
|
152
|
+
// frames per second = 1 second divided by time to render; time is currently in ms so 1sec = 1000ms
|
153
|
+
self.framerate = self.frames_per_second = 1.0 / self.time_to_render;
|
154
|
+
self.last_render_start = current_render_start;
|
155
|
+
}
|
156
|
+
|
157
|
+
function updateUpdateRate(self) {
|
158
|
+
var current_update_start = Jax.uptime;
|
159
|
+
if (!self.last_update_start) self.last_update_start = current_update_start;
|
160
|
+
var time_to_update_this_frame = current_update_start - self.last_update_start;
|
161
|
+
|
162
|
+
if (self.calculateUpdateRate) {
|
163
|
+
self.time_to_update = (self.time_to_update || 0) * self.framerate_sample_ratio
|
164
|
+
+ time_to_update_this_frame * (1 - self.framerate_sample_ratio);
|
165
|
+
|
166
|
+
// update rate = seconds / time
|
167
|
+
self.updates_per_second = 1.0 / self.time_to_update;
|
168
|
+
}
|
169
|
+
|
170
|
+
// in order to avoid recalculating the above for updates, we'll return the timechange
|
171
|
+
// to be used in subsequent updates.
|
172
|
+
var timechange = current_update_start - self.last_update_start;
|
173
|
+
self.last_update_start = current_update_start;
|
174
|
+
return timechange;
|
175
|
+
}
|
176
|
+
|
177
|
+
function startRendering(self) {
|
178
|
+
if (self.isRendering()) return;
|
179
|
+
|
180
|
+
function render() {
|
181
|
+
try {
|
182
|
+
if (self.isDisposed()) return;
|
183
|
+
if (self.calculateFramerate) updateFramerate(self);
|
184
|
+
if (self.current_view) {
|
185
|
+
self.prepare();
|
186
|
+
self.current_view.render();
|
187
|
+
var len = self.afterRenderFuncs.length;
|
188
|
+
for (var i = 0; i < len; i++) self.afterRenderFuncs[i].call(self);
|
189
|
+
self.render_interval = requestAnimFrame(render, self.canvas);
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
self.stopRendering();
|
193
|
+
}
|
194
|
+
} catch(error) {
|
195
|
+
self.handleError('render', error);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
self.render_interval = setTimeout(render, Jax.render_speed);
|
200
|
+
}
|
201
|
+
|
202
|
+
function startUpdating(self) {
|
203
|
+
if (self.isUpdating()) return;
|
204
|
+
|
205
|
+
function updateFunc() {
|
206
|
+
try {
|
207
|
+
if (self.isDisposed()) return;
|
208
|
+
var timechange = updateUpdateRate(self);
|
209
|
+
|
210
|
+
self.update(timechange);
|
211
|
+
var len = self.afterUpdateFuncs.length;
|
212
|
+
for (var i = 0; i < len; i++) self.afterUpdateFuncs[i].call(self);
|
213
|
+
self.update_interval = setTimeout(updateFunc, Jax.update_speed);
|
214
|
+
|
215
|
+
if (Jax.SHUTDOWN_IN_PROGRESS) self.dispose();
|
216
|
+
} catch(error) {
|
217
|
+
self.handleError('update', error);
|
218
|
+
}
|
219
|
+
}
|
220
|
+
updateFunc();
|
221
|
+
}
|
222
|
+
|
223
|
+
function setupView(self, view) {
|
224
|
+
view.context = self;
|
225
|
+
view.world = self.world;
|
226
|
+
view.player = self.player;
|
227
|
+
for (var i in self) {
|
228
|
+
if (i.indexOf("gl") == 0) {
|
229
|
+
/* it's a WebGL method */
|
230
|
+
view[i] = eval("(function() { return this.context."+i+".apply(this.context, arguments); })");
|
231
|
+
}
|
232
|
+
}
|
233
|
+
/* TODO we should set up helpers, etc. here too */
|
234
|
+
}
|
235
|
+
|
236
|
+
function reloadMatrices(self) {
|
237
|
+
self.matrix_stack.reset(); // reset depth
|
238
|
+
self.matrix_stack.loadModelMatrix(mat4.IDENTITY);
|
239
|
+
self.matrix_stack.loadViewMatrix(self.player.camera.getTransformationMatrix());
|
240
|
+
self.matrix_stack.loadProjectionMatrix(self.player.camera.getProjectionMatrix());
|
241
|
+
}
|
242
|
+
|
243
|
+
var klass = Jax.Class.create({
|
244
|
+
/**
|
245
|
+
* new Jax.Context(canvas[, options])
|
246
|
+
* - canvas (String|HTMLCanvasElement): the canvas or the ID of the canvas to tie this context to
|
247
|
+
* - options (Object): optional set of configuration options; see below
|
248
|
+
*
|
249
|
+
* Constructs a new Jax.Context, which is the basic object that ties together
|
250
|
+
* models, controllers and views to produce a coherent application.
|
251
|
+
*
|
252
|
+
* Like most Jax objects, Jax.Context takes some optional initialization
|
253
|
+
* options. They are as follows:
|
254
|
+
*
|
255
|
+
* <table>
|
256
|
+
* <tr>
|
257
|
+
* <th>alertErrors</th>
|
258
|
+
* <td>see +Jax.Context#alertErrors+</td>
|
259
|
+
* </tr>
|
260
|
+
* </table>
|
261
|
+
*
|
262
|
+
*
|
263
|
+
**/
|
264
|
+
initialize: function(canvas, options) {
|
265
|
+
try {
|
266
|
+
if (typeof(canvas) == "string") canvas = document.getElementById(canvas);
|
267
|
+
if (!canvas) throw new Error("Can't initialize a WebGL context without a canvas!");
|
268
|
+
|
269
|
+
/**
|
270
|
+
* Jax.Context#alertErrors -> Boolean
|
271
|
+
*
|
272
|
+
* If true, an +alert+ prompt will be used to display errors encountered in development mode.
|
273
|
+
* In production, they will be silenced (but logged to the console). If an error is silenced,
|
274
|
+
* regardless of runmode, this won't happen.
|
275
|
+
*
|
276
|
+
* Defaults to +true+.
|
277
|
+
*
|
278
|
+
**/
|
279
|
+
options = Jax.Util.normalizeOptions(options, { alertErrors: true });
|
280
|
+
this.alertErrors = options.alertErrors;
|
281
|
+
this.id = ++Jax.Context.identifier;
|
282
|
+
this.canvas = canvas;
|
283
|
+
this.setupEventListeners();
|
284
|
+
this.render_interval = null;
|
285
|
+
this.world = new Jax.World(this);
|
286
|
+
this.player = {camera: new Jax.Camera()};
|
287
|
+
this.player.camera.perspective({width:canvas.width, height:canvas.height});
|
288
|
+
this.matrix_stack = new Jax.MatrixStack();
|
289
|
+
this.current_pass = Jax.Scene.AMBIENT_PASS;
|
290
|
+
this.afterRenderFuncs = [];
|
291
|
+
this.afterUpdateFuncs = [];
|
292
|
+
this.framerate = 0;
|
293
|
+
this.frames_per_second = 0;
|
294
|
+
this.updates_per_second = 0;
|
295
|
+
|
296
|
+
/**
|
297
|
+
* Jax.Context#framerate_sample_ratio -> Number
|
298
|
+
*
|
299
|
+
* A number between 0 and 1, to be used in updates to frames per second and updates per second.
|
300
|
+
*
|
301
|
+
* Setting this to a high value will produce "smoother" results; they will change less frequently,
|
302
|
+
* but it will take longer to get initial results. High values are better for testing framerate
|
303
|
+
* over the long term, while lower values are better for testing small disruptions in framerate
|
304
|
+
* (such as garbage collection).
|
305
|
+
*
|
306
|
+
* Defaults to 0.9.
|
307
|
+
**/
|
308
|
+
this.framerate_sample_ratio = 0.9;
|
309
|
+
|
310
|
+
setupContext(this);
|
311
|
+
this.glClearColor(0.0, 0.0, 0.0, 1.0);
|
312
|
+
this.glClearDepth(1.0);
|
313
|
+
this.glEnable(GL_DEPTH_TEST);
|
314
|
+
this.glDepthFunc(GL_LEQUAL);
|
315
|
+
this.glEnable(GL_BLEND);
|
316
|
+
this.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
317
|
+
this.checkForRenderErrors();
|
318
|
+
|
319
|
+
this.startUpdating();
|
320
|
+
} catch(e) {
|
321
|
+
this.handleError('initialize', e);
|
322
|
+
}
|
323
|
+
|
324
|
+
if (options && options.root)
|
325
|
+
this.redirectTo(options.root);
|
326
|
+
},
|
327
|
+
|
328
|
+
/**
|
329
|
+
* Jax.Context#startUpdating() -> Jax.Context
|
330
|
+
*
|
331
|
+
* Starts updating. This is done automatically within the constructor, but you can call it
|
332
|
+
* again. Useful for resuming operation after processing an error.
|
333
|
+
**/
|
334
|
+
startUpdating: function() { startUpdating(this); return this; },
|
335
|
+
|
336
|
+
/**
|
337
|
+
* Jax.Context#startRendering() -> Jax.Context
|
338
|
+
*
|
339
|
+
* Starts rendering. This is done automatically within the constructor, but you can call it
|
340
|
+
* again. Useful for resuming operation after processing an error.
|
341
|
+
**/
|
342
|
+
startRendering: function() { startRendering(this); return this; },
|
343
|
+
|
344
|
+
/**
|
345
|
+
* Jax.Context#stopRendering() -> Jax.Context
|
346
|
+
*
|
347
|
+
* Stops rendering.
|
348
|
+
**/
|
349
|
+
stopRendering: function() {
|
350
|
+
clearTimeout(this.render_interval);
|
351
|
+
this.render_interval = null;
|
352
|
+
return this;
|
353
|
+
},
|
354
|
+
|
355
|
+
/**
|
356
|
+
* Jax.Context#stopUpdating() -> Jax.Context
|
357
|
+
*
|
358
|
+
* Stops updating.
|
359
|
+
**/
|
360
|
+
stopUpdating: function() {
|
361
|
+
clearTimeout(this.update_interval);
|
362
|
+
this.update_interval = null;
|
363
|
+
return this;
|
364
|
+
},
|
365
|
+
|
366
|
+
/**
|
367
|
+
* Jax.Context#getFramesPerSecond() -> Number
|
368
|
+
* The average number of frames rendered in one second.
|
369
|
+
*
|
370
|
+
* Implicitly enables calculation of frames-per-second, which is initially disabled by default
|
371
|
+
* to improve performance.
|
372
|
+
**/
|
373
|
+
getFramesPerSecond: function() { this.calculateFramerate = true; return this.frames_per_second; },
|
374
|
+
|
375
|
+
/**
|
376
|
+
* Jax.Context#getUpdatesPerSecond() -> Number
|
377
|
+
* The average number of updates performed in one second. See also Jax.Context#getFramesPerSecond().
|
378
|
+
*
|
379
|
+
* Implicitly enables calculation of updates-per-second, which is initially disabled by default
|
380
|
+
* to improve performance.
|
381
|
+
**/
|
382
|
+
getUpdatesPerSecond: function() { this.calculateUpdateRate = true; return this.updates_per_second; },
|
383
|
+
|
384
|
+
/**
|
385
|
+
* Jax.Context#disableFrameSpeedCalculations() -> Jax.Context
|
386
|
+
* Disables calculation of frames-per-second. Note that this calculation is disabled by default
|
387
|
+
* to improve performance, so you should only need to call this if you've previously called
|
388
|
+
* Jax.Context#getUpdatesPerSecond().
|
389
|
+
**/
|
390
|
+
disableFrameSpeedCalculations: function() { this.calculateFramerate = false; },
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Jax.Context#disableUpdateSpeedCalculations() -> Jax.Context
|
394
|
+
* Disables calculation of updates-per-second. Note that this calculation is disabled by default
|
395
|
+
* to improve performance, so you should only need to call this if you've previously called
|
396
|
+
* Jax.Context#getUpdatesPerSecond().
|
397
|
+
**/
|
398
|
+
disableUpdateSpeedCalculations: function() { this.caclulateUpdateRate = false; },
|
399
|
+
|
400
|
+
/**
|
401
|
+
* Jax.Context#afterRender(func) -> Jax.Context
|
402
|
+
*
|
403
|
+
* Registers the specified function to be called immediately after every render pass.
|
404
|
+
* Returns this context.
|
405
|
+
*
|
406
|
+
* When the function is called, its +this+ object is set to the context itself.
|
407
|
+
**/
|
408
|
+
afterRender: function(func) {
|
409
|
+
this.afterRenderFuncs.push(func);
|
410
|
+
},
|
411
|
+
|
412
|
+
/**
|
413
|
+
* Jax.Context#afterUpdate(func) -> Jax.Context
|
414
|
+
*
|
415
|
+
* Registers the specified function to be called immediately after every update pass.
|
416
|
+
* Returns this context.
|
417
|
+
*
|
418
|
+
* When the function is called, its +this+ object is set to the context itself.
|
419
|
+
**/
|
420
|
+
afterUpdate: function(func) {
|
421
|
+
this.afterUpdateFuncs.push(func);
|
422
|
+
},
|
423
|
+
|
424
|
+
/**
|
425
|
+
* Jax.Context#hasStencil() -> Boolean
|
426
|
+
*
|
427
|
+
* Returns true if this context supports stencil operations.
|
428
|
+
**/
|
429
|
+
hasStencil: function() {
|
430
|
+
return !!this.gl.stencil;
|
431
|
+
},
|
432
|
+
|
433
|
+
/**
|
434
|
+
* Jax.Context#redirectTo(path) -> Jax.Controller
|
435
|
+
* - path (String): the path to redirect to
|
436
|
+
*
|
437
|
+
* Redirects to the specified route, and then returns the Jax.Controller that
|
438
|
+
* was just redirected to. The act of redirecting will dispose of the current
|
439
|
+
* World, so be prepared to initialize a new scene.
|
440
|
+
**/
|
441
|
+
redirectTo: function(path) {
|
442
|
+
try {
|
443
|
+
this.stopRendering();
|
444
|
+
this.stopUpdating();
|
445
|
+
|
446
|
+
var current_controller = this.current_controller, current_view = this.current_view;
|
447
|
+
var route = Jax.routes.recognizeRoute(path);
|
448
|
+
|
449
|
+
/* yes, this is necessary. If the routing fails, controller must be null to prevent #update with a new world. */
|
450
|
+
// this.current_controller = this.current_view = null;
|
451
|
+
|
452
|
+
if (!current_controller || current_controller.klass != route.controller) {
|
453
|
+
// different controller, unload the scene
|
454
|
+
this.unloadScene();
|
455
|
+
this.current_controller = Jax.routes.dispatch(path, this);
|
456
|
+
|
457
|
+
if (!this.current_controller.view_key)
|
458
|
+
throw new Error("Controller '"+this.current_controller.getControllerName()+"' did not produce a renderable result");
|
459
|
+
|
460
|
+
this.current_view = Jax.views.find(this.current_controller.view_key);
|
461
|
+
setupView(this, this.current_view);
|
462
|
+
} else {
|
463
|
+
current_controller.fireAction(route.action);
|
464
|
+
this.current_controller = current_controller;
|
465
|
+
|
466
|
+
var newView, currentKey = current_controller.view_key;
|
467
|
+
try {
|
468
|
+
if (current_controller.view_key && (newView = Jax.views.find(current_controller.view_key))) {
|
469
|
+
this.current_view = newView;
|
470
|
+
setupView(this, newView);
|
471
|
+
}
|
472
|
+
} catch(e) {
|
473
|
+
current_controller.view_key = currentKey;
|
474
|
+
this.current_view = current_view;
|
475
|
+
}
|
476
|
+
}
|
477
|
+
|
478
|
+
if (!this.isRendering()) this.startRendering();
|
479
|
+
if (!this.isUpdating()) this.startUpdating();
|
480
|
+
|
481
|
+
if (this.current_controller)
|
482
|
+
this.registerMouseListeners(this.current_controller);
|
483
|
+
} catch(e) {
|
484
|
+
this.handleError('redirect', e);
|
485
|
+
}
|
486
|
+
|
487
|
+
return this.current_controller;
|
488
|
+
},
|
489
|
+
|
490
|
+
/**
|
491
|
+
* Jax.Context#unloadScene() -> Jax.Context
|
492
|
+
*
|
493
|
+
* Unloads the scene by detaching all mouse listeners, removing all
|
494
|
+
* objects from the World, and resetting the player's camera.
|
495
|
+
*
|
496
|
+
* Note that the current controller is not modified, and continues
|
497
|
+
* to be called as if nothing had happened (but the mouse events
|
498
|
+
* are ignored).
|
499
|
+
**/
|
500
|
+
unloadScene: function() {
|
501
|
+
this.unregisterMouseListeners();
|
502
|
+
this.world.dispose();
|
503
|
+
this.player.camera.reset();
|
504
|
+
return this;
|
505
|
+
},
|
506
|
+
|
507
|
+
/**
|
508
|
+
* Jax.Context#prepare() -> Jax.Context
|
509
|
+
*
|
510
|
+
* Loads the matrices from +player.camera+ into the matrix stack, then
|
511
|
+
* sets up the viewport. This should be run prior to rendering anything.
|
512
|
+
* This is done automatically when the context has a View associated
|
513
|
+
* with it, but if there is no View then the render process will be
|
514
|
+
* halted, leaving it up to you to prepare the canvas explicitly.
|
515
|
+
**/
|
516
|
+
prepare: function() {
|
517
|
+
reloadMatrices(this);
|
518
|
+
this.glViewport(0, 0, this.canvas.width, this.canvas.height);
|
519
|
+
},
|
520
|
+
|
521
|
+
/**
|
522
|
+
* Jax.Context#update(timechange) -> Jax.Context
|
523
|
+
* - timechange (Number): the amount of time, in seconds, since the previous update
|
524
|
+
*
|
525
|
+
* Automatically called over time, this function will trigger an update
|
526
|
+
* of all controllers and objects attached to this context.
|
527
|
+
*
|
528
|
+
* You can programmatically trigger updates to these objects by calling
|
529
|
+
* this method directly. Doing this is useful for constructing consistent
|
530
|
+
* test cases.
|
531
|
+
**/
|
532
|
+
update: function(timechange) {
|
533
|
+
if (this.current_controller && this.current_controller.update)
|
534
|
+
this.current_controller.update(timechange);
|
535
|
+
this.world.update(timechange);
|
536
|
+
return this;
|
537
|
+
},
|
538
|
+
|
539
|
+
/**
|
540
|
+
* Jax.Context#isRendering() -> Boolean
|
541
|
+
* Returns true if this Jax.Context currently has a render interval set.
|
542
|
+
* This will be false by default if there is no root route; otherwise
|
543
|
+
* it will be true. It is also enabled automatically upon the first
|
544
|
+
* valid redirect.
|
545
|
+
**/
|
546
|
+
isRendering: function() {
|
547
|
+
return this.render_interval != null;
|
548
|
+
},
|
549
|
+
|
550
|
+
/**
|
551
|
+
* Jax.Context#isUpdating() -> Boolean
|
552
|
+
* Returns true if this Jax.Context currently has an update interval set.
|
553
|
+
* This will be false by default if there is no view; otherwise
|
554
|
+
* it will be true. It is also enabled automatically upon the first
|
555
|
+
* valid redirect.
|
556
|
+
**/
|
557
|
+
isUpdating: function() {
|
558
|
+
return this.update_interval != null;
|
559
|
+
},
|
560
|
+
|
561
|
+
/**
|
562
|
+
* Jax.Context#dispose() -> undefined
|
563
|
+
*
|
564
|
+
* Permanently disposes of this context, freeing the resources it is using.
|
565
|
+
* This stops actions from running, closes any open rendering contexts, and
|
566
|
+
* clears all other timeouts and intervals.
|
567
|
+
*
|
568
|
+
* A Jax.Context cannot be used once it is disposed.
|
569
|
+
**/
|
570
|
+
dispose: function() {
|
571
|
+
this.disposed = true;
|
572
|
+
this.stopRendering();
|
573
|
+
this.stopUpdating();
|
574
|
+
this.disposeEventListeners();
|
575
|
+
},
|
576
|
+
|
577
|
+
/**
|
578
|
+
* Jax.Context#isDisposed() -> Boolean
|
579
|
+
* Returns true if this context has been disposed.
|
580
|
+
**/
|
581
|
+
isDisposed: function() {
|
582
|
+
return !!this.disposed;
|
583
|
+
},
|
584
|
+
|
585
|
+
/**
|
586
|
+
* Jax.Context#pushMatrix(yield_to) -> Jax.Context
|
587
|
+
* - yield_to (Function): a function to be called
|
588
|
+
*
|
589
|
+
* Pushes a new level onto the matrix stack and then calls the given function.
|
590
|
+
* After the function completes, the matrix stack is reverted back to its
|
591
|
+
* original state, effectively undoing any modifications made to the matrices
|
592
|
+
* in the meantime.
|
593
|
+
*
|
594
|
+
* Example:
|
595
|
+
*
|
596
|
+
* context.pushMatrix(function() {
|
597
|
+
* context.loadModelMatrix(mat4.IDENTITY);
|
598
|
+
* context.multViewMatrix(this.camera.getTransformationMatrix());
|
599
|
+
* // do some rendering
|
600
|
+
* });
|
601
|
+
* // matrix is restored to its previous state
|
602
|
+
**/
|
603
|
+
pushMatrix: function(yield_to) {
|
604
|
+
this.matrix_stack.push();
|
605
|
+
yield_to();
|
606
|
+
this.matrix_stack.pop();
|
607
|
+
return this;
|
608
|
+
},
|
609
|
+
|
610
|
+
/**
|
611
|
+
* Jax.Context#getViewMatrix() -> mat4
|
612
|
+
* Returns the view matrix. See Jax.MatrixStack#getViewMatrix for details.
|
613
|
+
**/
|
614
|
+
getViewMatrix: function() { return this.matrix_stack.getViewMatrix(); },
|
615
|
+
|
616
|
+
/**
|
617
|
+
* Jax.Context#getInverseViewMatrix() -> mat4
|
618
|
+
* Returns the inverse view matrix. See Jax.MatrixStack#getInverseViewMatrix for details.
|
619
|
+
**/
|
620
|
+
getInverseViewMatrix: function() { return this.matrix_stack.getInverseViewMatrix(); },
|
621
|
+
|
622
|
+
/**
|
623
|
+
* Jax.Context#getFrustum() -> Jax.Scene.Frustum
|
624
|
+
* Returns the frustum for the player's camera. Equivalent to calling
|
625
|
+
*
|
626
|
+
* context.player.camera.getFrustum()
|
627
|
+
*
|
628
|
+
* Note that changes to the matrix via #multMatrix will not be represented
|
629
|
+
* in this Jax.Scene.Frustum.
|
630
|
+
**/
|
631
|
+
getFrustum: function() { return this.player.camera.frustum; },
|
632
|
+
|
633
|
+
checkForRenderErrors: function() {
|
634
|
+
/* Error checking is slow, so don't do it in production mode */
|
635
|
+
if (Jax.environment == Jax.PRODUCTION) return;
|
636
|
+
|
637
|
+
var error = this.glGetError();
|
638
|
+
if (error != GL_NO_ERROR)
|
639
|
+
{
|
640
|
+
var str = "GL error in "+this.canvas.id+": "+error+" ("+Jax.Util.enumName(error)+")";
|
641
|
+
error = new Error(str);
|
642
|
+
var message = error;
|
643
|
+
if (error.stack)
|
644
|
+
{
|
645
|
+
var stack = error.stack.split("\n");
|
646
|
+
stack.shift();
|
647
|
+
message += "\n\n"+stack.join("\n");
|
648
|
+
}
|
649
|
+
|
650
|
+
throw error;
|
651
|
+
}
|
652
|
+
},
|
653
|
+
|
654
|
+
/**
|
655
|
+
* Jax.Context#handleError(phase, error) -> Jax.Context
|
656
|
+
* - phase (String): the processing stage during which this error was encountered; examples
|
657
|
+
* include +initialize+, +update+ and +render+.
|
658
|
+
* - error (Error): the error itself
|
659
|
+
*
|
660
|
+
* Handles the given error by first notifying any 'error' event listeners,
|
661
|
+
* then passing the error into the current controller's +error+ method. If
|
662
|
+
* there is no current controller or if the controller has no +error+ method,
|
663
|
+
* the ApplicationController's +error+ method is called instead. In both
|
664
|
+
* cases, the +error+ method may optionally return a non-false expression;
|
665
|
+
* if they do, the error is silenced and the next processing step is skipped.
|
666
|
+
*
|
667
|
+
* If the error has not been silenced by either an error event listener or
|
668
|
+
* a controller, the error is logged to the console and, in development mode,
|
669
|
+
* an +alert+ box is shown indicating all known information about the error.
|
670
|
+
*
|
671
|
+
* Finally, the method returns this instance of Jax.Context.
|
672
|
+
**/
|
673
|
+
handleError: function(phase, error) {
|
674
|
+
// not to be confused with handleRenderError(), this function is called
|
675
|
+
// by render() and update() when an error is encountered anywhere within
|
676
|
+
// them.
|
677
|
+
var message = error.toString();
|
678
|
+
error = {
|
679
|
+
phase: phase,
|
680
|
+
error: error.error || error,
|
681
|
+
stack: error._stack || error.stack,
|
682
|
+
message: error.toString(),
|
683
|
+
toString: function() { return message; }
|
684
|
+
};
|
685
|
+
this.fireEvent('error', error);
|
686
|
+
|
687
|
+
var errorHandler = this.current_controller;
|
688
|
+
if ((!errorHandler || !errorHandler.error) && typeof(ApplicationController) != 'undefined')
|
689
|
+
errorHandler = Jax.getGlobal().ApplicationController.prototype;
|
690
|
+
if (errorHandler && errorHandler.error) error.silence = errorHandler.error(error);
|
691
|
+
|
692
|
+
// default error handling
|
693
|
+
if (!error.silence && !error.silenced) {
|
694
|
+
if (error.phase == 'initialize') {
|
695
|
+
// init failure: most likely, webgl is not supported
|
696
|
+
// TODO solidify this with new error types. Can check the error type for verification.
|
697
|
+
|
698
|
+
if (Jax.webgl_not_supported_path)
|
699
|
+
document.location.pathname = Jax.webgl_not_supported_path;
|
700
|
+
throw error.toString()+"\n\n"+error.stack;
|
701
|
+
}
|
702
|
+
|
703
|
+
var log = null, stack = error._stack || error.stack || "(backtrace unavailable)";
|
704
|
+
var message = error.toString()+"\n\n"+stack.toString();
|
705
|
+
|
706
|
+
if (typeof(console) != 'undefined') {
|
707
|
+
log = console.error || console.log;
|
708
|
+
if (log) log.call(console, message);
|
709
|
+
}
|
710
|
+
if (Jax.environment != Jax.PRODUCTION && this.alertErrors)
|
711
|
+
alert(message);
|
712
|
+
throw error.error;
|
713
|
+
}
|
714
|
+
|
715
|
+
return this;
|
716
|
+
},
|
717
|
+
|
718
|
+
handleRenderError: function(method_name, args, err) {
|
719
|
+
// FIXME this is going to be eventually caught by the try{} around render()
|
720
|
+
// so, I'm not convinced we even need this function any more... maybe better
|
721
|
+
// to throw the error outright than to call handleRenderError().
|
722
|
+
throw err;
|
723
|
+
}
|
724
|
+
});
|
725
|
+
|
726
|
+
/* set up matrix stack delegation */
|
727
|
+
klass.delegate(/^(get|load|mult)(.*)Matrix$/).into("matrix_stack");
|
728
|
+
|
729
|
+
/** alias of: Jax.Context#getFramesPerSecond
|
730
|
+
* Jax.Context#getFramerate() -> Number
|
731
|
+
* The average numebr of frames rendered in one second.
|
732
|
+
**/
|
733
|
+
klass.prototype.getFramerate = klass.prototype.getFramesPerSecond;
|
734
|
+
|
735
|
+
return klass;
|
736
|
+
})();
|
737
|
+
|
738
|
+
Jax.Context.identifier = 0;
|
739
|
+
Jax.Context.addMethods(GL_METHODS);
|
740
|
+
Jax.Context.addMethods(Jax.EVENT_METHODS);
|
741
|
+
Jax.Context.addMethods(Jax.Events.Methods);
|