Chapter 61. Qt 3D Graphics

This chapter will reveal the topic of 3D in Qt, where complex scenes cease to be a problem. Here you’ll discover how Qt 3D architecture allows thinking not in meshes and coordinates, but in behavior, lighting, and interaction. It will show how professional developers achieve visual depth.

The entity component system (ECS), three types of light sources, several types of cameras, and at least 5 key transformations that change scene perception will be employed. It shows how animation in 3D can be implemented without game engines — using tools already available in Qt.

Skipping this chapter means remaining at the “static models” level, while true spatial thinking in Qt begins here.

This chapter includes ready-to-use code examples.

Chapter Self-Check

Why was the entity component system (ECS) borrowed in Qt 3D from game engines?Answer
Correct answer: The main advantage of ECS is the flexibility to change entity behavior in real-time by adding or removing components without interrupting program execution.
Why does an Entity itself not carry behavior and characteristics?Answer
Correct answer: Entities are containers for components. Behavior is added by combining components (geometry, material, transformation), which provides architecture modularity and flexibility.
What type of light should be used to simulate sunlight and why?Answer
Correct answer: Directional light (DirectionalLight), since it emits rays from infinite distance and illuminates all scene objects equally, regardless of their location, which corresponds to the nature of sunlight.
Why is pure white color not recommended for daylight lighting?Answer
Correct answer: For greater realism, tints should be added (e.g., yellowish), since in the real world daylight is not absolutely white.
Why can cameras in Qt 3D have their position changed and animated?Answer
Correct answer: This allows creating motion effects inside or along objects (buildings, tunnels), showing the scene from different angles, and creating cinematic effects.
What are normal vectors (vn) used for in the OBJ format?Answer
Correct answer: Normals are perpendicular to face surfaces and are necessary for correct calculation of lighting, shadows, and reflections on 3D objects.
What’s the key difference between PhongMaterial and GoochMaterial in terms of performance?Answer
Correct answer: GoochMaterial renders faster since it doesn’t create smoothing and highlights, making it perfect for test visualizations, while PhongMaterial creates more realistic shiny surfaces.
What will happen if you don’t set cameraAspectRatioMode to Scene3D.AutomaticAspectRatio?Answer
Correct answer: When resizing the window, scene objects will be distorted, since display proportions won’t automatically adjust to new window dimensions.
Why can standard Qt 3D objects be used as “building material”?Answer
Correct answer: Simple shapes (spheres, cylinders, cones) can compose complex objects using transformations, as shown in the snowman example made of five spheres, two cylinders, and a cone.
What problem does the sequence of rotate() and translate() calls solve in the transformation matrix?Answer
Correct answer: First rotate() rotates the object, then translate() shifts it, allowing creation of an object rotation effect at a distance from center (orbital motion).
Why specify “input” and “logic” values in the aspects property of the Scene3D element?Answer
Correct answer: This is necessary for the scene to receive and interpret user input (keyboard, mouse, touchpad) for camera control and scene interaction.
Why is geometry (Mesh) alone insufficient for displaying a 3D object?Answer
Correct answer: Geometry defines only the object’s shape, not its visual display. A material is needed for display, which creates the surface and determines how it reflects light.
What advantage does the new PrincipledMaterial material give in Qt6?Answer
Correct answer: It’s based on physically-based rendering (PBR) and provides more realistic display with roughness, metalness, and normal parameters.
How can you create a cylinder using the ConeMesh element?Answer
Correct answer: Assign the same values to topRadius and bottomRadius properties, which will turn the cone into a cylinder with equal bases.
Why can elements used for 2D animation be used for 3D animation?Answer
Correct answer: Elements like NumberAnimation change object properties over time, which is universal for any type of graphics — whether changing position, rotation angle, or scale in 2D or 3D.

Practical Assignments

Easy Level

Interactive Geometric Shapes Gallery
Create a 3D scene with three different geometric objects (sphere, cube, torus) arranged on one horizontal line. Each object should have its own unique material color. Add a point light source and set up camera control for viewing the scene.
Hints: Use SphereMesh, CuboidMesh, and TorusMesh. To position objects along a line, apply Transform with different translation values along the X axis. Assign each object PhongMaterial with a unique diffuse color. Don’t forget FirstPersonCameraController for camera control.

Medium Level

Animated Solar System
Create a simplified solar system model: a central “Sun” (large sphere with bright material) and two “planets” (smaller spheres) rotating around it on different orbits and at different speeds. Use directional light to simulate sunlight. Add planet rotation around their own axis.
Hints: For orbital motion, use Transform with a transformation matrix: first rotate() for orbit angle, then translate() for distance from center. Apply NumberAnimation to the property controlling the angle. For axis rotation, create a separate rotationY animation. Set different duration values for different speeds.

Hard Level

3D Scene with Multiple Lighting and Composite Object
Create a complex composition from standard 3D objects (e.g., a robot or architectural structure) using at least 6 different geometric shapes. Implement a lighting system with three different source types (point, directional, spotlight) with different colors. Add animation for two composition components and animated spotlight movement that “follows” one of the moving elements.
Hints: Group related objects in separate Entities for convenience. Use transformations for precise positioning of each composition part. For spotlight (SpotLight), animate Transform properties, synchronizing them with the target object’s movement. Experiment with intensity and color properties of light sources to create dramatic effects. Use different materials (PhongMaterial, GoochMaterial) for contrast.

💬 Join the Discussion!

Figured out the entity component system? Experimented with different types of lighting and materials?

Share your 3D creations, talk about difficulties working with transformations, or help other readers master Qt 3D! Your experience creating animated scenes can be very useful to the community.

Discuss: What types of projects are you planning to create with Qt 3D? Have questions about rendering performance or scene optimization?

Leave a Reply

Your email address will not be published. Required fields are marked *