It is currently Sat Aug 22, 2020 1:44 pm


All times are UTC




Post new topic Reply to topic  [ 12 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Voxel trees
PostPosted: Sat Mar 17, 2012 8:50 pm 

Joined: Wed Feb 29, 2012 12:35 am
Posts: 25
Greetings everyone,

I had a very long week deciding on how I should implement the tree generation on my game, and I still didn't figure it out, I'm really lost :|

I need your opinion regarding this matter, my game uses polyvox and ogre3d, I almost finished the basic world random generation, I'm now stuck at the trees. What I'm planning on doing is implementing a procedural voxel trees generation, I wonder what's the best method/implementation to follow?

How does voxeliens trees work? is it a simple mesh? or a voxel data?

I saw some voxel editors but I guess all it does is create a static mesh at the end of the output right? thus its not a voxel/fully destructible object.

Any input about how I should go about implementing a procedural voxel trees in my game are welcome :D

Thanks for your attention.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Mon Mar 19, 2012 2:24 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Sorry for the slow reply, I didn't get to repond to your last post (glad you sorted it) and have been busy.

xelons wrote:
What I'm planning on doing is implementing a procedural voxel trees generation, I wonder what's the best method/implementation to follow?


Actually I don't have any experience here. Conventional polygon trees are often generated using L-Systems so you might want to investigate these. Also check out the videos below and maybe follow through some of the links.

http://www.youtube.com/watch?v=L8E64m0GAIA
http://www.youtube.com/watch?v=L8E64m0GAIA
http://www.youtube.com/watch?v=Hc3sb6lx0ag

xelons wrote:
How does voxeliens trees work? is it a simple mesh? or a voxel data?

I saw some voxel editors but I guess all it does is create a static mesh at the end of the output right? thus its not a voxel/fully destructible object.

The trees in Voxeliens are real voxels so that they can be destroyed by the attackers. I modelled them in Sproxel and then exported the data as a .csv file (as I recall) which is real voxels. It was fairly easy to load this data into a PolyVox volume. Sproxel can also output a polygon mesh if you prefer. Be aware that I found Sproxel 0.4 to be much faster than 0.5.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Mon Mar 19, 2012 3:38 pm 

Joined: Wed Feb 29, 2012 12:35 am
Posts: 25
David Williams wrote:
The trees in Voxeliens are real voxels so that they can be destroyed by the attackers. I modelled them in Sproxel and then exported the data as a .csv file (as I recall) which is real voxels. It was fairly easy to load this data into a PolyVox volume. Sproxel can also output a polygon mesh if you prefer. Be aware that I found Sproxel 0.4 to be much faster than 0.5.

Thanks for the reply, I think I will go with the .csv method for now until I learn more about the L-system, any hints on how to use the .csv files to convert it into polyvox data volume?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Mon Mar 19, 2012 3:49 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
The code below is copied from Voxeliens. It might not work as-is but should show you how to start.

Code:
//Based on code from Sproxel
bool loadCSV(const QString& filename, Thermite::Volume* volume, qint32 posX, qint32 posY, qint32 posZ)
{
   PolyVox::SimpleVolume<PolyVox::Material16>* pPolyVoxVolume = volume->m_pPolyVoxVolume;

   int fscanfStatus = 0;
   FILE* fp = fopen(filename.toAscii().constData(), "rb");
   if (!fp) return false;

   // Read the dimensions
   int sizeX = 0, sizeY = 0, sizeZ = 0;
   fscanfStatus = fscanf(fp, "%d,%d,%d\n", &sizeX, &sizeY, &sizeZ);

   // Read the data
   QColor color;
   for (int y = sizeY-1; y >= 0; y--)
   {
      for (int z = 0; z < sizeZ; z++)
      {
         for (int x = 0; x < sizeX; x++)
         {
            int ir, ig, ib, ia;
            fscanfStatus = fscanf(fp, "#%02X%02X%02X%02X,", &ir, &ig, &ib, &ia);

            /*float r = ir / (float)0xff;
            float g = ig / (float)0xff;
            float b = ib / (float)0xff;
            float a = ia / (float)0xff;*/

            QColor color(ir, ig, ib, ia);

            if(ia > 0)
            {
               PolyVox::Material16 voxel;
               voxel.setMaterial(QColorToMaterial(color));

               int xToWrite = posX + x;
               int yToWrite = posY + y;
               int zToWrite = posZ + z;
               if((xToWrite >= 0) && (xToWrite < pPolyVoxVolume->getWidth()) &&
                  (yToWrite >= 0) && (yToWrite < pPolyVoxVolume->getHeight()) &&
                  (zToWrite >= 0) && (zToWrite < pPolyVoxVolume->getDepth()))
               {
                  pPolyVoxVolume->setVoxelAt(xToWrite, yToWrite, zToWrite, voxel);
               }
            }

            if (x != sizeZ-1)
               fscanfStatus = fscanf(fp, ",");
         }
         fscanfStatus = fscanf(fp, "\n");
      }
      fscanfStatus = fscanf(fp, "\n");
   }

   fclose(fp);
   return true;
}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Mon Mar 19, 2012 4:56 pm 

Joined: Wed Feb 29, 2012 12:35 am
Posts: 25
David Williams wrote:
The code below is copied from Voxeliens. It might not work as-is but should show you how to start.

Thanks, this for sure will help me a lot, however there is one thing I noticed doing a quick scan to your code, it's about the Qt sdk, does that mean that I need to use the Qt sdk into my project in order to convert the csv file into polyvox volume?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Mon Mar 19, 2012 9:05 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
No, you don't need to use Qt. I'm using it for Voxeliens, but in that example code I'm only using as a way to store the colour. The file handling is standard C++ and you can write your own colour class or just use seperate variables for red, green and blue.

Be aware that Sproxel only stores colours for voxels, it doesn't apply textures to them for example. I don't know what kind off voxels you have in your game. Material8? You might need to decide that a green voxel in Sproxel represent a 'leaf' voxel in your world, for example. It's really up to you how you convert the voxel data.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Sat Apr 14, 2012 1:55 am 

Joined: Wed Feb 29, 2012 12:35 am
Posts: 25
Thanks David, I have successfully implemented a voxel model loader into my project, I will be using it for many things, however I'm also trying to implement the L-system in order to get random trees and vegetation, I wonder if anyone have successfully implemented a 3d L-system using voxels? or if anyone have a good example or documentation. I have found many things about the L-system on the net but most of them seems to be complicated and over detailed for my project, I'm looking for a very basic and simple implementation written in c++.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Tue May 29, 2012 4:30 pm 

Joined: Sun Jan 08, 2012 10:00 am
Posts: 31
Location: Germany
With a 3D-Turtle-graphic http://en.wikipedia.org/wiki/Turtle_graphics
its one way to get plants, heres a test of recursive plants (no Lindenmayer (L)-system).

Image

Idea of the recursive plants from here http://bonelake.blogspot.com/2009/04/vp ... ion-5.html

I started with the drawline-method from a modified version of polyvox-raycast i "loan" from polyvox:
Code:
   void DrawLine(float x1, float y1, float z1, float x2, float y2, float z2)
   {
      int i = (int)floorf(x1);
      int j = (int)floorf(y1);
      int k = (int)floorf(z1);

      int iend = (int)floorf(x2);
      int jend = (int)floorf(y2);
      int kend = (int)floorf(z2);

      int di = ((x1 < x2) ? 1 : ((x1 > x2) ? -1 : 0));
      int dj = ((y1 < y2) ? 1 : ((y1 > y2) ? -1 : 0));
      int dk = ((z1 < z2) ? 1 : ((z1 > z2) ? -1 : 0));

      float minx = floorf(x1), maxx = minx + 1.0f;
      float tx = ((x1 > x2) ? (x1 - minx) : (maxx - x1)) / abs(x2 - x1);
      float miny = floorf(y1), maxy = miny + 1.0f;
      float ty = ((y1 > y2) ? (y1 - miny) : (maxy - y1)) / abs(y2 - y1);
      float minz = floorf(z1), maxz = minz + 1.0f;
      float tz = ((z1 > z2) ? (z1 - minz) : (maxz - z1)) / abs(z2 - z1);

      float deltatx = 1.0f / abs(x2 - x1);
      float deltaty = 1.0f / abs(y2 - y1);
      float deltatz = 1.0f / abs(z2 - z1);

      SetPos(i,j,k);

      for(;;)
      {
         if(tx <= ty && tx <= tz)
         {
            if(i == iend) break;
            tx += deltatx;
            i += di;

            if(di == 1) pos.setX(pos.getX()+1);
            if(di == -1) pos.setX(pos.getX()-1);
            SetVoxel();
         } else if (ty <= tz)
         {
            if(j == jend) break;
            ty += deltaty;
            j += dj;

            if(dj == 1) pos.setY(pos.getY()+1);
            if(dj == -1) pos.setY(pos.getY()-1);
            SetVoxel();
         } else
         {
            if(k == kend) break;
            tz += deltatz;
            k += dk;

            if(dk == 1) pos.setZ(pos.getZ()+1);
            if(dk == -1) pos.setZ(pos.getZ()-1);
            SetVoxel();
         }
      }
   } 


my website:
http://zenprogramming.tripde]od.com


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Tue May 29, 2012 7:26 pm 

Joined: Wed Feb 29, 2012 12:35 am
Posts: 25
zprg wrote:
With a 3D-Turtle-graphic http://en.wikipedia.org/wiki/Turtle_graphics
its one way to get plants, heres a test of recursive plants (no Lindenmayer (L)-system).

Image

Idea of the recursive plants from here http://bonelake.blogspot.com/2009/04/vpython-version-5.html

I started with the drawline-method from a modified version of polyvox-raycast i "loan" ;) from polyvox:

...

my website:
http://zenprogramming.tripod.com


Nice idea and implementation, I was looking for something simple similar to this, I will read more about the 3D-turtle graphics and hopefully implement something similar to this and see how it goes :)

EDIT:
I have a couple of questions regarding this implementation,
Code:
 SetPos(i,j,k);
I suppose this sets the tree coordinates? another one is this
Code:
pos.setX(pos.getX()+1);
what does pos.set and get stand for?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Voxel trees
PostPosted: Tue May 29, 2012 9:04 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Ok, I've sorted out the confusion in this thread. @stoertebecker - Your user name is now zprg and the posts above still make sense @xelons - Thanks, that was exactly what I needed to sort it out (as strange as that sounds).

Anyway, back on topic I must say I really like this idea of a 3D turtle. It seems some other people have had a similar idea, but the use of voxels really brings it to life. This could make a fun little educational tool :-)


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