PnP TerrainCreator - Forum

The PnP TerrainCreator Forum
It is currently Sat Nov 18, 2017 7:43 pm

All times are UTC




Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: exporter plugin for ogre
PostPosted: Tue Jan 06, 2009 12:03 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
I will add support for shared geometry in the Ogre mesh loader today.
And clean up the code a bit more.
I also need to look into why the Ogre scene exporter is ignoring local scale.
The barrel is exported way too small. :)

I hope you got the files I sent you, Ralf.

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Tue Jan 06, 2009 12:21 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 892
Location: Braunschweig
Yes, everything is fine, thank you.

There are three scale factors involved overall. The global scale of the object manager (gs), the gobal scale of a single object definition (os) in the object manager, and the scale of the object placement (ps).

Generally it is a good Idea to scale the mesh file during export (using the available parameters of the save-to method) by the factor gs*os, while using ps for the scale in the scene file.

Usually you have an additional world scale (ws) for the terrain, which should also be used for exporting the meshes gs*os*ws.

I'll try to finish a new update over the weekend with your additions.


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Tue Jan 06, 2009 1:26 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
I made a mistake of assuming that people will use stock Ogre media, which requires to be scaled by 1/10, when using a terrain with a detail element size of 1 metre. :oops:
Stock media will look right with a detail element size of 10.
Most real projects decide on a scale to use, and model their models accordingly.
If people have a problem with the size of the terrain versus their models, they should choose another detail element size, or scale their models.

I need to send you an updated test application, where I scale things down, within Ogre, so that what you see in PnPTC is what you get in Ogre.
And an updated scene exporter.

The scene exporter could hint the camera settings, by exporting the size of terrain, the detail element size, etc.

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Tue Jan 06, 2009 2:15 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
I will make the demo app load a camera configuration file, where you can set things like near and far clip planes, speed, etc.
That should make it flexible enough for rigorous testing.

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Tue Jan 06, 2009 7:07 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
Done. :)

Now, on to shared geometry in the Ogre mesh loader ..

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Tue Jan 06, 2009 8:17 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
Me again. :)
I just realised that the models I were using - ie stock Ogre media - really is not optimal for testing because they are not modelled at scale.
I'll upload updated media, modelled to fit a terrain with a unit size of 1 metre. :wink:

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Tue Jan 06, 2009 10:31 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
Yes!
I finally fixed the orientation issues.
Don't ask me how, but it works:
Code:
// get object rotation
// swap Z and Y, flip X and Y
float theta_x = -pPlacement->GetRotX();
float theta_y = -pPlacement->GetRotZ();
float theta_z = pPlacement->GetRotY();

:lol:

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Wed Jan 07, 2009 12:18 am 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
Found that we indeed need to scale by 10 when exporting the objects:
Code:
// get scale. we need to scale it down by 10.
float scale_x = pPlacement->GetScaleX() / 10;
float scale_z = pPlacement->GetScaleZ() / 10;
float scale_y = pPlacement->GetScaleY() / 10;


Or, should it be scaled by pObjects->GetGlobalScale() ?
Will that global scale change if the detail element is changed?
<edit>
No, I think it should be scaled by Terrain.GetDetailHorizontalScaleFactor().
I will make a test.
</edit>

Because, what remains is to scale the scale by whatever the detail element size is.

I just have to find where the terrain properties are stored.

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Wed Jan 07, 2009 11:32 am 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 892
Location: Braunschweig
As these scales also affect physics for example. It would be a better choice to scale the terrain surface according to the Terrain.GetDetailHorizontalScaleFactor() parameter than scaling the objects by it.


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Wed Jan 07, 2009 1:01 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
I figured out why the orientation code works when I turned off my computer yesterday:
It's simply a 270 degree rotation around the X-axis. :)

The models should be scaled down by 10 because that's the difference between objects in the real world and objects in PnPTC. Scale by 10 will not change the relative size. It's just internal to PnPTC.
I think I changed my mind about scaling again with Terrain.GetDetailHorizontalScaleFactor(), because - as I found out earlier - it should be up to the users to use properly scaled media.
Because most of the time, doing a lot of scaling up/down in a 3D application is bad performance.

However, maybe it could be an option: to scale terrain or models by some value?
I don't know MFC good enough to figure that out, so I leave that as an exercise to you, Ralf.

