---
title: SCNGeometrySource
framework: scenekit
role: symbol
role_heading: Class
path: scenekit/scngeometrysource
---

# SCNGeometrySource

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

## Declaration

```swift
class SCNGeometrySource
```

## Overview

Overview You use geometry sources together with SCNGeometryElement objects to define custom SCNGeometry objects or to inspect the data that composes an existing geometry. You create a custom geometry using a three-step process: Create one or more 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 semantic, to create a custom geometry; typically you also provide geometry sources for surface normals and texture coordinates. Create at least one 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. Create an 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 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 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

- [init(data:semantic:vectorCount:usesFloatComponents:componentsPerVector:bytesPerComponent:dataOffset:dataStride:)](scenekit/scngeometrysource/init(data:semantic:vectorcount:usesfloatcomponents:componentspervector:bytespercomponent:dataoffset:datastride:).md)
- [init(vertices:)](scenekit/scngeometrysource/init(vertices:).md)
- [init(normals:)](scenekit/scngeometrysource/init(normals:).md)
- [init(textureCoordinates:)](scenekit/scngeometrysource/init(texturecoordinates:).md)

### Inspecting a Geometry Source

- [data](scenekit/scngeometrysource/data.md)
- [semantic](scenekit/scngeometrysource/semantic-swift.property.md)
- [vectorCount](scenekit/scngeometrysource/vectorcount.md)
- [usesFloatComponents](scenekit/scngeometrysource/usesfloatcomponents.md)
- [componentsPerVector](scenekit/scngeometrysource/componentspervector.md)
- [bytesPerComponent](scenekit/scngeometrysource/bytespercomponent.md)
- [dataOffset](scenekit/scngeometrysource/dataoffset.md)
- [dataStride](scenekit/scngeometrysource/datastride.md)

### Creating GPU-Mutable Geometry Sources

- [init(buffer:vertexFormat:semantic:vertexCount:dataOffset:dataStride:)](scenekit/scngeometrysource/init(buffer:vertexformat:semantic:vertexcount:dataoffset:datastride:).md)

### Geometry Source Semantics

- [SCNGeometrySource.Semantic](scenekit/scngeometrysource/semantic-swift.struct.md)

### Initializers

- [init(coder:)](scenekit/scngeometrysource/init(coder:).md)
- [init(data:semantic:vectorCount:floatComponents:componentsPerVector:bytesPerComponent:dataOffset:dataStride:)](scenekit/scngeometrysource/init(data:semantic:vectorcount:floatcomponents:componentspervector:bytespercomponent:dataoffset:datastride:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Geometry

- [SCNGeometry](scenekit/scngeometry.md)
- [SCNGeometryElement](scenekit/scngeometryelement.md)
- [Built-in Geometry Types](scenekit/built-in-geometry-types.md)
