Create a button
04 February 2018 17:23
12 February 2018 13:46
I'm also interested in this. I've seen your example, but I wonder how I can achive this via normal html buttons with the webplayer.html?
When I'm not mistaken your example only works when you create a user interface in blender directly.
EDIT:
Ok, I looked a little bit deeper and searched through other treads. I think I can achieve the camera moves via html buttons with an "entry point" marked as "run from script". Problem with this, is that I can not use javascript functions/commands when I'm using the webplayer. I have to create project as "custom type". But is there anyway I can use the preprogrammed webplayer interface and just add my buttons and using javascript functions?
When I'm not mistaken your example only works when you create a user interface in blender directly.
EDIT:
Ok, I looked a little bit deeper and searched through other treads. I think I can achieve the camera moves via html buttons with an "entry point" marked as "run from script". Problem with this, is that I can not use javascript functions/commands when I'm using the webplayer. I have to create project as "custom type". But is there anyway I can use the preprogrammed webplayer interface and just add my buttons and using javascript functions?
12 February 2018 16:22
But is there anyway I can use the preprogrammed webplayer interface and just add my buttons and using javascript functions?No, you can't connect additional javascript code to the original WebPlayer application, but you can modify it just like a usual application by including script tag to the html-file.
Alexander (Blend4Web Team)
twitter
12 February 2018 17:21
How exactly does that work?
At the moment I got the normal "webplayer. html" which got the "webplayer.min.js" loaded. When I now try to load another javascript file with this code to execute the entry point I created:
But this doesnt work because "require isn't defined".
At the moment I got the normal "webplayer. html" which got the "webplayer.min.js" loaded. When I now try to load another javascript file with this code to execute the entry point I created:
var m_logic_n = require("logic_nodes");
function ChangeCam() {
m_logic_n.run_entrypoint("Scene", "ChangeCam");
}
But this doesnt work because "require isn't defined".
13 February 2018 11:07
You should use require inside register callback if you are using old-style:
But Webplayer now uses ES6, so you should just do:
"use strict"
// register the module
b4w.register("module1", function(exports, require) {
var m_logic_n = require("logic_nodes");
exports.ChangeCam = function() {
m_logic_n.run_entrypoint("Scene", "ChangeCam");
}
})
But Webplayer now uses ES6, so you should just do:
var m_logic_n = b4w.logic_nodes
Alexander (Blend4Web Team)
twitter
13 February 2018 14:00
I'm sorry, but I cant get it work. I get no errors anymore in console but when I hit the button nothing happends. This is my code at the moment
Is there anything more I can do to debug this?
var el = document.getElementById("testbutton");
if(el){
el.addEventListener('click', function() {
"use strict"
// register the module
b4w.register("module1", function(exports, require) {
var m_logic_n = b4w.logic_nodes;
exports.ChangeCam = function() {
m_logic_n.run_entrypoint("Scene", "ChangeCam");
}
})
});
}
Is there anything more I can do to debug this?
13 February 2018 14:25
What version of Blend4Web are you using?
If it is 17.12 you can just get logic_nodes from "b4w" global variable:
Anyway you are using b4w.register in incorrectly. b4w.register is registering your module with the name "module1". The body of module is defined in "function(exports, require)". After b4w.register is being called other modules can get this module with 'var m_mod1 = require("module1").'
If it is 17.12 you can just get logic_nodes from "b4w" global variable:
var m_logic_n = b4w.logic_nodes
Anyway you are using b4w.register in incorrectly. b4w.register is registering your module with the name "module1". The body of module is defined in "function(exports, require)". After b4w.register is being called other modules can get this module with 'var m_mod1 = require("module1").'
Alexander (Blend4Web Team)
twitter
20 February 2018 12:00
I'm using the latest version 17.12 and tried both approaches, with the same result.
I don't really get what you mean with using b4w.register incorrectly. But maybe I need to get deeper into your api.
Maybe I should avoid the webplayer as basis and start from scratch, in the end it seems to be simpler.
I don't really get what you mean with using b4w.register incorrectly. But maybe I need to get deeper into your api.
Maybe I should avoid the webplayer as basis and start from scratch, in the end it seems to be simpler.
20 February 2018 12:14
I don't really get what you mean with using b4w.register incorrectly.
In your example b4w.register is called in the click handler, but b4w.register should be called just once for registering the module which then can be received using b4w.require.
If you will attach a simple project, it will help to understand the issue deeper.
Alexander (Blend4Web Team)
twitter