向 2D 对象添加 3D 效果 - DirectX

发布于 2024-09-14 01:24:56 字数 372 浏览 5 评论 0原文

我编写了一个简单的程序来加载 directX .x 网格文件。我加载的图像显示如下

但是MeshViewer显示的是这样的

应该怎样做才能获得 3D 外观?我应该调用 DirectX 库中的哪个?

I wrote a simple program to load a directX .x mesh file. My loaded image is displayed like this
.

But the one which the MeshViewer shows is like this
.

What should be done to get the 3D look? Which call in the DirectX library should I make?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

千笙结 2024-09-21 01:24:56

您是否将相同的文件加载到查看器中,就像加载到您自己的应用程序中一样?因为它实际上看起来网格中没有任何法线。如果您使用与查看器相同的文件,它们应该位于网格文件中。

除此之外,您的照明非常明亮(所有值均为 1.0),我会将漫反射值设置为 0.0 并尝试将环境设置为 0.5 红色。那么至少你可以判断你的灯是否正常工作。

Are you loading the same file into the viewer as into your own application? 'Cause it actually looks like you don't have any normals in the mesh. If your using the same file as the viewer, they should be in the mesh file though.

Other than that, your lighting is incredibly bright (all values at 1.0), I would set the diffuse values to 0.0 and try setting the ambient to 0.5 red. Then at least you can tell if your light is working.

风柔一江水 2024-09-21 01:24:56

看来你还没有设置任何灯光。

您必须加载网格中定义的材质,并设置至少一盏灯。

设置灯光后,使用 DirectX 9 中的固定管道的渲染代码如下所示:

// NumMaterials and ShipMaterialshave already been loaded with the call to D3DXLoadMeshFromX
D3DXMATERIAL* ShipMats = (D3DXMATERIAL*) ShipMaterials->GetBufferPointer();
device->SetTexture(0, NULL); // assume a mesh with no texture
for (DWORD i = 0; i < NumMaterials; ++i) 
{
    device->SetMaterial(&ShipMats[i].MatD3D);
    this->pShipMesh->DrawSubset(i);
}

如果您仍然看不到任何内容,请设置您自己定义的材质。

Looks like you haven't set any light.

You have to load the materials defined in the mesh, and set at least one light.

Once you've set a light, the rendering code using the fixed pipeline in DirectX 9 looks like this:

// NumMaterials and ShipMaterialshave already been loaded with the call to D3DXLoadMeshFromX
D3DXMATERIAL* ShipMats = (D3DXMATERIAL*) ShipMaterials->GetBufferPointer();
device->SetTexture(0, NULL); // assume a mesh with no texture
for (DWORD i = 0; i < NumMaterials; ++i) 
{
    device->SetMaterial(&ShipMats[i].MatD3D);
    this->pShipMesh->DrawSubset(i);
}

If you still don't see anything, set a material you've defined yourself.

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