SOLVED: My node that I was attaching the mesh to was offset by 20 units on the X plane - doh!
UPDATE: Looks like I found the problem thanks to David. I printed out what voxel was currently being hit and realized it's hitting voxels outside the mesh. I looked further into this and it looks as though the mesh is shifted about 20 voxels away from where the actual invisible voxels are. I'm not sure why or how this happened but I'll post a screenshot showing that voxels and mesh aren't matched up properly, but wrong only in one dimension ( x or z plane I think). So my guess is that somewhere in the voxel to mesh code, the mesh is shifted by 20 ogre units or so.
David Williams wrote:
Can you say how far inside it is? Perhaps print the start and end points? Is it just a few voxels inside or is it hundreds of voxels inside? I can see it's going in the right direction now but I'm concerned it might not be finding the solid voxels at all. Perhaps it's just stopping because it reached the end of the ray (which you set to have a length of 1000)?
It's really hard to answer this question because it varies all over the terrain. On some surfaces it's an accurate hit, on other surfaces it can range anywhere from 1- 10 voxels(an estimate) inside the surface. I'll try to print some numbers soon if you think it will help.
Quote:
If it is only going inside by a few voxels then the density values must be playing up somehow. What happens as you move towards and away from the surface? Does the amount of penetration change? We can try swapping the density volume for a material one but let's get confirmation of what is happening first.
I think there's definately something along these lines happening, but how voxels are being rendered properly but raycasts are screwy is where I'm confused. Towards and away from the surface makes no difference, so it's definately nothing to do with ray length, as the amount of penetration does not change.
Quote:
I'll try to elaborate on the precision issues here to give you a better understanding. The Raycast class considers each voxel to be a cube, in the same way as the CubicSurfaceExtractorWithNormals does. The position it returns is the first solid voxel which it encounters, where 'solid' is defined by it having a density greater than the threshold. This is always an integer position because voxels are only defined at integer positions.
I'm not really sure I have any kind of threshold with my code but maybe I do? I didn't have any range of density from what I know, just solid or empty.
Quote:
This should all be 100% accurate so far. But the point to realise is that this integer position corresponds to the center of one of the rendered cubes. Therefore, even though you have the exact correct position, it is still behind the surface. The center of the cube is always inside the cube, so the marker sphere has to be bigger than the cube in order to be seen.
As you can see from the pictures, my marker is about the width of 10 voxel cubes, so I don't think this is the problem.
Quote:
In other words, the raycast does not give you the position the ray intersects the mesh, it only gives you the position of the first solid voxel. This is where ker's code comes in (I believe, I haven't really studied it). Once the raycast has found the center of the cube, Ker's code backtracks a little to find where it actually penetrated the mesh. But you can't use this until you are hitting the correct cube center every time, and it will only work for the cubic mesh anyway.
I think ker's code hasn't made a difference because I'm somehow hitting the wrong cube in certain areas of the mesh - being off by 10 voxels instead of hitting the suface voxel
Quote:
All the above is with regard to the cubic mesh, and things are more complex with a smooth mesh so we'll come to that later.
I agree completely, I definately just want the cubicSurface working before moving on which is why I've got minimal code in place.