[英]Create a model change shape in XNA 3D
I want to create an object that moves (like people are moving or elastic springs), when moving, the shape of the object will be changed. 我想创建一个可移动的对象(例如人在移动或弹性弹簧),移动时,对象的形状将发生变化。 And I do not know how to create a 3D model shape changes in XNA 4.0.
而且我不知道如何在XNA 4.0中创建3D模型形状更改。 Can you help me??
你能帮助我吗?? Thanks!
谢谢!
I might be able to give you some beginner-to-beginner advice. 我也许可以给您一些初学者到初学者的建议。
I just learned how to make a model from this example and based on your quesiton I applied an additional scale transform to one of the bones to see if I could manipulate its size the same way I can its position, and it did work. 我刚刚从该示例中学到了如何制作模型,并根据您的要求,对其中一个骨骼应用了一个额外的比例变换,以查看是否可以用与它的位置相同的方式来操纵其尺寸,并且它确实起作用。
So I'm implying the answer to your question may be that while a model's vertex data remains constant you can make it change shape using Scale transforms. 因此,我暗示您的问题的答案可能是,虽然模型的顶点数据保持不变,但是您可以使用Scale变换使它改变形状。
Here's my model: 这是我的模型:
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.