mcpField
A
axiom-scenekit-ref

axiom-scenekit-ref

github.com/charleswiltgen开发1.2k130 次安装今天更新
代码仓库

关于 axiom-scenekit-ref

面向 SceneKit 开发者的 API 参考,提供主要 API 的说明及其与 RealityKit 概念的映射。通过列出对应项和需采用不同实现的部分,支持迁移规划。

主要功能

  1. 01SceneKit 到 RealityKit 概念映射
  2. 02场景图与变换参考
  3. 03材质和光照对照
  4. 04物理 API 映射
  5. 05动画与交互参考
  6. 06AR 集成映射

适用场景

  1. 01迁移时查找 RealityKit 对应 API
  2. 02查询 SceneKit 类的属性和方法
  3. 03规划 SceneKit 功能的替代方案
  4. 04比较场景图与 ECS 设计

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/charleswiltgen/axiom --skill axiom-scenekit-ref

安装后在 Claude Code 中输入/axiom-scenekit-ref确认已加载。

详细介绍

SceneKit API 参考与迁移映射

SceneKit 完整 API 参考,涵盖所有主要概念及其对应的 RealityKit 等效项。

何时使用此参考

在以下情况下使用此参考:

  • 迁移时查找 SceneKit → RealityKit API 等效项
  • 检查特定 SceneKit 类的属性或方法
  • 规划哪些 SceneKit 功能在 RealityKit 中有直接对应项
  • 了解场景图与 ECS 之间的架构差异

第 1 部分:SceneKit → RealityKit 概念映射

核心架构
SceneKitRealityKit说明
SCNSceneRealityViewContent / Entity(根)RealityKit 场景由实体层级构成
SCNNodeEntity两者中都是轻量级容器
SCNViewRealityView(SwiftUI)iOS 上 UIKit 对应 ARView
SceneView(SwiftUI)RealityViewSceneView 在 iOS 26 中已弃用
SCNRendererRealityRenderer底层 Metal 渲染
节点属性组件ECS 将数据与层级结构分离
SCNSceneRendererDelegateSystem / SceneEvents.Update帧级更新
.scn 文件.usdz / .usda 文件使用 xcrun scntool 转换
几何体与渲染
SceneKitRealityKit说明
SCNGeometryMeshResourceRealityKit 可通过代码生成,或加载 USD
SCNBox、SCNSphere 等MeshResource.generateBox()、.generateSphere()类似的内置形状
SCNMaterialSimpleMaterial、PhysicallyBasedMaterialRealityKit 优先采用 PBR
SCNMaterial.lightingModel = .physicallyBasedPhysicallyBasedMaterialRealityKit 中的默认选项
SCNMaterial.diffusePhysicallyBasedMaterial.baseColor属性名称不同
SCNMaterial.metalnessPhysicallyBasedMaterial.metallic属性名称不同
SCNMaterial.roughnessPhysicallyBasedMaterial.roughness概念相同
SCNMaterial.normalPhysicallyBasedMaterial.normal概念相同
着色器修饰符ShaderGraphMaterial / CustomMaterial无直接迁移方式 — 必须重写
SCNProgram(自定义着色器)使用 Metal 函数的 CustomMaterialAPI 形式不同
SCNGeometrySourceMeshResource.Contents底层网格数据
变换与层级结构
SceneKitRealityKit说明
node.positionentity.position两者分别使用 SCNVector3 / SIMD3
node.eulerAnglesentity.orientation(四元数)RealityKit 更倾向使用四元数
node.scaleentity.scale两者均为 SIMD3
node.transformentity.transform4×4 矩阵
node.worldTransformentity.transform(relativeTo: nil)世界空间变换
node.addChildNode(_:)entity.addChild(_:)层级结构概念相同
node.removeFromParentNode()entity.removeFromParent()概念相同
node.childNodesentity.children子级集合
node.parententity.parent父级引用
node.childNode(withName:recursively:)entity.findEntity(named:)按名称查找
光照
SceneKitRealityKit说明
SCNLight(.omni)PointLightComponent点光源
SCNLight(.directional)DirectionalLightComponent太阳光/方向光
SCNLight(.spot)SpotLightComponent锥形光
SCNLight(.area)无直接对应项使用多个点光源
SCNLight(.ambient)EnvironmentResource(IBL)优先使用基于图像的光照
SCNLight(.probe)EnvironmentResource环境探针
SCNLight(.IES)无直接对应项使用光照强度配置文件
Camera(相机)
SceneKitRealityKit说明
SCNCameraPerspectiveCamera entity带有相机组件的实体
camera.fieldOfViewPerspectiveCameraComponent.fieldOfViewInDegrees相同概念
camera.zNear / camera.zFarPerspectiveCameraComponent.near / .far裁剪平面
camera.wantsDepthOfField后期处理效果机制不同
camera.motionBlurIntensity后期处理效果机制不同
allowsCameraControl自定义手势处理没有内置的环绕相机
Physics(物理)
SceneKitRealityKit说明
SCNPhysicsBodyPhysicsBodyComponent基于组件
.dynamic.dynamic相同模式
.static.static相同模式
.kinematic.kinematic相同模式
SCNPhysicsShapeCollisionComponent / ShapeResource在 RealityKit 中与刚体分离
categoryBitMaskCollisionGroup命名组,而非原始位掩码
collisionBitMaskCollisionFilter基于筛选器
contactTestBitMaskCollisionEvents.Began 订阅基于事件的接触
SCNPhysicsContactDelegatescene.subscribe(to: CollisionEvents.Began.self)类似 Combine 的事件
SCNPhysicsFieldPhysicsBodyComponent 力直接施加力
SCNPhysicsJointPhysicsJoint关节类型相似
Animation(动画)
SceneKitRealityKit说明
SCNActionentity.move(to:relativeTo:duration:)变换动画
SCNAction.sequence动画串联在 RealityKit 中声明性较弱
SCNAction.group并行动画应用于不同实体
SCNAction.repeatForeverAnimationPlaybackController 重复播放API 不同
SCNTransaction(隐式)无直接对应项仅支持显式动画
CAAnimation 桥接entity.playAnimation()从 USD 加载
SCNAnimationPlayerAnimationPlaybackController播放控制
Morph targets(变形目标)USD 中的 Blend shapes(混合形状)通过 USD 文件加载
Interaction(交互)
SceneKitRealityKit说明
hitTest(_:options:)RealityViewContent.entities(at:)API 不同
SCNView 上的手势识别器ManipulationComponent内置拖动/旋转/缩放
allowsCameraControl自定义实现没有内置的环绕功能
AR Integration(AR 集成)
SceneKitRealityKit说明
ARSCNViewRealityView + AnchorEntity旧版 → 现代
ARSCNViewDelegateAnchorEntity 自动跟踪事件驱动
renderer(_:didAdd:for:)AnchorEntity(.plane)声明式锚定
ARWorldTrackingConfigurationSpatialTrackingSessioniOS 18+

