L3DT users' community
Large 3D terrain generator

calling ameshdecimator plugin

Correspondence concerning plugins and scripts; development, use, bugs and ideas.

calling ameshdecimator plugin

Postby JohnD » Thu Jun 04, 2009 10:32 pm

Hi there,
Firstly may I say I'm impressed with L3DT and what a one man army can do :)

I'm in the process of developing a plugin for exporting DirectX files from L3DT, the plugin itself works no problem but the mesh is too highly detailed, my first thought was to use the mesh decimator in a similar manner to what you use for obj, .x & blitz files. The way I had thought to do it was to call the function
'ExtDecimateUI' but the parameters for calling this plugin function are a little ambigious, I'm not sure what the parameters are meant to be, I've tried doing a bit of guesswork but all have produced errors; but the errors are not very clear either (is there a way to generate more verbose log file entries?).

If you could recommend a better way or perhaps provide a small code fragment my head & the wall I've began beating it against would greatly appreciate it :D
JohnD
New member
 
Posts: 3
Joined: Thu Jun 04, 2009 10:19 pm

Postby Aaron » Sat Jun 06, 2009 12:46 pm

Hi JohnD,

I've uploaded the up-to-date source for the OBJ plugin here:

http://www.bundysoft.com/L3DT/downloads ... BJ-src.zip

The mesh decimator is invoked in the 'SaveMapDecimated' function, which starts on line 166 in the L3DTio_OBJ.cpp file. On line 185 you find how to set the three arguments for the DecimateUI function.

Best of luck, and please let me know if you find any problems.

Cheerio,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Postby JohnD » Mon Jun 08, 2009 7:55 pm

Wow! now thats what I call a code fragment. :wink:

Thanks a lot Aaron.
JohnD
New member
 
Posts: 3
Joined: Thu Jun 04, 2009 10:19 pm

Re: calling ameshdecimator plugin

Postby miko » Tue May 03, 2011 7:01 pm

Although this thread is a bit dusted, I'd like to jump in here. :)
I'm currently reworking my DXMESH exporter plugin, as a preparation for upcoming L3DT v3. While on it, I'm adding new features, too.

For a single HM-to-Mesh export, I'm invoking the decimator by UI.MeshDecimator.DecimateUI and subsequent f.Execute2(). This brings up the ui to set height threshhold, then starts decimation.

Now, when it comes to tiled export (HM split into several meshes), I'd need to "cut" the un-decimated HM (as in the example code), then run each tile through the decimator, then export as mesh. This is to ensure the rectangular shape of each mesh, I reckon.
Doing it this way would invoke the decimator UI each time - which gets quite annoying when having split the original terrain into a lot of tiles. So, I imagine I'd need a possibility to call the decimator with *and* without UI (or so). Is that possible, or is there another way to achieve what I want? Thanks
miko
Contributing member
 
Posts: 26
Joined: Tue May 03, 2011 6:41 pm
Location: Regensburg, Germany

Re: calling ameshdecimator plugin

Postby Aaron » Tue May 03, 2011 10:24 pm

Hi Miko,

Ah, you've touched on a subject close to my heart; I've just been working on the mesh decimator plugin. More on that later...

In the current release there is no way to run atMeshDecimator without a UI, but I have added this to the next developmental build. The new function goes under the name of 'calc.mesh.DecimateHF', with similar arguments but for the addition of a float for 'MaxError', which was previously set in the UI.

In the next release I have also modified the mesh decimator, and indeed all the mesh-related plugins (OBJ, 3DS, X, B3D, etc.) to use a common mesh structure. Previously, some of these plugins passed around meshes as a collection of vertex/norm/face buffers in a list, whilst others used a more complex representation that included face groups, materials, etc. In the next release, all of these plugins use this more complex representation. However, for plugins that just use the vertex/norm/face buffers (such as those that use atMeshDecimator), the code to use the new mesh class is almost identical. I'll release the source and examples for this stuff with the next dev built also.

Please also note that cutting the heightfield into tiles and then decimating those tiles will not ensure that the tiles match perfectly at their edges, as the optimiser may split or combine some triangles on one side of the edge but not on the other side (it all depends on the local roughness). My vague plan for this goal was to decimate the whole terrain at once and then cut thee output mesh into tiles, splitting triangles as necessary. To this end I have also changed atMeshdecimator to support larger triangle counts via dynamically allocated pages of memory, rather than one big static array as in the current release. However, I haven't started on the mesh cutting yet. Another option would be to force atMeshDecimator to not optimise triangles at the tile edges; this is also on the to-do list.

