Position of a modelmesh in XNA

Deadly 提交于 2019-12-12 05:37:14

问题


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

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.

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.


回答1:


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)


来源:https://stackoverflow.com/questions/14873609/position-of-a-modelmesh-in-xna

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!