A container for vertex data forming part of the definition for a three-dimensional object, or geometry.
- iOS 8.0+
- macOS 10.8+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
You create a custom geometry using a three-step process:
Create one or more
SCNGeometryobjects containing vertex data. Each geometry source defines an attribute, or semantic, of the vertices it describes. You must provide at least one geometry source, using the
vertexsemantic, to create a custom geometry; typically you also provide geometry sources for surface normals and texture coordinates.
Create at least one
SCNGeometryobject, containing an array of indices identifying vertices in the geometry sources and describing the drawing primitive that SceneKit uses to connect the vertices when rendering the geometry.
SCNGeometryinstance from the geometry sources and geometry elements.
Interleaving Vertex Data
Because most geometries use more than one geometry source and the GPU typically uses data from multiple sources together, you can achieve better rendering performance for custom geometries by interleaving the vertex data for multiple semantics in the same array.
To do this, first create an array where each element contains values for multiple semantics for the same vertex. Next, create an
NSData object from that array, and create each geometry source from that data using the
stride parameters to specify where the values for each semantic can be found in the array. To make specifying the sizes and locations of vectors more convenient, you can define your own data structure for vertices and use the
sizeof (and, in Objective-C,
offsetof) functions, as shown in Listing 1.