【问题标题】:exporting textures 3d models and textures from blender to xna 4.0将纹理 3d 模型和纹理从搅拌机导出到 xna 4.0
【发布时间】:2012-06-15 08:20:35
【问题描述】:

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

我确保为平面创建材质,并确保添加纹理并使用正确的 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();
    }
}

【问题讨论】:

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


    【解决方案1】:

    我想通了。我的纹理没有显示在我的模型上的原因是因为我没有正确设置 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();
        }
      }
    

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

    【讨论】:

      猜你喜欢
      • 2013-06-14
      • 2013-02-21
      • 2017-05-08
      • 2011-07-31
      • 2016-06-05
      • 2014-05-27
      • 2014-12-23
      • 2018-05-21
      • 2016-05-09
      相关资源
      最近更新 更多