LogicalError / realtime-CSG-for-unity

Realtime-CSG, CSG level editor for Unity
https://realtimecsg.com
MIT License
761 stars 80 forks source link

Incorrect width and height when generating boxes of smaller sizes #295

Closed ezdotjs closed 2 years ago

ezdotjs commented 5 years ago

When using grid snapping to create boxes, the smaller the grid division the more innacurate the dimensions.

Sizes are perfect for 1, 0.5 and 0.25, but are incorrect when lower, e.g: 0.0625 becomes a height of 0.061999 and width of 0.063.

Using version 1.556 on Unity 2017.4.28f

image

ezdotjs commented 5 years ago

Also tested with unity 2018.4.3f1 using asset store version of plugin, and the same issue occurs

LogicalError commented 4 years ago

Sorry, this is due to hardware limitations. It's not possible to have infinite precision in a finite amount of bits, so inaccuracies will unavoidably creep in :-/

ezdotjs commented 4 years ago

Rather than having the length divide every time, therefore hitting the issue of floating point precision, would it be possible to have preconfigured amounts instead? e.g:

1/2: 0.5 1/4: 0.25 1/8: 0.125 1/16: 0.0625 ...

Or does the issue not lie in the division, but the way Unity handles its units?

ezdotjs commented 4 years ago

Having delved into the code, I can see that this thinking was a little naive of me - it has nothing to do with the halving of the float when pressing + and -, but to do with the mesh generation itself.

@LogicalError I wanted to add something that would do the following:

Could you point me in the right direction to where I might start?