0

Im trying to create a cube world game. So there is 3d array of blocks, and each of them is an array of mesh (for now the mesh array is actually a single mesh, cube). It works, but when I use a big amount of blocks (50x1x50 is enough) the fps drops very low (something like 3).

I use clone() function when I use a block more than once, but its not enough. The geometry of the meshes is BoxBufferGeometry. I also tried to use the same geometry and texture(instead of using clone) but it didn't get better.

So, How can I increase the fps? what magic do similar games do?

1 Answers1

2

You can look into instancing: https://codepen.io/ykob/pen/xqvXex

Or you can use the .merge method on your geometries to merge them into a single geometry, and render one mesh per region.

someFakeCodeSoSOWillLetMePost();
manthrax
  • 4,918
  • 1
  • 17
  • 16
  • May I suggest adding some of the logic from the codepen into the answer instead of this fake function? – Neil Oct 15 '19 at 12:13
  • 1
    Like.. seriously.. it would be one persons work to eliminate this as a friction point across all SO, but instead SO tries to guilt unpaid volunteers into fixing a redundancy issue. It's disgusting. Thanks for the suggestion though @Neil :) – manthrax Oct 15 '19 at 17:47
  • @manthrax I created a short code based on it, and it mainly works greate (something like ~40 fps), but not always. There is a huge heap of blocks, and a viewer. If the viewer looks at the general direction of the first block, the fps drops to ~10, but if he is look to anywhere else the fps is ~40. This is strange because he is at the center above the heap, so the view looks the same. What can cause it? The example is here - bipolo.rf.gd/meow.html. – Bipolo TheGod Oct 16 '19 at 10:45
  • Your app would only render a single frame for me.. maybe you have changed it in the mean time.. .but looking at your fragment shader logic with the array lookup.. looks suspicious to me.. it wouldn't surprise me if that shader is whats causing your slowdown. If you want to chat about it further, join me in slack... I am thrax: https://join.slack.com/t/threejs/shared_invite/enQtMzYxMzczODM2OTgxLTQ1YmY4YTQxOTFjNDAzYmQ4NjU2YzRhNzliY2RiNDEyYjU2MjhhODgyYWQ5Y2MyZTU3MWNkOGVmOGRhOTQzYTk – manthrax Oct 16 '19 at 18:06
  • 2
    @Neil: Not to mention the ethical and legal implications of taking code from one platform and copying it to SO which then applies some version of GPL to it. This is really something SO needs to fix, and stop shoving the responsibility onto unpaid volunteers. – manthrax Oct 16 '19 at 18:09
  • @manthrax - you have some valid points there, hopefully the SO gurus will look into this problem Karma +1 to you! – Neil Oct 17 '19 at 10:09