fenomas / noa

Experimental voxel game engine.
MIT License
612 stars 87 forks source link

Mesh billboard mode not working #48

Closed haitaoli closed 6 years ago

haitaoli commented 6 years ago

The old version of the engine supported billboardMode. But it's broken in recent versions, as shown in . http://andyhall.github.io/noa-lt/ demo app.

terrac commented 6 years ago

I can see the billboard mode just fine as far as I can tell. Maybe it is an issue with the version of babylon js and the browser ?

haitaoli commented 6 years ago

I should have attached screenshots earlier. Here the "Old" screenshot is taken from https://andyhall.github.io/noa-testbed/ which is using the version of the engine from two years ago. When you move around the flower, you can see it's always facing the camera. "New" is from http://andyhall.github.io/noa-lt/ which is using a more recent version of the engine, you can the "edge" of the texture.

Old New
screen shot 2018-04-06 at 9 02 47 am screen shot 2018-04-06 at 9 04 20 am
fenomas commented 6 years ago

Hi, if you look closely the updated version isn't a billboard mesh at all. See here (the comment is wrong!).

I replaced it when I did some optimization for static object meshes.

haitaoli commented 6 years ago

Thanks for the reply! Is billboard mode supposed to work, or totally removed? I tried adding this code to makeFlowerSpriteMesh but it has no effect:

mesh.billboardMode = BABYLON.Mesh.BILLBOARDMODE_Y
fenomas commented 6 years ago

Hi, I'm not sure about the state of billboard mode in Babylon generally. I assume it still works but there were some changes last year or so, so old code may need to be tweaked to work in current BJS.

However for noa specifically, in version 0.22 I changed the way terrain object meshes work. When you define a terrain block with an object mesh (like the flowers in this demo), noa assumes the mesh is static, and when it builds the chunk it merges all the object meshes (to improve performance). That is, in the demo you're looking at, all those flowers are merged into one big mesh (per-chunk), so they can't individually rotate like billboards.

If you want to have non-static meshes for your terrain, you can add them manually with block events. That is, register the "flower" terrain block with noa as having no mesh, but use the block events to create/destroy any custom mesh whenever a block with that ID is added or removed from the scene.

PS: remember to call noa.rendering.addMeshToScene when adding your own meshes - it's annoying, but this lets noa use octrees when rendering, which generally improves performance a lot.