【发布时间】:2020-09-18 00:42:55
【问题描述】:
【问题讨论】:
标签: swift augmented-reality arkit realitykit
【问题讨论】:
标签: swift augmented-reality arkit realitykit
将新的Physics Material 应用到您的模型实体。
为此使用generate(friction:restitution:)type method:
static func generate(friction: Float = 0,
restitution: Float = 0) -> PhysicsMaterialResource
在哪里
/* the coefficient of friction is in the range [0, infinity] */
/* and the coefficient of restitution is in the range [0, 1] */
这是一个代码:
arView.environment.background = .color(.darkGray)
let mesh = MeshResource.generateSphere(radius: 0.5)
let material = SimpleMaterial()
let model = ModelEntity(mesh: mesh,
materials: [material]) as (ModelEntity & HasPhysics)
let physicsResource: PhysicsMaterialResource = .generate(friction: 0,
restitution: 0)
model.components[PhysicsBodyComponent] = PhysicsBodyComponent(
shapes: [.generateSphere(radius: 0.51)],
mass: 20, // in kilograms
material: physicsResource,
mode: .dynamic)
model.generateCollisionShapes(recursive: true)
let anchor = AnchorEntity()
anchor.addChild(model)
arView.scene.anchors.append(anchor)
附:由于 RealityKit 中物理引擎的一些不完善,我想不可能创建一个永恒的弹跳。似乎下一个 RealityKit 的更新将修复物理引擎的缺陷。
【讨论】:
.rcproject场景