第 2 部分:场景图 API

SCNScene
// Loading
let scene = SCNScene(named: "scene.usdz")!
let scene = try SCNScene(url: url, options: [
    .checkConsistency: true,
    .convertToYUp: true
])

// Properties
scene.rootNode                    // Root of node hierarchy
scene.background.contents        // Skybox (UIImage, UIColor, MDLSkyCubeTexture)
scene.lightingEnvironment.contents // IBL environment map
scene.fogStartDistance            // Fog near
scene.fogEndDistance              // Fog far
scene.fogColor                   // Fog color
scene.isPaused                   // Pause simulation
SCNNode
// Creation
let node = SCNNode()
let node = SCNNode(geometry: SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0))

// Transform
node.position = SCNVector3(x, y, z)
node.eulerAngles = SCNVector3(pitch, yaw, roll)
node.scale = SCNVector3(1, 1, 1)
node.simdPosition = SIMD3<Float>(x, y, z)  // SIMD variants available
node.pivot = SCNMatrix4MakeTranslation(0, -0.5, 0) // Offset pivot point

// Visibility
node.isHidden = false
node.opacity = 1.0
node.castsShadow = true
node.renderingOrder = 0   // Lower = rendered first

// Hierarchy
node.addChildNode(child)
node.removeFromParentNode()
node.childNodes
node.childNode(withName: "name", recursively: true)
node.enumerateChildNodes { child, stop in }

第 3 部分:材质

光照模型
模型说明用例
.physicallyBasedPBR 金属度-粗糙度真实感渲染(推荐)
.blinnBlinn-Phong 高光简单的光亮表面
.phongPhong 高光经典高光
.lambert仅漫反射,无高光哑光表面
.constant无光照、纯色UI 元素、调试可视化
.shadowOnly不可见,可接收阴影AR 地面平面
材质属性
let mat = SCNMaterial()
mat.lightingModel = .physicallyBased

