I need to implement an importer to 3ds Max that will load some custom mesh data. I have implemented most of the loading code, but I still have one problem to resolve.
The data format I need to use uses structures called 'Hard Edges' to describe surface smoothness, but the 3ds Max uses 'Smoothing Groups' and while both approaches work very well I need some way to convert one to the second.
Basically I have some mesh vertices/faces loaded into 3ds, now I need to compute Smoothing Groups for those faces, based on the list of hard edges in my file.
Can you point me to any algorithm or just any clue that will help me implement the conversion?
I tried to search google, etc., there are many tutorials and articles about smoothing groups but from the view of 3ds Max user (modeling). I can't find anything about doing the same with code (and I don't ask about API for doing this, I know the API but I need an algorithm to compute SGs).
OK, I've found some workaround...
It uses 3D MAX internal code instead of my own one but at least it works:
Let's assume I have a list or vector of edge structs:
struct Edge
{
int nEd0;
int nEd1;
};
And a function to check if an edge is in the list:
bool findHardEdge( int v1, int v2 );
Here is the code to compute Smoothing Groups from Hard Edges, using MNMesh class:
MNMesh mm = *pMesh; // pMesh contains vert/face data already and is copied to MNMesh
mm.FillInMesh(); // computes helper data in MNMesh
for( int i = 0; i < mm.nume; i++ ) // iterate over all edges
{
int v1 = mm.E(i)->v1;
int v2 = mm.E(i)->v2;
bool found = findHardEdge( v1, v2 ); // check if the edge is a 'hard' one
if( found )
mm.E(i)->SetFlag( 32 ); // mark an edge with some flag
}
mm.SmoothByCreases( 32 ); // this method does the job
mm.OutToTri( *pMesh ); // copy data back to the original mesh instance
I realize that this code is quite slow, especially for bigger meshes but it's also simplest thing I came up with. If you know any better way let me know :)