SceneKit 命名空間
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
SceneKit 命名空間提供高階、基於場景圖的 3D 圖形。
類別
結構
| 名稱 | Description |
|---|---|
| SCNMatrix4 |
表示一個使用 欄位主記憶體配置的 4x4 矩陣。 |
| SCNQuaternion |
代表一個四元數。 |
| SCNVector3 |
表示使用三個單精度浮點數的三維向量。 |
| SCNVector4 |
表示使用四個單精度浮點數的四維向量。 |
介面
| 名稱 | Description |
|---|---|
| ISCNActionable |
允許執行動作。 |
| ISCNAnimatable |
允許套用動畫。 |
| ISCNAnimationProtocol |
此介面代表 Objective-C 協定 |
| ISCNAvoidOccluderConstraintDelegate |
此介面代表 Objective-C 協定 |
| ISCNBoundingVolume |
定義三維空間體積的函數。 |
| ISCNBufferStream |
管理自訂著色器的 Metal 緩衝區介面。 |
| ISCNCameraControlConfiguration |
此介面代表 Objective-C 協定 |
| ISCNCameraControllerDelegate |
此介面代表 Objective-C 協定 |
| ISCNNodeRendererDelegate |
介面定義代理物件函式,用於新增自訂 OpenGL 繪圖程式碼。 |
| ISCNPhysicsContactDelegate |
委接物件函式以回應物件間 SCNPhysicsBody 的觸碰...... |
| ISCNProgramDelegate |
將物件委派給 SCNProgram 物件。 |
| ISCNSceneExportDelegate |
定義處理場景匯出到檔案的方法的協定。 |
| ISCNSceneRenderer |
介面的 ISCNSceneRenderer 實作類別。 |
| ISCNSceneRendererDelegate |
SCNRenderer 類別的 Delegate 物件,定義方法反映渲染事件。 |
| ISCNShadable |
的實作 ISCNShadable。 |
| ISCNTechniqueSupport |
該實作 ISCNTechniqueSupport 僅僅引用 SCNTechnique。 |
列舉
委派
備註
Scene Kit 是一個基於階層場景圖的 3D 圖形框架。
Scene Kit 的基本類別為 SCNScene,該類別包含所有內容,以及 SCNView,a UIView 一個能渲染 。SCNScene
An SCNScene 具有 RootNode 一種屬性 SCNNode為 。
SCNNode擁有 ChildNodes 並實作 System.Collections.Generic.IEnumerable`1<class SceneKit.SCNNode>。 的 SCNNode 性質包括 Camera,型別 SCNCamera、 Geometry,型別 SCNGeometry,且 Light,型別 SCNLight。
此外,每個 SCNNode 都具有 Position 定義相對於 SCNNode空間 ParentNode中位置的性質。 要定義節點的外觀,先將 a SCNGeometry 附加到節點(利用屬性 Geometry ),然後將物件加入 SCNMaterial 幾何體。
以下範例展示了最小的場景套件視圖:
public MySceneView (CGRect frame) : base(frame)
{
BackgroundColor = UIColor.Blue;
this.Scene = new SCNScene ();
var material = new SCNMaterial ();
material.Diffuse.Contents = UIImage.FromFile("textureX.png");
material.Specular.Contents = UIColor.Gray;
material.LocksAmbientWithDiffuse = true;
Scene.RootNode.Geometry = new SCNBox {
Width = 1,
Height = 1,
Length = 1,
ChamferRadius = 0.2f,
FirstMaterial = material
};
Scene.RootNode.Light = new SCNLight {
LightType = SCNLightType.Ambient,
Color = UIColor.Gray,
};
var camera = new SCNCamera ();
var cameraNode = new SCNNode () {
Camera = camera,
Position = new SCNVector3 (3, 3, 3),
Constraints = new SCNConstraint[] { SCNLookAtConstraint.Create(Scene.RootNode) }
};
Scene.RootNode.AddChildNode (cameraNode);
}

Geometry
SceneKit 中的所有幾何體皆由 的 SCNGeometry子類別描述:
| SCNCapsule | 一個帶可調端蓋的膠囊膠囊 | |
| SCNCone | 一個頂部可以被截斷的錐體。 | |
| SCNBox | 一個長方形的盒子。 | |
| SCNCylinder | 圓柱圖。 | |
| SCNFloor | 一個無限平面,能反射其上方的幾何形狀。 | |
| SCNPlane | 一個單面長方形。 | |
| SCNPyramid | 四面體。 | |
| SCNShape | 一個被擠出到三維空間的二維形狀。 | |
| SCNSphere | 一顆舞會。 | |
| SCNText | 摘要。 | |
| SCNTorus | 一個甜甜圈形狀。 | |
| SCNTube | 一個沒蓋的圓筒。 | |
此外,SceneKit 也能從 . 載入整個場景。DAE 檔案中也有該 FromFile 方法。
最後,開發者可利用此 Create 方法建立包含適當 SCNGeometrySource 與 SCNGeometryElement 物件陣列的自訂幾何體。 以下展示了自訂金字塔的創建過程:
//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 });
