PorlyBe Posted September 16, 2017 Share Posted September 16, 2017 Hi all, first post here. I'm new to babylon (and JavaScript generally). I've been playing around with physics in babylon and came up with this... my virtual money box https://www.babylonjs-playground.com/#BEFOO#201 My question is, what would you recommend to speed it up when there are lots of coins (cylinders) being created. Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 18, 2017 Share Posted September 18, 2017 Hello @PorlyBe, welcome to the forum. Physics is fun! for someone being new to babylon and javascript, you did very well creating your first playground A few notes that might get move you forward: 1) There is nothing you can do about the amount of impostors and their impact on performance. If you need ALL coins to always react correctly, they will all have to have their own impostors. 2) Try disposing unneeded impostors. Meaning - If you are 100% sure a coin will never be a part of the pile that needs to react to a new coin, dispose its impostor (and recreate it when needed). This will increase performance. I di it usually when an object is below a certain threshold (for example, if it falls into a pit or something) or when it is not visible to the user. Of course, you need to set your own rules. 3) Try using OimoJS instead - Oimo is wonderful when it comes to a greater number of objects. A simple example - https://www.babylonjs-playground.com/#P13KEN You will notice, that I changed your code a bit. First, I took setTimeout out. The reason for that is rather simple - setTimeout is not being "disposed" when you press run again. I guess you noticed your console is full of errors, and you didn't know why - this is because each time you press "run", the setTimeout function(s) of the last playground is still set and is still being executed. I used registerBeforeRender with a simple frame counter, but you can use whatever your heart desires. Second - I created a new impostor for each object and removed it from the cloning object. I don't see a reason doing that and then changing the mass. It is a change that is simple not needed. Create your impostor with the right mass at the right time. Hope this gets you started! Let me know if you have any other questions. Quote Link to comment Share on other sites More sharing options...
fenomas Posted September 18, 2017 Share Posted September 18, 2017 Main thing that jumps out at me is, Cannon's cylinder primitive isn't a mathematically exact cylinder - it creates an approximation out of subdivisions, and Babylon passes in 16 for the number of subdivisions (which is probably overkill for your case). So anyway each coin in the simulation is a convex polyhedron with like 64 faces (?), so that's why it gets so slow. If Oimo has precise cylinder primitives, using it instead should be way faster. You should probably also search for coins that are on the bottom of the pan, or under other coins, and change them to static if they're not moving. That wouldn't be exactly physically correct, but it would limit the number of collisions and make things scale much better. Quote Link to comment Share on other sites More sharing options...
Valik Posted September 25, 2017 Share Posted September 25, 2017 Opening this pg https://www.babylonjs-playground.com/#P13KEN i get a Syntax error and loading assets...please wait. What do i wrong, i get this often when i try to open pgs? Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 25, 2017 Share Posted September 25, 2017 Hi @Valik, it is working for me. Any error in the console? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 25, 2017 Share Posted September 25, 2017 Hello can you make sure to clean your cache. I have no error on this PG Which browser / OS are you using? Quote Link to comment Share on other sites More sharing options...
Valik Posted September 26, 2017 Share Posted September 26, 2017 win 10 home x64 - ie11 with the error. edit: opening the console is crashing the tab edge and ff working.. sorry for that Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.