Jump to content
  • Advertisement
Sign in to follow this  
zyfu0000

Why my model exported from 3dmax looks fragmentized

This topic is 3413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I developed a plugin for 3dmax to export static model only,it can work well when export some simple models like a phere or a box,but when it turns to more complex models like a teapot etc,it doesn't work well.It looks fragmentized. Please help to look at my code,is there somewhere incorrect? if (m_pGame) { m_pGame->ReleaseIGame(); m_pGame=NULL; } m_pGame=GetIGameInterface(); IGameConversionManager *cm=GetConversionManager(); cm->SetCoordSystem(IGameConversionManager::IGAME_D3D); m_pGame->InitialiseIGame(true); int nodeCount=m_pGame->GetTopLevelNodeCount(); m_nNodes=nodeCount; int materialCount=m_pGame->GetRootMaterialCount(); if (nodeCount==0) { MessageBox(GetActiveWindow(),"No nodes available to export","Realm Engine Exporter",MB_OK|MB_ICONERROR); m_pGame->ReleaseIGame(); return; } for (int nodeIndex=0;nodeIndex<nodeCount;nodeIndex++) { IGameNode *node=m_pGame->GetTopLevelNode(nodeIndex); IGameObject *obj=node->GetIGameObject(); if (obj->GetIGameType()!=IGameMesh::IGAME_MESH) { break; } obj->InitializeData(); IGameMesh *mesh=(IGameMesh*)obj; int vertCount=mesh->GetNumberOfVerts(); m_vertices=(ModelVertex*)realloc(m_vertices,sizeof(ModelVertex)*(m_header.nNumVertices+vertCount)); int faceCount=mesh->GetNumberOfFaces(); m_faces=(ModelFace*)realloc(m_faces,sizeof(ModelFace)*(m_header.nNumFaces+faceCount)); bool flags[65535]={false}; for (int i=0;i<faceCount;i++) { FaceEx *face=mesh->GetFace(i); m_faces[m_header.nNumFaces+i].nMaterialID=(face->matID-1); for (int j=0;j<3;j++) { int k=m_header.nNumVertices+face->vert[j]; m_faces[m_header.nNumFaces+i].nIndices[j]=k; if (flags[face->vert[j]]) { break; } Point3 p=mesh->GetVertex(face->vert[j]); m_vertices[k].fPos[0]=p.x; m_vertices[k].fPos[1]=p.y; m_vertices[k].fPos[2]=p.z; p=mesh->GetNormal(i,j); m_vertices[k].vNormal.x=p.x; m_vertices[k].vNormal.y=p.y; m_vertices[k].vNormal.z=p.z; p=mesh->GetMapVertex(1,face->vert[j]); m_vertices[k].fTexture[0]=p.x; m_vertices[k].fTexture[1]=p.y; flags[face->vert[j]]=true; } } m_header.nNumVertices+=vertCount; m_header.nNumFaces+=faceCount; } I would like to post the screenshot of my model,but I don't know how to post a picture on. Thank you !

Share this post


Link to post
Share on other sites
Advertisement
Well, for starters, I wouldn't try to convert inside your application. It is going to take you _alot_ longer to load models. I'd export in one format that your application expects. Especailly if you have to iterate through all the vertices, normals, and UVs to transform into a new coordinate system.

Looking at your code, that seems to be what you are doing.

I just went through this with MaxScript and converted as I exported.

It's hard to say what the problem is, because you aren't showing the data format coming out of max, or the data format coming into your application, or the data format after you convert it in your application. All I can tell from your code is that you get some data, and do some kind of conversion operations on it. I imagine the problem is there :P

What I did in my MaxScript was:
switch y and z components of every vertex
switch y and z components of every normal

switch the order of drawing for each face:
v0 v1 v2 becomes v0 v2 v1

and depending on the texture addressing mode:
either subtract V from the integer cieling of the largest V
or simply make V negative

It works fine so far.

You can also use "[" source "]" tags for your code. See the FAQ.

Share this post


Link to post
Share on other sites
Appreciate for your reply.
1. I need not to "switch y and z components of every vertex
switch y and z components of every normal",
because I'm using the "IGame" interface developed by Autodesk for game developers to use.See this:
"cm->SetCoordSystem(IGameConversionManager::IGAME_D3D);"
It has changed the coordsystem to D3D for me,so that is not the point.

As you said
"switch the order of drawing for each face:
v0 v1 v2 becomes v0 v2 v1
and depending on the texture addressing mode:
either subtract V from the integer cieling of the largest V
or simply make V negative",
I have tried,but it doesn't work.
Maybe there is something in my loading and drawing modul.I will check it out.



Share this post


Link to post
Share on other sites
Oh, I didn't know they developed an interface for conversion.

Hmm, I'd still do it in a seperate application though to save loading CPU, if you aren't already. Maybe you already are :) When I got to 3 models in my demo app it started taking 15 minutes to load up, until I preconverted everything.

Sorry, can't be more help.

Oh for posting images...why not just make your PC into an FTP as well? That's what I do. Almost all Windows version have ISS and you can easily set up an FTP directory with anonymous log in. Then I just use DynDNS.com to provide me with a free DNS. Most routers can do it automatically and keep it up to date even when your ISP changes your IP address.

It is very conveniant to just cut and paste images you want to show on forums into your ftp folder :)

Share this post


Link to post
Share on other sites
Oh,good advise,I will have a try.
You said you have to use 15 minutes to load only 3 models,oh that's crazy.I thank you may have problems in your loading code.I just sort the vertices by material,then to render.
By the way,is it hard to use MAXScript to develop a plugin?Will I need to take much time to learn MAXScript? :)

Share this post


Link to post
Share on other sites
I thought it was easy, but it is documented like crap. I had to get on the Area forums several times. The syntax isn't hard. It's just figuring out how they store the different things you need access to. For example I thought I could iterate through UVs and they matched Vertices, but you have to get the face from a map channel, get 3 indices to UVS, and then get the UVs. Stuff like that.

It took me about 3 days to get basic position, normal, uv, and texture filenames out in script.

Probably easier for someone whose used max itself for awhile.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!