Best regards,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: calling ameshdecimator plugin

Postby miko » Wed May 04, 2011 7:06 pm

Aaron, thanks very much for your detailed reply. 8)
Yeah, 'calc.mesh.DecimateHF' will be a really handy function. Great thing - looking forward to the next dev build!

Actually, I didn't consider the "edges could not perfectly match" problem. Doh, I do now see it is not just "cut and pipe through the decimator per tile".
While the "splitting edge triangles" approach might be the overall most effective method (in terms of final triangle count), I feel the "leave edge faces as they are" option could (maybe) be achieved more easily. Like, 'zoom in a bit', decimate, 'zoom out again' (I'm certainly not into the algorithms used, tho).
So, you might want to go for the latter concept first :?: - just to provide the functionality, before enhancing it even more?

Again, thanks.
miko
Contributing member
 
Posts: 26
Joined: Tue May 03, 2011 6:41 pm
Location: Regensburg, Germany

Re: calling ameshdecimator plugin

Postby Aaron » Sun May 15, 2011 1:02 pm

Hi Miko,

In the latest developmental build of L3DT (v2.9 build 19) I have included the new 'calc.mesh.DecimateHF' function. An example of calling the function is included below:

Code: Select all
CzFunc f;
if(!f.GetFunc("calc.mesh.DecimateHF")) {
  return false;
}

f.m_args.SetItemValueI(0, VarID_hvar, &hMap); // 1st argument is a handle to the heightfield

CzMesh m; // using the new CzMesh class
m.Create();
ZVAR hMesh = m;
f.m_args.SetItemValueI(1, VarID_hvar, &hMesh); // 2nd argument is a handle to the mesh

float MaxError = 2.0f; // or whatever you please
f.m_args.SetItemValueI(2, VarID_float, &MaxError); // 3rd argument is the MaxError value

unsigned long Flags = 0;
f.m_args.SetItemValueI(3, VarID_uint, &Flags); // 4th argument is flags, which should be left as 0 for now.

// execute the function
if(!f.Execute2()) {
   return false;
}

// get the function return value
bool rval = false;
if(!f.m_rval.GetValue(VarID_bool, &rval)) {
   return false;
}

// check the return value
if(!rval) {
   return false;
}

// now use the mesh object 'm'...


Please note that this function requires the use of the new 'CzMesh' class, which is available in the very latest version of the plugin API:

http://www.bundysoft.com/L3DT/downloads/zeolite/zeolite_v2.9.7.zip

In turn, this very latest version of the plugin API is only supported by L3DT v2.9 build 19 or later, so any plugin that uses this API version cannot be used with older versions of L3DT, including the current stable release.

Best regards,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: calling ameshdecimator plugin

Postby miko » Sun May 15, 2011 7:19 pm

Whoohoo, this is simply great! Thanks a lot for that fast response.
I'm going to give it a try over the coming days - will report back in case I get stuck or something :twisted:
miko
Contributing member
 
Posts: 26
Joined: Tue May 03, 2011 6:41 pm
Location: Regensburg, Germany

Re: calling ameshdecimator plugin

Postby miko » Mon May 16, 2011 6:38 pm

A few remarks, at first glance:

vectors.cpp
Code: Select all
vector3f VectorSet3f(vector3d v) { // double to float

Might be useful to type cast to float, to avoid compiler warnings. Same goes for
Code: Select all
vector3f VectorNormalise3f(vector3f v)


zMeshIO.cpp
Code: Select all
zeoReportError(_T(""));

Causes an Error with unicode apps. I believe the _T macro should be omitted.
Attachments
zMesh.zip
zMeshIO.cpp/vectors.cpp out of zeolite_v2.9.7, as I use them now
(3.8 KiB) Downloaded 1494 times
miko
Contributing member
 
Posts: 26
Joined: Tue May 03, 2011 6:41 pm
Location: Regensburg, Germany

Re: calling ameshdecimator plugin

Postby Aaron » Mon May 16, 2011 10:18 pm

Hi Miko,

Oops, thanks for pointing those errors/warnings out. Fixes will be included in the next update.

For what it's worth, you can find the source code of an example plugin that uses the mesh class here:

http://www.bundysoft.com/L3DT/downloads ... _X-src.zip

It's pretty rustic and poorly documented, but starting at line 219 in L3DTio_X.cpp you can see the code to write the mesh object out as a DirectX 'x' mesh file in text mode.

Best regards,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: calling ameshdecimator plugin

Postby miko » Sun May 22, 2011 2:12 pm

Okay, here is an update. First of all, let me state that the new CzMesh is really handy. It makes life a lot easier, and is fun to work with. :D

What I'm currently doing (still WIP):

- Add a new export option to the right-click menu
- Call an own export dlg and routine (as shown in the Atlas plugin)
- In the routine, always access the *full* HM, TX and TN maps
- Slice HM, TX and TN to tiles (if requested), by creating temp maps and copying over needed pixel ranges
- Pipe the sliced (tmp) HM field through 'calc.mesh.DecimateHF', to get a CzMesh (decimated; even non-decimated by submitting 'error=0.0')
- Calculate vertex normals of the mesh with an own routine
- export as textured/normal mapped (sliced) dxmesh terrain

Things I noted:

- The normals/normals indices of the CzMesh are not yet being filled, right? Or did I miss something (size of these buffers is always 0 over here)?
- How does 'calc.mesh.DecimateHF' currently handle tile (terrain) edges? I noticed, that after reduction, there are some "joining issues" with my tile maps (see Image1 attached). This would be as expected, if the decimation does not care about edges/seams. Now, when looking at Image2 attached, I see that *some* edges actually do remain with "high face density" (which would point to the fact that some edge/seam workaround is in place), while others do not. So, I'm not completely sure what the original intention was.
Attachments
Image2.png
Picture 2
Image2.png (85.76 KiB) Viewed 40493 times
Image1.png
Picture 1
Image1.png (188.17 KiB) Viewed 40493 times
miko
Contributing member
 
Posts: 26
Joined: Tue May 03, 2011 6:41 pm
Location: Regensburg, Germany

Re: calling ameshdecimator plugin

Postby Aaron » Mon May 23, 2011 1:02 pm

Hi Miko,

The current build doesn't generate vertex normals, nor does it properly tessellate all edges to full resolution. I have added these features to the next build, and am testing it presently. It should be available in the next day or so, weather permitting.

Best regards,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: calling ameshdecimator plugin

Postby Aaron » Tue May 24, 2011 10:57 pm

Hi Miko,

Just a quick progress report: There's a slight problem with the decimator that results in dodgy normal vectors on the brute-force tessellated triangles. This has been with us for a while, but is now particularly problematic with brute force tessellation of tile edges. I'll let you know when the fix is available. I apologise for any inconvenience caused by this delay.

Cheers,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: calling ameshdecimator plugin

Postby Aaron » Wed May 25, 2011 9:38 pm

Hi Miko,

The problem with the decimator is now fixed, or so it would seem. I will do some more testing just to make sure I can properly line up adjoining tiles. I'll probably have to build my own tiled mesh exporter for this.

Anyway, whilst I've got my head under the hood, I thought I might also add support for generating texture coordinates in the mesh decimator, and also support bump maps in the mesh material class (CzMeshMtl). I'll post back here when these changes are available.

By the way, out of curiosity, do you use the world-space terrain normals ("TN") or the tangent-space normals ("TN-tangent") ?

Cheers,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: calling ameshdecimator plugin

Postby Aaron » Thu May 26, 2011 12:59 pm

Hi Miko,

Great success! The geometry decimator and vertex normal generator have been fixed such that when used for tiled exports, the tiles overlap exactly, and there are no more wonky normals.

The screenshot below shows an area of the heightfield (shaded polygons) that I had split into 3x2 array of tiles and decimated, then exported from L3DT as a set of mesh files, and finally re-imported as mesh objects into Sapphire and overlaid on the normal heightfield geometry (wireframe):

MeshTileExportOverlay.png
MeshTileExportOverlay.png (354.82 KiB) Viewed 40457 times


This shows that there are no seams, and the geometry lines up as it should. I now need to tidy up these changes, comment the code, and test the texture coordinate generator. I'll post back here when the changes are available for your testing.

Cheers,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Next

Return to Plugins and scripts

Who is online

Users browsing this forum: No registered users and 3 guests

cron