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


All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How do I setup a simple modifiable terrain in an Ogre scene?
PostPosted: Tue Sep 04, 2012 3:04 pm 
User avatar

Joined: Tue Sep 04, 2012 2:35 pm
Posts: 11
Hi everyone. I've been wanting to make project for a while using the Ogre engine, with a world containing destructible smooth terrain. I looked for many voxel terrain implementations... but none worked well, had source / license available, or were still under development. I came across PolyVox and it seems to be exactly what I'm looking for. I'm a beginner programmer and also new to Ogre, so I have some issues with setting everything up.

I got Ogre's tutorial framework to compile and render a simple scene, as explained here. I also compiled PolyVox and it generated two .lib files which I'm referencing in my project (together with the PolyVox source). For starters, I'm trying to get it to render some simple terrain I can modify using the wiki example code. I added that code to TutorialApplication::createScene but I now get a dozen compile errors. Here is the compile log.

Since there can be many reasons for this and I'm still new, I'm wondering if anyone has some specific, clear and descriptive instructions on how to setup Ogre to render a simple patch of voxel terrain, with simple digging / building support. What Ogre functions and plugins must I include, and are there more detailed examples and instructions? After I get a basic scene working I'll probably be more specific with what I'm trying to make. I'm also curious if there's a list with all the functions in PolyVox, and what lines of code can be used to do things to the terrain.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Tue Sep 04, 2012 5:38 pm 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
skimming your log perhaps you forgot to link to PolyVox lib. You seemed to have compiled and build PolyVox libs, now you need to link to it in your application.

Double check to see if the following are there:

-In solution explorer
--right click on your project and select properties to open the Application Properities Page
--in that page on the left hand pane open up c/c++
--in the general tab, to the right make sure you included the header files for PolyVox in additional include directories
--next goto the linker tab
--under the general tab include polyvox's lib directory where you can find the .lib files
--next goto the input tab
--in additional dependencies add PolyVoxCore.lib; and PolyvVoxUtil.lib; Don't forget the semicolons

Doing things with PolyVox is at an intermediate level for graphics related programming. So I suggest you do some simple programs first. Well if you are patient you can still do it, the polyvox sample programs is a good place to start.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Tue Sep 04, 2012 6:48 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
There is a lot of output there, but the first actual error appears to be the following:

Quote:
2>D:\OGRE\Project\src\TutorialApplication.cpp(33): error C2065: 'ogreSceneManager' : undeclared identifier


In other words your trying to use a variable called ogreSceneManager which you haven't actually created. Note that the sample code on the Wiki is not a complete working example, as it assumes you have already set up Ogre and created a working scene manager.

I would recommend that you seperate learning Ogre from learning PolyVox, as both are fairly complex. If you focus on just Ogre to start with then you can learn how to set up a scene and (most importantly) use the Ogre::ManualObject class:

http://www.ogre3d.org/tikiwiki/tiki-index.php?page=ManualObject
http://www.ogre3d.org/docs/api/html/classOgre_1_1ManualObject.html

The sample code in the PolyVox wiki does use this ManualObject, and so you'll have a better chance of getting it to work if you are already familier with this.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Wed Sep 05, 2012 1:40 pm 
User avatar

Joined: Tue Sep 04, 2012 2:35 pm
Posts: 11
Someone on IRC helped last night, and corrected some of my very noobish mistakes (that wiki code is a bit downdated as well and several functions had to be replaced). It compiles and starts now, even if I don't see anything rendering.

I indeed need to read both the Ogre and PolyVox documentations, especially since I'm also learning C++ while I'm working on this. It would however help if someone can point out basic but complete examples of a code using PolyVox + Ogre. Like I said, for starters I'd like a simple code for spawning some terrain and using two keys to add and subtract to / from the volume where the crosshair / pointer is touching. I'm pretty much aiming for something like this, but of course it can be simpler for starters.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Wed Sep 05, 2012 2:20 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
MirceaKitsune wrote:
Someone on IRC helped last night, and corrected some of my very noobish mistakes (that wiki code is a bit downdated as well and several functions had to be replaced). It compiles and starts now, even if I don't see anything rendering.

You should definitely start by getting something on the screen without PolyVox, even just loading a sample Ogre mesh. Otherwise you later find out that the screen was black because your camera was facing the wrong way, or the lights were turned off, or some other simple mistake. I've been there before...

After that just try creating anything with the ManualObject, even just a cube. This ensures that you know at least the basics of how the ManualObject works and also that you have a working material which you can apply to the mesh.

MirceaKitsune wrote:
I indeed need to read both the Ogre and PolyVox documentations, especially since I'm also learning C++ while I'm working on this. It would however help if someone can point out basic but complete examples of a code using PolyVox + Ogre.

