我正在尝试在 silverlight 5 中实现 3d 模型碰撞。为此,我正在创建一个 BoundingBox(就像在 XNA4.0 中一样):
我在此链接中看到了相同的问题VertexBuffer.GetData() 和 Silverlight 5,但没有找到答案。
public BoundingBox GetBoundingBoxFromModel(Model model)
{
BoundingBox boundingBox = new BoundingBox();
foreach (ModelMeshPart part in model.Meshes[0].MeshParts)
{
VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[part.NumVertices];
Vector3[] vertexs = new Vector3[vertices.Length];
part.VertexBuffer.GetData<VertexPositionNormalTexture>(vertices);
for (int index = 0; index < vertexs.Length; index++)
{
vertexs[index] = vertices[index].Position;
}
boundingBox = BoundingBox.CreateMerged(boundingBox, BoundingBox.CreateFromPoints(vertexs));
}
return boundingBox;
}