NoCubes

NoCubes

829k Downloads

[extremely minor] Unnecessary addition in SurfaceNets

Jarred-Sumner opened this issue ยท 3 comments

commented

I was looking at your SurfaceNets implementation as an example implementation in use that works, and noticed you're adding 0 here:

v[0] = -0.5 + 0 + x + s * v[0];
v[1] = -0.5 + 0 + y + s * v[1];
v[2] = -0.5 + 0 + z + s * v[2];

I'm not super familiar with Java, but it's likely safe to remove that (assuming this isn't a way of doing type casting)

commented

It is safe to remove it.
It represents the "worldOffset".
However, I don't always use the world offset so if I do, I add it later on (before use of the vertex).

It's also there to remind me that the -0.5 shouldn't be there at all.
The equation should be simply v[0] = c + x + s * v[0]; (vertexPosition = positionOfChunkInWorld + positionOfCurrentBlockInChunk + interpolationMultiplier * vertexPositionInBlock).
Because my grid values are sampled at the centre of the block, but are recorded as the values at the corner of the block, I need to offset by +0.5 (I'm not 100% sure this is the reason, I'm guessing based on my limited knowledge of SurfaceNets).
Due to needing to generate the mesh for an extra block on all sides to resolve seams in the mesh, I need to subtract 1 from the mesh (turning +0.5 into -0.5).

commented

I've somehow accidentally deleted the credit header... that's bad.
I didn't write this code from scratch, I copied it from Mikola Lysenko's JavaScript code.
I've re-added them + the comments I also deleted

commented

I've documented everything and it seems to make sense (to me) so I'm closing this