GetData()和Silverlight 5

GetData()和Silverlight 5,silverlight,xna,Silverlight,Xna,我正在尝试在silverlight 5中实现3d模型碰撞。为此,我创建了一个边界框(就像在XNA4.0中一样): 公共边界框GetBoundingBoxFromModel(模型模型) { BoundingBox BoundingBox=新的BoundingBox(); foreach(模型中的ModelMeshPart零件。网格[0]。MeshParts) { VertexPositionNormalTexture[]顶点=新的VertexPositionNormalTe

我正在尝试在silverlight 5中实现3d模型碰撞。为此,我创建了一个边界框(就像在XNA4.0中一样):

公共边界框GetBoundingBoxFromModel(模型模型)
{            
BoundingBox BoundingBox=新的BoundingBox();
foreach(模型中的ModelMeshPart零件。网格[0]。MeshParts)
{
VertexPositionNormalTexture[]顶点=新的VertexPositionNormalTexture[part.NumVertices];
Vector3[]vertexs=新的Vector3[Vertex.Length];
part.VertexBuffer.GetData(顶点);
对于(int index=0;index

问题是Silverlight 5在XNA4中没有连接到VertexBuffer的GetData()方法。如何才能获得相同的结果?

出于安全原因,Microsoft拒绝访问GPU。所以他们有suspendGetData()方法。要在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;
    }