iOS Guides | Samples

SceneKit.SCNGeometrySource Class

Provides vertex data that, in conjunction with SCNGeometryElements, define a 3D object.

See Also: SCNGeometrySource


[Foundation.Register("SCNGeometrySource", true)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.WatchOS, 3, 0, ObjCRuntime.PlatformArchitecture.All, null)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.MacOSX, 10, 8, ObjCRuntime.PlatformArchitecture.All, null)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 8, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public class SCNGeometrySource : NSObject, INSSecureCoding, IDisposable


Developers who wish to programmatically generate custom SCNGeometry objects use the SCNGeometry.Create(SCNGeometrySource[],SCNGeometryElement[]) method. The form and number of the SCNGeometrySource objects varies based on the manner in which the developer is describing the geometry (for instance, whether vertex data comes as a series of triplets describing triangles or a moving series that describes a triangle strip) and whether the geometry will simply be colored or have a texture map.

The following code demonstrates the custom code to create a custom four-sided pyramid. This example shows the use of vertices, defining triangles, on which a single texture is mapped. Note how specific index values within locs are used to define indices and how the ordering within locs affects normals and txCoords. Also, notice how the triplets in indices are linked to SCNGeometryPrimitiveType.Triangles.

C# Example

var a = new SCNVector3(-1, -1, 0);
var b = new SCNVector3(1, 1, 0);

var halfX = (c.X + a.X) / 2;
var halfY = (c.Y + a.Y) / 2;
var halfZ = (c.Z + a.Z) / 2;

var b = new SCNVector3(a.X, c.Y, halfZ);
var d = new SCNVector3(c.X, a.Y, halfZ);
//Elevate the midpoint so that it's clearly a pyramid
var midPoint = new SCNVector3(halfX, halfY, halfZ + 1.0);

//The vertices of the geometry
var locs = new [] {
	a, b, c, d, midPoint
var locSource = SCNGeometrySource.FromVertices(locs);

//Note that this relies on the ordering of locs above
//and it defines triangles (could be triangle strips, etc.)
var indices = new [] {
	//Triangles are defined counter-clockwise!
	4, 1, 0,
	1, 4, 2,
	2, 4, 3,
	3, 4, 0

var idxArray = new byte[indices.Length][];
for(int i = 0; i < idxArray.Length; i++)
	idxArray[i] = BitConverter.GetBytes(indices[i]);
var idxData = NSData.FromArray(idxArray.SelectMany(id => id).ToArray());

//Note that this relies on indices defining triangles
var element = SCNGeometryElement.FromData(idxData, SCNGeometryPrimitiveType.Triangles, indices.Length / 3, sizeof(int));

//Normals are relative to geometry
var normals = new [] {
	new SCNVector3(0, 0, 1),
	new SCNVector3(0, 0, 1),
	new SCNVector3(0, 0, 1),
	new SCNVector3(0, 0, 1),
	new SCNVector3(0, 0, 1),
var normSource = SCNGeometrySource.FromNormals(normals);

//These texture coords will cause the texture to wrap 
var txCoords = new [] {
	new CGPoint(0, 0),
	new CGPoint(0, 1),
	new CGPoint(1, 1),
	new CGPoint(1, 0),
  new CGPoint(0.5, 0.5)

var txCoordsSource = SCNGeometrySource.FromTextureCoordinates(txCoords);

var geometry = SCNGeometry.Create(new [] { locSource, normSource, txCoordsSource }, new [] { element });

Related content


Namespace: SceneKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions:

The members of SceneKit.SCNGeometrySource are listed below.

See Also: NSObject

Public Constructors

Default constructor, initializes a new instance of this class.
A constructor that initializes the object from the data stored in the unarchiver object.

Protected Constructors

Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

BytesPerComponentnint. The size, in bytes, of the underlying vector data.
ClassHandleIntPtr. The handle for this class.
ComponentsPerVectornint. The number of components per vector element in this source.
DataNSData. The underlying data buffer.
DataOffsetnint. The distance, in bytes, from the beginning of SCNGeometrySource.Data to the first vertex element.
DataStridenint. The number of bytes between vertex elements in SCNGeometrySource.Data.
FloatComponentsBoolean. Whether the vertex component data is made of nfloat values.
SemanticNSString. Corresponds to the SCNGeometrySourceSemantic value for this source.
VectorCountnint. The total number of vectors in the underlying SCNGeometrySource.Data.

Public Methods

Encodes the state of the object on the provided encoder
FromData(NSData, NSString, nint, Boolean, nint, nint, nint, nint) : SCNGeometrySource
FromData(NSData, SCNGeometrySourceSemantics, nint, Boolean, nint, nint, nint, nint) : SCNGeometrySource
FromMetalBuffer(IMTLBuffer, MTLVertexFormat, NSString, nint, nint, nint) : SCNGeometrySource
Factory method to create a new SCNGeometrySource from a data buffer.
FromMetalBuffer(IMTLBuffer, MTLVertexFormat, SCNGeometrySourceSemantics, nint, nint, nint) : SCNGeometrySource
Factory method to create a new SCNGeometrySource from a data buffer.
FromNormals(SCNVector3[]) : SCNGeometrySource
Factory method that creates a source for vertex normals.
FromTextureCoordinates(CGPoint[]) : SCNGeometrySource
Factory method that creates a source for texture coordinates.
FromVertices(SCNVector3[]) : SCNGeometrySource
Factory method to create a source for vertex data.