It is currently Sat Aug 22, 2020 4:15 am


All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Porting PolyVox to the Unity engine
PostPosted: Sat Feb 26, 2011 9:39 pm 

Joined: Wed Feb 23, 2011 5:49 pm
Posts: 4
I am currently trying to figure out how to port PolyVox to the Unity game engine.

My main goal is to port its adaptive geometry features for terrain and to combine meshes. If that works well, I might push further into the realm of game-time terrain changes.

So I compiled the sources with cmake and brought them into VS, but from there I need to either translate them to C#, either compile them as a dll for use with Unity. Before I go any further, I'd like to know if anyone here ported Polyvox to other engines, or as a dll, and if so, how did you do it/were there any issues to be aware of?

Best regards.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Porting PolyVox to the Unity engine
PostPosted: Sun Feb 27, 2011 11:08 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Hi,

I have no experience with Unity but I'll do my best to help. It might be worth posting this question in the Unity forums, because using PolyVox from Unity is probably much like using any other C++ library fom Unity so they may have more insight. If you do post in their forums, you can post the link to the topic here so I can watch it and jump in if relevant.

If you do need to have C# bindings to the library then actually there has already been some work here. See the last couple of pges of this thread:

http://www.thermite3d.org/phpBB3/viewtopic.php?f=2&t=118

You'll probably need some programming skills (C++/C#/SWIG) to get them working but in priciple there is a starting point.

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

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=MetaBalls
http://forum.unity3d.com/threads/63149-After-playing-minecraft...?p=404126&viewfull=1#post404126

There was also an external project to add voxel terrain support to Unity but I can't find it now.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Porting PolyVox to the Unity engine
PostPosted: Sun Feb 27, 2011 2:30 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Oh, I remembered the name of the external voxel terrain project for Unity. It's the Unity Terrain Tools


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Porting PolyVox to the Unity engine
PostPosted: Sun Feb 27, 2011 3:29 pm 

Joined: Wed Feb 23, 2011 5:49 pm
Posts: 4
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=MetaBalls
http://forum.unity3d.com/threads/63149-After-playing-minecraft...?p=404126&viewfull=1#post404126

There 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


Last edited by BrokenToyGames on Sun Feb 27, 2011 4:29 pm, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Porting PolyVox to the Unity engine
PostPosted: Sun Feb 27, 2011 3:52 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
BrokenToyGames wrote:
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.


Yeah, that's what I had imagined.

BrokenToyGames wrote:
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).


I can't really help you sort through that code - you're probably best off contacting the author. However, if you look in the code comments at the start you can see he used this article for reference: http://local.wasp.uwa.edu.au/~pbourke/g ... olygonise/

Might be a good place to start if you want to understand it better.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Porting PolyVox to the Unity engine
PostPosted: Sun Feb 27, 2011 10:24 pm 

Joined: Wed Feb 23, 2011 5:49 pm
Posts: 4
Thanks a lot for your help, I'll look further into this.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net