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


All times are UTC




Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 6:13 am 

Joined: Sat Jul 20, 2013 6:10 am
Posts: 9
I want to create a walkthrough on how to create C# Bindings and then use PolyVox in a SunBurn/XNA graphics engine to render.

I had a little bit of a head start by checking out "Painect" which is a Kinect driven demo that uses PolyVox to render voxel generated art from what I suspect.

Alas, the project is old and no longer functions with the latest Kinect SDK. I was able to compile and run the project, however, I was unable to get it working properly. Once i finally gave up on it after having updated all the Kinect code and still not getting results, I decided to take what I found from that project, including it's PolyVox C# library that they already had included. At first it seemed to work well enough, but then I started running across odd error when using the SetSphereAt(0,0,0,12) in an attempt to generate some voxel data to be drawn.

This produced an unusual error:

Unable to find an entry point named '?' in DLL 'PolyVoxCore'.

Which is odd, because of the entry point '?' part mostly... So I'm not sure if this library is any good. I dont want to start with a faulty library. So I decided to get started using the real source code. I have tried both 0.2.1 and the GIT version.

I cannot produce CSharp libraries from either. Both have the same problem from what i can see. First off, I am able to run cmake, detects everything, everything turned on. Great.

Open the PolyVox.sln and build all (release) and I get three errors on three test/example projects:

error C2064: term does not evaluate to a function taking 2 arguments
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xrefwrap

This occures in the following projects:
OpenGLExample
TestAStarPathfinder
testvolume

However, i'm sure these are of no consequence. So I unload these and build all again, and all build successfully.

Now, I go to the next, step, where is the CSharp code? Where are the bindings we build? So I check out the folder: C:\polyvox\library\bindings

There are 2 batch files:
CleanCSharpBindings.bat
MakeCSharpBindings.bat

So this seems easy! Great, I run the "MakeCSharpBindings.bat" and the following output occurs:

C:\polyvox\library\bindings>swig -csharp -namespace PolyVoxCore -c++ -I../PolyVoxCore/include PolyVoxCore.i
PolyVoxCore.i(4) : Error: Unable to find 'Impl\TypeDef.h'
Vector.i(7) : Error: Unable to find 'Vector.h'
DefaultMarchingCubesController.i(6) : Error: Unable to find 'DefaultMarchingCube
sController.h'
Density.i(6) : Error: Unable to find 'MarchingCubesSurfaceExtractor.h'
Density.i(7) : Error: Unable to find 'Density.h'
Material.i(6) : Error: Unable to find 'DefaultIsQuadNeeded.h'
Material.i(7) : Error: Unable to find 'Material.h'
MaterialDensityPair.i(6) : Error: Unable to find 'MaterialDensityPair.h'
Region.i(12) : Error: Unable to find 'Region.h'
SimpleVolume.i(8) : Error: Unable to find 'BaseVolume.h'
SimpleVolume.i(9) : Error: Unable to find 'Material.h'
SimpleVolume.i(10) : Error: Unable to find 'Density.h'
SimpleVolume.i(11) : Error: Unable to find 'SimpleVolume.h'
VertexTypes.i(8) : Error: Unable to find 'Impl\TypeDef.h'
VertexTypes.i(9) : Error: Unable to find 'Vector.h'
VertexTypes.i(10) : Error: Unable to find 'VertexTypes.h'
SurfaceMesh.i(8) : Error: Unable to find 'Region.h'
SurfaceMesh.i(9) : Error: Unable to find 'VertexTypes.h'
SurfaceMesh.i(10) : Error: Unable to find 'SurfaceMesh.h'
MarchingCubesSurfaceExtractor.i(8) : Error: Unable to find 'SimpleVolume.h'
MarchingCubesSurfaceExtractor.i(9) : Error: Unable to find 'MarchingCubesSurfaceExtractor.h'

So I'm a bit confused now. I start looking around in the other folders, I see that there are folders:
C:\polyvox\library\PolyVoxCore
C:\polyvox\library\PolyVoxUtil

