Rich-Harris / svelte-cubed

Svelte ❤️ Three
svelte-cubed.vercel.app
MIT License
1.19k stars 76 forks source link

Physics engine? #39

Closed brianorwhatever closed 2 years ago

brianorwhatever commented 2 years ago

How would one extend this library to include a physics engine such as cannon?

I found this https://sbcode.net/threejs/physics-cannonjs tutorial but it requires access to the scene so I'm not sure how to use it with the component approach.

Myrmod commented 2 years ago

Currently I don't think it is easily possible to add a physics eninge to the project. You can only overwrite SC.Canvas.

In the future I myself would like to have one integrated and easily usable. For performance reasons I would suggest some library that uses webassembly like rapier.

On SC.Canvas you could simply add physics={true} and it should work with realistic default settings. That would be awesome.

Myrmod commented 2 years ago

I found the way you can access the scene and a lot of other objects. Though I don't really understand how this works.

    import { setup } from '../../utils/context.js';
    const { root } = setup(); // here we have scene inside
bfanger commented 2 years ago

I've created svelte-cannon. It's a declarative approach to setting up a cannon-es physics simulation using Svelte components.

It's designed with svelte-cubed in mind as renderer, check out this REPL or the Examples see it in action.

brianorwhatever commented 2 years ago

Awesome, thank you @bfanger. I will take a look at svelte-cannon when I get a free moment. Closing this issue now, thanks for your work.