Features and Functionalities
Features and Functionalities
This page covers every major feature area of Aspose.3D 26.1.0 with working C# examples.
Loading and Saving Scenes
Scene.Open() loads a file; Scene.Save() exports it. The format is detected from the file extension:
using Aspose.ThreeD;
var scene = new Scene();
scene.Open("input.obj");
scene.Save("output.glb");Use the static factory Scene.FromFile() as an alternative:
var scene = Scene.FromFile("input.fbx");
scene.Save("output.stl");Format-Specific Options
Pass LoadOptions or SaveOptions subclasses to fine-tune the import or export behavior for a specific file format:
using Aspose.ThreeD;
using Aspose.ThreeD.Formats;
var scene = new Scene();
scene.Open("model.obj", new ObjLoadOptions { FlipCoordinateSystem = true });
scene.Save("model.fbx");Available option classes:
| Class | Direction | Key Properties |
|---|---|---|
ObjLoadOptions | Import | FlipCoordinateSystem, EnableMaterials, Scale |
ObjSaveOptions | Export | FlipCoordinateSystem, EnableMaterials, PointCloud |
FbxLoadOptions | Import | (default settings) |
GltfLoadOptions | Import | (default settings) |
GltfSaveOptions | Export | (default settings) |
StlLoadOptions | Import | (default settings) |
StlSaveOptions | Export | (default settings) |
ColladaLoadOptions | Import | FlipCoordinateSystem |
ColladaSaveOptions | Export | Indented, TransformStyle |
PlyLoadOptions | Import | (default settings) |
Building a Scene Graph
Call CreateChildNode() on the root node to create named nodes and attach entities to build a scene hierarchy:
var scene = new Scene();
var root = scene.RootNode;
var boxNode = root.CreateChildNode("box", new Box(5, 5, 5));
var sphereNode = root.CreateChildNode("sphere", new Sphere(3));Access children via node.ChildNodes and the attached entity via node.Entity.
Mesh and Primitives
Add control points using mesh.ControlPoints.Add() and define face topology with CreatePolygon() to build a custom mesh programmatically:
// Mesh.ControlPoints uses Aspose.ThreeD.Utilities.Vector4
// (double-precision, lowercase fields: x, y, z, w)
using Aspose.ThreeD.Utilities;
var mesh = new Mesh("custom");
mesh.ControlPoints.Add(new Vector4(0.0, 0.0, 0.0)); // w defaults to 1.0
mesh.ControlPoints.Add(new Vector4(10.0, 0.0, 0.0));
mesh.ControlPoints.Add(new Vector4(10.0, 10.0, 0.0));
mesh.ControlPoints.Add(new Vector4(0.0, 10.0, 0.0));
mesh.CreatePolygon(0, 1, 2, 3);Built-in primitives (Box, Sphere, Cylinder) can be converted to Mesh:
var box = new Box(10, 10, 10);
Mesh boxMesh = box.ToMesh();Vertex Elements
Create a vertex element instance with a MappingMode and ReferenceMode, then call mesh.AddElement() to attach normals, UVs, or vertex colours to geometry:
var normals = new VertexElementNormal(MappingMode.ControlPoint, ReferenceMode.Direct);
mesh.AddElement(normals);Available vertex element types: VertexElementNormal, VertexElementUV, VertexElementVertexColor, VertexElementBinormal, VertexElementTangent.
Transforms
Every Node carries a Transform with Translation, Rotation, and Scale:
var node = scene.RootNode.CreateChildNode("moved", new Box());
node.Transform.Translation = new FVector3(10, 0, 5);
node.Transform.Scale = new FVector3(2, 2, 2);Read world-space position via node.GlobalTransform.Matrix or node.EvaluateGlobalTransform().
Materials
Create a material, set its diffuse, specular, and shininess properties, then assign it to a node to control shading in 3D viewers:
var mat = new PhongMaterial("shiny");
mat.Diffuse = new Vector4(0.8, 0.2, 0.2, 1.0);
mat.Specular = new Vector4(1, 1, 1, 1);
mat.Shininess = 32;
scene.RootNode.CreateChildNode("red_box", new Box(), mat);Material types: LambertMaterial, PhongMaterial, PbrMaterial.
Tips and Best Practices
- Use
Scene.FromFile()for a single-call load when you do not need customLoadOptions - Convert primitives to
MeshwithToMesh()before adding vertex elements - Use
GltfSaveOptionsand save with a binary extension to produce compact binary output - Check
node.Entityfornullbefore casting — not every node carries geometry - Use
PolygonModifier.Triangulate()to convert quad meshes before export to triangle-only formats like STL
Common Issues
| Issue | Cause | Fix |
|---|---|---|
ImportException on load | Unsupported or corrupted file | Verify the file opens in a 3D viewer; check the format is in the supported list |
| Missing materials after OBJ load | .mtl file not found | Place the .mtl file next to the .obj or set ObjLoadOptions.EnableMaterials = true |
| Scale mismatch after FBX import | Different unit systems | Use ObjLoadOptions.Scale or apply a Transform after loading |
FAQ
How do I detect the format of an unknown file?
Call FileFormat.Detect() with a file path to identify the format without loading the full scene:
var format = FileFormat.Detect("unknown_file.bin");
Console.WriteLine(format.Extension);Can I load from a stream instead of a file path?
Yes. Pass a Stream to Scene.Open() to load a 3D file from any stream source instead of a file path:
using var stream = File.OpenRead("model.glb");
scene.Open(stream);Which formats support both import and export?
The following formats support both import and export: OBJ, STL, glTF/GLB, FBX, COLLADA, and 3MF. PLY supports import only.
API Reference Summary
| Class / Method | Description |
|---|---|
Scene | Top-level 3D scene container |
Scene.Open() | Load a 3D file by path or stream |
Scene.Save() | Export scene to file or stream |
Scene.FromFile() | Static factory to load and return a Scene |
Node | Scene hierarchy node holding entities and transforms |
Node.CreateChildNode() | Create and attach a child node |
Mesh | Polygon mesh with control points and face lists |
Mesh.CreatePolygon() | Define a polygon face by vertex indices |
Box / Sphere / Cylinder | Built-in parametric primitives |
Transform | Local translation, rotation, and scale |
FileFormat | Registry and detector for supported formats |
LambertMaterial / PhongMaterial / PbrMaterial | Material types for shading |