Hard Light Productions Forums

Modding, Mission Design, and Coding => The Modding Workshop => Modding Tutorials => Topic started by: z64555 on January 14, 2011, 11:32:32 pm

Title: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: z64555 on January 14, 2011, 11:32:32 pm
Introduction

This is a simple tutorial that goes over the problem that sometimes arises when making a model for a game such as FS2. To start off, we'll go over a few definitions so that you'll know some terminology:







What is a Manifold Mesh?
A manifold mesh is essentially just a normal 3D model that is mesh or poly based. To my knowledge, patchs and NURBS based objects are not considered as a manifold mesh.

There are three types of manifold meshes that should be known: closed-, open-, and non-manifold meshes.


What is a Closed-Manifold Mesh?
A closed-manifold mesh has all of its edges sided by exactly 2 faces.


What is an Open-Manifold Mesh?
An open-manifold mesh has at least 1 edge that has only 1 face attached.


What is a Non-Manifold Mesh?
A non-manifold mesh has at least 1 edge that has more than 2 faces attached.


Open-  and Non-manifold meshes can have a significantly less Tri and Vertix count than closed meshes, but cannot be used in games such as FS2. This is because FS2 uses the mesh for collision detection of craft and weapon ordinance, as well as calculating the objects "mass." This latter calculation absolutely requires closed-meshes... and may be imagined as filling the inside of the mesh with "mass" just like you would fill up a bucket with water.

Luckily, there is a procedure available for 3DS Max users that allows the modeler to stitch up and close the open mesh.





Finding the Open- and Non-Manifold Errors






Types of Errors and How to Fix Them

There are four types of errors that the STL Check can find:






Conclusion
The Editable Poly type object is an insanely useful tool for gaming, especially when dealing with objects that have already been UVW mapped. They are also very useful in optimization, and, as this tutorial showed, invaluable in repairing non- and open-manifold meshes.

Remember to check your UVW mapping once you have done your modifications. There are some times when the UVW is changed during your operations.





Addendum: Reducing the Rendering Load Caused by the Addition of Unseen Faces

In many instances, there will be faces that will never be seen by the players on closed-manifold meshes. This poses an interesting problem efficiency wise, because the faces will still have a texture applied to them.

Luckily, for FS2 there is a special default texture known as "invisible.tga"

This texture is a unique stock texture that is 10x10 and has an alpha value of 255, but most importantly it has a significantly lower memory usage.

The solution then should become readily apparent: simply select all faces that will not be seen by the player, and apply the invisible.tga texture to them.

As a modeling aide in 3DS, you can "hide" the diffuse map (invisible.tga) in the maps rollout of the material editor, and use the "Self Illumination" and "Opacity" settings to make the invisible areas visible. Don't worry, when you export your model, the map will still be applied to the faces.


Additionally, there are some faces drawn between very close together points, such as a scaled down cap on a cylinder to represent a point. The STL Check modifier will not detect these. You can, however, easily weld together any vertix that's within a specified distance to another vertix by first selecting all verticies and then performing a "Weld within threshold" command.

