Files
blend4web-first-person-preset/preset.js
Victor Giers fb577e7687 initial commit
2017-07-16 17:58:38 +02:00

97 lines
2.3 KiB
JavaScript

"use strict"
// register the application module
b4w.register("preset_main", function(exports, require) {
// import modules used by the app
var m_app = require("app");
var m_cfg = require("config");
var m_data = require("data");
var m_preloader = require("preloader");
var m_ver = require("version");
var m_fps = require("fps"); //kek
//kek
var cb = function(element) {
console.log("pointerlock is enabled");
}
// detect application mode
var DEBUG = (m_ver.type() == "DEBUG");
// automatically detect assets path
var APP_ASSETS_PATH = m_cfg.get_assets_path("preset_firstperson");
/**
* export the method to initialize the app (called at the bottom of this file)
*/
exports.init = function() {
m_app.init({
canvas_container_id: "main_canvas_container",
callback: init_cb,
show_fps: false, //set to DEBUG for editing / if you need debug
console_verbose: false, //set to DEBUG for editing / if you need debug
autoresize: true
});
}
/**
* callback executed when the app is initialized
*/
function init_cb(canvas_elem, success) {
if (!success) {
console.log("b4w init failure");
return;
}
m_preloader.create_preloader();
// ignore right-click on the canvas element
canvas_elem.oncontextmenu = function(e) {
e.preventDefault();
e.stopPropagation();
return false;
};
load();
}
/**
* load the scene data
*/
function load() {
m_data.load(APP_ASSETS_PATH + "preset.json", load_cb, preloader_cb);
}
/**
* update the app's preloader
*/
function preloader_cb(percentage) {
m_preloader.update_preloader(percentage);
}
/**
* callback executed when the scene data is loaded
*/
function load_cb(data_id, success) {
if (!success) {
console.log("b4w load failure");
return;
}
//m_app.enable_camera_controls();
//your code here
m_fps.enable_fps_controls(); //instead of camera controls
m_fps.set_plock_enable_cb(cb); //mouse no drag and drop, but direct input
var current_state = m_fps.get_character_state();
if (current_state == m_fps.CS_FLY) //disable fly
m_fps.switch_state(m_fps.CS_WALK);
}
});
// import the app module and start the app by calling the init method
b4w.require("preset_main").init();