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


All times are UTC




Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: PolyVox and Unity3D
PostPosted: Mon Nov 18, 2013 3:17 pm 

Joined: Mon Nov 18, 2013 3:06 pm
Posts: 8
Ok so after looking at Cubiquity I feel that PolyVox is the way to go for a voxel terrain engine in Unity3D. Cubiquity is looking great but with out details on pricing and the fact that I have barely any budget for my Indie Titles I can't commit to using it and then find the pricing is way too high.

So I downloaded the Source Code for PolyVox, built it, and built the C# bindings. I have everything working great for simple terrains. I'm now trying to add in the ability to add and remove voxels. By pressing 1 I have it so it should be adding a Voxel and pressing 2 should remove a voxel.

Code:
if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            int x = (int)_player.position.x;
            int y = (int)_player.position.y;
            int z = (int)_player.position.z;

            Debug.Log("Player Location: X: " + x.ToString() + " Y: " + y.ToString() + " Z: " + z.ToString());

            volData.setVoxel(x+1, y+1, z+1, 255);


I'm guessing I would then need to rebuild the voxel data and then rebuild the mesh which I do however it never actually adds the voxel. Is there any Documentation available on this subject?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Mon Nov 18, 2013 3:23 pm 

Joined: Mon Nov 18, 2013 3:06 pm
Posts: 8
lol Ok never mind. As I was typing this I thought of something else I could try and sure enough that was the key... I had to null out the sharedmesh of the meshfilter and add the mesh again.

GetComponent<MeshFilter>().sharedMesh = null;
GetComponent<MeshFilter>().sharedMesh = _mesh;


Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Mon Nov 18, 2013 3:56 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
GM_JamesP wrote:
As I was typing this I thought of something else I could try and sure enough that was the key...


Yep, I've been there ;-)

As for Cubiquity be sure to check out this recent blog post on licensing: http://www.volumesoffun.com/new-license-for-cubiquity/

Right at the bottom it mentions $200 for a per-seat Cubiquity license, though I'm afraid it's not set in stone yet. You're welcome to work with PolyVox instead of course, though I know for experience that you are in for some work ;-)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Mon Nov 18, 2013 6:45 pm 

Joined: Mon Nov 18, 2013 3:06 pm
Posts: 8
Thanks for the response.

Just some questions about the PolyVox C# bindings... Do we have access to the Large Volume or is the smaller simple Volume the only one we have access to?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Mon Nov 18, 2013 8:14 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Actually I don't really remember... we're not actually using the C# bindings for Cubiquity as it provides a C interface which we call directly. But I think the LargeVolume might not be supported because there's no easy way to provide from C# the callback which is needed in order to page or compress data.

You may find you can adjust the LargeVolume code and/or SWIG scripts such that it automatically uses PolyVox's MinizBlockCompressor and FilePager, thereby avoiding the need to set these from C#.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Mon Nov 18, 2013 8:49 pm 

Joined: Mon Nov 18, 2013 3:06 pm
Posts: 8
Ok.

On the SimpleVolume what is the largest area it supports and does the lower bound always have to be 0,0,0? I try setting the height value to a negative and it crashes. I try paging it using multiple Simple Volumes so I set the lower bounds and upper bounds like this:

Code:
Region(new Vector3Dint32_t(PageSize * x, 0, PageSize * y), new Vector3Dint32_t(PageSize * x + PageSize, 600, PageSize * y + PageSize))


which again crashes Unity.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Tue Nov 19, 2013 5:42 am 

Joined: Mon Nov 18, 2013 3:06 pm
Posts: 8
I've made progress in paging however I currently have it disabled while I start work on tools to improve the user friendliness of Building.

I have a line tool which allows you to construct a line of Voxels going in any axis. I have controls which increases and decreases the scale of the tool which determines how many voxels will be added. After creating the Line tool I realized that that was pretty much the only thing I needed to have in order to build things.

I still need to work on texturing but here's a Screenshot of me testing things out and building. I took like 5 minutes here to build a little structure. Really have no idea what it is... lol


Attachments:
VoxelConstruction.jpg
VoxelConstruction.jpg [ 181.74 KiB | Viewed 5238 times ]
Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Tue Nov 19, 2013 3:38 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Great work, it's good to see you got something working already. However, you need to be careful about attempting to use the SimpleVolume to implement your own paging system - this is not recommended because the surface extractors only process a single volume at a time, and you will get seams on the volume boundaries. Have a read of this: http://www.volumesoffun.com/polyvox/doc ... aller-ones

To avoid this you will probably want to get the LargeVolume working with C# eventually, and this might mean modifying your local copy such that the callbacks are hard-coded and you don't need to set them up from C#.

GM_JamesP wrote:
On the SimpleVolume what is the largest area it supports and does the lower bound always have to be 0,0,0?


There is no particualr maximum (it is just memory depenant) and should not need to start at the origin.

GM_JamesP wrote:
I try setting the height value to a negative and it crashes.


You don't set a height value as such, you set the upper and lower bounds. These can be positive or negative but the upper must always be greater than the lower.

Tracking down crashes from Unity (or probably from C# in general) can be tricky. You might want a separate simple test application for this kind of stuff. When you say crash it is probably actually a POLYVOX_ASSERT(), so be aware that the develop version of PolyVox has some logging functionality available which might help here. Have a look at the code to see. But if you can step into the code then this is by far the easiest way to debug.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Tue Nov 19, 2013 3:46 pm 

Joined: Mon Nov 18, 2013 3:06 pm
Posts: 8
Do we have access to the version of PolyVox that Cubiquity uses? If so would that version have better C# support then the C# bindings?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: PolyVox and Unity3D
PostPosted: Wed Nov 20, 2013 9:26 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Yes, the version of PolyVox which Cubiquity uses is here. The main change is to the format of the vertices, which unfortunately is enough the break the tests and examples as these have not been updated. It may also break the SWIG bindings but I haven't tested these. Overall you are best of sticking with the develop version.

The state of the SWIG bindings probably can be improved, and there might be a way to expose the callbacks for the LargeVolume. I don't think we've looked into it much. But wrapping a heavily-templatized library like PolyVox is a difficult problem, and I think SWIG actually does a pretty amazing job.

You could also do what Cubiquity does - i.e create a C++ library which makes use of PolyVox internally but exposes just a C API. then you can call it from any language quite easily.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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