(http://v7qtwq.blu.livefilestore.com/y1pigYwEznpX9rs7alznxavLCjeBtzEjU2VdUHZzyMEX-ajAw87Zgy9uLqpemT9x6fQa3saAbOgJeNDhe3auQF2cQ68sqV5liED/SZ_Manifold_002.jpg?psid=1)
Example of a 0m2 surface. The cone on the right is really a cylinder with the top face scaled way down.



(http://v7qtwq.blu.livefilestore.com/y1p_kc907sc3MXa5N5lOJ0K_A3lnO7t659GMu2lHvslJ2JQNWnwHDokcOV0hW0QBpiMA-GcAjHVSbNvPLoiAhd_wObr33kvDDo2/SZ_Manifold_003.jpg?psid=1)
Select all verticies of the object in question, and then press the "Settings" button near the "Weld" command either in the quad-menu (right click) or on the sidebar.



(http://v7qtwq.blu.livefilestore.com/y1pPSwkwifzByKdM_AHPByr2pn3IXNV49qpdwukAUDCpWJD574E9fIG66ibic29UfuqtdDHJqNqC5ET9JCEphAAi6QlY7pYvCvB/SZ_Manifold_004.jpg?psid=1)
Finally, press the up arrow (highlighted) until the "After" vertix count is lower than the "Before."

You can rotate and pan around in your veiwport while this dialog is open, which is useful to check for any possible distortion that might have occurred. If there is distortion, then you must either reduce your threshold or reduce your vertix selection to only the corners.





References:
STL Check Modifier (http://www.3dmax-tutorials.com/STL_Check_Modifier.html)
Fixing Non-Manifold Meshes (Video) (http://www.shapeways.com/video/fixing-non-manifold-meshes)
Wikipedia: Manifold (technical definitions) (http://en.wikipedia.org/wiki/Manifold)





Special Thanks:
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: FUBAR-BDHR on January 14, 2011, 11:41:46 pm
Where did you get the idea that only closed meshes can be used? 
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: z64555 on January 14, 2011, 11:54:16 pm
From the fact that none of the open-manifold's I've made have exported into PCS2?
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Shivan Hunter on January 15, 2011, 02:23:53 pm
Esarai's Kvasir (BP's Atalanta) is open-manifold
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Flipside on January 15, 2011, 02:30:42 pm
It can still cause problems the last time I checked, particularly with collision stuff.

Either way, thanks for the tutorial, it's probably safer not to have open-manifold meshes if for no other reason than the fact that manipulating that mesh can turn a non-connected point into a hole.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: z64555 on January 15, 2011, 05:36:52 pm
Your very welcome. If I didn't mention it before, if you have any suggestions for improvement of this tutorial, feel free to post.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Rampage on January 19, 2011, 01:54:25 am
To avoid most of these errors, just use Wings3D.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: JGZinv on January 19, 2011, 03:05:19 am
Very nice tut Z... clean looking and thought out too.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: z64555 on January 27, 2011, 12:51:38 am
Included "Addendum: Reducing the Rendering Load Caused by the Addition of Unseen Faces." to original post

Addendum: Reducing the Rendering Load Caused by the Addition of Unseen Faces

In many instances, there will be faces that will never be seen by the players on closed-manifold meshes. This poses an interesting problem efficiency wise, because the faces will still have a texture applied to them.

Luckily, for FS2 there is a special default texture known as "invisible.tga"

This texture is a unique stock texture that is 10x10 and has an alpha value of 255, but most importantly it has a significantly lower memory usage.

The solution then should become readily apparent: simply select all faces that will not be seen by the player, and apply the invisible.tga texture to them.

As a modeling aide in 3DS, you can "hide" the diffuse map (invisible.tga) in the maps rollout of the material editor, and use the "Self Illumination" and "Opacity" settings to make the invisible areas visible. Don't worry, when you export your model, the map will still be applied to the faces.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Col. Fishguts on January 27, 2011, 08:28:12 am
But doesn't this cause the engine to attempt an additional render pass with the "invisible" texture?
I vaguely remember that the engine doesn't render polygons with the "invisible" texture applied, but does it really stop the render pass early enough that you get a performance gain?
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: z64555 on January 27, 2011, 12:06:49 pm
But doesn't this cause the engine to attempt an additional render pass with the "invisible" texture?
I vaguely remember that the engine doesn't render polygons with the "invisible" texture applied, but does it really stop the render pass early enough that you get a performance gain?

Well, that, I'm not sure of. PCS2 responded very well when I applied a high-poly object with the texture, but there needs to be in-game testing to see if it's a truly viable option.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Vasudan Admiral on January 29, 2011, 05:08:20 am
Just to clarify a few things: FSO works fine with open edges, as does PCS2.

The part that would be causing problems here is the save to DAE from the 3d app - in this case Max. I can only speak from experience with the Blender DAE export script, but it does work fine with open edges. As such, if your DAE save operation is ok with it, then the best solution by far is to delete the internal faces completely, because that way they don't interfere with the rendering system, the collision system or the invisible texture system. (invisible polys do still get counted for collision calculations unless you have the dont-collide-invisible flag set in that ship's table.)

TBH I suspect there's more at work in this case than a problem of manifold vs non-manifold.

About the invisible texture trick - it's a clever idea definitely, however I would only recommend using it if you 1) HAVE to use completely manifold meshes (due to your DAE exporter as described above) and also 2) you have more than about 1000 faces that are completely internal and will never be seen. Otherwise it'd be extra work for both you and the collision detection system that would be basically of no benefit to the final result.

Anyway all other common errors in your tut are very much valid ones modellers should learn how to deal with. Nice work. :)
I'd also suggest adding how to find and deal with 0m² area faces, such as occur if you were making an antenna by taking a cylinder and shrinking one end-face of it down to something absolutely tiny so that it LOOKS like a point, but is not. Does Max have a way to detect that?
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Black Wolf on January 29, 2011, 05:34:52 am
Yeah, I just select all verts and weld all within a tiny threshhold. Gets rtid of them micely.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: z64555 on January 29, 2011, 02:08:30 pm
Just to clarify a few things: FSO works fine with open edges, as does PCS2.

The part that would be causing problems here is the save to DAE from the 3d app - in this case Max. I can only speak from experience with the Blender DAE export script, but it does work fine with open edges. As such, if your DAE save operation is ok with it, then the best solution by far is to delete the internal faces completely, because that way they don't interfere with the rendering system, the collision system or the invisible texture system. (invisible polys do still get counted for collision calculations unless you have the dont-collide-invisible flag set in that ship's table.)

TBH I suspect there's more at work in this case than a problem of manifold vs non-manifold.

I keep hearing about collision problems on some models because they were non-manifold, so the safest bet is to have at least 1 LOD that is a closed-manifold. Non-manifold's are by far more poly efficient in comparison to most manifolds, but can't hold water (theoritically speaking).


Quote
About the invisible texture trick - it's a clever idea definitely, however I would only recommend using it if you 1) HAVE to use completely manifold meshes (due to your DAE exporter as described above) and also 2) you have more than about 1000 faces that are completely internal and will never be seen. Otherwise it'd be extra work for both you and the collision detection system that would be basically of no benefit to the final result.

I plan on doing some collision tests of the mixed LOD's, with detail-0 a closed manifold and the others an non-manifold. I'm hoping that my guesses will work.  :p

Quote
Anyway all other common errors in your tut are very much valid ones modellers should learn how to deal with. Nice work. :)

Yay, I did something right! Thanks.

Quote
I'd also suggest adding how to find and deal with 0m² area faces, such as occur if you were making an antenna by taking a cylinder and shrinking one end-face of it down to something absolutely tiny so that it LOOKS like a point, but is not. Does Max have a way to detect that?

The STL check will only find what's mentioned in the tut, it doesn't find 0m2 surfaces. However, as BlackWolf mentioned, you can do a "Weld within threshold" command to take care of this easily.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Vasudan Admiral on January 29, 2011, 09:03:17 pm
Collision problems won't be specifically caused by non-manifold models - they'll be caused by some other issue that may or may not be related to the reason the mesh is non-manifold. IIRC, there were massive collision detection issues on the colossus, which I *think* were completely fixed by triangulating it prior to DAE export for example.

If you look at any model which displays sharp edges (ie, has not been 100% smoothed all over) then those edges you are looking at in PCS2 or FSO are actually holes, meaning pretty much every ship in FS is non-manifold in some way. The way it works is that each vertex on a model has a normal, and that normal is calculated as I think an average direction of the normals of all the faces that vert is a part of. Shading each face involves interpolating between the vertex normals of that face. As such, AFAIK in FS the only way to have a sharp edge where one face does not affect the shading of the one on the other side of the edge is to have separate verts that share the same location but have different normals. You can prove it by comparing the (true) vertex count of a faceted sphere vs a smoothed sphere after conversion. It's far lower on the smoothed sphere because there is no duplication of verts.

Oh and for the 0 area faces - bad example sorry. Try a scenario more like this: http://www.hard-light.net/wiki/index.php/File:BlenderErrorHoles.jpg (Imagine the hole on the bottom being filled with a face so that a STL check does not detect it) Here all 3 verts of the face are in a line rather than being close enough to weld. You'll need some kind of special selection tool to detect that. In blender for example you have a "Clean meshes" script that will delete 0 area faces, thus allowing select-non-manifold to detect those bits as problem areas.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: z64555 on January 30, 2011, 02:23:17 am
Ahh, yeah... that would be more of a problem in Max.

I don't know of any built-in tools to detect those, but there might be a Maxscript floating out there that would try to calculate the area of all selected faces, and then clean up the ones that have lower than some threshold...
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: zookeeper on January 30, 2011, 02:53:56 am
If you look at any model which displays sharp edges (ie, has not been 100% smoothed all over) then those edges you are looking at in PCS2 or FSO are actually holes, meaning pretty much every ship in FS is non-manifold in some way. The way it works is that each vertex on a model has a normal, and that normal is calculated as I think an average direction of the normals of all the faces that vert is a part of. Shading each face involves interpolating between the vertex normals of that face. As such, AFAIK in FS the only way to have a sharp edge where one face does not affect the shading of the one on the other side of the edge is to have separate verts that share the same location but have different normals. You can prove it by comparing the (true) vertex count of a faceted sphere vs a smoothed sphere after conversion. It's far lower on the smoothed sphere because there is no duplication of verts.

I can't be 100% sure whenever PCS2 is involved, but I still dare to say that's not true. I can export a model all the way from .max to .dae to .pof to .dae to .max to .dae to .pof and have the smoothing retained (although it does have a problem; after importing a .dae in Max, I can't actually manipulate the smoothing groups even though they are rendered right) without any kind of silly duplication of vertices in order to simulate smoothing.

I can't recall ever having seen such behaviour in any model (although I haven't looked at retail models much) and I get distinctly different-looking shading in-game depending on how I've smoothed the model in Max.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Col. Fishguts on January 30, 2011, 05:44:48 am
after importing a .dae in Max, I can't actually manipulate the smoothing groups even though they are rendered right) without any kind of silly duplication of vertices in order to simulate smoothing.

I also noticed this when importing a DAE file into max, even tough smooth groups can still be edited, it has zero effect on the model. I suspect it has something to do with the vertex normals, but I can't find a way to edit those in Max.

Does anyone know what the cause of this is?
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Droid803 on January 30, 2011, 12:35:37 pm
Convert it to editable poly, which will clear the smoothgroups entirely.
Then you can re-apply them.
Title: Re: Tutorial - Closing the Open-Manifold Mesh (3DS Max)
Post by: Col. Fishguts on January 31, 2011, 09:50:59 am
Convert it to editable poly, which will clear the smoothgroups entirely.
Then you can re-apply them.

It's already "editable poly" when it's imported, but converting to "editable patch" and back to poly/mesh works. Thanks :)