【发布时间】:2018-12-25 18:16:42
【问题描述】:
我正在开发一个 iOS 应用程序,该应用程序应该识别墙上的数字(使用 CoreML + Vision),然后将多个平面(平面数取决于该房间时间表(horario))添加到同一面墙上各种内容,如工作日和开放(inicio)或关闭(fim)时间。我遇到的问题是,如果我在添加第一架飞机后继续将相机对准数字,则会不断添加飞机,这是不应该发生的。我有类似删除所有节点/使它们在添加新节点之前立即消失或停止为已检测到的特定房间添加但请随意思考和提出不同方法的方法!
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor)
{
guard let planeAnchor = anchor as? ARPlaneAnchor else { return }
let dataformatter = DateFormatter()
dataformatter.dateFormat = "HH:mm"
let dataformatter_wk = DateFormatter()
dataformatter_wk.dateFormat = "EEEE"
var i = 0
for horario in (self.room?.horario)!{
//Convert Dates
let comp_inicio: DateComponents = Calendar.current.dateComponents([.hour, .minute], from: (horario.hora_ini)!)
let comp_fim: DateComponents = Calendar.current.dateComponents([.hour, .minute], from: (horario.hora_fim)!)
let comp_wk: DateComponents = Calendar.current.dateComponents([.weekday, .day, .month, .year, .hour, .minute], from: (horario.hora_ini)!)
let data_inicio = Calendar.current.date(from: comp_inicio)
let data_fim = Calendar.current.date(from: comp_fim)
let data_wk = Calendar.current.date(from: comp_wk)
let hora_inicio = dataformatter.string(from: data_inicio!)
let hora_fim = dataformatter.string(from: data_fim!)
let horario_final = (hora_inicio + "-" + hora_fim).uppercased()
let weekday = dataformatter_wk.string(from: data_wk!).uppercased()
//Plane
let plane = SCNPlane(width: CGFloat(0.09), height: CGFloat(0.09))
plane.materials.first?.diffuse.contents = UIColor.planeColor
let planeNode = SCNNode(geometry: plane)
//Text
let material_text = SCNMaterial()
material_text.diffuse.contents = UIColor.black
//Get the content from JSON
let text_horario = SCNText(string: horario_final, extrusionDepth: 0.1)
let text_weekday = SCNText(string: weekday, extrusionDepth: 0.1)
let text_descr = SCNText(string: horario.descr?.uppercased() ?? 0, extrusionDepth: 0.1)
text_weekday.materials = [material_text]
text_descr.materials = [material_text]
text_horario.materials = [material_text]
let node_text_weekday = SCNNode(geometry: text_weekday)
let node_text_horario = SCNNode(geometry: text_horario)
let node_text_descr = SCNNode(geometry: text_descr)
//Piones
let piones = SCNCylinder(radius: 0.002, height: 0.005)
let material_piones = SCNMaterial()
material_piones.diffuse.contents = UIColor.red
piones.materials = [material_piones]
let node_piones = SCNNode(geometry: piones)
// 5 Get the planeAnchor positions
let x = CGFloat(planeAnchor.center.x) // Esquerda e direita
let y = CGFloat(planeAnchor.center.y) // +y = Mais perto do telemovel
let z = CGFloat(planeAnchor.center.z) // -z = Mais alto
// Rotate and scale the nodes
planeNode.eulerAngles.x = -.pi / 2
node_text_weekday.eulerAngles.x = -.pi / 2
node_text_horario.eulerAngles.x = -.pi / 2
node_text_descr.eulerAngles.x = -.pi / 2
node_text_weekday.scale = SCNVector3(x: 0.0005, y: 0.0005, z: 0.0005)
node_text_horario.scale = SCNVector3(x: 0.0005, y: 0.0005, z: 0.0005)
node_text_descr.scale = SCNVector3(x: 0.0007, y: 0.0007, z: 0.0007)
// Add the nodes positions
planeNode.position = SCNVector3(x + CGFloat(i%3)/10 ,y , z + CGFloat(i/3)/10)
node_text_weekday.position = SCNVector3(x - 0.025 + CGFloat(i%3)/10 ,y , z + CGFloat(i/3)/10)
node_text_horario.position = SCNVector3(x - 0.020 + CGFloat(i%3)/10 ,y , z+0.035 + CGFloat(i/3)/10)
node_text_descr.position = SCNVector3(x - 0.029 + CGFloat(i%3)/10 ,y , z-0.015 + CGFloat(i/3)/10)
node_piones.position = SCNVector3(x + CGFloat(i%3)/10 ,y , z-0.035 + CGFloat(i/3)/10)
node.addChildNode(planeNode)
node.addChildNode(node_text_weekday)
node.addChildNode(node_text_horario)
node.addChildNode(node_text_descr)
node.addChildNode(node_piones)
//Used for positioning of the planes on the wall
i=i+1
}
}
【问题讨论】:
-
所有数字都是唯一的吗?
-
@JoshRobbins 是的!所有数字都是唯一的!
标签: ios swift arkit scnnode coreml