Example #1
0
 public static void GetMesh(IGraphicsService graphicsService, Shape shape, out Submesh submesh, out Matrix44F 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 = Matrix44F.Identity;
   }
 }
Example #2
0
    private void CreateMesh(Shape shape, out Submesh submesh, out Matrix44F 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 = Matrix44F.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
                 * Matrix44F.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 = Matrix44F.Identity;
    }