David Williams wrote:
Hi,
You also mention porting the code to C# (i.e. going through and converting it?). I think you will find this very difficult - PolyVox makes heavy use of templates which C# doesn't support (at least not in the way that C++ does) and it also does alot of memory management which may be hard to reproduce in C#.
That confirms what I thought from browsing through the source. However the problem with C++ libraries from Unity is multiplatform integration, and the fact that they are completely disabled in the webplayer for security reasons.
If I could get only the bare geometry processing through that would suit my needs, since Unity already takes care of rendering/etc. I also have the C# logic to process normals and tangents from raw triangles. So ideally I would need a script to which I input a list of triangles and/or a voxel field then get a list of triangles as an output. That's my last stumbling block.
David Williams wrote:
If you can't get PolyVox working and you want a real Unity solution then I have seen some relevant stuff in passing:
http://www.unifycommunity.com/wiki/index.php?title=MetaBallshttp://forum.unity3d.com/threads/63149-After-playing-minecraft...?p=404126&viewfull=1#post404126There was also an external project to add voxel terrain support to Unity but I can't find it now.
Thanks. I am actually moving here after trying to tweak the Unity metaballs script to no avail.
The solution is probably in my face but I'm not really an expert with marching cubes. The only relevant calculation I could figure out in that script is an equation that calculates blobs
and the exponential increase from mutual proximity to the entire list of blobs all in one... something which I wasn't able to take apart successfully.
Code:
/*Calculate the power of a point only if it hasn't been calculated already for this frame*/
public float i()
{
float pwr;
if(cntr<mcblob.pctr) {
cntr=mcblob.pctr;
pwr=0f;
for(int jc=0;jc<this.mcblob.blobs.Length;jc++) {
float[] pb=this.mcblob.blobs[jc];
pwr+=(1.0f/Mathf.Sqrt(((pb[0]-this.x)*(pb[0]-this.x))+((pb[1]-this.y)*(pb[1]-this.y))+((pb[2]-this.z)*(pb[2]-this.z))))*pb[3];
}
this._i=pwr;
}
return this._i;
}
My next attempt will be to process only the 26 possible adjacent blobs for this calculation. We'll see how that goes. But I'm getting the intuition this isn't the right approach to a voxel field (hence my presence here).
My thread on the Unity forums is located here:
http://forum.unity3d.com/threads/67194-WIP-Dynamic-Terrain-Shaders