【问题标题】:Generate normals for Direct3D 9 Mesh为 Direct3D 9 Mesh 生成法线
【发布时间】:2014-10-28 17:13:44
【问题描述】:

我已经知道这可以通过使用 D3DXComputeNormals() 方法实现,但我只是不知道如何正确使用它。没有任何教程或课程可以做到这一点。有人可以给我解释或提供有用的代码吗?

【问题讨论】:

    标签: c++ directx direct3d mesh normals


    【解决方案1】:

    “正确”是什么意思?您在寻找计算邻接的教程吗?如果不是,MSDN 文档说明它很好 here,为 pAdjacency 参数传入 NULL。

    【讨论】:

    【解决方案2】:

    DirectXMesh 库可以生成可用于任何版本的 Direct3D 的法线。

    std::unique_ptr<WaveFrontReader<uint16_t>> mesh( new WaveFrontReader<uint16_t>() );
    
    if ( FAILED( mesh->Load( L"test.obj" ) ) )
       // Error
    
    if ( mesh->hasNormals )
       // Skip next computation
    
    size_t nFaces = mesh->indices.size() / 3;
    size_t nVerts = mesh->vertices.size();
    
    std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
    for( size_t j = 0; j < nVerts; ++j )
       pos.get()[ j ] = mesh->vertices[ j ].position;
    
    std::unique_ptr<XMFLOAT3[]> normals( new XMFLOAT3[ nVerts ] );
    if ( FAILED( ComputeNormals( &mesh->indices.front(), nFaces,
       pos.get(), nVerts, CNORM_DEFAULT, normals.get() ) ) )
       // Error
    

    该库和源代码位于 CodePlex 上,因此您可以随时进入它以查看它在做什么,它旨在替代已弃用的 D3DX 库。

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-05
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多