我正在下载Collada DAE场景并在SceneKit中渲染它们,但无法让下载的节点"适应"其父节点.我主要关心缩放它的y高度以适应父节点.
这是我正在使用的代码:
// Reset everything
node.position = SCNVector3(0, 0, 0)
node.pivot = SCNMatrix4Identity
node.scale = SCNVector3(1, 1, 1)
// Calculate absolute bounding box
let (min, max) = node.boundingBox
let size = max - min
// Get the biggest dimension of the node
guard let scaleRef = [size.x, size.y, size.z].max() else {
return
}
// Desired bounding box is of size SCNVector3(0.4, 0.4, 0.4)
let parentSize: Float = 0.4
let ratio = (parentSize/scaleRef)
node.scale = SCNVector3(node.scale.x * ratio, node.scale.y * …Run Code Online (Sandbox Code Playgroud)