ammo.js icon indicating copy to clipboard operation
ammo.js copied to clipboard

btSoftBody constructor cannot be passed an array

Open kchodorow opened this issue 7 years ago • 3 comments

I have manually created an array of btVector3's:

var vertices = [];
for (var i = 0; i < 10; i++) {
  vertices.push(new Ammo.btVector3(i, i, 0);
}

var softBody = new Ammo.btSoftBody(worldInfo, 10, vertices, 0);

If you then examine softBody.get_m_nodes().at(anything), its coordinates are (0,0,0).

This seems to be because the function's .idl describes it as a btVector3* (void btSoftBody(btSoftBodyWorldInfo worldInfo, long node_count, btVector3 x, float[] m)), so it tries to take a ptr:

function btSoftBody(arg0, arg1, arg2, arg3) {
        ensureCache.prepare();
        if (arg0 && typeof arg0 === "object")
            arg0 = arg0.ptr;
        if (arg1 && typeof arg1 === "object")
            arg1 = arg1.ptr;
        if (arg2 && typeof arg2 === "object") // <--- typeof [] is "object", but Array has no ptr field!
            arg2 = arg2.ptr; // <-- now arg2 is undefined
        if (typeof arg3 == "object") {
            arg3 = ensureFloat32(arg3)
        }
        this.ptr = _emscripten_bind_btSoftBody_btSoftBody_4(arg0, arg1, arg2, arg3);
        getCache(btSoftBody)[this.ptr] = this
    }

I couldn't figure if there was a way to indicate "an array of btVector3 values" (the way float[] m is described). The ammo.idl language doesn't seem sufficiently nuanced to express this, but I'm not too familiar with it.

kchodorow avatar Dec 23 '16 17:12 kchodorow

Yes, it looks like this is not properly handled. The one usage of this, in examples/webgl_demo_softbody_volume2/index.html, appears to work around it by passing in one vertex and then appending more.

WebIDL does have vector support, so perhaps this could work: void btSoftBody(btSoftBodyWorldInfo worldInfo, long node_count, btVector3[] x, float[] m); (adding [] to that param). But I'm not sure if it would work, as I don't see a test of it in emscripten (I see just tests of basic types like float[], but not a wrapped type). It's probably not too hard to add, though, if it doesn't just work.

kripken avatar Dec 23 '16 18:12 kripken

btVector3[] x doesn't work, unfortunately, since btVector3 is already assumed to already be a pointer, so btVector3[] is mapped to btVector3**, which doesn't match any constructor. I tried something like [Value] btVector3[] x, but emscripten had no idea what I was talking about.

kchodorow avatar Dec 23 '16 19:12 kchodorow

does it support char[] as function argument?

navigator117 avatar Jan 08 '19 08:01 navigator117