fenomas / noa

Experimental voxel game engine.
MIT License
615 stars 88 forks source link

Terrain remeshing bug when block is neither solid nor opaque #180

Closed MCArth closed 2 years ago

MCArth commented 2 years ago

Hi, I've encountered an issue when changing a chunk's block state (via setBlock) from a water block (neither solid nor opaque) to an air block (0)

The problem seems to be caused by this logic:

    if (solidityChanged || opacityChanged
        || (!objNew && (newID !== 0))) this._terrainDirty = true

https://github.com/fenomas/noa/blob/d9fe5d1549bc4596c5756fdcac852c9b07e535f0/src/lib/chunk.js#L156

I've changed it to this:

    if (!objOld || !objNew) this._terrainDirty = true

as it seems to me the terrain has to be remeshed if a terrain id has changed, no matter what

It seems to work but maybe I'm missing something?

fenomas commented 2 years ago

Hi, nice catch. The intent there was that remeshing isn't needed when a non-solid non-opaque object block changes into air, but I was only checking if the new block is terrain, and not the old.

I will replace it with something like:

    var wasTerrain = (!objOld && (oldID !== 0))
    var nowTerrain = (!objNew && (newID !== 0))
    if (solidityChanged || opacityChanged || wasTerrain || nowTerrain) {
        this._terrainDirty = true
    }
MCArth commented 2 years ago

ah yes, I don't have any opaque objects but that does make sense - looks good

fenomas commented 2 years ago

Ok thanks! This is done and I'll push it soon.