and inside these, there are include and source folders. The include folders have nothing in them but more folders:
C:\polyvox\library\PolyVoxCore\include\PolyVoxCore
C:\polyvox\library\PolyVoxUtil\include\PolyVoxUtil

so that's bizzare again. It's almost as if all the files are in the wrong place! I tried moving the files down one into the "include" folders, but that did not help, it only changed the output of the MakeCSharpBindings to be even more cryptic:

Vector.i(9) : Error: Syntax error in input(3).

So I checked out Vector.i's line 9 and at this point I'm in really uncharted waters because I know nothing about this SWIG thing that does these .i files and their syntax.

So now, I'm not sure how to proceed from here. There was a page on the internet (http://tepidpond.com/polyvox-for-csharp/) that detailed the steps to produce the wrappers, but it's instructions fail and they never go over actually creating the CS stuff with the MakeCSharpBindings.bat file.

Which says that after having build I need to:
cd library\bindings
csc.exe /target:library /out:PolyVoxCoreActualCSharp.dll PolyVoxCorePINVOKE.cs Vector3Duint32_t.cs Region.cs SimpleVolumeuint8.cs SurfaceMeshPositionMaterialNormal.cs MarchingCubesSurfaceExtractorSimpleVolumeuint8.cs Vector3Dint32_t.cs BaseVolumeuint8.cs Vector3Dfloat.cs WrapMode.cs uint32Vector.cs PositionMaterialNormalVector.cs LodRecordVector.cs SWIGTYPE_p_PolyVox__DefaultMarchingCubesControllerT_unsigned_char_t.cs PositionMaterialNormal.cs LodRecord.cs

But of course this fails, because the folder they brought me to, does not have any of the files mentioned above. I assume thats what "MakeCSharpBindings.bat" is supposed to do, but something is not aligned correctly... I'll keep trying to figure this out if noone answers my post, but I was hoping at least someone could assist me a little bit.

I think in the end, I will make sure that I create a nice complete walkthrough on using the polyvox library in the way I want to use it, and it will make more clear for others who want to use it this way.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 6:39 am 

Joined: Sat Jul 20, 2013 6:10 am
Posts: 9
FYI. I edited the Vertex.i file and removed the three PROPERTY calls that are in that file. This actually allowed me to proceed and it built all of the .cs files with many warnings (of course, I do not know what this will cause, or break, in the actual code itself).

Not sure if it's because something changed in SWIG over time?

Now that I have the .CS files, I was able to build a DLL file. The only part that is unfortunately here, is that the XNA portions that had been built by Painect, are no longer compiling as there are several things that have changed in PolyVox since then. I'm going to try and re-create these classes so that rendering to XNA is possible. I'll ask questions about things that have changed and hopefully I'm able to accomplish this part.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 7:47 am 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
First up I must admit that Matt is the expert here... I don't have much experience with the bindings. But I'll throw out a couple of notes.

Firstly, the Python bindings at least do work (at least on Linux). They are tested as part of the nightly build process. I have a feeling (and Matt can confirm this) that C# bindings are tested as well? So your issues are probably specific to Windows or your environment.

I can't really comment on the library which comes with the Painect project, but I think you would be best of learning to rebuild it from PolyVox rather than using their library.

Draek wrote:
Open the PolyVox.sln and build all (release) and I get three errors on three test/example projects...


PolyVox does not currently build under VS2012 - this is a known issue which we should fix before release: https://bitbucket.org/volumesoffun/poly ... -on-vs2012

Draek wrote:
C:\polyvox\library\PolyVoxCore\include\PolyVoxCore
C:\polyvox\library\PolyVoxUtil\include\PolyVoxUtil

so that's bizzare again.


The recursive nature of the folder layout is indeed a bit bizarre. However, there was a good reason for it which I only vaguely recall. The basic issue was that the folder layout of installed software on Windows (C:/Program Files/LibraryName/include) is reversed compared to Linux (/usr/include/LibraryName). The bizarre folder layout in PolyVox is an attempt to allow examples to compile against installed versions of the PolyVox on both Linux and Windows, and also against the source distribution.

