使用具有 12 个浮点中断的声明克隆 ID3DXMesh?
我有以下顶点声明:
struct MESHVERTInstanced
{
float x, y, z; // Position
float nx, ny, nz; // Normal
float tu, tv; // Texcoord
float idx; // index of the vertex!
float tanx, tany, tanz; // The tangent
const static D3DVERTEXELEMENT9 Decl[6];
static IDirect3DVertexDeclaration9* meshvertinstdecl;
};
我将其声明如下:
const D3DVERTEXELEMENT9 MESHVERTInstanced::Decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
D3DDECL_END()
};
接下来我尝试做的是将 ID3DXMesh 复制到另一个具有新顶点声明的 ID3DXMesh 中:
model->CloneMesh( model->GetOptions(), MESHVERTInstanced::Decl,
gd3dDevice, &pTempMesh );
当我尝试获取 pTempMesh 的 FVF 大小 (D3DXGetFVFVertexSize(pTempMesh- >GetFVF())) 虽然大小应该是 48,但我得到 '0'。
如果我没有最后一个声明 '{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },' 则整个事情都很好其中,CloneMesh 函数不会返回 FAIL。我还尝试过使用不同的声明,例如 D3DDECLUSAGE_TEXCOORD,效果很好,返回大小为 48。我不知道 D3DDECLUSAGE_TANGENT 有什么具体内容吗?
我完全不知道为什么这不起作用......
I have the following vertex declration:
struct MESHVERTInstanced
{
float x, y, z; // Position
float nx, ny, nz; // Normal
float tu, tv; // Texcoord
float idx; // index of the vertex!
float tanx, tany, tanz; // The tangent
const static D3DVERTEXELEMENT9 Decl[6];
static IDirect3DVertexDeclaration9* meshvertinstdecl;
};
And I declare it as such:
const D3DVERTEXELEMENT9 MESHVERTInstanced::Decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
D3DDECL_END()
};
What I try to do next is copy an ID3DXMesh into another one with the new vertex declaration as such:
model->CloneMesh( model->GetOptions(), MESHVERTInstanced::Decl,
gd3dDevice, &pTempMesh );
When I try to get the FVF size of pTempMesh (D3DXGetFVFVertexSize(pTempMesh->GetFVF())) I get '0' though the size should be 48.
The whole thing is fine if I don't have the last declaration, '{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },' in it and the CloneMesh function does not return a FAIL. I've also tried using different declarations such as D3DDECLUSAGE_TEXCOORD and that has worked fine, returning a size of 48. Is there something specific about D3DDECLUSAGE_TANGENT I don't know?
I'm at a complete loss as to why this isn't working...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TBH AS DeadMG 指出顶点 decl 与 FVF 不兼容。您询问是否有其他方法来获取顶点缓冲区的大小。显然,您知道缓冲区中有多少个顶点,并且您显然知道顶点结构有多大(48 字节),因为您在顶点声明中如此定义它。
如果失败,只需使用 D3DXGetDeclLength。
TBH AS DeadMG points out that vertex decl is NOT FVF compatible. You ask if there is another way to get the size of the vertex buffer. You evidently know how many vertices are in the buffer and you, OBVIOUSLY, know how large the vertex structure is (48 bytes) as you DEFINE it as such in your vertex declaration.
Failing that just use D3DXGetDeclLength.
并非每个 D3DVERTEXDECL 都可以转换为 FVF。在尝试获取 FVF 大小之前,您应该三重检查您是否具有 FVF 兼容声明。虽然我不明白你为什么要使用 FVF,但它相当无用,而且你不会获得未来的技能,因为 D3D10 甚至不允许 FVF。
Not every D3DVERTEXDECL can be converted to FVF. You should triple-check that you have an FVF-compatible declaration before trying to get the FVF size. Although, it's beyond me why you're using FVF, it's fairly useless and you won't be gaining future skills, as D3D10 doesn't even allow FVF.