iOS Guides | Samples

SceneKit.SCNGeometrySource Class

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

See Also: SCNGeometrySource

Syntax

[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

Remarks

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

//Lower-left
var a = new SCNVector3(-1, -1, 0);
//Upper-right
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

Requirements

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

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

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

Public Methods

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