首先,ModelEntity是主父节点类的子类Entity。
根据文档:
实体代表场景中的“某物”。 PerspectiveCamera、SpotLight 或 ModelEntity 等后代继承自 Entity 类。
class Entity : HasHierarchy, HasSynchronization, HasTransform
ModelEntity(与任何其他实体一样)更具体。它表示一个被渲染和可选模拟的模型。它继承自 Entity 类,符合 HasModel 和 HasPhysics 协议。
class ModelEntity : Entity, HasModel, HasPhysics
通常两个实体类可以互换(在设置组件时)。例如,您可以使用 Entity 代替 SpotLight 类。
Entity().components[SpotLightComponent] = SpotLightComponent(color: .red,
intensity: 2000,
innerAngleInDegrees: 45,
outerAngleInDegrees: 90,
attenuationRadius: 5.0)
对
SpotLight().components[SpotLightComponent] = SpotLightComponent(color: .red,
intensity: 2000,
innerAngleInDegrees: 45,
outerAngleInDegrees: 90,
attenuationRadius: 5.0)
但是,下面的例子可以作为一个例外。向下转换时需要准确使用Entity 类。
arView.installGestures([.all], for: entity as! Entity & HasCollision)