Sign in to follow this  
D3DXVECTOR3

3ds Max Exporter (Vertices and Matrices)

Recommended Posts

I'm writing an exporter plugin for 3ds max and I have a problem getting the vertices. The vertices I get are already scaled/rotated/translated, but I want them from the origin so that I can set the scale/rotation/translation via the matrices. I cant find any info about this, its for 3ds Max 5 btw :) One more thing is there a way to get just the name of the texture and not the full path!? ie "Metal.jpg" and not "C:\3ds Max\Maps\Metal.jpg"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
1. You can get the current transformation matrix of each node. Just build the inverse and apply it to the vertices and you'll get your vertices in object space. I've decided not to do that and store my vertices in worldspace and also provide the the local matrix (along with hierachy). That's very nice if you just want to write or debug your fileformat (since you can leave out all the math and get something usable on the screen).

2. If you really think that's a wise idea write that on your own.

If I remember right there was a function called splitpath that does the work for you.. Otherwise char * name = strrchr (string, '\')+1 does the trick.



Share this post


Link to post
Share on other sites
Quote:

One more thing is there a way to get just the name of the texture and not the full path!? ie "Metal.jpg" and not "C:\3ds Max\Maps\Metal.jpg"


I do exactly that in my Milkshape3D exporter by using the following simple function:

std::string cPlugIn::ExtractNameFromAbsolutePath( std::string& str )
{
// just modify the str
std::string texName;
int len = 0;
len = (int)( str.size() );
for ( int i = len-1; i >=0; i-- )
{
if ( str[i] == '\\' || str[i] == '/' )
break;
}
// last '\' is in i index
texName = str.substr( i+1, len-i-1 );// copy the texture name
return texName;
}



I use std::string for flexibility. It takes std::string as param, but i can send a char* by using: string( strPtr )

Share this post


Link to post
Share on other sites
^^ Thanks for the code :)

The reason why I want the vertices in object space is because some object are scaled with -1 and for some reason they are not applied to the vertices when exporting.

The function in the SDK is BMMSplitFilename. This will split the file into path, file and the extention.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
[Quote]
How do I apply the inverse to the vertices?
[/Quote]
Multiply the vertex coords with it. With the normal you have to be more careful, since you normally transform a normal with the inverse transpose of transformation matrix.
If you use DX you want to look the functions
D3DXTransformCoord() and D3DXTransformNormal(). For the case you have to create you matrix from a translation vector, a scale vector and rotation quaternion there is function for this as well. Look for something like D3DXAffineTransformation() - IIRC.
If you want to decompose the matrix you can use D3DXDecomposeMatrix().

[Quote]
is there a way to get just the name of the texture and not the full path
[/Quote]


std::string( pFilename ) str;
std::string::size_type pos = str.find_last_of( "\\" );
std::string tex = str.substr( pos );



Hence that you must use std::string::size_type, using int could cause some hard to find bugs. See "The C++ Standard Library" for an explanation of this.


Share this post


Link to post
Share on other sites
Hi I wrote an exporter for 3ds Max 5. It exports meshes/skeletal animation using the IGame interface. I provide the full source and a brief tutorial on how to create your own. Basically why I do is make the object and IGame Object and query the interface to return all the info I want.

Share this post


Link to post
Share on other sites
IIRC, you can get your vertices untransformed from 3dsmax...
I did have the same problem in the begining, this because one of the interface functions did give you an transformed mesh/node you can get the same data untransformed by calling another function insted. right now i can recall what the names of the invloved functions was, but seek and you shall find =)

good luck!

// ziruz

Share this post


Link to post
Share on other sites
IMO, the documentation is some of the worst I've ever encountered in a professional application. Don't count on being able to pull anything good out of it at all. It's very slim on actual information, and what there is is so badly organised it's impossible to find.

Share this post


Link to post
Share on other sites
In later stadium of my project, I'll be very kind if I add one 3D Studio Max file format importer. Well, forgive me on my laziness but I'll be grateful if you will say me - where to start with making this.

Share this post


Link to post
Share on other sites
I used this tutorial for the exporter: http://sparks.discreet.com/knowledgebase/techdocs/searchable/techdoc_exporter/EXPORTER_LAB.htm
Its an ASCII like format but you can see how 2 extracts all data.

I 1st had it like this :
Matrix3 tm = node->GetObjTMAfterWSM(currtime);
and multiplid the vertices with this matrix.

I tried this:
Matrix3 tm = node->GetObjTMBeforeWSM(currtime);
but this 1 has makes all object in its original size.

Is the same as the 1st one so I will use this since this is the matrix from the node itself.
Matrix3 tm = node->GetNodeTM(currtime);


I looks like that the problem that I have has nothing 2 do with the matrices but with face normals. I thought that by storing the vertex normals everything would be fine, but a vertex is just a point in 3d space and has no normal. A face has a normal.
I now have the normal for each face but I dont know what 2 do with this info. A vertex connects with several faces with different normals and UV's. How do I apply this on indices vertices!?

Share this post


Link to post
Share on other sites
Actually I think the vertices should be untransformed when you get them, unless you have applied an reset xform modifier. I wouldnt trust this though, better do as the previous posters suggested.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this