Sub topic 1
Objects and their data: what you are actually editing
Prerequisites
This chapter assumes you have the following:
- Blender is installed and open on the default startup scene.
- You can orbit, pan, and zoom the viewport.
- You can select objects and use Move, Rotate, and Scale.
- You know that a 3D mesh is made of vertices, edges, and faces.
- For the optional Python snippets, you know basic Python syntax.
Everything else is explained as it comes up.
Two layers: the object and its data
In Blender, the thing you click on in the viewport is usually not one thing. It is two layers that work together:
- The object is a container that places something in the scene. It stores a name, a location, a rotation, a scale, a parent, modifiers, and a link to some data.
- The object data is the content the object points to. For a mesh object, the data is the mesh: its vertices, edges, faces, UV maps, and so on. For a camera object, the data is the camera settings. For a light object, it is the light settings.
A useful picture is a picture frame and the picture in it. Moving or rotating the frame moves the whole picture. Painting on the picture changes what the picture looks like, and the frame stays where it is.
You can see this split in the interface. Select the default cube and open the Properties editor. The Object tab holds the container settings, such as Transform. The Data tab (a green triangle icon for meshes) holds the mesh settings, such as vertex groups and UV maps. The tabs for Modifiers and Materials also show up here, and they connect the two layers: modifiers belong to the object, while materials are linked through the data.
Which mode edits which layer
Blender uses interaction modes to decide which layer your tools act on. This chapter only introduces the idea. The next chapters cover each mode in detail.
| Mode | Layer you are working on | Typical actions |
|---|---|---|
| Object Mode | The object (the container) | Move, rotate, scale, duplicate, parent, delete whole objects |
| Edit Mode | The object's data (the mesh) | Move vertices, extrude faces, loop cut, bevel, merge |
If you press G and drag in Object Mode, the whole cube moves, because you are changing the object's location. If you press Tab, select one vertex, and press G, only that vertex moves, because you are changing the mesh data. The cube's origin point stays where it was.
Seeing the split in the Outliner
The Outliner shows the same structure as a tree. Expand an object, such as Cube, and you will see a child entry with the same icon as the Data tab, usually named Cube as well. This entry is the mesh data. Under it you may see materials, and objects may also list their modifiers.
The names are independent. Renaming the object to Crate does not rename the mesh. This matters for how you read the file, because two names can refer to different things:
Crateis the object name. It appears in the viewport and in the Outliner object list.Cubeis still the mesh name. It appears under the object and in the Data tab.
To rename the mesh, double-click its name in the Outliner or edit the name field at the top of the Data tab.
Shared data and linked duplicates
Because the object and its data are separate, several objects can use the same data. This is the practical result of the two-layer design, and it is the main source of surprises for people who learn it late.
Blender offers two kinds of duplicate:
- Duplicate Objects (
Shift+D) creates a new object and, for meshes by default, a new copy of the mesh data. The two objects are independent. Editing one mesh does not affect the other. - Duplicate Linked (
Alt+D) creates a new object that points to the same mesh data. The objects have separate transforms, but they share one mesh. Edit the mesh of one in Edit Mode and the other changes as well.
The Data tab tells you when this happens. The mesh name field shows a number next to it, such as 2, which is the user count: how many objects use this data block. If the count is above 1, edits to the mesh affect every user.
You can break the link with the Make Single User command, or by clicking the user count number next to the name field. After that, the object has its own private copy of the mesh.
Checking it from Python
Python exposes the same two layers. bpy.data.objects holds the containers, and bpy.data.meshes holds the mesh data. An object's data property is the link between them.
The next script prints the structure for every mesh object in the file, including the user count.
import bpy
for obj in bpy.data.objects:
if obj.type == 'MESH':
mesh = obj.data
print(
f"object={obj.name!r} "
f"mesh={mesh.name!r} "
f"users={mesh.users} "
f"vertices={len(mesh.vertices)}"
)On the default scene this prints one line, with Cube as both names and users=1. After a linked duplicate, you get two lines with different object names, the same mesh name, and users=2.
The following script shows that the two layers change independently. It moves the object and then moves one vertex of its mesh.
import bpy
obj = bpy.context.active_object
if obj is not None and obj.type == 'MESH':
bpy.ops.object.mode_set(mode='OBJECT')
obj.location.x += 2.0 # object-level change (transform)
obj.data.vertices[0].co.z += 1.0 # data-level change (one vertex)The first change moves the whole object by 2 units along X in world space. The second line changes the stored position of vertex 0 in the mesh's own local space. If the mesh is shared, every object that uses it shows the moved vertex.
Local space and world space
A vertex coordinate is stored relative to the object, not to the world. This is called local space. Blender combines the local coordinates with the object's location, rotation, and scale to get the vertex's position in the scene, called world space.
For the default cube with location (0, 0, 0), rotation (0, 0, 0), and scale (1, 1, 1), local and world coordinates are equal. Move the object to x = 5 and vertex coordinates in the mesh remain the same, but each vertex now appears 5 units further along X.
The following is a quick way to see both values for the first vertex:
import bpy
obj = bpy.context.active_object
if obj is not None and obj.type == 'MESH':
local_co = obj.data.vertices[0].co
world_co = obj.matrix_world @ local_co
print("local:", tuple(local_co))
print("world:", tuple(world_co))If you scale the object to 2 in Object Mode, the local values do not change, but the world values double (relative to the origin). This is why a scaled object can behave oddly when you add a Bevel modifier or use physics. The tools read the mesh and the transform separately. A later chapter covers applying transforms, which folds the object's scale and rotation into the mesh so that the object's transform returns to neutral.
Common errors
- Editing the wrong layer. You move the object when you meant to reshape the mesh, or the reverse. Check the mode shown in the header's mode menu before you transform something.
- Surprise changes on another object. An edit in one object also appears in another because the mesh is shared. Check the user count in the Data tab.
- Naming confusion. The object and mesh have different names. Rename both when you want the file to stay readable.
- Origin away from geometry. You moved vertices in Edit Mode and the origin did not follow. Rotation then pivots around a point outside the shape.
- Scripting in Edit Mode. Reading
obj.data.verticeswhile the object is in Edit Mode gives out-of-date data. Switch to Object Mode first, or use BMesh.
Summary of the model
An object is a container with a transform. Its data is the content. Object Mode works on containers, and Edit Mode works on the content. Several containers can share one content block, and the user count tells you when that is happening.
Exercise
You select an object named Wheel and use Duplicate Linked (Alt+D) to make Wheel.001. You then enter Edit Mode on Wheel.001 and extrude one face. What happens to Wheel, and what does the Data tab show for the mesh user count? How would you give Wheel.001 its own private mesh?
Show answer
Wheel changes too, because both objects point to the same mesh data and the extrusion edits that mesh. The user count next to the mesh name shows 2. To give Wheel.001 its own mesh, click the user count number next to the mesh name in the Data tab, or use Make Single User for the object data. The user count then drops to 1 for each mesh, and later edits affect only one object.
Exercise
A script runs obj.data.vertices[0].co.z += 1.0 on a mesh object that is currently in Edit Mode, and the change does not show up. Why, and what are two ways to fix it?
Show answer
In Edit Mode, Blender holds the editable mesh in a separate edit-time structure and only writes it back to obj.data when you leave Edit Mode, so the direct change is lost or ignored. One fix is to call bpy.ops.object.mode_set(mode='OBJECT') before changing obj.data.vertices. The other is to stay in Edit Mode, use bmesh.from_edit_mesh(obj.data) to change the vertices, and call bmesh.update_edit_mesh(obj.data) afterward.