Demonstrates how to generate and save an image of a model.
Overview
In this example we create a View.ImageWriter object which allows us to generate and save an image of ModelData.Model .
- Note
- Thumbnail generation uses OpenGL 2.1+ rendering (FBO support is required). On Linux it typically requires an X11 display; the DISPLAY environment variable must point to a running X server (e.g. :0, or :99 when using Xvfb). On headless servers/containers, run under Xvfb/xvfb-run.
Implementation
The main function will have the following structure:
Model aModel = new Model();
if (!new ModelReader().Read(new UTF16String(aSource), aModel))
{
Console.WriteLine("Failed to read the file " + aSource);
return 1;
}
ImageWriter aWriter = new ImageWriter();
ImageWriterParameters aWriterParameters = new ImageWriterParameters();
aWriterParameters.SetImageWidth(1280);
aWriterParameters.SetImageHeight(720);
aWriterParameters.SetViewIsFitAll(true);
var aBackground = new ColorBackgroundStyle(new Color(255, 255, 255));
aWriterParameters.SetViewBackground(aBackground);
aWriter.SetParameters(aWriterParameters);
- Generate an image of a model and save it into a file:
if (!aWriter.WriteFile(aModel, new UTF16String(aDest)))
{
Console.WriteLine("Failed to write the file " + aDest);
return 1;
}
Files