SceneKit 命名空间
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
SceneKit 命名空间提供基于场景图的高级 3D 图形。
类
结构
| 名称 | 说明 |
|---|---|
| SCNMatrix4 |
表示使用列主内存布局的 4x4 矩阵。 |
| SCNQuaternion |
表示四元数。 |
| SCNVector3 |
表示使用三个单精度浮点数的 3D 向量。 |
| SCNVector4 |
表示使用四个单精度浮点数的 4D 向量。 |
接口
| 名称 | 说明 |
|---|---|
| ISCNActionable |
允许应用操作。 |
| ISCNAnimatable |
允许应用动画。 |
| ISCNAnimationProtocol |
此接口表示 Objective-C 协议 |
| ISCNAvoidOccluderConstraintDelegate |
此接口表示 Objective-C 协议 |
| ISCNBoundingVolume |
在 3D 空间中定义卷的函数。 |
| ISCNBufferStream |
用于管理自定义着色器的金属缓冲区的接口。 |
| ISCNCameraControlConfiguration |
此接口表示 Objective-C 协议 |
| ISCNCameraControllerDelegate |
此接口表示 Objective-C 协议 |
| ISCNNodeRendererDelegate |
定义用于添加自定义 OpenGL 绘图代码的委托对象函数的接口。 |
| ISCNPhysicsContactDelegate |
委托响应对象之间的 SCNPhysicsBody 触摸的对象函数。 |
| ISCNProgramDelegate |
SCNProgram 对象的委托对象。 |
| ISCNSceneExportDelegate |
用于定义将场景导出到文件的方法的协议。 |
| ISCNSceneRenderer |
接口的 ISCNSceneRenderer 实现类。 |
| ISCNSceneRendererDelegate |
SCNRenderer 类的委托对象,定义方法反映呈现事件。 |
| ISCNShadable |
ISCNShadable 的实现。 |
| ISCNTechniqueSupport |
其 ISCNTechniqueSupport 实现只是保留对 的 SCNTechnique引用。 |
枚举
委托
注解
场景工具包是基于分层场景图的 3D 图形框架。
场景工具包中的基本类包含SCNScene所有内容,以及SCNView呈现元素SCNScene的类UIView。
一 SCNScene 个 RootNode 属性的类型 SCNNode为 .
SCNNode's have ChildNodes and implement System.Collections.Generic.IEnumerable`1<class SceneKit.SCNNode>.
SCNNode类型Camera、类型SCNCameraGeometry、类型、类型的SCNGeometry属性和Light类型的SCNLight属性。
此外,每个 SCNNode 属性都有一个 Position 属性,用于定义空间中相对于 SCNNode's ParentNode的位置。 若要定义节点的外观,请附加到 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 还可以从中加载整个场景。使用该方法的 FromFile DAE 文件。
最后,开发人员可以使用包含适当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 });
