Chapter 9: Comprehensive Project
9.1 Comprehensive use of the learned technologyProject development
In this chapter, we will use the various techniques learned in the previous chapters to develop a complete3D animationproject. This project will include 3D modeling, animation making, rendering, and some advanced techniques such as lighting and material settings. Through this comprehensive project, you will be able to consolidate and improve your understanding and application of these technologies.
9.1.1 Project Overview
We will create a simple 3D animation scene with the following elements:
A ground plane
A cube with material
A sphere with animation
Set up ambient lighting using HDRI maps
Use Python scripts forautomationcontrol
9.1.2 Project preparation
Before starting the project, we need to prepare some material files and tools:
Material file:
HDRI map files (for example:): can be downloaded for free from HDRI Haven. Visit [HDRI Haven]() and download your favorite HDRI stickers.
Texture files (for example:): can be downloaded for free from or Poly Haven. Visit [](/) or [Poly Haven](/textures) and download the texture file you need.
tool:
Blender (installed)
Make sure all material files are placed in the same directory as Python scripts to simplify path issues. Assuming your Python script path is E:\PycharmProjects\pythonProject3\run_manim.py, place all the material files in the E:\PycharmProjects\pythonProject3\ directory.
Sample directory structure:
E:\PycharmProjects\pythonProject3\
├── run_manim.py
├──
└──
9.1.3 Project implementation steps
We will implement this comprehensive project in steps, each step containing detailed code examples and explanations.
Step 1: Create a ground plane
Sample code:
import bpy # Delete all objects .select_all(action='SELECT') (use_global=False) # Create a ground plane .primitive_plane_add(size=10, location=(0, 0, 0)) plane = |
Code explanation:
.select_all(action='SELECT') and (use_global=False): Delete all objects.
.primitive_plane_add(size=10, location=(0, 0, 0)): Add a plane of size 10.
Step 2: Create a cube with material
Sample code:
# Create a cube .primitive_cube_add(location=(0, 0, 1)) cube = # Create a new material material = (name="Cube_Material") material.use_nodes = True # Get the material node tree node_tree = material.node_tree # Create image texture node tex_image = node_tree.('ShaderNodeTexImage') tex_image.image = ("E:\\PycharmProjects\\pythonProject3\\") # Get the original BSDF node bsdf = node_tree.nodes['Principled BSDF'] # Connect image texture node to BSDF node node_tree.(tex_image.outputs['Color'], ['Base Color']) # Apply material to cube if : [0] = material else: (material) |
Code explanation:
.primitive_cube_add(location=(0, 0, 1)): Add a cube.
(name="Cube_Material"): Create a new material.
material.use_nodes = True: Enable node system.
node_tree.('ShaderNodeTexImage'): Create an image texture node.
tex_image.image = ("E:\\PycharmProjects\\pythonProject3\\"): Load the image texture.
node_tree.(tex_image.outputs['Color'], ['Base Color']): Connect the image texture node to the BSDF node.
(material): Apply material to cubes.
Step 3: Create an animation sphere
Sample code:
# Create a sphere .primitive_uv_sphere_add(radius=0.5, location=(0, 0, 2)) sphere = # Set the initial position of the sphere and insert the keyframe = (0, 0, 2) sphere.keyframe_insert(data_path="location", frame=1) # Set the position of the sphere and insert keyframes = (0, 0, 0.5) sphere.keyframe_insert(data_path="location", frame=50) # Set the return position of the sphere and insert the keyframe = (0, 0, 2) sphere.keyframe_insert(data_path="location", frame=100) |
Code explanation:
.primitive_uv_sphere_add(radius=0.5, location=(0, 0, 2)): Add a sphere with a radius of 0.5.
sphere.keyframe_insert(data_path="location", frame=1): The keyframe of the position of the sphere inserted in the first frame.
sphere.keyframe_insert(data_path="location", frame=50): The position keyframe of the sphere is inserted at frame 50.
sphere.keyframe_insert(data_path="location", frame=100): The keyframe of the position of the sphere inserted at frame 100.
Step 4: Set ambient light
Sample code:
# Set the rendering engine to Cycles = 'CYCLES' # Load HDRI maps (filepath="E:\\PycharmProjects\\pythonProject3\\") hdri_image = [""] # Set up ambient light world = world.use_nodes = True env_node_tree = world.node_tree env_background = env_node_tree.nodes['Background'] env_tex_coord = env_node_tree.('ShaderNodeTexCoord') env_mapping = env_node_tree.('ShaderNodeMapping') env_env_texture = env_node_tree.('ShaderNodeTexEnvironment') # Connect to nodes env_node_tree.(env_tex_coord.outputs['Generated'], env_mapping.inputs['Vector']) env_node_tree.(env_mapping.outputs['Vector'], env_env_texture.inputs['Vector']) env_node_tree.(env_env_texture.outputs['Color'], env_background.inputs['Color']) # Set up HDRI maps env_env_texture.image = hdri_image |
Code explanation:
= 'CYCLES': Set the rendering engine to Cycles.
(filepath="E:\\PycharmProjects\\pythonProject3\\"): Load HDRI maps.
world.use_nodes = True: Enable node system.
env_node_tree.('ShaderNodeTexCoord'): Create texture coordinate nodes.
env_node_tree.('ShaderNodeMapping'): Create a mapping node.
env_node_tree.('ShaderNodeTexEnvironment'): Create an environment texture node.
env_node_tree.(...): Connect to node.
env_env_texture.image = hdri_image: Set HDRI map.
summary
Through the comprehensive project in this section, you will learn how to use the Python API for advanced use in Blender3D Modelingand render. We created a scene that contains ground planes, cubes with materials, spheres with animations, and sets ambient lighting using HDRI maps. Through these steps, you can apply the techniques learned in the previous chapters to a practical project to create more complex and high-quality 3D animations and scenes. In the following chapters, we will explore more advanced features and applications to further enhance your 3D creation skills.