使用具有 12 个浮点中断的声明克隆 ID3DXMesh?

发布于 2024-09-01 07:37:30 字数 1460 浏览 5 评论 0原文

我有以下顶点声明:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

み格子的夏天 2024-09-08 07:37:31

TBH AS DeadMG 指出顶点 decl 与 FVF 不兼容。您询问是否有其他方法来获取顶点缓冲区的大小。显然,您知道缓冲区中有多少个顶点,并且您显然知道顶点结构有多大(48 字节),因为您在顶点声明中如此定义它。

const D3DVERTEXELEMENT9 MESHVERTInstanced::Decl[] =
{
    { 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, //Starts at offset 0 and is 3 floats, or 12 bytes in size.  Total = 12 bytes.
    { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 }, //Starts at offset 12 and is 3 floats, or 12 bytes in size.  Total = 24 bytes.
    { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, //Starts at offset 24 and is 2 floats, or 8 bytes in size.  Total = 32 bytes.
    { 0, 32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, //Starts at offset 32 and is 1 float, or 4 bytes in size.  Total = 36 bytes.
    { 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT,  0 }, //Starts at offset 36 and is 3 floats, or 12 bytes in size.  Total = 48 bytes.
    D3DDECL_END()
};

如果失败,只需使用 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.

const D3DVERTEXELEMENT9 MESHVERTInstanced::Decl[] =
{
    { 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, //Starts at offset 0 and is 3 floats, or 12 bytes in size.  Total = 12 bytes.
    { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 }, //Starts at offset 12 and is 3 floats, or 12 bytes in size.  Total = 24 bytes.
    { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, //Starts at offset 24 and is 2 floats, or 8 bytes in size.  Total = 32 bytes.
    { 0, 32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, //Starts at offset 32 and is 1 float, or 4 bytes in size.  Total = 36 bytes.
    { 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT,  0 }, //Starts at offset 36 and is 3 floats, or 12 bytes in size.  Total = 48 bytes.
    D3DDECL_END()
};

Failing that just use D3DXGetDeclLength.

不必在意 2024-09-08 07:37:31

并非每个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文