Anyway: the scene exporter works great.

I will move on the Ogre serializer and finish it. :)

Maybe I should do a pretty Ogre scene and post some screen shots in the showcase forum.? :wink:

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Wed Jan 07, 2009 3:37 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
The Ogre serializer is done.
The file is sent.
It handles shared geometry, and should be ready for production use. :)

Now I just need to make a pretty Ogre scene.. :wink:

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Wed Jan 07, 2009 3:44 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
Seems like my work is done, so I can stop spamming you, Ralf. :P
Let me know if you need a tester. :wink:

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Wed Jan 07, 2009 3:49 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 892
Location: Braunschweig
I'm really thankful for your work. So don't worry about spamming the forum :D

Great. I'll be testing it over the weekend and let you know if a run into any troubles.


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Thu Jan 08, 2009 2:59 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
Right.
I modified the vegetation plugin to accept "mesh.xml" as one of the supported formats.

And then I realised that support for alpha textures needs to be added to the Ogre serializer:
Code:
   // open xml document
   TiXmlDocument xml_materials;
   if (!xml_materials.LoadFile(strDummy + ".pnpogremat" ))
   {
      return false;
   }

   std::map<std::string,std::string> matMap;
   typedef std::pair <std::string, std::string> Material_Pair;
   std::map<std::string,bool> matMapAlpha;
   typedef std::pair <std::string, bool> MaterialAlpha_Pair;
   // get materials node
   TiXmlElement* pMaterialsNode = xml_materials.FirstChildElement("materials");
   if (!pMaterialsNode)
   {
      return false;
   }
   // fill out the materials map
   for (TiXmlElement* material = pMaterialsNode->FirstChildElement("material");
      material != 0; material = material->NextSiblingElement())
   {
      std::string strMatName = GetOgreXmlAttributeString(material,"material");   
      std::string strTextureName = GetOgreXmlAttributeString(material,"texture");
      bool bUseAlpha = EqualNoCase(material->Attribute("alpha"), std::string("true"));
      matMap.insert(Material_Pair(strMatName,strTextureName));
      matMapAlpha.insert(MaterialAlpha_Pair(strMatName,bUseAlpha));
   }


   // get ogre mesh base node
   TiXmlElement* pOgreMeshNode=xml.FirstChildElement("mesh");
   if (!pOgreMeshNode)
   {
      return false;
   }
   
   int iMaterialCount = 0;

   bool bUseSharedVertices = false;
   // Get a pointer to shared geometry node, if any.
   TiXmlElement* pSharedGeometryNode = pOgreMeshNode->FirstChildElement("sharedgeometry");

   // loop through submeshes
   TiXmlElement* pSubmeshesNode = pOgreMeshNode->FirstChildElement("submeshes");
    for (TiXmlElement* submesh = pSubmeshesNode->FirstChildElement();
        submesh != 0; submesh = submesh->NextSiblingElement())
    {
      // We don't support anything other than triangle_list based meshes.
      if (!EqualNoCase(submesh->Attribute("operationtype"), std::string("triangle_list")))
      {
         return false;
      }

      // Check if this mesh uses shared vertices
      bUseSharedVertices = EqualNoCase(submesh->Attribute("usesharedvertices"), std::string("true"));

      // create material
      PNPTC_MATERIAL mat;
      mat.strName = GetOgreXmlAttributeString(submesh,"material");
      mat.bAlphaBlend= matMapAlpha[mat.strName];
      mat.bUseVertexColors=false;
      mat.colAmbient=PNPTC_RGB(255,255,255);
      mat.colDiffuse=PNPTC_RGB(255,255,255);
      mat.iTextures=1;
      mat.strTexture[0]= matMap[mat.strName];

      // add material
      ObjectData.AddMaterial(mat);

Line 139 to 206.

But it does not work. The alpha isn't picked up.

Is there anything I need to do to make PnPTC heed the alpha?
The trees are not very pretty without, but we can probably live with it.

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: exporter plugin for ogre
PostPosted: Thu Jan 08, 2009 3:39 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 892
Location: Braunschweig
Have you tried

Code:
matMapAlpha[strMatName]=bUseAlpha;


instead of

Code:
matMapAlpha.insert(MaterialAlpha_Pair(strMatName,bUseAlpha));


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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: