Maya + Direct3D

Started by
10 comments, last by MrDoomMaster 18 years, 8 months ago
I would like to use Maya to create my basic polygonal shapes and then import those into my Direct3D game. I want my imported shapes to act exactly as if I had manually created it with a vertex buffer. I read into X files. When you install the SDK, a plugin is installed into Maya. Yet, I am not sure if this plugin allows the features I want. Again, I want to create, for example, a cube in Maya and possibly apply some of my own textures (bitmaps) to the faces of it in the editor as well. If anyone could help, that would be very nice. Thank you!
Advertisement
there's a .x exporter for maya and i think it is included in the sdk...the plugin you're speaking of is the Maya Previwe pipeline i think. It will create a new D3DMaterial and you can associate a effect file(.fx) with this Material and directly view these effects in maya.

If you ahve installed the .x-exporter and want to use it you have to turn that plug-in on @Windows->Settings/Preferences->Plug-in Manager there should somewhere be a plug-in called D3DMaya65ExportX.mll just activate the loaded and auto-loaded checkbox.

regards,
m4gnus

"There are 10 types of people in the world... those who understand binary and those who don't."
Hmm now to only learn how to create a simple red cube. Any help? I just want to export a cube colored RED. No textures or anything. I can't seem to find a tutorial for this.

Thanks.
Is there an option to export vertex color?

Have you read this MSDN page? It looks like the new Maya exporter has an extension for effects and parameters. You may be able to do something with that.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
In the latest release the maya exporter supports a naive coversion of maya materials to D3DXMaterials in addition to HLSL/FX support
Which version of Maya are you using? If you have the option you should use Maya 5 and use a program called DeepExploration to export your models.
If you are using Maya 6 and that is your only option, be prepared to cry yourself to sleep everynight. To date I have yet to find an exporter that can successfully export everything (mesh,bones,materials/textures) from maya to .X
Every exporter that has released with every version of the SDK DO NOT WORK... some don't export materials, some export crazy meshes with backwards geometry, some don't export animations correctly....
If you really want to use Maya 6.0 I advise you look into a file format other than .X OR if you are adventurous.... have a look at this:

http://www.gamedev.net/reference/articles/article1906.asp

On another note... I am not sure what you mean when you say you want it to be like you created it with a VB.... when you use .X files you need to load them as D3DXMesh objects (D3DXLoadMeshFromX) but the meshes contain a vertex buffer... so it should work out.

Good Luck : /
The cheese stands alone.
Thanks for the replies guys.

I've given up on Maya, because the program is too complicated for me at the moment. I don't have the time to learn it right now. I was using Maya 7, for those who wanted to know. I could find no exporter for it.

Anyway, I'm using Truespace 6.5 now, since I'm pretty familiar with it. It has the option to "save as" an X file. I have done this, and I kind of have it displaying in my game. It is very distorted though. Have a look:

http://img.photobucket.com/albums/v356/MrDoomMaster/SS009.jpg

The link above shows the camera located at (0,3,3) and looking at (0,0,0). The Cube is centered and normalized. As you can see, the shape of the cube is fully intact, but the texture is all screwed up. In Truespace I didn't use any colors. I simply created a cube, and saved it. No modifications. I loaded the X file into the DXViewer, which shows you a preview of the cube. Below is the preview:

http://img.photobucket.com/albums/v356/MrDoomMaster/SS010.jpg

As you can see, the cube is completely fine. I just can't seem to get it displaying properly. I have no lights in my application, but still the cube should appear better than that you saw above. Below I will paste the code contained in a class of mine I use to load and display meshes, named CMesh:

