Silverlight 5 and VertexBuffer.GetData ()

I am trying to achieve a 3d model collision in silverlight 5. For this, I create a BoundingBox (as in XNA4.0):

I saw the same question VertexBuffer.GetData () and Silverlight 5 in this link, but no answers were found.

 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;
    }
+5
source share
1 answer

For security reasons, Microsoft has access to the GPU. Therefore, they pause the GetData () method. To overcome this problem in Silverlight 5, you can write a content pipeline to load the object and try to read the vertex data, and it solves your problem.

0
source

All Articles