Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btDynamicsWorld::setInternalTickCallback() has no effect #30

Open
laurie71 opened this issue Nov 18, 2012 · 12 comments
Open

btDynamicsWorld::setInternalTickCallback() has no effect #30

laurie71 opened this issue Nov 18, 2012 · 12 comments

Comments

@laurie71
Copy link

I'm trying to get called back on internal ticks, without success. I tried the naive approach:

    dynamicsWorld  = new ammo.btDiscreteDynamicsWorld(...)
    dynamicsWorld.setInternalTickCallback(pretick, this, true)
    dynamicsWorld.setInternalTickCallback(posttick, this, false)
    dynamicsWorld.stepSimulation(1/30, 5)

    function pretick(dw, timeStep)  { /* XXX never called */ }
    function posttick(dw, timeStep) { /* XXX never called */ }

I looked at Callbacks from C++ to JS in tests/wrapping.js, but that doesn't seem to apply in this case, as I'm not replacing a function on an object, just trying to pass JS objects/functions.

I think I can work around not being able to use the worldUserInfo parameter to setInternalTickCallback(), but I do need the callback function to get invoked.

Am I doing something wrong, or is this just not possible right now?

@ghost
Copy link

ghost commented Dec 7, 2013

I'm having the same issue. It says setInternalTickCallback is supposed to take a 'btInternalTickCallback':
http://bulletphysics.org/Bullet/BulletFull/btDynamicsWorld_8h.html#ab9ff268d3f8e17f20d6bcd7a7ef354c5

Ammo.btInternalTickCallback is undefined...

@cschinko
Copy link

Any news regarding this issue?

@kripken
Copy link
Owner

kripken commented Apr 17, 2014

I hope in the next few weeks to have a new version of ammo that uses a new
bindings generator, which should help with things like this.

On Thu, Apr 17, 2014 at 4:15 AM, cschinko notifications@github.com wrote:

Any news regarding this issue?


Reply to this email directly or view it on GitHubhttps://github.com//issues/30#issuecomment-40703726
.

@Usnul
Copy link

Usnul commented Aug 12, 2014

this seems to be axed entirely in the new build, can we bring it back please?
by the way, for those still searching, you need to first create a function pointer to pass in:

function callback(dw,timeDelta){
...
}
var fp = Ammo.Runtime.addFunction(callback);
dynamicWorld.setInternalTickCallback(fp);

also, you might need to go into your ammo.js and search for "functionPointers" then change value from "[]" to "new Array(x)" where x is number of pointers you wish to be able to hold, if this isn't done you will likely see an error in console when trying to invoke "addFunction".

@kripken
Copy link
Owner

kripken commented Aug 14, 2014

Adding this to the new IDL files seems to require support for passing in function pointers, which I don't think we support yet. But shouldn't be too hard to add.

@ghost
Copy link

ghost commented Feb 1, 2015

Any word on how to do this with the new IDL? I'd like to create a btInternalTickCallback to handle kinematic rigidbodies, since nothing I do will prevent dynamic rigidbodies from passing through fast moving kinematic rigidbodies (A and D to move the kinematic flippers, hold space to shoot the ball https://goote.ch/169f43e6e96e434d879039deede2bb7e.scene). Even if we were to create an interface for setInternalTickCallback() in the btDiscreteDynamicsWorld class, how would we be able to pass in a JavaScript function?

@Usnul
Copy link

Usnul commented Feb 2, 2015

Just a note, you can still do this, but you need to bypass IDL however, you will need to edit generated C files by hand. If you really need this then a gap-stop solution might work for you.

@cybafelo
Copy link

Hey all - I'm also struggling with this - is there some way to set a substep callback in ammo js? I really need this to speed up my game, and I don't want to write any gap-stop code..

@cybafelo
Copy link

Hey guys - any feedback on this - is it a simple thing? I don't know the details of emscripten but will try to build a new version of ammo soon - so that I could at least set an internal substep callback - or can someone tell me know if I should not even try this?

@Usnul
Copy link

Usnul commented May 27, 2016

@cybafelo
I did this in the past, might try to find it later. But it boils down to generation of C files from IDL that comes with ammo, IDL generator does not allow expression of interface such as one you describe, so you will have to edit generated C file by hand to add it, the rest is simple - just follow build process as usual.

@cybafelo
Copy link

cybafelo commented Jun 9, 2016

ok - I tried the following - i modified the ammo.idl to have the following lines:

callback btInternalTickCallback = void (btDynamicsWorld world, float timeStep);

the float above should actually be btScalar but i didnt want to modify the idl too much (also btScalar is just a typedef for float or double)

then, in interface btDynamicsWorld i added the following line

void setInternalTickCallback(btInternalTickCallback cb, optional VoidPtr worldUserInfo, optional boolean isPreTick);

Now I rebuild ammo.js with python make.py, which builds a temp.js which I copy over to my ammo.js - it loads fine, everything still works - i have the function 'setInternalTickCallback' - but my callback doesn't execute (its a closure, ex.
myDiscreteDynamicsWorld.setInternalTickCallback( function(){ console.log('hello'); } );
I tried the example above with Ammo.Runtime but Ammo.Runtime is not defined. Help anyone?

So - it appears to be the same problem, setInternalTickCallback has no effect

my last attempt is

this.world.setInternalTickCallback( function(__a, __b) { console.log('internal tick callback'); } , null, true);

this.world is an instance of btDiscreteDynamicsWorld

@Usnul
Copy link

Usnul commented Jun 9, 2016

@cybafelo
it was a long time ago since i did this. However, reading my posts here - it appears that editing IDL will not work. I have been suggesting editing C files that are generated from the IDL. I'm sorry, but I can not help you further.

@MackeyK24
Copy link
Contributor

Hey guys... I tried every thing listed above...

tried both 10 and 20 (make.py)

  emcc_args += '-s RESERVED_FUNCTION_POINTERS=10'.split(' ')

But i have NO Ammo.addFunction and/or NO Ammo.Runtime.addFunction

Anybody know what gives ???

@modstorm
Copy link

modstorm commented May 20, 2019

Do you have this arg included, it fixed it for me?

-s EXPORTED_RUNTIME_METHODS=[\'addFunction\']

@MackeyK24
Copy link
Contributor

Thats weird... I could not get EXPORTED_RUNTIME_METHODS to work with Pointers_stringify

But luckily there is a EXTRA_EXPORTED_RUNTIME_METHODS that worked for me:

Update make.py

EMCC_ARGS:
emcc_args += '-s RESERVED_FUNCTION_POINTERS=20'.split(' ')
emcc_args += '-s EXTRA_EXPORTED_RUNTIME_METHODS=["addFunction"]'.split(' ')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants