Rendering 3D Scenes

Rendering 3D Scenes

Aspose.3D for .NET can render a scene to a raster image. The render pipeline requires a Camera (point of view), one or more Light sources, and ImageRenderOptions (output resolution and format). The Renderer class drives the render pass.


Setting Up a Camera

Add a Camera entity to a scene node. Set the camera’s position through the node’s Transform, and point it at a target using LookAt:

using Aspose.ThreeD;
using Aspose.ThreeD.Entities;
using Aspose.ThreeD.Utilities;

var scene = new Scene();

// Create the camera entity
var camera = new Camera(ProjectionType.Perspective);
camera.NearPlane = 0.1;
camera.FarPlane = 1000.0;
camera.FieldOfViewY = 45.0;

// Attach to a node and position it
Node cameraNode = scene.RootNode.CreateChildNode("main_camera", camera);
cameraNode.Transform.Translation = new Vector3(0, 5, 10);
// Aim the camera toward the scene origin by rotating around the X axis
cameraNode.Transform.EulerAngles = new Vector3(-30, 0, 0);

For orthographic rendering, set ProjectionType.Orthographic and specify OrthoHeight.


Adding Lights

Scenes without lights render completely dark. Add at least one Light to illuminate the geometry:

using Aspose.ThreeD.Entities;

// Directional (sun-like) light
var sunLight = new Light("sun");
sunLight.LightType = LightType.Directional;
sunLight.Color = new Vector3(1.0, 1.0, 0.95); // slightly warm white
Node sunNode = scene.RootNode.CreateChildNode("sun", sunLight);
sunNode.Transform.EulerAngles = new Vector3(45, -30, 0); // direction in degrees

// Point light
var pointLight = new Light("fill");
pointLight.LightType = LightType.Point;
pointLight.Intensity = 150.0;
Node pointNode = scene.RootNode.CreateChildNode("fill_light", pointLight);
pointNode.Transform.Translation = new Vector3(-3, 4, 3);

Rendering to an Image File

Use Scene.Render with ImageRenderOptions to produce a PNG, JPEG, or BMP image:

using Aspose.ThreeD;
using Aspose.ThreeD.Utilities;

// Render to a PNG file at 1280x720 — size is Vector2, format is a string
scene.Render(camera, "output.png", new Vector2(1280, 720), "png");

Tip: For production use, ensure at least one directional or ambient light is present. An unlit scene renders as a silhouette or solid black surface depending on the material.


API Quick Reference

MemberDescription
new Camera(projectionType)Create a camera; use ProjectionType.Perspective or Orthographic
camera.FieldOfViewYVertical field of view in degrees (perspective only)
camera.NearPlaneNear clipping plane distance
camera.FarPlaneFar clipping plane distance
new Light(name)Create a light source
light.LightTypeDirectional, Point, or Spot
light.IntensityLight intensity (positive float)
light.ColorRGB colour as Vector3
new ImageRenderOptions()Render output configuration (background colour, shadows)
scene.Render(camera, path, size, format)Render scene from camera viewpoint; size is Vector2, format is "png", "jpg", etc.

See Also