A blend4web project with first person controls, no flying, and a locked pointer to look around without drag'n'drop.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

preset.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict"
  2. // register the application module
  3. b4w.register("preset_main", function(exports, require) {
  4. // import modules used by the app
  5. var m_app = require("app");
  6. var m_cfg = require("config");
  7. var m_data = require("data");
  8. var m_preloader = require("preloader");
  9. var m_ver = require("version");
  10. var m_fps = require("fps"); //kek
  11. //kek
  12. var cb = function(element) {
  13. console.log("pointerlock is enabled");
  14. }
  15. // detect application mode
  16. var DEBUG = (m_ver.type() == "DEBUG");
  17. // automatically detect assets path
  18. var APP_ASSETS_PATH = m_cfg.get_assets_path("preset_firstperson");
  19. /**
  20. * export the method to initialize the app (called at the bottom of this file)
  21. */
  22. exports.init = function() {
  23. m_app.init({
  24. canvas_container_id: "main_canvas_container",
  25. callback: init_cb,
  26. show_fps: false, //set to DEBUG for editing / if you need debug
  27. console_verbose: false, //set to DEBUG for editing / if you need debug
  28. autoresize: true
  29. });
  30. }
  31. /**
  32. * callback executed when the app is initialized
  33. */
  34. function init_cb(canvas_elem, success) {
  35. if (!success) {
  36. console.log("b4w init failure");
  37. return;
  38. }
  39. m_preloader.create_preloader();
  40. // ignore right-click on the canvas element
  41. canvas_elem.oncontextmenu = function(e) {
  42. e.preventDefault();
  43. e.stopPropagation();
  44. return false;
  45. };
  46. load();
  47. }
  48. /**
  49. * load the scene data
  50. */
  51. function load() {
  52. m_data.load(APP_ASSETS_PATH + "preset.json", load_cb, preloader_cb);
  53. }
  54. /**
  55. * update the app's preloader
  56. */
  57. function preloader_cb(percentage) {
  58. m_preloader.update_preloader(percentage);
  59. }
  60. /**
  61. * callback executed when the scene data is loaded
  62. */
  63. function load_cb(data_id, success) {
  64. if (!success) {
  65. console.log("b4w load failure");
  66. return;
  67. }
  68. //m_app.enable_camera_controls();
  69. //your code here
  70. m_fps.enable_fps_controls(); //instead of camera controls
  71. m_fps.set_plock_enable_cb(cb); //mouse no drag and drop, but direct input
  72. var current_state = m_fps.get_character_state();
  73. if (current_state == m_fps.CS_FLY) //disable fly
  74. m_fps.switch_state(m_fps.CS_WALK);
  75. }
  76. });
  77. // import the app module and start the app by calling the init method
  78. b4w.require("preset_main").init();