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

helper tools #87

Open
bdanis opened this issue May 8, 2017 · 1 comment
Open

helper tools #87

bdanis opened this issue May 8, 2017 · 1 comment

Comments

@bdanis
Copy link

bdanis commented May 8, 2017

I've been trying to work with the helper tools, but found that they don't work as they come

I had to refactor the .allocate function to _malloc and change Box2D.SetValue to _memAlloc

But at the moment, I still can't create a polygon because I get an assertion error on PolygonShape.Set

I have tried placing my vertices clockwise and counterclockwise, both to no avail

Any ideas?

@alperencaliskan
Copy link
Contributor

With new emscripten builds helper code doesn't work because they removed allocate and setvalue functions. https://github.com/kripken/ammo.js/pull/121
I am using this modified code for creating polygons

function createPolygonShape(vertices) {
    var shape = new Box2D.b2PolygonShape();
    // var buffer = Box2D.allocate(vertices.length * 8, 'float', Box2D.ALLOC_STACK);
    var buffer = Box2D._malloc(vertices.length * 8);
    var offset = 0;
    for (var i = 0; i < vertices.length; i++) {
        // Box2D.setValue(buffer + (offset), vertices[i].get_x(), 'float'); // x
        Box2D.HEAPF32[buffer + offset >> 2] = vertices[i].get_x();
        // Box2D.setValue(buffer + (offset + 4), vertices[i].get_y(), 'float'); // y
        Box2D.HEAPF32[buffer + (offset + 4) >> 2] = vertices[i].get_y();
        offset += 8;
    }
    var ptr_wrapped = Box2D.wrapPointer(buffer, Box2D.b2Vec2);
    shape.Set(ptr_wrapped, vertices.length);
    return shape;
}

huy-nguyen added a commit to huy-nguyen/box2d.js that referenced this issue Apr 18, 2020
kripken pushed a commit that referenced this issue Jun 1, 2020
Adapt the solution from #87 (comment) and fix script loading error to make the test bed work again.

Fixes #97.
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

2 participants