2

だから私は 2D スプライトで 3D ゲームを作ろうとしています。Blender で平面を作成し、UV マップを使用してスプライトの 1 つを平面にマッピングしました。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();
    }
}
4

1 に答える 1

2

私はそれを考え出した。モデルにテクスチャが表示されない理由は、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();
    }
  }

指定した位置にモデルを描画します。他の効果が必要な場合は、ドローに簡単に追加できます。

于 2012-06-13T04:13:33.207 に答える