Forum

(Clojurescript) accidental munging of elapsed sensor

28 September 2016 23:06
Hi guys,

In my ongoing quest to integrate Clojurescript with blend4web, I've run into another issue. I can't seem to create a sensor type. I've tried the elapsed sensor, and the callback sensor.

In both of those cases, I start by invoking the control module's create_elapsed_sensor function, and what it returns is an object with all its attributes munged.

Now, Clojurescript uses Google Closure (like b4w) to compile into Javascript. So I suspect the problem is how I declared Clojurescript's b4w externs. But before I start altering the externs, I want to make sure I'm not doing some other blend4web-specific mistake. Here's a screencap of what is supposed to be the elapsed sensor object:

Thanks
29 September 2016 15:36
Hi, Mike!

In both of those cases, I start by invoking the control module's create_elapsed_sensor function, and what it returns is an object with all its attributes munged.
This is normal, it looks the same as in compiled b4w.min.js. I don't see a problem here.

Now, Clojurescript uses Google Closure (like b4w) to compile into Javascript. So I suspect the problem is how I declared Clojurescript's b4w externs. But before I start altering the externs, I want to make sure I'm not doing some other blend4web-specific mistake.

Yes, you should declare b4w-specific externs to avoid possible bugs. Firstly, here you can find the list of the externs that we use for compilation: source.

Besides them, we also generate a special temporary file during the compilation, which contains some data gathered from the source files: source. We find API functions/variables declared as "exports.IDENTIFIER" and also indetifiers under the @cc_externs token. You can see it here: source.
30 September 2016 16:40
Hi Ivan,

Hi, Mike!
This is normal, it looks the same as in compiled b4w.min.js. I don't see a problem here.

Ok good to hear. It turns out I'm a goddamn fool – I was trying to create the manifold from the elapsed sensor object, *not* from the controls module :P Of course that elapsed sensor doesn't have that method! Once I realized my idiocy, I was able to create the manifold callback with the sensor.

Yes, you should declare b4w-specific externs to avoid possible bugs. Firstly, here you can find the list of the externs that we use for compilation: source.

Thank-you. That's similar to what I've been using – only I used everything in your google closure directory. I really shouldn't have said 'declaring externs' because it was more like 'taking your externs, putting them in the right clojurescript extern directory and see what happens'. From your link, it looks like I've included a few too many :P cljs externs

Besides them, we also generate a special temporary file during the compilation, which contains some data gathered from the source files: source. We find API functions/variables declared as "exports.IDENTIFIER" and also indetifiers under the @cc_externs token. You can see it here: source.
Thanks – this is good to know. I should familiarize myself with this part of the compilation process, as I've been ignoring it until now.

Cheers!
30 September 2016 17:25
It turns out I'm a goddamn fool – I was trying to create the manifold from the elapsed sensor object, *not* from the controls module :P
don't blame yourself, this is what happens from time to time with all of us
glad you've solved the problem
01 October 2016 16:49
Cheers Ivan!

I've managed to cobble together a basic scene – some animation, manipulating a simple cube via clojurescript. Check it out here

Here's that same project's source code – you can find the 'meat' of the logic in ../src/cube_test/core.cljs.

Note that it seems to work better on Chrome – FF doesn't seem to load shadows the same way.
03 October 2016 11:17
I've managed to cobble together a basic scene – some animation, manipulating a simple cube via clojurescript. Check it out here

Here's that same project's source code – you can find the 'meat' of the logic in ../src/cube_test/core.cljs.
Cool, it works nice. Do you plan to do something more complex than that?
Also a little advice, the animation via elapsed sensor depends on frame rate, so in Chrome with gpu vsync disabled and around 600 FPS the cube moves very fast . To avoid this you can use the time.animate method.

Note that it seems to work better on Chrome – FF doesn't seem to load shadows the same way.
Hmm… I don't see the difference. Can you show a screenshot?
This can be related to a specific GPU. FYI, we apply some compatibility hacks depending on the GPU's renderer/vendor info - you can see them as warnings in a browser console. Unfortunately, FF doesn't allow to retrieve such data, hence some of that hacks don't work.
05 October 2016 15:08
Oh yeah, I'm definitely planning on making more complex scenes – I just want to ensure I understand simple scenes first. Speaking of which, yes – I'm not a fan of my update loop right now, its just that elapsed sensor was the only one I could figure out. So time.animate sounds like a more reliable (sane) way of animating values. But I'm confused on how to use it – would I invoke this in my elapsed sensor callback? Or do I invoke it somewhere else?

Hmm… I don't see the difference. Can you show a screenshot?

I re-opened it today in latest FF, and….it's now the same as in Chrome :P Mind you, I think there was a small update that FF downloaded before I re-opened..maybe it was that fix. Either that, or I'm hallucinating.

At any rate, b4w is working pretty good on both now!
07 October 2016 10:50
But I'm confused on how to use it – would I invoke this in my elapsed sensor callback? Or do I invoke it somewhere else?
Wherever you want, no sensors are required. This method just registers a given callback for calling it every frame until the time expires. For example:

var cb = function(value) {
    var cube = m_scenes.get_object_by_name("Cube");
    m_trans.set_translation(cube, 0, 0, value);
}

m_time.animate(-5, 5, 10000, cb);


another example here: https://github.com/TriumphLLC/Blend4Web/blob/16.09.2/apps_dev/victory_day_2015/victory_day_2015.js#L248-L256
08 October 2016 21:39
Sweet – thanks Ivan it works just as you said. I put it up here, in case anyone wants to check it out. The corrresponding clojurescript is here.

And thanks for pointing out the victory day code – this will probably answer a lot my other questions.
 
Please register or log in to leave a reply.