【问题标题】:What's the difference between Entity and ModelEntity in RealityKit?RealityKit 中的 Entity 和 ModelEntity 有什么区别?
【发布时间】:2020-10-09 06:11:28
【问题描述】:

我是 SwiftUI、ARKit 和 RealityKit 的新手,很抱歉我的基本问题 有人告诉我使用这些方法来加载模型

Entity.load(named: "abc.usdz") 

ModelEntity.load(named: "abc.usdz")

那么 ModelEntity 和 Entity 之间有什么区别?

【问题讨论】:

    标签: augmented-reality arkit realitykit


    【解决方案1】:

    首先,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)
    

    【讨论】:

      猜你喜欢
      • 2021-05-05
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-03
      • 1970-01-01
      • 1970-01-01
      • 2013-01-15
      相关资源
      最近更新 更多