glTF2Image is a package for rendering screenshots or thumbnail images of 3D models. It provides an easy-to-use .NET API around Filament and SwiftShader. It is suitable for web servers that don't have a GPU.
// Create a Renderer instance.awaitusingvarrenderer=awaitRenderer.CreateAsync();// Load the model.awaitusingvarmodel=renderer.CreateGLTFAsset(File.ReadAllBytes(Path.Join(TestDataPath,"Avocado.glb")));// Load another gltf model defining the lights and camera.awaitusingvarlightsAndCamera=renderer.CreateGLTFAsset(File.ReadAllBytes(Path.Join(TestDataPath,"avocado_lights_and_camera.gltf")));// Render the scene.intwidth=576;intheight=324;vardata=awaitrenderer.RenderAsync(576,324,new[]{model,lightsAndCamera});// We currently have a pixel buffer in RGBA format. Use your favorite library to encode this as a PNG.// For this example, we'll use ImageSharp.varimage=Image.LoadPixelData<Rgba32>(data,width,height);awaitimage.SaveAsPngAsync("avocado.png");Result:
glTF2Image accepts models in glTF or glb (glTF binary) format.
Your scene must have exactly one camera to tell glTF2Image what to render. If your model does not define a camera, you can add a separate glTF file with a camera, like the example above.
To validate your model, download a recent Filament release and use the gltf_viewer tool to ensure that Filament renders your model as expected. Be sure to uncheck the "Scene > Scale to unit cube" option, since glTF2Image will not scale your model.
Filament has good support for many glTF features and extensions. There are a small number of limitations:
- Only one directional light is supported
- .NET 8 or later
- Windows or Linux
- x64