We don't really have any complete examples of using PolyVox with Ogre. PolyVox is entirely independant of the rendering system and so we just have examples in OpenGL. The most important thing is to understand how index/vertex buffers are used to store data, because this is the representation that PolyVox outputs and it can be converted into an Ogre ManualObject.

MirceaKitsune wrote:
Like I said, for starters I'd like a simple code for spawning some terrain and using two keys to add and subtract to / from the volume where the crosshair / pointer is touching. I'm pretty much aiming for something like this, but of course it can be simpler for starters.

Yes, that's possible. This video is similar and was made using PolyVox. I don't have the code anymore though and it would be out of date anyway.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Wed Sep 05, 2012 7:01 pm 
User avatar

Joined: Tue Sep 04, 2012 2:35 pm
Posts: 11
David Williams wrote:
You should definitely start by getting something on the screen without PolyVox, even just loading a sample Ogre mesh. Otherwise you later find out that the screen was black because your camera was facing the wrong way, or the lights were turned off, or some other simple mistake. I've been there before...

After that just try creating anything with the ManualObject, even just a cube. This ensures that you know at least the basics of how the ManualObject works and also that you have a working material which you can apply to the mesh.


Already got that working with the OGRE tutorial which renders a simple mesh (I based the PolyVox test from that). But I didn't check the position of the PolyVox scene, and indeed haven't added any lights yet. Was trying to understand how everything works first, and how to generate / modify a volume. I think that's what I'm mostly looking for to begin with.

David Williams wrote:
We don't really have any complete examples of using PolyVox with Ogre. PolyVox is entirely independant of the rendering system and so we just have examples in OpenGL. The most important thing is to understand how index/vertex buffers are used to store data, because this is the representation that PolyVox outputs and it can be converted into an Ogre ManualObject.


Yeah, I read that PolyVox is a system for calculating voxel volumes, and is to be used with any renderer the developer finds appropriate. I assumed that someone tried it with Ogre as well, and might have posted some simple examples of this scenario (like I'd assume someone tried it with Irrlicht, but I'm sticking with Ogre in my case). Also that there might be instructions on how to get it working with most popular engines.

I might be looking for two separate tutorials. One for how to setup a PolyVox volume (and make it modifiable), and second how I convert that volume into something Ogre can render. If I understand right the two are completely separate steps.

David Williams wrote:
Yes, that's possible. This video is similar and was made using PolyVox. I don't have the code anymore though and it would be out of date anyway.


That looks really beautiful and very close to what I'd like! But the code using PolyVox is probably very complex for something like that... hard to tell without examples.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Thu Sep 06, 2012 7:49 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
MirceaKitsune wrote:
I might be looking for two separate tutorials. One for how to setup a PolyVox volume (and make it modifiable), and second how I convert that volume into something Ogre can render. If I understand right the two are completely separate steps.

Yep, that's basically the case. The examples which come with PolyVox do show how to set up a basic volume, fill it with data, and create the mesh but it's then rendered with OpenGL instead of Ogre. But if you're experienced with Ogre then it shouldn't be too difficult to convert it to use the ManaulObject, as shown in the Wiki snippet you found.

But overall I do agree that the documentation is rather lacking, and this is something we are actively working on (my last 10-20 commits were all adding new documentation). Hopefully it will be better by the next release.

MirceaKitsune wrote:
That looks really beautiful and very close to what I'd like! But the code using PolyVox is probably very complex for something like that... hard to tell without examples.

For completeness I should also point out that a voxel terrain implementation is being added to Ogre. I'm not sure how advanced it is though, I skimmed through the vieos but didn't see the terrain being modified.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Mon Oct 08, 2012 11:32 am 
User avatar

Joined: Tue Sep 04, 2012 2:35 pm
Posts: 11
Sorry for being late to reply. I might check that alternative implementation for OGRE as well. Personally I prefer PolyVox as it's a library developed specifically for this purpose, so it should be better and more consistent to use.

Anyway, I haven't made any progress with my code. The latest changes are still using the OGRE Tutorial Framework, combined with that wiki article on how to add a PolyVox scene to it. As I said last time, nothing renders... possibly because I need to add data to my scene.

If anyone wishes to help, here is the code function I got running so far. Please tell me what I should change and add to it. For starters, I'm looking to get a simple area of terrain which I can modify (add / subtract to / from). Once that works I'll probably make another thread with more information about what I'm trying to get going and other questions.

