Sending information/mesh to the server
16 January 2016 23:38
Hello! I have a quick question about Blend4Web's features.
Similar to https://www.blend4web.com/en/forums/topic/758/, I'd like to write an application that lets the user change some values to modify an object mesh, and then either
a) communicates to the server what values the user specified, or
b) sends the modified mesh to the server.
Is either of these options possible with blend4web now?
Thanks!
Andrew
Similar to https://www.blend4web.com/en/forums/topic/758/, I'd like to write an application that lets the user change some values to modify an object mesh, and then either
a) communicates to the server what values the user specified, or
b) sends the modified mesh to the server.
Is either of these options possible with blend4web now?
Thanks!
Andrew
17 January 2016 12:22
Hello and welcome to the forum.
Yes, it's possible. I've created a simple example, using dynamic geometry. I use browser local storage to save cnanged geometry, but you should use server requests.
The application remembers the latest geometry data and save it. When you open the app again, it sets the geometry from memory.
Here is the example (it was created with using the project manager)
And the application code:
Is either of these options possible with blend4web now?
Yes, it's possible. I've created a simple example, using dynamic geometry. I use browser local storage to save cnanged geometry, but you should use server requests.
The application remembers the latest geometry data and save it. When you open the app again, it sets the geometry from memory.
Here is the example (it was created with using the project manager)
And the application code:
"use strict"
// register the application module
b4w.register("test_geometry", 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_ver = require("version");
var m_scs = require("scenes");
var m_geom = require("geometry");
var m_obj = require("objects");
var m_stor = require("storage");
// detect application mode
var DEBUG = (m_ver.type() === "DEBUG");
// automatically detect assets path
var APP_ASSETS_PATH = m_cfg.get_std_assets_path() + "test_geometry/";
var _indices = new Uint16Array([0,1,2,3,4,5]);
var _changed_positions = new Float32Array([0,1,0, -1,0,1, 1,0,-1, 1,0,-1, -1,0,1, 1,0,1]);
var _default_positions = new Float32Array([-1,0,-1, -1,0,1, 1,0,-1, 1,0,-1, -1,0,1, 1,0,1]);
/**
* export the method to initialize the app (called at the bottom of this file)
*/
exports.init = function() {
m_stor.init("test_geometry");
m_app.init({
canvas_container_id: "main_canvas_container",
callback: init_cb,
show_fps: DEBUG,
console_verbose: DEBUG,
autoresize: true
});
}
/**
* callback executed when the app is initizalized
*/
function init_cb(canvas_elem, success) {
if (!success) {
console.log("b4w init failure");
return;
}
load();
}
/**
* load the scene data
*/
function load() {
m_data.load(APP_ASSETS_PATH + "test_geometry.json", load_cb);
}
/**
* callback executed when the scene is loaded
*/
function load_cb(data_id, success) {
if (!success) {
console.log("b4w load failure");
return;
}
m_app.enable_controls();
m_app.enable_camera_controls();
var plane = m_scs.get_object_by_name("Plane");
document.getElementById("def_geom").onclick = function() {
geometry_change(plane, "Material", _default_positions);
remember_positions(_default_positions);
}
document.getElementById("chan_geom").onclick = function() {
geometry_change(plane, "Material", _changed_positions);
remember_positions(_changed_positions);
}
var positions_str = m_stor.get("positions");
if (positions_str) {
var positions_float = new Float32Array(positions_str.toString().split(",").map(parseFloat));
geometry_change(plane, "Material", positions_float);
}
}
function geometry_change(obj, material_name, positions) {
m_geom.override_geometry(obj, material_name, _indices, positions, false);
m_obj.update_boundings(obj);
}
function remember_positions(positions) {
m_stor.set("positions", positions.toString());
}
});
// import the app module and start the app by calling the init method
b4w.require("test_geometry").init();
19 January 2016 00:56
19 January 2016 22:47
I think you should check the state using a combination of get/post and delay nodes. You can set 5 second delay, for example, and make a cycle.
Alexander (Blend4Web Team)
twitter
22 January 2016 12:16