Create 3D Scene in C#

A simple 3D scene is a three-dimensional graphical representation of geometric data. In this article, we will learn how to create a 3D scene using C# from scratch without needing to install any 3D modeling or rendering software. We will save the 3D scene in FBX file format, a popular 3D file format used to exchange 3D formats. The FBX can be saved on a disk either as a binary or ASCII data file.

The following topics shall be covered in this article:

  1. C# 3D API to Create 3D Scene - Free Download
  2. Create a Simple 3D Scene in C#
  3. Read 3D Scene using C#

C# 3D API to Create 3D Scene - Free Download

To create and read a 3D scene we will be using the Aspose.3D for .NET API. It allows to create & save a 3D scene in the supported formats. It also enables to work with geometry & scene hierarchy, animate objects in a Scene, and conversion of 3D File Formats.

The API provides the Scene class which is a top-level object that contains the nodes, geometries, materials, textures, animation, poses, sub-scenes, etc. The CreateChildNode(Entity) method creates a new child node with a given entity attached. The API provides the shading model for LambertMaterial, PhongMaterial, and ShaderMaterial. The light illuminates the scene, the Light class of the API enables the addition of some light to the scene.

Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.3D

Create a Simple 3D Scene using C#

We can create a simple 3D scene by following the steps given below:

  1. Create an instance of the Scene class.
  2. Call the CreateChildNode() method to add some geometry, a shape to show on screen e.g Cylinder.
  3. Set child node properties such as Material.
  4. Initialize a Light class object.
  5. Call the CreateChildNode() method to add Light entity.
  6. Finally, save the scene as FBX using the Save() method. It takes the output file path and FileFormat.FBX7500ASCII as arguments.

The following code sample shows how to create a simple 3D scene using C#.

Read 3D Scene using C#

We can read a 3D scene from the FBX document by following the steps given below:

  1. Create an instance of the Scene class.
  2. Load an existing 3D document using the Open() method.
  3. Loop through ChildNodes properties
  4. Finally, display property values.

The following code sample shows how to load and read a 3D scene using C#.

Get Free Temporary License

You can get a free temporary license to try Aspose.3D for .NET without evaluation limitations.

Conclusion

In this article, we have learned how to:

  • create a 3D scene programmatically;
  • add objects/entities to the 3D scene such as Cylinder, material, light, etc.;
  • read 3D scene child notes and properties in C#.

Besides creating and reading 3D scene in C#, you can learn more about Aspose.3D for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also