簡體   English   中英

在XNA 3D中創建模型更改形狀

[英]Create a model change shape in XNA 3D

我想創建一個可移動的對象(例如人在移動或彈性彈簧),移動時,對象的形狀將發生變化。 而且我不知道如何在XNA 4.0中創建3D模型形狀更改。 你能幫助我嗎?? 謝謝!

我也許可以給您一些初學者到初學者的建議。

我剛剛從該示例中學到了如何制作模型,並根據您的要求,對其中一個骨骼應用了一個額外的比例變換,以查看是否可以用與它的位置相同的方式來操縱其尺寸,並且它確實起作用。

因此,我暗示您的問題的答案可能是,雖然模型的頂點數據保持不變,但是您可以使用Scale變換使它改變形狀。

這是我的模型:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace SimpleAnimation
{
    public class Body
    {
        Model bodyModel;
        ModelBone headBone;
        ModelBone bodyBone;
        Matrix headTransform;
        Matrix bodyTransform;
        Matrix[] boneTransforms;

        public Body()
        {
            HeadScale = 1;
        }

        public void Load(ContentManager content)
        {
            // Load the tank model from the ContentManager.
            bodyModel = content.Load<Model>("body");

            // Look up shortcut references to the bones we are going to animate.
            headBone = bodyModel.Bones["head"];
            bodyBone = bodyModel.Bones["body"];

            // Store the original transform matrix for each animating bone.
            headTransform = headBone.Transform;
            bodyTransform = bodyBone.Transform;

            // Allocate the transform matrix array.
            boneTransforms = new Matrix[bodyModel.Bones.Count];
        }

        public void Draw(Matrix world, Matrix view, Matrix projection)
        {
            // Set the world matrix as the root transform of the model.
            bodyModel.Root.Transform = world;

            // Calculate matrices based on the current animation position.
            Matrix headRotation = Matrix.CreateRotationX(HeadRotation);
            Matrix headScale = Matrix.CreateScale(HeadScale);
            Matrix bodyRotation = Matrix.CreateRotationX(BodyRotation);

            // Apply matrices to the relevant bones.
            headBone.Transform = headScale * headRotation * headTransform;
            bodyBone.Transform = bodyRotation * bodyTransform;

            // Look up combined bone matrices for the entire model.
            bodyModel.CopyAbsoluteBoneTransformsTo(boneTransforms);

            // Draw the model.
            foreach (ModelMesh mesh in bodyModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = boneTransforms[mesh.ParentBone.Index];
                    effect.View = view;
                    effect.Projection = projection;

                    effect.EnableDefaultLighting();
                }

                mesh.Draw();
            }
        }

        public float HeadRotation { get; set; }

        public float HeadScale { get; set; }

        public float BodyRotation { get; set; }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM