I'm making a unity3d game which requires using a voxel engine to build structures, except I plan to include more models than just simple cubes, and some of these are quite small. So I need the voxels to be smaller than 1 unity unit each (3 per unit). The problem is I'm having trouble converting between world space and voxel coordinates due to the unequal sizes (if they were the same size it wouldn't be a problem). This is what I've tried so far:
public Vector3 GetIndexFromWorld(Vector3 worldPos, Vector3 normals) {
float half = ((1f / (float)VoxelsPerMeter) / 2f); // VoxelsPerMeter equals 3
Vector3 point = worldPos + normals * -half;
return new Vector3(Mathf.RoundToInt(point.x) * VoxelsPerMeter, Mathf.RoundToInt(point.y) * VoxelsPerMeter, Mathf.RoundToInt(point.z) * VoxelsPerMeter);
}
Thanks in advance for any help.