我有一个SCNSphere,我希望以屏幕像素(或更准确地说,点数)获得其投影尺寸。
我认为这样做会:
Inno Setup Compiler
然而,这不起作用。 let bounds = endNode.boundingBox
let projectedMin = renderer.projectPoint(bounds.min)
let projectedMax = renderer.projectPoint(bounds.max)
let sizeInPts = CGSize(width: CGFloat(projectedMax.x - projectedMin.x), height: CGFloat(projectedMax.y - projectedMin.y))
中的宽度和高度总是偏离。
答案 0 :(得分:2)
我认为你应该检查边界框的所有顶点 我没有测试这段代码,但我希望它有效。
let (localMin, localMax) = endNode.boundingBox
let min = endNode.convertPosition(localMin, to: nil)
let max = endNode.convertPosition(localMax, to: nil)
let arr = [
renderer.projectPoint(SCNVector3(min.x, min.y, min.z)),
renderer.projectPoint(SCNVector3(max.x, min.y, min.z)),
renderer.projectPoint(SCNVector3(min.x, max.y, min.z)),
renderer.projectPoint(SCNVector3(max.x, max.y, min.z)),
renderer.projectPoint(SCNVector3(min.x, min.y, max.z)),
renderer.projectPoint(SCNVector3(max.x, min.y, max.z)),
renderer.projectPoint(SCNVector3(min.x, max.y, max.z)),
renderer.projectPoint(SCNVector3(max.x, max.y, max.z))
]
let minX: CGFloat = arr.reduce(CGFloat.infinity, { $0 > $1.x ? $1.x : $0 })
let minY: CGFloat = arr.reduce(CGFloat.infinity, { $0 > $1.y ? $1.y : $0 })
let minZ: CGFloat = arr.reduce(CGFloat.infinity, { $0 > $1.z ? $1.z : $0 })
let maxX: CGFloat = arr.reduce(-CGFloat.infinity, { $0 < $1.x ? $1.x : $0 })
let maxY: CGFloat = arr.reduce(-CGFloat.infinity, { $0 < $1.y ? $1.y : $0 })
let maxZ: CGFloat = arr.reduce(-CGFloat.infinity, { $0 < $1.z ? $1.z : $0 })
let width = maxX - minX
let height = maxY - minY
let depth = maxZ - minZ
let sizeInPts = CGSize(width: width, height: height)
我将Xcode Playground示例上传到Github。