3D in Python

3D modeling and visualization have become an essential part of various industries, such as gaming, architecture, and virtual reality. In this article, we’ll explore how to work with 3D models in Python, focusing on creating and reading 3D model scenes. We will explore the Aspose.3D library in Python, a powerful and easy-to-use tool for creating, manipulating, and reading 3D models. Let’s dive into 3D modeling with Python!

This article covers the following topics:

  1. Python 3D Library – 3D in Python
  2. Create a Simple 3D Scene in Python
  3. Create a Material in 3D Scene
  4. Add Light to a 3D Scene
  5. Create a Primitive 3D Model in Python
  6. Read 3D Scene in Python

Python 3D Library – 3D in Python

Aspose.3D for Python is a versatile, feature-rich, and highly efficient 3D modeling solution for Python developers. It offers a comprehensive set of features that enable users to create, read, and modify 3D models easily. Some key features of this Python 3D library include:

  • Support for popular 3D file formats such as FBX, OBJ, STL, and more
  • High-performance 3D rendering and visualization capabilities
  • Advanced scene management and manipulation tools
  • Extensive documentation and code samples to help developers get started quickly

Please either download the package or install the API from PyPI using the following pip command in the console:

pip install aspose-3d

Create a Basic 3D Scene in Python

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

  1. Create an instance of the Scene class.
  2. After that, call the create_child_node() method to add some geometry, a shape to show on screen, e.g., a sphere.
  3. Finally, save the scene as FBX using the save() method.

The following code sample shows how to create a simple 3D scene in Python.

3D Scene in Python

3D Scene in Python.

Create a Material in 3D Scene using Python

We can create the material with diffuse color in a 3D scene by following the steps below:

  1. Create an instance of the Scene class.
  2. Call the create_child_node() method to add a sphere.
  3. Initialize the LambertMaterial class object.
  4. Specify the diffuse_color and name properties.
  5. After that, assign the material object to the Sphere model.
  6. Finally, save the scene as FBX using the save() method.

The following code sample shows how to create material with diffuse color in a 3D scene using Python.

Material in 3D Scene

Creating Material in 3D Scene.

Add Light to a 3D Scene using Python

We can also add light to a 3D scene by following the steps below:

  1. Create an instance of the Scene class.
  2. Call the create_child_node() method to add a sphere.
  3. Initialize the Light class object.
  4. Specify the light_type and name properties.
  5. After that, call the create_child_node() method to add the light entity.
  6. Finally, save the scene as FBX using the save() method.

The following code sample shows how to create light in a 3D scene using Python.

Primitive 3D Model Python

A primitive is a three-dimensional geometric shape that is the basis for creating complex geometric forms. We can create a primitive 3D model by following the steps mentioned earlier. However, we need to add multiple geometric shapes or objects, as shown in the code sample below:

Read 3D Scene in Python

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

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

The following code sample shows how to load and read a 3D scene in Python.

{0} Box
{0} Cylinder

Get a Free License

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

3D in Python – Python 3D Library Learning Resources

You can learn more about creating and manipulating 3D models and scenes in Python and explore other features of the library using the resources given below:

Conclusion

In this article, we introduce the Aspose.3D library and demonstrate its capabilities in creating, reading, and manipulating 3D models in Python. With support for various 3D file formats, advanced scene management, and high-performance rendering, the Aspose.3D library is an invaluable tool for Python developers working with 3D content. By using the Aspose.3D library, you can streamline your 3D modeling projects and create stunning 3D scenes easily. In case of any ambiguity, please contact us on our free support forum.

See Also