// Textures or scalar values
mat.diffuse.contents = UIImage(named: "albedo")    // Base color
mat.metalness.contents = 0.0                        // 0 = dielectric, 1 = metal
mat.roughness.contents = 0.5                        // 0 = mirror, 1 = rough
mat.normal.contents = UIImage(named: "normal")      // Normal map
mat.ambientOcclusion.contents = UIImage(named: "ao") // AO map
mat.emission.contents = UIColor.blue                // Glow
mat.displacement.contents = UIImage(named: "height") // Height map

// Options
mat.isDoubleSided = false        // Render both sides
mat.writesToDepthBuffer = true
mat.readsFromDepthBuffer = true
mat.blendMode = .alpha           // .add, .subtract, .multiply, .screen
mat.transparencyMode = .aOne     // .rgbZero for pre-multiplied alpha

第 4 部分:物理

刚体类型和属性
// Dynamic body with custom shape
let shape = SCNPhysicsShape(geometry: SCNSphere(radius: 0.5), options: nil)
let body = SCNPhysicsBody(type: .dynamic, shape: shape)
body.mass = 1.0
body.friction = 0.5
body.restitution = 0.3       // Bounciness
body.damping = 0.1            // Linear damping
body.angularDamping = 0.1     // Angular damping
body.isAffectedByGravity = true
body.allowsResting = true     // Sleep optimization
node.physicsBody = body

// Compound shapes
let compound = SCNPhysicsShape(shapes: [shape1, shape2],
    transforms: [transform1, transform2])

// Concave (static only)
let concave = SCNPhysicsShape(geometry: mesh, options: [
    .type: SCNPhysicsShape.ShapeType.concavePolyhedron
])
关节类型
关节说明
SCNPhysicsHingeJoint单轴旋转(门)
SCNPhysicsBallSocketJoint绕点自由旋转(摆锤)
SCNPhysicsSliderJoint沿轴线性移动(抽屉)
SCNPhysicsConeTwistJoint限制旋转(布娃娃肢体)

第 5 部分:动画 API

SCNAction 目录
类别动作
移动move(by:duration:)、move(to:duration:)
旋转rotate(by:around:duration:)、rotateTo(x:y:z:duration:)
缩放scale(by:duration:)、scale(to:duration:)
淡入淡出fadeIn(duration:)、fadeOut(duration:)、fadeOpacity(to:duration:)
可见性hide()、unhide()
音频playAudio(source:waitForCompletion:)
自定义run { node in }、customAction(duration:action:)
组合sequence([])、group([])、repeat(_:count:)、repeatForever(_:)
控制wait(duration:)、removeFromParentNode()
计时函数
action.timingMode = .linear        // Default
action.timingMode = .easeIn        // Slow start
action.timingMode = .easeOut       // Slow end
action.timingMode = .easeInEaseOut // Slow start and end
action.timingFunction = { t in     // Custom curve
    return t * t  // Quadratic ease-in
}

第 6 部分:约束

约束用途
SCNLookAtConstraint节点始终面向目标
SCNBillboardConstraint节点始终面向摄像机
SCNDistanceConstraint保持最小/最大距离
SCNReplicatorConstraint复制目标的变换
SCNAccelerationConstraint平滑变换变化
SCNSliderConstraint锁定到轴
SCNIKConstraint反向运动学链
let lookAt = SCNLookAtConstraint(target: targetNode)
lookAt.isGimbalLockEnabled = true  // Prevent roll
lookAt.influenceFactor = 0.8       // Partial constraint
node.constraints = [lookAt]

在 RealityKit 中:没有直接的约束系统。可通过 System 更新逻辑或 entity.look(at:from:relativeTo:) 实现。


第 7 部分:场景配置

SCNView 配置
属性默认值描述
antialiasingMode.multisampling4XMSAA 级别
preferredFramesPerSecond60目标帧率
allowsCameraControlfalse内置环绕/平移/缩放
autoenablesDefaultLightingfalse若无灯光则添加默认灯光
showsStatisticsfalseFPS/节点/绘制次数叠加信息
isTemporalAntialiasingEnabledfalseTAA 平滑
isJitteringEnabledfalse用于 TAA 的时间抖动
debugOptions[].showPhysicsShapes、.showBoundingBoxes、.renderAsWireframe

资源

WWDC:2014-609、2014-610、2017-604、2019-612

文档:/scenekit、/scenekit/scnscene、/scenekit/scnnode、/scenekit/scnmaterial、/scenekit/scnphysicsbody、/scenekit/scnaction

技能:axiom-scenekit、axiom-realitykit、axiom-realitykit-ref

评论

支持 Markdown