model - 将纹理 3D 模型和纹理从 blender 导出到 xna 4.0

标签 model 3d textures xna-4.0 blender-2.61

所以我正在尝试用 2d Sprite 制作 3d 游戏。 在 blender 中,我创建了一个平面并使用 uv 贴图将其中一个 Sprite 映射到该平面。当我按 f12 并渲染平面时,将显示 Sprite 。

我确保为飞机创建 Material ,并确保添加纹理并使用正确的 uv 贴图启用 uv 贴图。

我将文件模型导出为 .fbx 文件,并将其与纹理图像一起放入项目的内容文件夹中。

但是,当我渲染模型而不是显示纹理时,平面是纯黑色的。

这可能是什么原因造成的?我的画看起来像这样:

public void Draw(Matrix View, Matrix Projection)
{
    // Calculate the base transformation by combining
    // translation, rotation, and scaling
    Matrix baseWorld = Matrix.CreateScale(Scale)
    * Matrix.CreateFromYawPitchRoll(
    Rotation.Y, Rotation.X, Rotation.Z)
    * Matrix.CreateTranslation(Position);

    foreach (ModelMesh mesh in Model.Meshes)
    {
        Matrix localWorld = modelTransforms[mesh.ParentBone.Index]
        * baseWorld;
        foreach (ModelMeshPart meshPart in mesh.MeshParts)
        {
            BasicEffect effect = (BasicEffect)meshPart.Effect;

            effect.World = localWorld;
            effect.View = View;
            effect.Projection = Projection;
            effect.EnableDefaultLighting();
        }
        mesh.Draw();
    }
}

最佳答案

我明白了。我的纹理没有显示在我的模型上的原因是因为我没有正确设置effect.world

我改变了设置世界矩阵的方式并编辑了一些模型类代码。 如果其他人想要渲染具有良好类的纹理模型

public class CModel
{
    public Matrix Position { get; set; }
    public Vector3 Rotation { get; set; }
    public Vector3 Scale { get; set; }
    public Model Model { get; private set; }
    private Matrix[] modelTransforms;




  public CModel(Model Model, Vector3 Position)
  {
    this.Model = Model;
    modelTransforms = new Matrix[Model.Bones.Count];
    Model.CopyAbsoluteBoneTransformsTo(modelTransforms);
    this.Position = Matrix.CreateTranslation(Position);

  }

  public void Draw(Matrix viewMatrix, Matrix proMatrix)
  {

    foreach (ModelMesh mesh in Model.Meshes)
    {
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();

            effect.View = viewMatrix;
            effect.Projection = proMatrix;
            effect.World = modelTransforms[mesh.ParentBone.Index] * Position;
        }

        mesh.Draw();
    }
  }

在指定位置绘制模型。如果您想要任何其他效果,您可以轻松地将它们添加到绘图中。

关于model - 将纹理 3D 模型和纹理从 blender 导出到 xna 4.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10996868/

相关文章:

php - 使用 Autodesk Forge 从 IFC 文件获取几何数据(尺寸)

OpenGL/GLSL 比 imageStore() 更快的方法来设置纹理的多个像素?

android - 在哪里可以获得所有 Android 设备的 Build.MODEL 名称列表?

OpenCV三角函数: find object closest to the camera

Sequelize ORM 中的 MySQL View 支持

scala - 为什么我的透视图实现无法显示多维数据集的面孔?

c++ - 如何在不破坏其纹理的情况下将 Sprite 正确传递给 std::Vector?

c# - 如何在代码中更改地形纹理

python - 模型继承效果不佳

php - 模型可以链接到数据库中的 View 而不是 CakePHP 中的表吗?