Silverlight 5 and VertexBuffer.GetData()

本文关键字:GetData VertexBuffer and Silverlight | 更新日期: 2023-09-27 17:55:13

我正在尝试在Silverlight 5中实现3D模型碰撞。为此,我创建了一个边界框(就像在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;
    }

Silverlight 5 and VertexBuffer.GetData()

出于安全原因,Microsoft拒绝访问 GPU。所以他们有挂起的 GetData() 方法。若要在 Silverlight 5 中解决此问题,可以编写自定义内容管道来加载对象并尝试读取顶点数据,这将解决您的问题。