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

liquidfun's GetPositionBuffer() doesn't return a list #77

Open
8Observer8 opened this issue Jun 14, 2024 · 2 comments
Open

liquidfun's GetPositionBuffer() doesn't return a list #77

8Observer8 opened this issue Jun 14, 2024 · 2 comments

Comments

@8Observer8
Copy link

8Observer8 commented Jun 14, 2024

I try to use liquid fun. GetPositionBuffer doesn't return a list:

    const positions = particleSystem.GetPositionBuffer();
    console.log(positions[0]);

I prints undefined.

But it must return a list because C++ works like this:

    b2Vec2 *pos = m_particleSystem->GetPositionBuffer();
    qDebug() << pos[0].x  << pos[0].y;

Full example that includes the liquid fun lib library: get-position-buffer-box2dwasm-js.zip

index.js

import { box2d, initBox2D } from "./init-box2d.js";

async function init() {
    await initBox2D();

    const {
        b2CircleShape,
        b2ParticleGroupDef,
        b2ParticleSystemDef,
        b2Vec2,
        b2World
    } = box2d;

    const world = new b2World();
    const pixelsPerMeter = 50;

    const particleSystemDef = new b2ParticleSystemDef();
    particleSystemDef.radius = 5 / pixelsPerMeter;
    const particleSystem = world.CreateParticleSystem(particleSystemDef);
    const spawnArea = new b2CircleShape();
    spawnArea.m_radius = 20 / pixelsPerMeter;
    spawnArea.m_p.x = 100 / pixelsPerMeter;
    spawnArea.m_p.y = 30 / pixelsPerMeter;
    const particleGroupDefinition = new b2ParticleGroupDef();
    particleGroupDefinition.shape = spawnArea;
    particleSystem.CreateParticleGroup(particleGroupDefinition);

    const positions = particleSystem.GetPositionBuffer();
    console.log(positions[0].x);
}

init();

index.html

<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Liquid fun</title>
</head>

<body>
    <script type="importmap">
        {
            "imports": {
                "box2d-wasm": "/libs/[email protected]/es/entry.js"
            }
        }
    </script>

    <script type="module" src="./js/index.js"></script>
</body>

</html>
@8Observer8
Copy link
Author

And I have this messages: wasm streaming and falling back to ArrayBuffer when I run the example above:

image

@flygOn-LiTe
Copy link

I am having the same issue. The GetPositionBuffer method is returning a single object with x and y properties instead of a buffer. I can confirm all particles are there when debugging but cannot render the particles due to GetPositionBuffer not working as expected.

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