Code:
void TutorialApplication::createScene(void)
{
   using namespace std;
   using namespace PolyVox;
   typedef PolyVox::PositionMaterialNormal VertexType;
   SurfaceMesh <VertexType> mesh;
   SurfaceMesh <VertexType> mesh2;
   Region regValid(Vector3DInt32(0,0,0), Vector3DInt32(128,128,128));

   Ogre::ManualObject* ogreMesh;
   // create something to draw the PolyVox stuff to
   ogreMesh = mSceneMgr->createManualObject("PolyVox Mesh");
   // YES we do intend to change the mesh later -.-
   /*
   ogreMesh->setDynamic(true);
   ogreMesh->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
   {
      // do nothing, this will be updated
   }
   ogreMesh->end();
   */
   Ogre::SceneNode* ogreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("testnode1", Ogre::Vector3(20, 0, 0));
   ogreNode->attachObject(ogreMesh);

   SimpleVolume<Material8> volume(regValid);
   // now add some data to it
   std::cout << "smoothing volume" << std::endl;
   // smoothRegion<Material8>(volume, volume.getEnclosingRegion());
   std::cout << "updating volume surface" << std::endl;
   {
      PolyVox::SurfaceExtractor<SimpleVolume,Material8> suf(&volume, volume.getEnclosingRegion(), &mesh);
      suf.execute();
   }
   std::cout << "decimating meshes" << std::endl;
   {
      PolyVox::MeshDecimator<PolyVox::PositionMaterialNormal> decim(&mesh, &mesh2);
      decim.execute();
   }
   // std::cout << "drawing mesh: " << mesh2.getNoOfVertices() << std::endl;
   ogreMesh->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
   {
      const vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh2.getVertices();
      const vector<uint32_t>& vecIndices = mesh2.getIndices();
      unsigned int uLodLevel = 0;
      int beginIndex = mesh2.m_vecLodRecords[uLodLevel].beginIndex;
      int endIndex = mesh2.m_vecLodRecords[uLodLevel].endIndex;
      for(int index = beginIndex; index < endIndex; ++index) {
         const PolyVox::PositionMaterialNormal& vertex = vecVertices[vecIndices[index]];
         const PolyVox::Vector3DFloat& v3dVertexPos = vertex.getPosition();
         const PolyVox::Vector3DFloat& v3dVertexNormal = vertex.getNormal();
         //const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
         const PolyVox::Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<PolyVox::Vector3DFloat>(mesh2.m_Region.getLowerCorner());
         ogreMesh->position(v3dFinalVertexPos.getX(), v3dFinalVertexPos.getY(), v3dFinalVertexPos.getZ());
         ogreMesh->normal(v3dVertexNormal.getX(), v3dVertexNormal.getY(), v3dVertexNormal.getZ());
         uint8_t mat = vertex.getMaterial() + 0.5;
         uint8_t red = mat & 0xF0;
         uint8_t green = mat & 0x03;
         uint8_t blue = mat & 0x0C;
         ogreMesh->colour(red*2, green*4, blue*4);// just some random colors, I'm too lazy for hsv
      }
   }
   ogreMesh->end();

   mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
}


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Mon Oct 08, 2012 12:50 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
The first problem which I see is that you are not adding any data to your volume. You have the code:

Code:
void TutorialApplication::createScene(void)
{
   .
   .
   .
   SimpleVolume<Material8> volume(regValid);
   // now add some data to it
   std::cout << "smoothing volume" << std::endl;
   // smoothRegion<Material8>(volume, volume.getEnclosingRegion());
   std::cout << "updating volume surface" << std::endl;
   {
      PolyVox::SurfaceExtractor<SimpleVolume,Material8> suf(&volume, volume.getEnclosingRegion(), &mesh);
      suf.execute();
   }
   .
   .
   .

}


This is just creating an empty volume and then attempting to extract a surface from it, but no surface will exist because you haven't set any of the voxels. You need to replace the comment '// now add some data to it' with code which actually does this. For example, the BasicExample which comes with PolyVox shows how to create a sphere in your volume data.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: How do I setup a simple modifiable terrain in an Ogre sc
PostPosted: Mon Oct 08, 2012 2:01 pm 
User avatar

Joined: Tue Sep 04, 2012 2:35 pm
Posts: 11
David Williams wrote:
The first problem which I see is that you are not adding any data to your volume. You have the code:

Code:
void TutorialApplication::createScene(void)
{
   .
   .
   .
   SimpleVolume<Material8> volume(regValid);
   // now add some data to it
   std::cout << "smoothing volume" << std::endl;
   // smoothRegion<Material8>(volume, volume.getEnclosingRegion());
   std::cout << "updating volume surface" << std::endl;
   {
      PolyVox::SurfaceExtractor<SimpleVolume,Material8> suf(&volume, volume.getEnclosingRegion(), &mesh);
      suf.execute();
   }
   .
   .
   .

}


This is just creating an empty volume and then attempting to extract a surface from it, but no surface will exist because you haven't set any of the voxels. You need to replace the comment '// now add some data to it' with code which actually does this. For example, the BasicExample which comes with PolyVox shows how to create a sphere in your volume data.


Someone told me something similar, but being very new to the code and C++ in general it was hard to tell. I'll look for examples on how to add some voxel data, and see if then it will render anything. If anyone else notices something bad, let me know if there are issues in any other parts of the code until I get to this.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 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