SCNGeometry Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Base class for SceneKit geometry objects
[Foundation.Register("SCNGeometry", true)]
public class SCNGeometry : Foundation.NSObject, Foundation.INSCopying, Foundation.INSSecureCoding, IDisposable, SceneKit.ISCNAnimatable, SceneKit.ISCNBoundingVolume, SceneKit.ISCNShadable
[<Foundation.Register("SCNGeometry", true)>]
type SCNGeometry = class
inherit NSObject
interface INSCoding
interface INativeObject
interface IDisposable
interface INSCopying
interface INSSecureCoding
interface ISCNAnimatable
interface ISCNBoundingVolume
interface ISCNShadable
- Inheritance
- Derived
- Attributes
- Implements
Remarks
All geometry in SceneKit is described by subclasses of SCNGeometry:
| SCNCapsule | A pill-shaped capsule with adjustable end caps | |
| SCNCone | A cone whose top can be truncated | |
| SCNBox | A rectangular box. | |
| SCNCylinder | A cylinder. | |
| SCNFloor | An infinite plane with the ability to reflect the geometry above it. | |
| SCNPlane | A one-sided rectangle. | |
| SCNPyramid | A tetrahedron. | |
| SCNShape | A 2D shape that has been extruded into the 3rd dimension. | |
| SCNSphere | A sphere. | |
| SCNText | Extruded text. | |
| SCNTorus | A donut shape. | |
| SCNTube | An uncapped cylinder. | |
Subclasses are typically instantiated with a static Create factory method rather than a constructor.
In addition, SceneKit can load entire scenes from .DAE files with the FromFile(String) method.
Developers can create geometry from a ModelIO mesh using FromMesh(MDLMesh).
Finally, developers can create custom geometry using the Create(SCNGeometrySource[], SCNGeometryElement[]) method with arrays of appropriate SCNGeometrySource and SCNGeometryElement objects. The following shows the creation of a custom pyramid:
//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(-1, -1),
new CGPoint(-1, 1),
new CGPoint(1, 1),
new CGPoint(1, -1)
};
var txCoordsSource = SCNGeometrySource.FromTextureCoordinates(txCoords);
var geometry = SCNGeometry.Create(new [] { locSource, normSource, txCoordsSource }, new [] { element });

Constructors
| Name | Description |
|---|---|
| SCNGeometry(NativeHandle) |
A constructor used when creating managed representations of unmanaged objects. Called by the runtime. |
| SCNGeometry(NSCoder) |
A constructor that initializes the object from the data stored in the unarchiver object. |
| SCNGeometry(NSObjectFlag) |
Constructor to call on derived classes to skip initialization and merely allocate the object. |