public static void GetMesh(IGraphicsService graphicsService, Shape shape, out Submesh submesh, out Matrix matrix) { // Update submesh. var graphicsManager = graphicsService as GraphicsManager; if (graphicsManager != null) { graphicsManager.ShapeMeshCache.GetMesh(shape, out submesh, out matrix); } else { // This happens if the user has implemented his own graphics manager - // which is very unlikely. submesh = MeshHelper.CreateSubmesh(graphicsService.GraphicsDevice, shape.GetMesh(0.05f, 4), MathHelper.ToRadians(70)); matrix = Matrix.Identity; } }
private void CreateMesh(Shape shape, out Submesh submesh, out Matrix matrix) { // Use a special shared submesh for box shapes. var boxShape = shape as BoxShape; if (boxShape != null) { if (_boxSubmesh == null) _boxSubmesh = MeshHelper.GetBox(_graphicsService); submesh = _boxSubmesh; matrix = Matrix.CreateScale(boxShape.Extent); return; } var transformedShape = shape as TransformedShape; boxShape = (transformedShape != null) ? transformedShape.Child.Shape as BoxShape : null; if (boxShape != null) { if (_boxSubmesh == null) _boxSubmesh = MeshHelper.GetBox(_graphicsService); submesh = _boxSubmesh; matrix = transformedShape.Child.Pose * Matrix.CreateScale(transformedShape.Child.Scale * boxShape.Extent); return; } // Create the submesh. Return EmptySubmesh if the MeshHelper returns null. var newSubmesh = MeshHelper.CreateSubmesh( _graphicsService.GraphicsDevice, shape.GetMesh(MeshRelativeError, MeshIterationLimit), NormalAngleLimit); submesh = newSubmesh ?? EmptySubmesh; matrix = Matrix.Identity; }