//====================================================================================// Defines/Macros//====================================================================================//====================================================================================//====================================================================================// Includes//====================================================================================#include    <windows.h>#include    <d3d9.h>#include    <d3dx9.h>#include    <dxerr9.h>#include    <atlstr.h>#include    <math.h>#include    <vector>#include    "Shared.h"#include    "Display.h"#include    "Mesh.h"//====================================================================================//====================================================================================// Function Definitions//====================================================================================/******/DXLIB::CMesh::CMesh(CDisplay* DisplayObject) :    m_Display(DisplayObject),    m_Materials(NULL),    m_Textures(NULL),    m_DefaultTexture(NULL),    m_Mesh(NULL),    m_NumMaterials(0){    // TODO}//====================================================================================DXLIB::CMesh::~CMesh(void){    Cleanup();}//====================================================================================/******/int DXLIB::CMesh::LoadMesh(const char* Path){    if(!m_Display->IsInitialized())        return 0;    if(!m_DefaultTexture)        return 0;    ID3DXBuffer* MatBuffer;    D3DXMATERIAL* pMaterials;    if(FAILED(hr = D3DXLoadMeshFromX(Path, D3DXMESH_SYSTEMMEM, m_Display->GetDevice(),        NULL, &MatBuffer, NULL, &m_NumMaterials, &m_Mesh)))    {        return 0;    }    pMaterials = (D3DXMATERIAL*)MatBuffer->GetBufferPointer();    m_Materials = new D3DMATERIAL9[m_NumMaterials];    m_Textures  = new IDirect3DTexture9*[m_NumMaterials];    memset(m_Materials, 0, sizeof(D3DMATERIAL9) * m_NumMaterials);    memset(m_Textures, 0, sizeof(IDirect3DTexture9*) * m_NumMaterials);    for(UINT i = 0; i < m_NumMaterials; ++i)    {        m_Materials = pMaterials.MatD3D;        m_Materials.Ambient = m_Materials.Diffuse;        if(pMaterials.pTextureFilename)        {            if(FAILED(D3DXCreateTextureFromFile(m_Display->GetDevice(),                pMaterials.pTextureFilename, &m_Textures)))            {                Cleanup();                return 0;            }        }        else            m_Textures = m_DefaultTexture;    }    MatBuffer->Release();    return 1;}//====================================================================================/******/int DXLIB::CMesh::LoadDefaultTexture(const char* Path){    if(!m_Display->IsInitialized())        return 0;    if(m_DefaultTexture)        return 0;    if(FAILED(hr = D3DXCreateTextureFromFile(m_Display->GetDevice(), Path, &m_DefaultTexture)))        return 0;    return 1;}//====================================================================================/******/int DXLIB::CMesh::DrawMesh(void){    if(!m_Display->IsInitialized())        return 0;    for(UINT i = 0; i < m_NumMaterials; ++i)    {        m_Display->SetMaterial(&m_Materials);        m_Display->SetTexture(m_Textures);        if(FAILED(hr = m_Mesh->DrawSubset(i)))            return 0;    }    return 1;}//====================================================================================/******/void DXLIB::CMesh::Cleanup(void){    if(m_DefaultTexture)    {        m_DefaultTexture->Release();        m_DefaultTexture = 0;    }    if(m_Materials)        delete[] m_Materials;    if(m_Textures)    {        for(UINT i = 0; i < m_NumMaterials; ++i)        {            if(m_Textures)                m_Textures->Release();        }        delete[] m_Textures;        m_Textures = 0;    }    if(m_Mesh)    {        m_Mesh->Release();        m_Mesh = 0;    }}//====================================================================================


If you'll take a look at specifically the DrawMesh() and LoadMesh() functions, you can see how I load the X file and display it. Perhaps some of you more professional game developers can point out a mistake I'm making.

Above you'll notice that if a texture is attempting to be set which is actually a null pointer, I assign a default texture to it, which is nothing more than a simple 64x64 white bitmap.

Again, I thank everyone for helping. I feel sometimes as if I'll never understand these things...
I'm sorry for the bump, but I really need help on this. Can anyone help? Thanks!
There are 2 potential problems I can think of but I am not sure about either of them.....

First if you did not add any colors or anything in Truespace then maybe the cube does not have a material assigned to it... but the exporter may give it a default one when it creates the file so you may want to look in your .X file and see if there is any Materials for your cube... or you can try just creating a D3DMATERIAL and set everything to white and then just call setmaterial with that white material...

My other thought is that in all of your loops you set the last value as ++i meaning you increment i then go through the loop.... if the cube only has 1 material and it is at index 0 in its material array and you set the material to whatever is at index 1... it is just going to return some garbage data as your material.... so try changing your loops to i++ instead and see if that fixes it.


Hope this helps (I am really not sure either of my ideas is right).
The cheese stands alone.
You know you could write your own custom Maya exporter plugin.

I know it sounds quite daunting at first but once you get into it, its really not so bad - I've written quite a few now with varying functionality - its a terrific learning experience and a great thing to be able to say you can do (e.g. at a job interview - suprisingly few people know their way around the Maya API).

Rob Bateman has written an extrememly good tutorial on writing maya exporters.

This topic is closed to new replies.

Advertisement