模型网格在XNA中的位置 [英] Position of a modelmesh in XNA

查看:68
本文介绍了模型网格在XNA中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在XNA(全局坐标系)中找到模型内部网格的矢量3位置?

How do you find the vector 3 position of a mesh inside of a model in XNA(in global coordinates)?

我在搅拌机中制作了一个简单灯柱的模型.在应该放置光源的位置,我将一个单个顶点作为其自己的对象,并将其命名为"Light",在位置,典型的灯光将在灯柱中

I've made a model of a simple lamp post in blender. Where the light should be, I've put a single vertice as its own object and named it "Light", in the position a typical light would be in a lamp post.

在我的XNA程序中,我想在模型的位置放置一个浮点光源.我可以按名称找到网格.但是需要"Light"网格的 Vector3位置来实现.

In my XNA program, I want to put a floating point light at the position from the model. I can find the mesh by name. But need the Vector3 position of the "Light" mesh to do it.

推荐答案

这取决于在网格/骨骼层次结构方面如何建立模型.最终,将光(灯泡)矩阵乘以其父级,然后先将其乘以其父级,依此类推一直到根,然后采用结果的平移属性.有一个内置的方法可以做到这一点,称为Model.CopyAbsoluteBoneTransformsTo(Matrix [])

It depends how the model is set up in terms of mesh/bone hierarchy. Ultimately, you multiply the light (bulb) matrix by its parent, who was first multiplied by its parent, and so on all the way to the root, then take the translation property of the result. There is a built in method to do this called Model.CopyAbsoluteBoneTransformsTo(Matrix[])

Matrix[] transforms = new Matrix[SimpleLampPostModel.Bones.Count];
SimpleLampPostModel.CopyAbsoluteBoneTransformsTo(transforms);

Vector3 lightPosition = transforms[SimpleLampPostModel.Meshes["light"].parentBone.Index].Translation;
lightPosition += modelWorld.Translation;// if the model is located in some arbitrary location in your 3d
                                        // world as represented by a world matrix (modelWorld)

这篇关于模型网格在XNA中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