Building a Simple 3D Scene with Physics in JavaScript & Three.js

Поделиться
HTML-код
  • Опубликовано: 22 фев 2022
  • Quick and easy setup of a JavaScript 3d Physics Engine in three.js and ammo.js.
    Support me on:
    Patreon: / simondevyt
    Follow me on:
    Twitter: / iced_coffee_dev
    Instagram: / beer_and_code
    Github: github.com/simondevyoutube/
    In this project I'll show you how to use ammo.js and three.js to setup a simple 3d scene with phyics in just a few minutes. We'll step through the basics of how to instantiate your physics world, and what the various options are, which can server to add a whole new dimension of possibilities to your 3D scenes.
    What we'll cover:
    * Three.js and Ammo.js initialization, how to instantiate your 3d physics world
    * Creating rigid bodies and simple shapes such as boxes and spheres
    * Using MotionState to synchronize transforms between the physics world and 3d scene.
    There's a lot of options for JavaScript 3d engines, like Ammo.js, oimo.js. cannon.js, etc. They're all extremely capable physics engines, but we'll be focusing on one in particular, ammo.js which is a wrapper around the Bullet physics engine.
    Full source code for the project is available, so if you're interested in fiddling with the code, screwing around with it, or improving it.
  • НаукаНаука

Комментарии • 81

  • @simondev758
    @simondev758  2 года назад +2

    If you enjyoed this, check out my GLSL course: simondev.teachable.com/p/glsl-shaders-from-scratch
    Or support me on patreon!: www.patreon.com/simondevyt

  • @SuboptimalEng
    @SuboptimalEng 2 года назад +20

    I just started a project with Three.js physics today - this could not have popped up on my recommendations at a better time. Thanks Simon!

  • @SweeperFlies
    @SweeperFlies 5 месяцев назад +1

    Newcomer to Three.js here. Very cool to see you building the solar system this way! Thank you for sharing this

  • @SaajidAkram
    @SaajidAkram 2 года назад +3

    You're content is exceptionally entertaining and educating ... Thanks Simon. I am looking forward for your next video.

  • @panmateusz
    @panmateusz 2 года назад +14

    That would be super cool if you could do a video explaining web assembly.

  • @aj35lightning
    @aj35lightning 2 года назад +1

    Glad to see you back!

  • @MYMPSWORLD
    @MYMPSWORLD 2 года назад +2

    Another great video after a long time. I missed these 👍

  •  2 года назад +2

    Glad to have you back, Simon. 😊

  • @napapt
    @napapt 2 года назад +1

    I love your tutorials, it has such good content quality, it's unbelievable it's for free... I thank you for the entire community of developers that like me are being inspired by you! please never stop this I'll to spread the word about this channel!

  • @Rssks
    @Rssks 2 года назад +1

    Very neat Simon!

  • @manuelgamez8074
    @manuelgamez8074 2 года назад +5

    I've used ammojs in a project a while ago, not remember precisely what made it really hard to setup (guess the integration with webassembly), but now I use cannon.js and let me tell you it works like a charm and it's really easy to setup and work with. Anyways, thanks for all these great videos!

    • @simondev758
      @simondev758  2 года назад

      I haven't tried it, but it looks great. For a while it was unmaintained, which was a negative but it looks like it's been picked up again. I'll try it out :)

    • @D3NM0NT3UR
      @D3NM0NT3UR 2 года назад

      @Manuel, aside from the easy-to-use; which one has more stability and bdtrer performance? I'm genuinely curious

    • @manuelgamez8074
      @manuelgamez8074 2 года назад

      @@D3NM0NT3UR Sincerely I have no opinion rather than the developer experience I had. Maybe ammojs is more performant cause the integration with webassembly (but that is just an assumption). If helpful, in a scene with cannonjs I had 300+ sphere collisions and worked just fine.

  • @NorwegianAids
    @NorwegianAids 2 года назад +2

    We need a interactive adventure game where you are the narrative voice.. guiding us to victory!!

  • @kanpekiken2481
    @kanpekiken2481 2 года назад +1

    Just when I thought he was gone for good, he comes back with something I was looking for!!!!

  • @dev_ression
    @dev_ression 2 года назад +1

    great explanation bro, love the vid

  • @koki10190
    @koki10190 Год назад +1

    this video helped me add Bullet Physics to my C++ Game Engine project
    Thank you for this video

  • @rickharold7884
    @rickharold7884 2 года назад +1

    That rocks! Love it

  • @tomm.4447
    @tomm.4447 2 года назад +3

    MY BOY BE POSTIN AGAIN
    Missed your content man, great to see you uploading more stuff

    • @simondev758
      @simondev758  2 года назад

      Trying :) Life/pandemic has been really getting in the way.

    • @tomm.4447
      @tomm.4447 2 года назад +1

      Also, I think I requested an Ammo.js tutorial amongst others. Really glad you're so open about suggestions and requests

    • @simondev758
      @simondev758  2 года назад

      @@tomm.4447 Always open to suggestions, can't guarantee I'll do them but every suggestion goes on my list :)

  • @shujaa
    @shujaa 2 года назад +6

    This tutorials are golden😍 I wonder how great it would be to see a legend like you recreating some simple games made in other game engines with three.js like subway surfers or creating a course I would buy one without a second thought.

    • @shujaa
      @shujaa 2 года назад +1

      or a tutorial on reusable game components or design patterns for game programming in JavaScript.

    • @shujaa
      @shujaa 2 года назад +1

      ooh man you literally blow my mind every time do you have a discord channel or smthn?

    • @simondev758
      @simondev758  2 года назад +1

      These are great ideas, wrote them down. Nah no discord, have a twitter account if you wanna reach me there

  • @claybowser
    @claybowser 2 года назад +1

    i love your videos so much thank you

  • @creativeprismstudio1003
    @creativeprismstudio1003 2 года назад +2

    "Code will always make things clear." XD

  • @kephas-media
    @kephas-media 2 года назад +1

    He's back gents lolololol, let's go!!!!

  • @Gamewithstyle
    @Gamewithstyle 2 года назад +1

    Wake up, SimonDev posted!

  • @dominicforster706
    @dominicforster706 2 года назад +2

    when tmpTransform_ appeared in the step_ function I could no longer follow, but I like to see you do physics now. Maybe there will be a RigidBody Component someday :)

  • @user-hd3pz2ow1b
    @user-hd3pz2ow1b 3 месяца назад +1

    nice

  • @creaky2436
    @creaky2436 2 года назад +3

    Nice! I have used cannon but not ammo.

  • @pavelschannel-alittleoutof3532
    @pavelschannel-alittleoutof3532 2 года назад +4

    At last, clean code. Most of the links I have found just throw the code together in a most messy and disorganised manner and I hope for the sake of humanity that these people are never accepted as true developers or programmers. Thank you.

  • @amisner2k
    @amisner2k 2 года назад +1

    You put an underscore at the _end_ of your private member names!? ARE YOU OUT OF YOUR MIND!!? lol
    You mad lad, you. I approve. 👍

    • @simondev758
      @simondev758  2 года назад +1

      I like to live dangerously

  • @MarvinDrude
    @MarvinDrude Год назад +2

    Can you make a small tutorial where u create a networked version of this with client side prediction and stuff?

  • @kanpekiken2481
    @kanpekiken2481 Год назад +1

    Hi Simon, picked a random video but my game is finally coming along using all the skills I’ve learned from your videos. Was wondering if you’d be interested in seeing it :)

  • @mehmetfurkandogan9057
    @mehmetfurkandogan9057 2 года назад +1

    ammo.js seems good

  • @elnur0047
    @elnur0047 2 года назад +9

    I am big fan of your work sir, what do you think about creating RTS game with a WebRTC p2p lock-step networking? I believe it's one of the hardest genre to make it work on a browser, so it might provide a very interesting content, I wanted to create it myself but no idea where and how to start as a Threejs game dev guides are very limited to say the least. would appreciate some tips as well.

    • @simondev758
      @simondev758  2 года назад +2

      Very cool idea, wrote it down

  • @ColinRichardson
    @ColinRichardson 9 месяцев назад

    I am planning on doing rocks and sand... would this library be a good place to start? the rocks it seems like it would be good, but sand? soil? mud?

  • @orionnft5960
    @orionnft5960 2 года назад

    Hello simon!!! When I'm trying to deploy my repository github with netlify I have code:2 doesn't matter what kind of project... can you make a video one day about deploy the web... your job is awesome and very easy understand!! 👏🙌

  • @lycan2494
    @lycan2494 2 года назад

    What are the requirements/recommendations to actually follow this project video

  • @williamjuicebutter6648
    @williamjuicebutter6648 2 года назад +2

    Use react-three-fiber

  • @hey476
    @hey476 2 года назад +3

    Can you make a three.js cave generation tutorial ? I am looking for it for a long time but i can't make it.

    • @manuelgamez8074
      @manuelgamez8074 2 года назад +4

      Maybe try looking up Marching Cubes. There is a great video from Sebastian Lague which explains it greatly.

    • @hey476
      @hey476 2 года назад

      @@manuelgamez8074 Actually i did found this video but i don't understand 😂

  • @mdsalahuddin2841
    @mdsalahuddin2841 2 года назад +2

    How is the idea of using Svelte for reactivity and less codeing lines?

    • @simondev758
      @simondev758  2 года назад

      Could be interesting

    • @manuelgamez8074
      @manuelgamez8074 2 года назад

      Do you mean svelte for UI or for 3D development with three js? Personally I use svelte without even doubting when I have to include small UI components to my threejs apps because they works great with OOP structures and has lightweight bundle sizes. For the 3D, there is a project called svelthree which is like react three fiber but with svelte. Haven't checked it out yet but seems great if you are into functional programming (not my case but still interesting)
      Hope I answered!

    • @mdsalahuddin2841
      @mdsalahuddin2841 2 года назад

      @@manuelgamez8074 I meant for 3D development using library like three.js with Svelte

  • @leshiq4214
    @leshiq4214 2 года назад +1

    Could you please try and move some of your game examples to React Native for Windows?

    • @simondev758
      @simondev758  2 года назад

      Yep those are on my list and I'm trying to get to that :)

  • @dizzybeepot9856
    @dizzybeepot9856 Год назад +1

    Would you be willling to upload the code for this 🥺.

  • @arturniko4293
    @arturniko4293 Год назад

    where does this.tmpTransform_ come from at 6:20 ?

  • @dhruvalraval8078
    @dhruvalraval8078 2 года назад +1

    How can i add gltf model as a rigid body?

  • @kalutstyle2256
    @kalutstyle2256 2 года назад

    Why do you prefer ThreeJS than BabylonJS ?

    • @simondev758
      @simondev758  2 года назад

      I don't, just haven't tried BabylonJS. It's eternally on my TODO list.

  • @ViciousViscount
    @ViciousViscount 2 года назад +1

    Anticlimactic boxes that don't fall down to the ground are the worst.

  • @cylam9188
    @cylam9188 2 года назад +1

    make a game,plz

  • @zigglyDev
    @zigglyDev 2 года назад +2

    Bro you are getting old. 😀 👍

  • @31redorange08
    @31redorange08 2 года назад

    Something's broken in your set-up. Your fields end in an underscore.

  • @0GRANATE0
    @0GRANATE0 Год назад

    Is Ammo.js better in performance than Cannon.js or Rapier.js? @SimonDev your 12cents on this?

    • @simondev758
      @simondev758  Год назад

      No idea, haven't tested. Pretty sure ammo.js is emscripten of the C++ version, whereas cannon is pure JS? No idea about rapier, if I had to guess between the 3, based on this and nothing else, I'd guess that ammo is the most performant.