Forum

A new lesson on object transformation programming

02 August 2016 16:29 #10919
Andrey Prakhov has written a new tutorial which certainly will help beginners in Blend4Web applications scripting. If it is not completely obvious to you how to give life to objects and move them with the help of programming code, you definitely have to pay attention to it.

Link to the article.
Blend4Web developer
28 October 2016 15:15 #13162
Hello,
I needed the scene or world to have zero gravity (the objects, or the balls I created from Blender should not fall).
If I set the objects as static in Blender, the set_translation does not work because the object should be dynamic.
But if I use dynamic/rigid, the objects fall (with gravity). I followed the example here.
28 October 2016 15:44 #13165
Hi!
In order to use translation methods you should enable the Force Dynamic Object flag. You don't need to change physics settings.
Actually, Andrey has pointed this in the following screenshot:
Blend4Web developer
01 November 2016 11:13 #13229
thank you. I'll try this.
04 November 2016 16:52 #13345
Hello, I tried again, but the yellowball (in the attached json file) does not collide with red ball, because they are static and I used "move local". And if I use rigid, they fall.
The balls should not fall since they are planets.
And then I decided to push up the blueball by 9.8 to achieve equilibrium but it looks like the engine is not working as it should be. There is a push going forward (y), I do not know where did it come from. I guess it is an engine bug.
Here is my code and it is also in the attachment.
————————————————————————–
"use strict"

b4w.register("gravity_simulation", function(exports, require) {

var m_app = require("app");
var m_data = require("data");
var m_scs = require("scenes");
var m_obj = require("objects");
var m_trans = require("transform");
var m_phy = require("physics");
var m_ctl = require("controls");
var m_cfg = require("config");
var m_version = require("version");

var DEBUG = (m_version.type() === "DEBUG");

var obj;
var yellowplanet;
var blueplanet;
var elapsed_sensor;


exports.init = function() {
m_app.init({
canvas_container_id: "canvas_cont",
callback: init_cb,
physics_enabled: true,
show_fps: true,
alpha: false,
autoresize: true,
assets_dds_available: !DEBUG,
assets_min50_available: !DEBUG,
console_verbose: true
});
}

function init_cb(canvas_elem, success) {

if (!success) {
console.log("b4w init failure");
return;
}
load();
}

function load() {
m_data.load("gravity_simulation.json", load_cb);

}

var speed = 1;

function main_cb (obj, id) {
var elapsed = m_ctl.get_sensor_value(obj, id, 0); 
//m_trans.set_translation(planet,2, 0, 0);
m_phy.apply_force(blueplanet,0,0,9.81,true) 
m_trans.move_local(yellowplanet, speed*elapsed, 0, 0);	
}

function load_cb(data_id) {
m_app.enable_camera_controls();
elapsed_sensor = m_ctl.create_elapsed_sensor();
m_ctl.create_sensor_manifold(null, "MAIN", m_ctl.CT_CONTINUOUS, [elapsed_sensor], null, main_cb);
yellowplanet = m_scs.get_object_by_name("Yellow");
blueplanet = m_scs.get_object_by_name("Blue");
//m_phy.apply_force_world(obj, 5, -1, 0)
//m_phy.apply_force(src_obj,0,9.8,9.8,false)
//m_trans.set_translation(obj,5, 0, 0);
}

//var loop = function () {
//	requestAnimationFrame(loop);
//m_trans.set_translation(obj,2, 0, 0);
//m_phy.apply_force(src_obj,10,0,0,false)
//};

//	requestAnimationFrame(loop);


});

b4w.require("gravity_simulation").init();
———————————————————————
04 November 2016 16:54 #13346
I forgot to tell, the "force dynamic object" did not solve the problem. Because I need an object that moves and at the same time collides (with physics), and does not fall.
04 November 2016 17:07 #13348
how to delete a comment?
07 November 2016 11:31 #13481
Change it to something like "delete this comment"
3D Generalist, contests administrator,
Blend4Web team.
art blog: http://contret-art.tumblr.com/
14 November 2016 11:52 #13812
Thank you. But I decided to just use Threejs. I will just use Blend4Web in my later projects.
 
Please register or log in to leave a reply.