Making a world
Say I wanted to make a world (like in any RPG), and load it into DirectX, how would I go about doing this?
you could make a world in a 3d modelling program
and then export as a .x file
then load and render it in direct3d
and then export as a .x file
then load and render it in direct3d
In the DX SDK there is built in support for .x files, Milkshape is a good program for working with models and it has a .x file exporter. In order to get it to work though, you will need to know more about directx, I suggest finding a book on it, on half.com you usually can find a good deal on used DirectX books.
Lata,
Ben
Lata,
Ben
This is what it says in the DX SDK help:
<b>Loading an X File</b>
<i>Use the following procedure to load an .x file.
Use the DirectXFileCreate function to create an IDirectXFile object.
If templates are present in the Microsoft® DirectX® file that you will load, use the IDirectXFile::RegisterTemplates method to register those templates.
Use the IDirectXFile::CreateEnumObject method to create an IDirectXFileEnumObject enumerator object.
Loop through the objects in the file. For each object, perform the following steps.
Use the IDirectXFileEnumObject::GetNextDataObject method to retrieve each IDirectXFileData object.
Use the IDirectXFileData::GetType method to retrieve the data''s type.
Load the data using the IDirectXFileData::GetData method.
If the object has optional members, retrieve the optional members by calling the IDirectXFileData::GetNextObject method.
Release the IDirectXFileData object.
Release the IDirectXFileEnumObject object.
Release the IDirectXFile object. </i>
One word "?" =P anyone have any actual CODE?
<b>Loading an X File</b>
<i>Use the following procedure to load an .x file.
Use the DirectXFileCreate function to create an IDirectXFile object.
If templates are present in the Microsoft® DirectX® file that you will load, use the IDirectXFile::RegisterTemplates method to register those templates.
Use the IDirectXFile::CreateEnumObject method to create an IDirectXFileEnumObject enumerator object.
Loop through the objects in the file. For each object, perform the following steps.
Use the IDirectXFileEnumObject::GetNextDataObject method to retrieve each IDirectXFileData object.
Use the IDirectXFileData::GetType method to retrieve the data''s type.
Load the data using the IDirectXFileData::GetData method.
If the object has optional members, retrieve the optional members by calling the IDirectXFileData::GetNextObject method.
Release the IDirectXFileData object.
Release the IDirectXFileEnumObject object.
Release the IDirectXFile object. </i>
One word "?" =P anyone have any actual CODE?
// -------------------------------------------------------------
// mesh.h
// -------------------------------------------------------------
// -------------------------------------------------------------
// mesh.cpp
// mesh.h
class CMesh_X{protected: IDirect3DDevice9* m_pd3dDevice; ID3DXMesh* m_pMesh; D3DMATERIAL9* m_pMaterials; IDirect3DTexture9** m_pTextures; DWORD m_dwNumMaterials;public: CMesh_X(); ~CMesh_X() { Destroy(); } bool Create(IDirect3DDevice9* pd3dDevice, LPCTSTR pFilename); void Destroy(); bool Render();};
// -------------------------------------------------------------
// -------------------------------------------------------------
// mesh.cpp
#include <d3dx9.h>#include "mesh.h"CMesh_X::CMesh_X(){ m_pd3dDevice = NULL; m_pMesh = NULL; m_pMaterials = NULL; m_pTextures = NULL; m_dwNumMaterials = 0L;}bool CMesh_X::Create(IDirect3DDevice9* pd3dDevice, LPCTSTR pFilename){ m_pd3dDevice = pd3dDevice; ID3DXBuffer* pAdjacencyBuffer = NULL; ID3DXBuffer* pMtrlBuffer = NULL; // Load the mesh from the specified file if( FAILED( D3DXLoadMeshFromX(pFilename, D3DXMESH_SYSTEMMEM, pd3dDevice, &pAdjacencyBuffer, &pMtrlBuffer, NULL, &m_dwNumMaterials, &m_pMesh) ) ) return false; // Allocate memory for the materials and textures m_pMaterials = new D3DMATERIAL9[m_dwNumMaterials]; m_pTextures = new LPDIRECT3DTEXTURE9[m_dwNumMaterials]; // Optimize the mesh if( FAILED( m_pMesh->OptimizeInplace(D3DXMESHOPT_COMPACT|D3DXMESHOPT_ATTRSORT|D3DXMESHOPT_VERTEXCACHE, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL, NULL) ) ) return false; // Get the materials and texture names from the material buffer D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); // Copy each material and create its texture for( DWORD i=0; i<m_dwNumMaterials; i++ ) { // Copy the material m_pMaterials = d3dxMaterials.MatD3D;<br> m_pTextures = NULL;<br><br> // Set the ambient color for the material (D3DX does not do this)<br> m_pMaterials.Ambient = m_pMaterials.Diffuse;<br><br> // Create texture<br> if( d3dxMaterials.pTextureFilename != NULL && lstrlen(d3dxMaterials.pTextureFilename) > 0 )<br> D3DXCreateTextureFromFile(pd3dDevice, d3dxMaterials.pTextureFilename, &m_pTextures);<br> }<br><br> // Release the adjacency buffer<br> if( pAdjacencyBuffer )<br> pAdjacencyBuffer->Release();<br><br> // Release the material buffer<br> if( pMtrlBuffer )<br> pMtrlBuffer->Release();<br><br> return true;<br>}<br><br>void CMesh_X::Destroy()<br>{<br> if( m_pMaterials )<br> {<br> delete[] m_pMaterials;<br> m_pMaterials = NULL;<br> }<br><br> if( m_pTextures )<br> {<br> for( DWORD i=0; i < m_dwNumMaterials; i++ )<br> {<br> if( m_pTextures )<br> {<br> m_pTextures->Release();<br> m_pTextures = NULL;<br> }<br> }<br> delete[] m_pTextures;<br> m_pTextures = NULL;<br> }<br><br> if( m_pMesh )<br> {<br> m_pMesh->Release();<br> m_pMesh = NULL;<br> }<br>}<br><br>bool CMesh_X::Render()<br>{<br><br> // Meshes are divided into subsets, one for each material. Render them in a loop<br> for( DWORD i=0; i<m_dwNumMaterials; i++ )<br> {<br> // Set the material and texture for this subset<br> m_pd3dDevice->SetMaterial(&m_pMaterials);<br> m_pd3dDevice->SetTexture(0, m_pTextures);<br> <br> // Draw the mesh subset<br> m_pMesh->DrawSubset(i);<br> }<br><br> return true;<br>}<br> </pre> </i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement