Forum Libraries, Components, and Plugins

DrawPath or DrawVertices with SKImage


Im wanting to do simple 3D rendering within my SkiaSharp app; a low poly world.

I have loaded a .obj and an image, so I have the vertex coordinates, texture coordinates (Ignoring the normals till I get something to display) and the SKImage.

At present I am only using the X and Y coordinates to display the sphere and can see the frame by setting the stroke width =1, however nothing is displayed from the image (That I can see). I can see the stokes from both front and back of the sphere.

Has this been done in Skia and/or SkiaSharp? I seem to find no examples and the API documentation is limited. I have not seen examples of images / bitmaps being used outside of being displayed as rectangles.

        var path = new SKPath();
        foreach (var face in model.Faces)
          path.MoveTo(face.Vertex1.X * scaleX + x, face.Vertex1.Y * scaleY + y);
          path.LineTo(face.Vertex2.X * scaleX + x, face.Vertex2.Y * scaleY + y);
          path.LineTo(face.Vertex3.X * scaleX + x, face.Vertex3.Y * scaleY + y);
          path.LineTo(face.Vertex1.X * scaleX + x, face.Vertex1.Y * scaleY + y);

        using (var paint = new SKPaint()//TODO: move these to a global level
          Shader = SKShader.CreateBitmap(image, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat),
          Style = SKPaintStyle.StrokeAndFill,
          Color = SKColors.Magenta,
          StrokeWidth = 1
          canvas.DrawPath(path, paint);

Also, how could I shade each triangle a different colour (Without using the SKImage)?


Best Answer


Sign In or Register to comment.