As for your actual problem... I'm going to wait for Matt to chime in and clarify the situation on Linux. If he confirms it's working there (maybe we have a test case?) then we can think more about Windows.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 9:38 am 
Developer
User avatar

Joined: Sun May 11, 2008 4:29 pm
Posts: 198
Location: UK
Hi,

The 0.2 release basically didn't have any useful bindings set up that we were supporting. For the 0.3 release I will be supporting the Python bindings but there will also be some C# bindings which I will support as much as I can. I don't have a lot of experience with C# so people like you testing it out is really appreciated.

As David says, the Python bindings are tested nightly on Linux and are working well. The C# bindings (created through the same SWIG system) should also work but it's more likely that there may be some bugs.

The first ting I would say is that you should (mostly) ignore the MakeCSharpBindings.bat file included in the bindings directory, that's a legacy method of creating the bindings. The very recommended way is to follow the instructions within INSTALL.txt. Once that's completed, then follow the instructions given by that article at tepidpond.com. I would also recommend getting the development version of PolyVox from Git develop branch since the bindings have been improved since the last release.

However, if you've got some C# files working then you could stick with what you've got for now.

Finally, if you're using the latest develop branch then take a look in the tests directory. In there you will find a file called TestSurfaceExtractor.cs. This file isn't run as part of an automatic test but if you look through it you should see a short example of how the C# bindings can be used.

My next step with the bindings will be to see if it is possible to automate as part of the build cycle the steps given by Jeremiah at teipond.com through CMake to make the whole process easier.

_________________
Matt Williams
Linux/CMake guy


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 2:17 pm 

Joined: Sat Jul 20, 2013 6:10 am
Posts: 9
I'm so glad you guys wrote back! I wasn't sure what kind of activity I would see, but I'm extremely pleased to hear you are still working on this!

For the record, appart from the errors I explained above with those examples, I was able to build in Visual Studio 2012 without any of the errors mentioned in the post you gave me. So perhaps building on VS2012 is no longer broken as you expected? The libraries themselves gave no errors, just those three samples.

I never noticed any instructions about CSharp bindings in the INSTALL.txt file. I will go back and re-read that to see what other instructions are listed there. The article you mention online, that you want to automate, he is missing steps. WIthout calling the out of date MakeCSharpBindings.cs I would not have had any .CS files (they were not produced by the normal build process).

I was under the impression I was using the polyvox-development branch from GIT, but I just have not downloaded the correct version? I will investigate this further.

Mostly my problem seemed to be with the final result, that not all the classes were built. When reading examples for the C++ version of polyvox, the class names are quite different. I assume there is some funky work going on here to make the C# bindings that creates classes that are named differently.

For example:

The older version of PolyVox C# had a different Extractor:

SurfaceExtractorSimpleVolumeMaterialDensityPair62

And now I only have access to one of them:

SurfaceExtractorSimpleVolumeDensity8

Although the original example used the volume:

SimpleVolumeMaterialDensityPair62 which is no longer in the new source code. But changing those in the sample source to SimpleVolumeMaterialDensityPair88 wouldn't work because there is no longer a MaterialDensityPair88 extractor.

Only the SimpleVolumeDesntiy8 class can be used with the extractor that remains.

Again if all this is because i'm using the wrong version, that will get cleared up soon enough when I get the correct one. I know I have a few things to learn still about polyvox and how to use it. So please be patient with me. I'm super persistent, so I will end up getting it to work and I will write a full account of how to do what I've done.

One of the reasons I'm focusing on the Painect project is that it added a couple new classes in order to be able to render the volume to XNA. These classes use older version of PolyVox, and my attempt to port it to the new version failed because of the classes changing and the lack of extractors.

I'll probably break it back down to basics instead of relying on Painect's code, but its a starting point.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 4:09 pm 

