SCNGeometry.Create Method

Definition

Overloads

Create()

Creates a new geometry element.

Create(SCNGeometrySource[], SCNGeometryElement[])

Creates a new geometry object from the specified arrays of sources and elements.

Create()

Creates a new geometry element.

[Foundation.Export("geometry")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.MacOSX, 10, 9, ObjCRuntime.PlatformArchitecture.All, null)]
public static SceneKit.SCNGeometry Create ();
static member Create : unit -> SceneKit.SCNGeometry

Returns

Attributes

Applies to

Create(SCNGeometrySource[], SCNGeometryElement[])

Creates a new geometry object from the specified arrays of sources and elements.

[Foundation.Export("geometryWithSources:elements:")]
public static SceneKit.SCNGeometry Create (SceneKit.SCNGeometrySource[] sources, SceneKit.SCNGeometryElement[] elements);
static member Create : SceneKit.SCNGeometrySource[] * SceneKit.SCNGeometryElement[] -> SceneKit.SCNGeometry

Parameters

sources
SCNGeometrySource[]

An array of SCNGeometrySource objects.

elements
SCNGeometryElement[]

An array of SCNGeometryElement objects.

This parameter can be null.

Returns

Attributes

Remarks

Used to create custom geometry. Depending on the needs of the developer, the number and types of the sources and elements arrays can be highly variable. The following 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.

//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);

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 });

Applies to