<!--
{
  "availability" : [
    "iOS: 8.0.0 - 26.0.0",
    "iPadOS: 8.0.0 - 26.0.0",
    "macCatalyst: 13.1.0 - 26.0.0",
    "macOS: 10.8.0 - 26.0.0",
    "tvOS: 9.0.0 - 26.0.0",
    "visionOS: 1.0.0 - 26.0.0",
    "watchOS: 3.0.0 - 26.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SceneKit",
  "identifier" : "/documentation/SceneKit/SCNGeometrySource",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "SceneKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SCNGeometrySource"
  },
  "title" : "SCNGeometrySource"
}
-->

# SCNGeometrySource

A container for vertex data forming part of the definition for a three-dimensional object, or geometry.

```
class SCNGeometrySource
```

## Overview

You use geometry sources together with [`SCNGeometryElement`](/documentation/SceneKit/SCNGeometryElement) objects to define custom [`SCNGeometry`](/documentation/SceneKit/SCNGeometry) objects or to inspect the data that composes an existing geometry.

You create a custom geometry using a three-step process:

1. Create one or more [`SCNGeometrySource`](/documentation/SceneKit/SCNGeometrySource) objects 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 [`vertex`](/documentation/SceneKit/SCNGeometrySource/Semantic-swift.struct/vertex) semantic, to create a custom geometry; typically you also provide geometry sources for surface normals and texture coordinates.
2. Create at least one [`SCNGeometryElement`](/documentation/SceneKit/SCNGeometryElement) object, 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.
3. Create an [`SCNGeometry`](/documentation/SceneKit/SCNGeometry) instance 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 <doc://com.apple.documentation/documentation/Foundation/NSData> object from that array, and create each geometry source from that data using the `offset` and `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.

Listing 1. Creating multiple geometry sources from interleaved data

```objc
typedef struct {
    float x, y, z;    // position
    float nx, ny, nz; // normal
    float s, t;       // texture coordinates
} MyVertex;
 
MyVertex vertices[VERTEX_COUNT] = { /* ... vertex data ... */ };
NSData *data = [NSData dataWithBytes:vertices length:sizeof(vertices)];
SCNGeometrySource *vertexSource, *normalSource, *tcoordSource;
 
vertexSource = [SCNGeometrySource geometrySourceWithData:data
                                                semantic:SCNGeometrySourceSemanticVertex
                                             vectorCount:VERTEX_COUNT
                                         floatComponents:YES
                                     componentsPerVector:3 // x, y, z
                                       bytesPerComponent:sizeof(float)
                                              dataOffset:offsetof(MyVertex, x)
                                              dataStride:sizeof(MyVertex)];
 
normalSource = [SCNGeometrySource geometrySourceWithData:data
                                                semantic:SCNGeometrySourceSemanticNormal
                                             vectorCount:VERTEX_COUNT
                                         floatComponents:YES
                                     componentsPerVector:3 // nx, ny, nz
                                       bytesPerComponent:sizeof(float)
                                              dataOffset:offsetof(MyVertex, nx)
                                              dataStride:sizeof(MyVertex)];
 
tcoordSource = [SCNGeometrySource geometrySourceWithData:data
                                                semantic:SCNGeometrySourceSemanticTexcoord
                                             vectorCount:VERTEX_COUNT
                                         floatComponents:YES
                                     componentsPerVector:2 // s, t
                                       bytesPerComponent:sizeof(float)
                                              dataOffset:offsetof(MyVertex, s)
                                              dataStride:sizeof(MyVertex)];
```

## Topics

### Creating Geometry Sources

[`+  geometrySourceWithData:semantic:vectorCount:floatComponents:componentsPerVector:bytesPerComponent:dataOffset:dataStride:`](/documentation/SceneKit/SCNGeometrySource/init(data:semantic:vectorCount:usesFloatComponents:componentsPerVector:bytesPerComponent:dataOffset:dataStride:))

Creates a geometry source from the specified data and options.

[`init(vertices:)`](/documentation/SceneKit/SCNGeometrySource/init(vertices:))

Creates a geometry source from an array of vertex positions.

[`init(normals:)`](/documentation/SceneKit/SCNGeometrySource/init(normals:))

Creates a geometry source from an array of normal vectors.

[`init(textureCoordinates:)`](/documentation/SceneKit/SCNGeometrySource/init(textureCoordinates:))

Creates a geometry source from an array of texture coordinate points.

[`+  geometrySourceWithVertices:count:`](/documentation/SceneKit/SCNGeometrySource/geometrySourceWithVertices:count:)

Creates a geometry source from an array of vertex positions.

[`+  geometrySourceWithNormals:count:`](/documentation/SceneKit/SCNGeometrySource/geometrySourceWithNormals:count:)

Creates a geometry source from an array of normal vectors.

[`+  geometrySourceWithTextureCoordinates:count:`](/documentation/SceneKit/SCNGeometrySource/geometrySourceWithTextureCoordinates:count:)

Creates a geometry source from an array of texture coordinate points.

### Inspecting a Geometry Source

[`data`](/documentation/SceneKit/SCNGeometrySource/data)

The data for the geometry source.

[`semantic`](/documentation/SceneKit/SCNGeometrySource/semantic-swift.property)

The semantic value (or attribute) the geometry source describes for each vertex.

[`vectorCount`](/documentation/SceneKit/SCNGeometrySource/vectorCount)

The number of vectors in the data.

[`floatComponents`](/documentation/SceneKit/SCNGeometrySource/usesFloatComponents)

A Boolean value that indicates whether vector components are floating-point values.

[`componentsPerVector`](/documentation/SceneKit/SCNGeometrySource/componentsPerVector)

The number of scalar components in each vector.

[`bytesPerComponent`](/documentation/SceneKit/SCNGeometrySource/bytesPerComponent)

The size, in bytes, of each vector component.

[`dataOffset`](/documentation/SceneKit/SCNGeometrySource/dataOffset)

The offset, in bytes, from the beginning of the data to the first vector component to be used in the geometry source.

[`dataStride`](/documentation/SceneKit/SCNGeometrySource/dataStride)

The number of bytes from a vector to the next one in the data.

### Creating GPU-Mutable Geometry Sources

[`+  geometrySourceWithBuffer:vertexFormat:semantic:vertexCount:dataOffset:dataStride:`](/documentation/SceneKit/SCNGeometrySource/init(buffer:vertexFormat:semantic:vertexCount:dataOffset:dataStride:))

Creates a geometry source whose vertex data resides in the specified Metal buffer, allowing modification through a Metal compute shader.

### Geometry Source Semantics

[`Semantic`](/documentation/SceneKit/SCNGeometrySource/Semantic-swift.struct)

## Relationships

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)