1

正对“骨头”准确地遇到一个模型对另一个模型附加的困难。我搜索了几个论坛,但没有结果。我看到很多人都问过同样的问题,但没有真正的结果,没有任何回应。发现线程:

https://gamedev.stackexchange.com/questions/21129/how-to-attach-two-xna-models-together

https://gamedev.stackexchange.com/questions/44515/how-can-i-attach-a-model-to-the-bone-of-another-model

https://stackoverflow.com/questions/11391852/attach-model-xna

但我认为这是可能的。

这是我的代码示例,附有我的玩家手的“立方体”

private void draw_itemActionAttached(Model modelInUse)
    {
        Matrix[] Model1TransfoMatrix = new Matrix[this.player.Model.Bones.Count];
        this.player.Model.CopyAbsoluteBoneTransformsTo(Model1TransfoMatrix);
        foreach (ModelMesh mesh in modelInUse.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                Matrix model2Transform = Matrix.CreateScale(1f) * Matrix.CreateFromYawPitchRoll(0, 0, 0);

                effect.World = model2Transform * Model1TransfoMatrix[0]; //root bone index
                effect.View = arcadia.camera.View;
                effect.Projection = arcadia.camera.Projection;
            }
            mesh.Draw();
        }
    }
4

1 回答 1

2

方法可能会有所不同,但一种常见的方法是为您的“装备”添加一个或多个骨骼,无论它们是否是手持的。这样,对象的骨骼可以在运行时添加到玩家的骨骼中,从而在所需位置“装备”物品。

一些阅读:http ://en.csharp-online.net/XNA_Game_Programming%E2%80%94PlayerWeapon

于 2012-12-19T10:42:14.960 回答