Cadiboo / NoCubes

A mod for 1.12.2+ that creates smooth terrain in Minecraft
https://Cadiboo.github.io/projects/nocubes/
GNU Lesser General Public License v3.0
140 stars 12 forks source link

[extremely minor] Unnecessary addition in SurfaceNets #77

Closed Jarred-Sumner closed 3 years ago

Jarred-Sumner commented 3 years ago

I was looking at your SurfaceNets implementation as an example implementation in use that works, and noticed you're adding 0 here: https://github.com/Cadiboo/NoCubes/blob/95c67559fc22169d1bccf0ba843b02932c9016f3/src/main/java/io/github/cadiboo/nocubes/mesh/SurfaceNets.java#L217-L219

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)

Cadiboo commented 3 years ago

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).

Cadiboo commented 3 years ago

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

Cadiboo commented 3 years ago

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