将任意d3d9游戏的模型截取到obj格式:工具下载
1,将d3d9.dll、snapconfig.cfg拷贝或覆盖到游戏运行目录(若果原先已经有d3d9.dll,则先备份以便还原)。
2,运行游戏,所有贴图和模型会自动保存到运行目录的SnapMesh文件夹。
3,截取完后不在使用时记得将d3d9.dll删除或还原,否则每次启动都会截取导致游戏很卡。
snapconfig.cfg配置说明:
[config]
snapAllTexture = 1 是否截取所有贴图(1是 包括ui贴图,0否 只截取模型贴图)
snapMesh = 1 是否截取模型
snapMeshNormal = 0 是否截取模型法线信息
snapIndexSeprate = 0 是否将同一缓冲区的不同段作为不同的模型截取
minMeshTrigonNum = 1 截取模型最小面数
logDrawCount = 0 日志记录数
worldTransform = 0 是否使用世界坐标系(否则模型坐标系)
flipTexCoordV = 1 是否反转V向纹理坐标
原理:
新的d3d9.dll实际起到了一个代理作用。每次绘制结束保存纹理和模型。
这个技术同样适用于制作带有游戏内界面的外挂程序。
部分代码
void IDirect3DDevice9Proxy::ExportMesh()
{
if (G_Config.m_snapMesh==false)
{
return;
}
m_textureCoordExported=false;
m_pOriIDirect3DDevice9->GetIndices(&m_pIndexBuffer);
m_iIndexBuffer = (int)m_pIndexBuffer;
int startIndex = m_startIndex;
if (G_Config.m_snapIndexSeprate==0)
{
startIndex = 0;
}
MeshKey key;
key.m_indexPointer = m_iIndexBuffer;
key.m_startIndex = startIndex;
key.m_primcount = m_PrimitiveCount;
if (m_drawType==D_DrawIndexedPrimitive
&&m_pIndexBuffer
&&G_SavedMesh.find(key)==G_SavedMesh.end()
&&(m_PrimitiveType==D3DPT_TRIANGLELIST||m_PrimitiveType==D3DPT_TRIANGLESTRIP||m_PrimitiveType==D3DPT_TRIANGLEFAN)
&&m_PrimitiveCount>=G_Config.m_minMeshTrigonNum
)
{
IDirect3DBaseTexture9* pTexture=NULL;
int stage = 0;
bool get = false;
while (stage<8)
{
HRESULT res = m_pOriIDirect3DDevice9->GetTexture(stage,&pTexture);
if (pTexture)
{
get = true;
break;
}
//G_FastLog.OutputStr("GetTexture() return %d!",(int)res);
stage++;
}
if (pTexture==NULL)
{
int stage = 0;
while (stage<8)
{
pTexture = m_pTexture[stage];
if (pTexture)
{
break;
}
stage++;
}
}
//文理有可能已经释放重新加载,而指针值正巧相等,所以重新保存一下
if(pTexture)
{
char buf[256];
//texture在前以便排序剔除重复纹理
sprintf(buf,"SnapMesh\\%d_%d_%d.png",(int)pTexture,m_iIndexBuffer,startIndex);
D3DXSaveTextureToFile(buf, D3DXIFF_PNG, pTexture, NULL);
//GetTexture加了引用技术,需要释放
if(get)pTexture->Release();
}
G_SavedMesh.insert(key);
///////
for (UINT i=0;i<8;i++)
{
m_pOriIDirect3DDevice9->GetStreamSource(i,m_pStreamVertexBuffer+i,m_streamOffsetInBytes+i,m_streamStride+i);
}
m_pIndexBuffer->GetDesc(&m_indexBufferDesc);
//if (SUCCEEDED(m_pOriIDirect3DDevice9->GetStreamSource(0,&pStreamData,&OffsetInBytes,&Stride)))
{
IDirect3DVertexDeclaration9* pDecl=NULL;
if (SUCCEEDED(m_pOriIDirect3DDevice9->GetVertexDeclaration(&pDecl)))
{
if (pDecl==NULL)
{
//DWORD FVF;
//if (SUCCEEDED(m_pOriIDirect3DDevice9->GetFVF(&FVF)))
//{
// if (FVF&D3DFVF_XYZ)
// {

本文介绍了一种将Direct3D 9游戏中模型和贴图截取为OBJ格式的方法,通过替换游戏运行目录中的d3d9.dll文件,并利用特定配置,自动保存游戏中的模型和贴图至指定文件夹。详细阐述了配置项的作用及代码实现,如模型和贴图的截取、坐标系转换、纹理坐标翻转等。
最低0.47元/天 解锁文章
612

被折叠的 条评论
为什么被折叠?