Joined: Sat Jul 20, 2013 6:10 am
Posts: 9
I suppose it makes a lot more sense once you start understanding GIT and how branches work in it.

I've used Subversion my whole career so I haven't used GIT before other than to just clone and get code.

Now I have the "develop" branch and I'm seeing a LOT MORE stuff going on with the bindings. Thanks for pointing me in the right direction there.

And yes, it does build the libraries automatically when using Visual Studio 2010. So now PolyVox build process is all setup properly.

Although the DLL produced doesn't work. When I try and add it to a normal project, it says that it cannot use it and I have to make sure its a proper assembly or COM object. I'll have to figure out how those DLLs are produced, perhaps they are not the actual CSharp library? The output of Release is:

_PolyVoxCore.lib
PolyVoxCoreCSharp.dll
PolyVoxCoreCSharp.lib

and the exp/py files as well (which i dont care for). So now I'm not sure. I"ll probably grab all the .cs files and create a project to put them into and compile it myself. not sure what is happening in the build process to make this DLL but it's no good from what I see.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 4:40 pm 
Developer
User avatar

Joined: Sun May 11, 2008 4:29 pm
Posts: 198
Location: UK
That .dll file is a native C++ DLL file containing native C++ PolyVox compiled code. The .cs files that are alongside it will DllImport from it to do the PolyVox stuff. In order to create a C# DLL file you need to compile all the .cs files with the C# compiler like is done at http://tepidpond.com/polyvox-for-csharp/ in the final step (10). You can then call the C# functions as is done in the TestSurfaceExtractor.cs example test.

I agree that this is a little complicated and convoluted at the moment since you end up with: PolyVoxCoreActualCSharp.dll (C# DLL) → PolyVoxCoreCSharp.dll (wrapper functions DLL) → PolyVoxCore.dll (native C++ PolyVox DLL) and you need all of these to run.

_________________
Matt Williams
Linux/CMake guy


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 4:49 pm 

Joined: Sat Jul 20, 2013 6:10 am
Posts: 9
Thanks for that answer yeah obviously I need to make the library (doh!) which is what I eventually did. I assumed that the regular polyvox build process not only setup the libraries but also actually built the CSharp libraries as well. My bad.

But I'm past that part now, and I've explained above the errors I'm getting when using the library's volume classes. Not sure if its broken because of work going on in the code right now, or if it's because there is something faulty with my library. (although most classes instantiate and work, which they wouldn't if the library wasn't working).


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 4:52 pm 

Joined: Sat Jul 20, 2013 6:10 am
Posts: 9
I apologize that I sometimes don't listen properly :P Sometimes my brain goes a little OCD.

I checked out the Test for CS you mentioned!

Region r = new Region(new Vector3Dint32_t(0, 0, 0), new Vector3Dint32_t(31, 31, 31));
SimpleVolumeuint8 vol = new SimpleVolumeuint8(r);

And there is a difference between the way I called mine and you do yours in there. Of course I'm glad that this solved my problem, but I wonder why the other fails:

Look how the region was built, I used instead:

Region r = new Region(0, 0, 0, 63, 63, 63);

Which I assumed would do the "Vector" instantiating for me.

When building the SimpleVolumes with that region, it was causing it to crash. Once I create the region the way you mentioned, it works :P

Thank you! So now, it looks like I have the C# library working and it's time to play!!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Creating a proper C# Sample and Bindings
PostPosted: Sun Jul 21, 2013 5:28 pm 
Developer
User avatar

Joined: Sun May 11, 2008 4:29 pm
Posts: 198
Location: UK
I've just had a look and you're right that there's a constructor for Region that takes 6 ints so what you tried with Region(0, 0, 0, 63, 63, 63) should work. Perhaps for some reason it is not being wrapped properly. I'll have to have a look into it.

I'm glad you've got something working for you now. Hopefully it will continue to but if you have any problems, please do ask.

_________________
Matt Williams
Linux/CMake guy


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

All times are UTC


Who is online

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