How to Render 3D Scenes to Images in .NET
How to Render 3D Scenes to Images in .NET
This article explains how to produce a raster image from a 3D scene using Aspose.3D for .NET. The minimum setup requires a Camera, at least one Light, and a call to Scene.Render.
Step 1 — Install the Package
dotnet add package Aspose.3D.Converter --version 1.0.0Step 2 — Load or Build a Scene
using Aspose.ThreeD;
using Aspose.ThreeD.Entities;
// Load an existing model
var scene = Scene.FromFile("model.fbx");
// Or build a scene in code
var scene = new Scene();
scene.RootNode.CreateChildNode("box", new Box(1, 1, 1));Step 3 — Add a Camera
using Aspose.ThreeD.Entities;
using Aspose.ThreeD.Utilities;
var camera = new Camera(ProjectionType.Perspective);
camera.FieldOfViewY = 45.0;
camera.NearPlane = 0.1;
camera.FarPlane = 500.0;
Node camNode = scene.RootNode.CreateChildNode("camera", camera);
camNode.Transform.Translation = new Vector3(0, 5, 10);
camNode.Transform.EulerAngles = new Vector3(-30, 0, 0); // tilt down toward originStep 4 — Add Lights
var sun = new Light("sun") { LightType = LightType.Directional };
Node sunNode = scene.RootNode.CreateChildNode("sun", sun);
sunNode.Transform.EulerAngles = new Vector3(45, -30, 0);
var fill = new Light("fill") { LightType = LightType.Point, Intensity = 100 };
Node fillNode = scene.RootNode.CreateChildNode("fill", fill);
fillNode.Transform.Translation = new Vector3(-4, 6, 4);Step 5 — Render to an Image File
using Aspose.ThreeD.Utilities;
// size is Vector2; format is a string ("png", "jpg", "bmp")
scene.Render(camera, "output.png", new Vector2(1280, 720), "png");
Console.WriteLine("Rendered: output.png");Tip: JPEG produces smaller files for screenshots. Use
ImageFormat.Jpeginstead ofImageFormat.Pngwhen lossless quality is not required.
Troubleshooting
| Symptom | Likely Cause | Fix |
|---|---|---|
| Black output image | No lights in scene | Add at least one Light node |
| Object not visible | Camera pointing the wrong way | Check LookAt target coordinates |
| Scene renders empty | Geometry not attached to a node | Call CreateChildNode(name, entity) |
Related Resources
- Rendering 3D Scenes — developer guide with full API details
- Working with Materials and Shading — material setup affects render output