本文整理汇总了C++中D3DXLoadMeshFromX函数的典型用法代码示例。如果您正苦于以下问题:C++ D3DXLoadMeshFromX函数的具体用法?C++ D3DXLoadMeshFromX怎么用?C++ D3DXLoadMeshFromX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了D3DXLoadMeshFromX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strcpy
Mesh::Mesh(char *catalog, char *filename)
{
char filepath[222];
LPD3DXBUFFER pMtrlBuffer = NULL;
pAdjBuffer = 0;
strcpy(filepath, catalog);
strcat(filepath, filename);
if (FAILED(D3DXLoadMeshFromX(filepath, D3DXMESH_MANAGED, gdevice,
&pAdjBuffer, &pMtrlBuffer, NULL, &Mtnum, &m_pmesh))) {
MessageBox(0, "load mesh fail ", 0, 0);
return;
}
//二,读取材质和纹理数据
D3DXMATERIAL*pMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); //创建一个D3DXMATERIAL结构体用于读取材质和纹理信息
pMaterial = new D3DMATERIAL9[Mtnum];
pTexture = new LPDIRECT3DTEXTURE9[Mtnum];
for (DWORD i = 0; i<Mtnum; i++) {
//获取材质,并设置环境光的颜色值
pMaterial[i] = pMtrls[i].MatD3D;
pMaterial[i].Ambient = pMaterial[i].Diffuse;
strcpy(filepath, catalog);
strcat(filepath, pMtrls[i].pTextureFilename);
if(FAILED(D3DXCreateTextureFromFileA(gdevice, filepath, &pTexture[i])))
MessageBox(0, "load mesh texture fail ", 0, 0);
}
LoadData(); // load vertex and face
RELEASE(pMtrlBuffer);
}
示例2: initGeometry
HRESULT initGeometry(){
LPD3DXBUFFER pD3DXMtrlBuffer;
if(FAILED(D3DXLoadMeshFromX(L"Heli.x", D3DXMESH_MANAGED,
g_pDevice, NULL, &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, &g_pMesh)))
return E_FAIL;
//Extract material & texture
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
if(g_pMeshMaterials == NULL)
return E_OUTOFMEMORY;
g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];
if(g_pMeshTextures == NULL)
return E_OUTOFMEMORY;
//Extract
for(DWORD i=0; i<g_dwNumMaterials; ++i){
g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;
g_pMeshTextures[i] = NULL;
if(d3dxMaterials[i].pTextureFilename != NULL && strlen(d3dxMaterials[i].pTextureFilename) > 0){
WCHAR name[256];
removePathFromFileName(d3dxMaterials[i].pTextureFilename, name);
if(FAILED(D3DXCreateTextureFromFile(g_pDevice, name, &g_pMeshTextures[i]))){
MessageBox(NULL, L"Cound not find texture file", L"initGeometry()", MB_OK);
}
}
}
pD3DXMtrlBuffer->Release();
return S_OK;
};
示例3: CleanUpMesh
HRESULT Mesh::LoadMesh(WCHAR* directory, WCHAR* name, WCHAR* extension)
{
HRESULT hr;
CleanUpMesh();
SetDirectory( directory );
SetName( name );
WCHAR meshfile[120];
WCHAR meshpathrel[120];
WCHAR meshpath[120];
Concat(meshfile, name, extension );
Concat(meshpathrel, directory, meshfile );
AppendToRootDir(meshpath, meshpathrel);
hr = D3DXLoadMeshFromX( meshpath,
D3DXMESH_MANAGED | D3DXMESH_32BIT, mDevice, NULL,
&mMaterialBuffer, NULL, &mNumMaterials, &mMesh );
PD(hr, L"load mesh from file");
if(FAILED(hr)) return hr;
mMaterials = (D3DXMATERIAL*)mMaterialBuffer->GetBufferPointer();
PD( AdjustMeshDecl(), L"adjust mesh delaration" );
PD( AttribSortMesh(), L"attribute sort mesh" );
PD( LoadTextures(), L"load textures" );
PD( CreateTopologyFromMesh(), L"create topology from mesh");
return D3D_OK;
}
示例4: D3DXLoadMeshFromX
void x_mesh_t::load( LPCWSTR file_name, LPDIRECT3DDEVICE9 device )
{
ID3DXBuffer *materials_buf = NULL;
HRESULT hr = D3DXLoadMeshFromX(file_name, 0, device, NULL, &materials_buf, NULL, &m_materials_count, &m_mesh);
if (hr != ERROR_SUCCESS)
return;
D3DXMATERIAL *materials_array = (D3DXMATERIAL *)materials_buf->GetBufferPointer();
m_materials = new D3DMATERIAL9[m_materials_count];
m_textures = new texture_t[m_materials_count];
bool result;
for (DWORD i = 0; i < m_materials_count; ++i)
{
m_materials[i] = materials_array[i].MatD3D;
m_materials[i].Ambient = m_materials[i].Diffuse;
std::wstring str;
A2W(str, std::string(materials_array[i].pTextureFilename));
result = m_textures[i].load(device, str.c_str());
}
if (materials_buf)
materials_buf->Release();
m_mesh->OptimizeInplace(D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT, NULL, NULL, NULL, NULL);
}
示例5: ObjectInit
bool ObjectInit(HWND hwnd)
{
srand(unsigned(time(nullptr)));
PlaySound(_T("コミネリサ - Resuscitated Hope.wav"), nullptr, SND_ASYNC | SND_FILENAME | SND_LOOP);
D3DXCreateFont(gPD3DDevice, 30, 0, 0, 0, 0, 0, 0, 0, 0, _T("微软雅黑"), &gPTextAdapterFont);
D3DXCreateFont(gPD3DDevice, 20, 0, 0, 0, 0, 0, 0, 0, 0, _T("华文中宋"), &gPTextHelperFont);
D3DXCreateFont(gPD3DDevice, 30, 0, 0, 0, 0, 0, 0, 0, 0, _T("黑体"), &gPTextInfoFont);
D3DXCreateFont(gPD3DDevice, 36, 0, 0, 0, 0, 0, 0, 0, 0, _T("楷体"), &gPTextFPSFont);
//////////////////////////////////////////////////////////////////////////
// Load mesh and materials here
//////////////////////////////////////////////////////////////////////////
LPD3DXBUFFER pAdjBuffer;
LPD3DXBUFFER pMtrlBuffer;
D3DXLoadMeshFromX(_T("loli.X"), D3DXMESH_MANAGED, gPD3DDevice, &pAdjBuffer, &pMtrlBuffer, nullptr, &gDwNumMtrl, &gPCharacter);
D3DXMATERIAL* pMaterial = (D3DXMATERIAL*)(pMtrlBuffer->GetBufferPointer());
gPMaterial = new D3DMATERIAL9[gDwNumMtrl];
gPTexture = new LPDIRECT3DTEXTURE9[gDwNumMtrl];
for (DWORD i = 0; i < gDwNumMtrl; i++)
{
gPMaterial[i] = pMaterial->MatD3D;
gPMaterial[i].Ambient = gPMaterial[i].Diffuse;
gPTexture[i] = nullptr;
D3DXCreateTextureFromFileA(gPD3DDevice, pMaterial[i].pTextureFilename, &gPTexture[i]);
}
pAdjBuffer->Release();
SAFE_RELEASE(pMtrlBuffer);
// 设置渲染状态
gPD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); //开启背面消隐
gPD3DDevice->SetRenderState(D3DRS_AMBIENT, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f)); //设置环境光
return true;
}
示例6: OnInitial
void OnInitial(DEVICEINSTANCE *device)
{
XInputEnable(true);
D3DXMATRIX projection;
D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI / 4, 800 / 600.0f, 1.0f, 10000.0f);
device->d3dDevice->SetTransform(D3DTS_PROJECTION, &projection);
D3DXLoadMeshFromX(L"skybox.x", 0, device->d3dDevice, nullptr, nullptr, nullptr, nullptr, &skybox);
D3DXCreateTextureFromFile(device->d3dDevice, L"sky copy.png", &texture);
D3DXCreateTextureFromFile(device->d3dDevice, L"terrain_01.jpg", &heightMap);
D3DXCreateTextureFromFile(device->d3dDevice, L"terrain_02.jpg", &heightMapTexture);
D3DXIMAGE_INFO heightMapInfo = { 0, };
D3DXGetImageInfoFromFile(L"terrain_01.jpg", &heightMapInfo);
terrainWidth = heightMapInfo.Width; terrainHeight = heightMapInfo.Height;
D3DCOLOR * colors;
D3DLOCKED_RECT lockedRect = { 0, };
RECT rect = { 0, 0, terrainWidth, terrainHeight };
terrainVertices = new TerrainVertex[numOfVertices = terrainWidth * terrainHeight];
heightMap->LockRect(0, &lockedRect, &rect, 0);
colors = (D3DCOLOR*)lockedRect.pBits;
TerrainVertex * tempVertices = terrainVertices;
for (int x = 0; x < terrainHeight; x++)
{
for (int z = 0; z < terrainWidth; z++)
{
int location = x * terrainWidth + z;
*tempVertices = TerrainVertex(
(x - terrainWidth / 2) * 5.0f, (colors[location] & 0xff) * 5.0f / 2,
(z - terrainWidth / 2) * 5.0f,
z / (float)terrainWidth, x / (float)terrainHeight
);
tempVertices++;
}
}
heightMap->UnlockRect(0);
heightMap->Release();
terrainIndices = new int[numOfIndices = (terrainWidth - 1) * (terrainHeight - 1) * 2 * 3];
struct Polygon { int index[3]; } *tempIndices = (Polygon*)terrainIndices;
for (int z = 0; z < terrainHeight - 1; z++)
{
for (int x = 0; x < terrainWidth - 1; x++)
{
(*tempIndices).index[0] = z * terrainWidth + x;
(*tempIndices).index[1] = z * terrainWidth + (x + 1);
(*tempIndices).index[2] = (z + 1) * terrainWidth + x;
tempIndices++;
(*tempIndices).index[0] = (z + 1) * terrainWidth + x;
(*tempIndices).index[1] = z * terrainWidth + (x + 1);
(*tempIndices).index[2] = (z + 1) * terrainWidth + (x + 1);
tempIndices++;
}
}
}
示例7: CreateMeshFromFileX
BOOL DMeshRender::CreateMeshFromFileX(LPCWSTR pFileName, DWORD options)
{
LPD3DXBUFFER ppAdjacency;
LPD3DXBUFFER ppMaterials;
LPD3DXBUFFER ppEffectInstances;
DWORD NumMaterials;
if (FAILED(D3DXLoadMeshFromX(pFileName, options, DDEInitialize::gRootDevice,
&ppAdjacency, &ppMaterials, &ppEffectInstances, &NumMaterials, &m_pMess)))
return FALSE;
D3DXMATERIAL *pMtrls = (D3DXMATERIAL*)ppMaterials->GetBufferPointer();
LPDIRECT3DTEXTURE9 tmpTexture = nullptr;
for (DWORD matRenderIndex = 0; matRenderIndex < NumMaterials; matRenderIndex++)
{
if (!FAILED(D3DXCreateTextureFromFileA(DDEInitialize::gRootDevice, pMtrls[matRenderIndex].pTextureFilename, &tmpTexture)))
{
DMaterialRender* matRender = new DMaterialRender(m_gameObj, 0, pMtrls[matRenderIndex].MatD3D, tmpTexture);
m_matRenders.push_back(matRender);
}
}
m_isEnabled = TRUE;
return TRUE;
}
示例8: D3DXLoadMeshFromX
DummyFace::DummyFace() {
m_pMesh = NULL;
m_pTexture = NULL;
D3DXLoadMeshFromX("resources/face01.x", D3DXMESH_MANAGED, g_pDevice, NULL, NULL, NULL, NULL, &m_pMesh);
D3DXCreateTextureFromFile(g_pDevice, "resources/face.jpg", &m_pTexture);
}
示例9: D3DXLoadMeshFromX
void Mesh::loadMesh(LPCWSTR filename, pBuffer adjBuffer)
{
pDevice device = Engine::DX::instance()->getDevice();
D3DXLoadMeshFromX(filename,
D3DXMESH_MANAGED,
device,
&adjBuffer,
&mat_buffer,
&effect,
&numMaterials,
&mesh);
// Pull material (including texture) information from loaded .x file
D3DXMATERIAL *d3dxMaterials = (D3DXMATERIAL*)mat_buffer->GetBufferPointer();
D3DMATERIAL9* mesh_material = new D3DMATERIAL9[numMaterials];
for(DWORD i = 0; i < numMaterials; ++i)
{
//Copy the material
mesh_material[i] = d3dxMaterials[i].MatD3D;
//Set the ambient color (if needed) for the material (D3DX doesn't do this)
mesh_material[i].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
}
for(unsigned int i = 0; i < numMaterials; i++){
materials.push_back(mesh_material[i]);
}
delete [] mesh_material;
}
示例10: init_geometry
//=======================================================================
HRESULT init_geometry()
{
LPD3DXBUFFER pD3DXMtrlBuffer;
{ // try load mesh from x-file
HRESULT hr = D3DXLoadMeshFromX(g_xFname, D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, NULL, &g_materialNums,
&g_pMesh);
if ( FAILED( hr ) ) return E_FAIL;
}
// init material & texture
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
g_pMeshMaterials = new D3DMATERIAL9[g_materialNums];
g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_materialNums];
for (int i = 0; i < g_materialNums; ++i) {
g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;
g_pMeshTextures[i] = NULL;
if (d3dxMaterials[i].pTextureFilename != NULL
&& lstrlen(d3dxMaterials[i].pTextureFilename) > 0 ) {
HRESULT hr = D3DXCreateTextureFromFile( g_pd3dDevice,
d3dxMaterials[i].pTextureFilename,
&g_pMeshTextures[i]);
if ( FAILED( hr ) ) return E_FAIL;
}
}
pD3DXMtrlBuffer->Release();
return S_OK;
}
示例11: Load
bool Mesh::Load(LPDIRECT3DDEVICE9 device, const char* filename, TextureManager* textureManager)
{
if(FAILED(D3DXLoadMeshFromX(filename, D3DXMESH_SYSTEMMEM, device, NULL, &m_materialBuffer, NULL, &m_numberOfMaterials, &m_mesh)))
{
return false;
}
m_filename = filename;
m_materials = new D3DMATERIAL9[m_numberOfMaterials];
m_meshTextures = new Texture*[m_numberOfMaterials];
D3DXMATERIAL* loadedMaterials = (D3DXMATERIAL*)m_materialBuffer->GetBufferPointer();
for(DWORD i = 0; i < m_numberOfMaterials; i++)
{
m_materials[i] = loadedMaterials[i].MatD3D;
m_materials[i].Ambient = m_materials[i].Diffuse;
char* textureFilename = loadedMaterials[i].pTextureFilename;
if(textureManager->Load(device, textureFilename))
{
m_meshTextures[i] = textureManager->GetTexture(textureFilename);
}
else
{
m_meshTextures[i] = NULL;
}
}
return true;
}
示例12: LoadMesh
HRESULT LoadMesh(IDirect3DDevice9* pd3dDevice, WCHAR* strFileName, ID3DXMesh** ppMesh)
{
ID3DXMesh* pMesh = NULL;
WCHAR str[MAX_PATH];
HRESULT hr;
V_RETURN(DXUTFindDXSDKMediaFileCch(str, MAX_PATH, strFileName));
V_RETURN(D3DXLoadMeshFromX(str, D3DXMESH_MANAGED, pd3dDevice, NULL, NULL, NULL, NULL, &pMesh));
DWORD* rgdwAdjacency = NULL;
if(!(pMesh->GetFVF() & D3DFVF_NORMAL))
{
ID3DXMesh* pTempMesh;
V(pMesh->CloneMeshFVF(pMesh->GetOptions(),
pMesh->GetFVF() | D3DFVF_NORMAL,
pd3dDevice, &pTempMesh));
V(D3DXComputeNormals(pTempMesh, NULL));
SAFE_RELEASE(pMesh);
pMesh = pTempMesh;
}
rgdwAdjacency = new DWORD[pMesh->GetNumFaces() * 3];
if(rgdwAdjacency == NULL)
return E_OUTOFMEMORY;
V(pMesh->GenerateAdjacency(1e-6f, rgdwAdjacency));
V(pMesh->OptimizeInplace(D3DXMESHOPT_VERTEXCACHE, rgdwAdjacency, NULL, NULL, NULL));
delete []rgdwAdjacency;
*ppMesh = pMesh;
return S_OK;
}
示例13: APP_ERROR
//------------------------------------------------------------------------------------------------
// Name: obtainSourceGeometry
// Desc: Loads geometry from the source file into the output subset geometry
//------------------------------------------------------------------------------------------------
bool XMesh::obtainSourceGeometry(LPDIRECT3DDEVICE9 pd3dDevice, SubsetGeometry* subsetGeometry) const
{
// Fail without a device or if something is wrong with the output pointer
if (APP_ERROR(!pd3dDevice || !subsetGeometry)("Invalid paramter to obtainSourceGeometry") ||
APP_ERROR(!subsetGeometry->empty())("Provided geometry subset for obtainSourceGeometry must be empty"))
return false;
// Check to make sure a file exists (if not, just exit)
if (mySourceFile.getValue().empty()) return true;
// Keeps track of how many subsets this mesh contains
DWORD subsets = 0;
// Stores the mesh that was loaded from the file
LPD3DXMESH pXMesh = NULL;
// Load the mesh from the specified file
if (APP_ERROR(D3DXLoadMeshFromX(mySourceFile.getValue().c_str(), D3DXMESH_SYSTEMMEM,
pd3dDevice, NULL, NULL, NULL, &subsets,
&pXMesh))("XMesh couldn't load \"%s\"", mySourceFile.getValue().c_str()))
return false;
// Convert the mesh
bool succeeded = buildGeometryFromD3DXMesh(pXMesh, subsetGeometry, subsets);
// Release the mesh
pXMesh->Release();
// Return an error code if an error occurred
if (APP_ERROR(!succeeded)("Unable to build geometry for mesh from \"%s\"", mySourceFile.getValue().c_str()))
return false;
// Success
return true;
}
示例14: D3DXLoadMeshFromX
void GameObject::InitMesh(LPDIRECT3DDEVICE9& d3dDevice)
{
LPD3DXBUFFER pD3DXMtrlBuffer = nullptr;
if ( d3dDevice )
D3DXLoadMeshFromX( L"spaceMan.x", D3DXMESH_SYSTEMMEM,
d3dDevice, NULL,
&pD3DXMtrlBuffer, NULL, &m_NumMaterial,
&m_pMesh );
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
// skip error handling -.-;;
m_pMeshMaterials = new D3DMATERIAL9[m_NumMaterial];
m_pMeshTextures = new LPDIRECT3DTEXTURE9[m_NumMaterial];
for ( DWORD i = 0; i < m_NumMaterial; ++i )
{
m_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
m_pMeshMaterials[i].Ambient = m_pMeshMaterials[i].Diffuse;
m_pMeshTextures[i] = NULL;
D3DXCreateTextureFromFileA( d3dDevice,
d3dxMaterials[i].pTextureFilename,
&m_pMeshTextures[i] );
}
pD3DXMtrlBuffer->Release();
}
示例15: D3DXLoadMeshFromX
void Meshes::load_meshes(LPCSTR pFilename, LPDIRECT3DDEVICE9 pD3DDevice)
{
ID3DXBuffer* buff_Material = NULL;
ID3DXBuffer* buff_Adjacency = NULL;
D3DXLoadMeshFromX(pFilename, D3DXMESH_MANAGED, pD3DDevice, &buff_Adjacency, &buff_Material, NULL, &numMaterials, &Model);
D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)buff_Material->GetBufferPointer();
material = new D3DMATERIAL9[numMaterials];
texture = new LPDIRECT3DTEXTURE9[numMaterials];
for(DWORD i = 0; i < numMaterials; i++)
{
material[i] = tempMaterials[i].MatD3D;
material[i].Ambient = material[i].Diffuse;
if(FAILED(D3DXCreateTextureFromFileA(pD3DDevice,tempMaterials[i].pTextureFilename,&texture[i])))
texture[i] = NULL;
}
return;
}