BlenderDev/derived mesh
Wikipedia,自由的百科全书
blender的mesh是最简单的那种数据结构,点线面,采用的是双向链表进行连接,分别有三种数据结构:mesh editmesh displistmesh,这些数据的操作都用derivedmesh 来完成。这里面有相当的优化。
http://wiki.blendercn.org/index.php/BlenderDev/BlenderArchitecture/DerivedMesh
Contents |
DerivedMesh
Blender Mesh Data Structures
Blender 网格数据结构
Blender has many different mesh types, each with data structures adapted to the task at hand. DerivedMesh provides an single interface for reading and drawing multiple mesh types. Here is an overview of the most important ones for this document.
Blender有很多不同的网格类型, 每一种类型都有适合特定任务的数据结构。DerivedMesh为读写多种网格类型提供了统一的接口。这份文档介绍了几种最重要的网格类型。
Mesh
This is the data structure that is used to hold the contents of Mesh datablocks. It is also written directly to file. Mesh stores its vertices, edges and faces in arrays. For this datatype memory efficient storage and fast drawing is most important.
这个数据结构用于存储Mesh数据块的内容。它可以直接写入文件中。Mesh数据结构用数组存储了顶点,边和面。这种数据类型增强了内存存储效率并实现了模型的迅速显示。
Defined in: DNA_mesh_types.h
定义:DNA_mesh_types.h
EditMesh
EditMesh is used to edit a Mesh data structure. When entering edit mode, Mesh is converted to EditMesh. Its vertices, edges and faces are stored as double linked lists. EditMesh is more convenient for editing than Mesh. For example, it allows vertices, edges and faces to be removed and added efficiently, without having to resize the whole array.
EditMesh用于编辑网格。进入编辑模式后,Mesh就被转换成EditMesh。它的顶点,边和面的存储方式转换成双向链表。EditMesh比Mesh更适合网格编辑。比如,它令添加和删除顶点、边和面的操作更加高效,因为双向链表不必修改整个数组。
Defined in: BLI_editVert.h
定义: BLI_editVert.h
Verse Geometry
Verse stores meshes in geometry nodes, and their vertices and faces in vertex and polygon layers respectively. Geometry may change at any point, and a Dynamic List with Acces Array is used to support this efficiently.
Verse将网格存储在几何体节点中,他们的顶点和面分别存储在顶点层和多边形层。几何体可能因其中一个层中的数据改变而改变。动态列表和附属数组使这一结构更加高效。
Defined: BKE_verse.h
定义: BKE_verse.h
DerivedMesh
Derived Mesh provides an abstraction of multiple Mesh data types. This way reading data from and drawing different types of meshes can be done using a single interface. When modifiers are applied to meshes, the resulting mesh is returned as a DerivedMesh. How elements are stored is decided by the backend. DerivedMesh also provides optional storage for elements and custom data as arrays, if the backend decides to use this.
派生网格(Derived Mesh)是多种网格数据类型的抽象概括形式。使用DerivedMesh,就是用统一的接口从不同类型的网格读取数据并将模型画到屏幕上。元素的存储方式由低端接口决定。如果低端接口要求使用数组存储,DerivedMesh也可以将数据优化存储成数组方式。
Defined in: BKE_DerivedMesh.h
定义: BKE_DerivedMesh.h
DerivedMesh Interface
The DerivedMesh interface is illustrated in (DerivedMesh operation). It consists of a number of function pointers, that are implemented by different backends. It has functions to:
- Read data by accessing individual or arrays of elements. For exporting to file, the renderer, python, ..
- Draw vertices, edges, faces, uvs with all kinds of options.
- Iterate over the mapped (original) elements of in a modified mesh for drawing and selection.
- Convert to a Mesh for applying modifiers, object conversion, ..
A DerivedMesh can be created from a Mesh, EditMesh or DispListMesh, with modifiers and deformations applied optionally. Objects and EditMesh cache the DerivedMesh result. This gives the following classes of DerivedMeshes that can be created:
- Mesh:
- Final: all modifiers visible in the viewport applied. Used for display in the 3d viewport, vertex/weight painting, faceselect mode selection.
- Deform: only deforming modifiers applied. Used by a few specific tools: softbody collision, texface text drawing, created shaded vertex colors, .. .
- Render: final with render specific settings, e.g. subsurf level. Used for rendering and python Mesh module.
- No deform: all non-deforming modifiers applied. For orco computation and alt+c conversion.
- EditMesh:
- Cage: all edit mode cage modifiers and deformations applied. For drawing and selection in edit mode.
- Final: all edit mode visible modifiers applied. For drawing in edit mode.
- Base: no modifiers or deformations. For linked drawing, and bone as mesh drawing.
DerivedMesh Backends
DerivedMesh has multiple backends that implement the functions mentioned above. This avoids having to copy the results to a common mesh data structure everytime, and so saves memory and time.
cdDM
Data structure: CDDerivedMesh
Used for:
- Mesh without or without deformation
- Creating meshes in the modifier stack
emDM
Data structure: EditMesh
Used for:
- EditMesh without deformations
- EditMesh with deformations (stored separate in an array)
vDM
Data structure: VNode, VLayer
Used for:
- Displaying meshes in object mode shared on a Verse server
ccgDM
Data structure: CCGSubSurf
Used for:
- Creating meshes in the subsurf modifier
This data structure is used instead of cdDM for efficiency. CCGSubsurf can be incrementally updated with changes, for faster repeated computation of the result. Drawing of ccgDM is optimized by using quad strips.
Modifier Stack
DerivedMesh is closely tied to the Modifier stack. It is the only way to retrieve modified meshes from the Modifier stack.
All modifiers take a DerivedMesh as input. For deforming modifiers, that change the vertex coordinates of the mesh, the modifiers must only fill an array of vertices coordinates. Modifiers that change the structure of the mesh must provide a DerivedMesh as output. For nearly all modifiers a cdDM should be created. The subsurf modifiers makes an exception here, and used its own ccgDM for efficiency, since it deals with large amounts of elements.
Some more info on modifiers: BlenderDev/Modifiers

