如何解决AnchorEntity便利initplane:分类:minimumBounds的使用
// add in viewWillAppear
let anchor = AnchorEntity(plane: [.horizontal,.vertical],classification: [.any],minimumBounds: [0.01,0.01])
anchor.name = "loongAnchor"
let boxModel = QDVirtualEntity.box(size: 0.1,corner: 0,color: .red)
anchor.addChild(boxModel)
arView.scene.anchors.append(anchor)
QDVirtualEntity函数:
public static func box(size: Float,corner: Float,color: UIColor = .orange) -> ModelEntity {
let entity = ModelEntity(mesh: .generateBox(size: size,cornerRadius: corner),materials: [SimpleMaterial(color: color,isMetallic: false)])
entity.position.y = size / 2.0
return entity
}
运行后,我找不到添加的框。这是为什么?这种方法如何工作。
解决方法
您的代码工作正常。唯一的问题可能是将minimumBounds
设置为[0.01,0.01]。太小了。将其设置为[0.2,0.2],这样您检测到的平面将具有稳健的尺寸。此外,还可以较慢地跟踪周围的环境,一旦检测到飞机,您就会在房间里看到您的小盒子。
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let anchor = AnchorEntity(plane: [.horizontal,.vertical],classification: [.any],minimumBounds: [0.2,0.2])
let boxModel = QDVirtualEntity.box(size: 0.1,corner: 0,color: .green)
anchor.addChild(boxModel)
arView.scene.anchors.append(anchor)
}
}
class QDVirtualEntity {
public static func box(size: Float,corner: Float,color: UIColor) -> ModelEntity {
let entity = ModelEntity(mesh: .generateBox(size: size,cornerRadius: corner),materials: [SimpleMaterial(color: color,isMetallic: false)])
entity.position.y = size / 2.0
return entity
}
}
,
1:您可以设置(默认)
row.push(output);
在添加上述代码后,将在检测到飞机时自动将其添加。
2:如果您 arView.automaticallyConfigureSession = true
set automaticallyConfigureSession = false
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。