Aspose.3D FOSS for .NET provides a comprehensive API for working with 3D scenes, nodes, materials, built-in primitives, and mesh operations. This post explores the key features that make up the library, with code examples for each area.
All examples assume the following using directive:
using Aspose.ThreeD;
using Aspose.ThreeD.Entities;
using Aspose.ThreeD.Shading;
And the NuGet package:
dotnet add package Aspose.3D.FOSSThe Scene Graph
The scene graph is the core data structure. A Scene contains a RootNode, and every Node can have child nodes and an attached Entity (such as a Mesh or Camera).
Creating and Navigating Nodes
Call CreateChildNode() on the root node to create named child nodes, and read ChildNodes.Count to traverse the hierarchy:
var scene = new Scene();
// Create a hierarchy
var parent = scene.RootNode.CreateChildNode("Parent");
var child1 = parent.CreateChildNode("Child1");
var child2 = parent.CreateChildNode("Child2");
// Navigate the tree
Console.WriteLine("Root children: " + scene.RootNode.ChildNodes.Count);
Console.WriteLine("Parent children: " + parent.ChildNodes.Count);
Attaching Entities to Nodes
Entities are the visual content of the scene – meshes, cameras, and lights. Attach them using CreateChildNode:
var scene = new Scene();
// Create a box primitive and attach it to the scene
var box = new Box(2, 2, 2);
var boxNode = scene.RootNode.CreateChildNode("BoxNode", box);
// Create a sphere primitive
var sphere = new Sphere(1);
var sphereNode = scene.RootNode.CreateChildNode("SphereNode", sphere);
scene.Save("primitives.gltf");
Built-In Primitives
The .NET edition includes parametric shape classes that generate geometry without manual vertex construction:
| Primitive | Description |
|---|---|
Box | Axis-aligned box with configurable width, height, and depth |
Sphere | Parametric sphere with configurable radius |
Cylinder | Parametric cylinder with configurable top/bottom radii and height |
These primitives can be attached directly to nodes or converted to a Mesh via ToMesh():
var cylinder = new Cylinder(1, 1, 2);
var mesh = cylinder.ToMesh();
Console.WriteLine("Vertices: " + mesh.ControlPoints.Count);
Console.WriteLine("Polygons: " + mesh.PolygonCount);
Mesh Construction
If you need full control, build meshes from scratch using control points and polygon definitions:
// Note: Mesh.ControlPoints uses Aspose.ThreeD.Utilities.Vector4
// which is double-precision with lowercase fields (x, y, z, w)
using Aspose.ThreeD.Utilities;
var mesh = new Mesh();
// Add vertex positions (double-precision; w=1.0 for Cartesian positions)
mesh.ControlPoints.Add(new Vector4(0.0, 0.0, 0.0, 1.0));
mesh.ControlPoints.Add(new Vector4(1.0, 0.0, 0.0, 1.0));
mesh.ControlPoints.Add(new Vector4(0.5, 1.0, 0.0, 1.0));
// Define a triangle face
mesh.CreatePolygon(0, 1, 2);
// Attach to a scene
var scene = new Scene();
scene.RootNode.CreateChildNode("triangle", mesh);
scene.Save("triangle.stl");
Control points use Aspose.ThreeD.Utilities.Vector4 (double-precision) with the w component set to 1.0 for standard Cartesian positions. Polygons are defined by passing control-point indices to CreatePolygon().
Transforms
Every Node has a Transform property that controls its local position, rotation, and scale:
var scene = new Scene();
using Aspose.ThreeD.Utilities;
var node = scene.RootNode.CreateChildNode("Moved");
node.Transform.Translation = new Vector3(5, 0, 0);
node.Transform.Scaling = new Vector3(2, 2, 2);
Transform Inheritance
Transforms compose through the scene hierarchy. A child’s world-space position is the product of all ancestor transforms:
var scene = new Scene();
using Aspose.ThreeD.Utilities;
var parent = scene.RootNode.CreateChildNode("Parent");
parent.Transform.Translation = new Vector3(10, 0, 0);
var child = parent.CreateChildNode("Child");
child.Transform.Translation = new Vector3(5, 0, 0);
// Child's world position is (15, 0, 0)
// Access via child.GlobalTransform
GlobalTransform
To get a node’s world-space transformation matrix (composing all ancestor transforms), call node.EvaluateGlobalTransform(false):
var worldMatrix = child.EvaluateGlobalTransform(false);
// worldMatrix is the world-space Matrix4 for `child`
Note: The
Node.GlobalTransformproperty exists but returns a static default value created at node construction time — it does not reflect the actual computed world transform. Always useEvaluateGlobalTransform(bool)to obtain the live world-space matrix. Passfalseto exclude geometric transforms (recommended for scene-graph traversal); passtrueto include them.
Materials
The library includes three material types with increasing complexity:
LambertMaterial
A LambertMaterial provides DiffuseColor, AmbientColor, and Transparency properties for surfaces without specular highlights:
// Material color properties use Aspose.ThreeD.Utilities.Vector3 (double-precision)
using Aspose.ThreeD.Utilities;
var material = new LambertMaterial("WoodMaterial");
material.DiffuseColor = new Vector3(0.6, 0.4, 0.2);
material.AmbientColor = new Vector3(0.1, 0.1, 0.1);
material.Transparency = 0.0;
PhongMaterial
PhongMaterial extends Lambert with SpecularColor, Shininess, and SpecularFactor properties that control glossy reflections:
var material = new PhongMaterial("ShinyMetal");
material.SpecularColor = new Vector3(0.8, 0.8, 0.8);
material.Shininess = 50.0;
material.SpecularFactor = 32.0;
PbrMaterial
PbrMaterial maps to the glTF 2.0 pbrMetallicRoughness schema; set Albedo, MetallicFactor, and RoughnessFactor to define physical appearance:
var material = new PbrMaterial();
material.Name = "GoldPBR";
material.Albedo = new Vector3(1.0, 0.8, 0.2);
material.MetallicFactor = 0.9;
material.RoughnessFactor = 0.1;
material.OcclusionFactor = 1.0;
PbrMaterial exposes named texture properties (AlbedoTexture, MetallicRoughness, NormalTexture, EmissiveTexture, OcclusionTexture) of type TextureBase – not string paths – for binding image maps. MetallicRoughness is the combined metallic/roughness texture slot.
Math Utilities
The library includes vector, matrix, quaternion, and bounding-box types in the Aspose.ThreeD.Utilities namespace for 3D spatial operations:
Vector Types
| Type | Namespace | Components | Precision | Component Access | Common Use |
|---|---|---|---|---|---|
Vector2 | Aspose.ThreeD.Utilities | 2 | double | U, V named-field properties | UV/texture scroll and scale properties |
Vector3 | Aspose.ThreeD.Utilities | 3 | double | Item indexer (v[0], v[1], v[2]) | General-purpose 3-component vector (material colors, Transform.Translation/Transform.Scaling) |
Vector4 | Aspose.ThreeD.Utilities | 4 | double | No public named-field or indexed access exposed in this API surface | Mesh.ControlPoints |
FVector3 | Aspose.ThreeD.Utilities | 3 | float | No public named-field or indexed access exposed in this API surface | Renderer variables (RendererVariableManager.CameraPosition, .ShadowCaster, .WorldAmbient) |
FVector4 | Aspose.ThreeD.Utilities | 4 | float | No public named-field or indexed access exposed in this API surface | RenderState.BlendColor |
Note: The
Aspose.ThreeD.Utilitiesnamespace defines exactly oneVector2, oneVector3, and oneVector4type (all double-precision) plus the float-precisionFVector3/FVector4siblings – confirmed againstapi_surface.json, which contains no second, uppercase, single-precisionVector2/Vector3/Vector4family.Mesh.ControlPointsuses the double-precisionVector4.
Quaternion
Quaternion stores a rotation as four components. Assign to node.Transform.Rotation to orient a node without gimbal-lock issues:
var rotation = Quaternion.Identity;
node.Transform.Rotation = rotation;
Matrix4
Matrix4 stores a 4×4 double-precision transformation matrix, used internally by EvaluateGlobalTransform() to compute world-space positions:
// Matrix operations are used internally by Transform
// and GlobalTransform for world-space computation
BoundingBox
BoundingBox stores Minimum and Maximum corner points as Vector3 values for frustum culling and spatial partitioning:
// BoundingBox stores Minimum and Maximum Vector3 corners
// Used for frustum culling and spatial partitioning
Vertex Elements
Meshes can carry additional per-vertex data layers beyond positions:
- VertexElementNormal – surface normals for lighting calculations.
- VertexElementUV – texture coordinates for mapping images onto geometry.
- VertexElementVertexColor – per-vertex RGBA colour data.
Each vertex element has a MappingMode (per control point, per polygon vertex, or per polygon) and a ReferenceMode (direct values or indexed values).
Animation Clips
The Scene class supports named animation clips via CreateAnimationClip() and GetAnimationClip(). In the current FOSS edition, animation clip creation and lookup are functional, but keyframe data and playback are not yet implemented.
var scene = new Scene();
var clip = scene.CreateAnimationClip("Walk");
// Retrieve by name
var found = scene.GetAnimationClip("Walk");
Console.WriteLine("Clip found: " + (found != null));
What’s Next
Aspose.3D FOSS for .NET also supports a variety of 3D file formats including OBJ, STL, glTF, FBX, and 3MF, with extensive load options, save options, and conversion patterns for each.