所以我正在尝试用 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/