RealityKit中的Entity和ModelEntity有什么区别?

问题描述

我是SwiftUI,ARKit和RealityKit的新手,非常抱歉我的基本问题 我被告知要使用这些方法加载模型

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

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

那么ModelEntity和Entity有什么区别?

解决方法

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

vs

SpotLight().components[SpotLightComponent] = SpotLightComponent(color: .red,attenuationRadius: 5.0)

但是,可以给出以下示例作为例外。向下广播时,您需要完全使用Entity类。

arView.installGestures([.all],for: entity as! Entity & HasCollision)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...