I find a way myself.
this method works well!
(https://gist.github.com/delasign/2b797c6afd819c7cc04ee42158ec5787)
Post
Replies
Boosts
Views
Activity
I have a same problem, did you resolve it?
Sorry, I did it. problem is in this code
(https://stackoverflow.com/questions/33730468/how-to-convert-camera-extrinsic-matrix-to-scncamera-position-and-rotation)
private func updateNodeMatrix(_ camNode: SCNNode) {
guard let camera = camNode.camera else {
return
}
let modelMatrix = transform
let viewMatrix = SCNMatrix4Invert(camNode.transform) // invert is right
let projectionMatrix = camera.projectionTransform
let viewProjection = SCNMatrix4Mult(viewMatrix, projectionMatrix)
let modelViewProjection = SCNMatrix4Mult(modelMatrix, viewProjection)
nodeMatrix.modelViewProjectionTransform = float4x4(modelViewProjection)
}
As your answer, I resolve this issue like this.
This code download all web url file to local cache.
And check total and completed number of them.
private static func downloadAllFilesAsync(_ medicalInfo: MedicalInfo)
async throws -> (total: Int, completed: Int) {
...
let download: (URL) async throws -> Int = { url in
do {
_ = try await WWW.downloadFileAsync(url)
return 1
} catch {
throw error
}
}
return try await withThrowingTaskGroup(of: Int.self) {
group -> (Int, Int) in
buildURLSet() // To be requested url array ([URL]) is set.
let total = requested.count
var completed = 0
for requestUrl in requested {
group.addTask {
return try await download(requestUrl)
}
}
completed = try await group.reduce(0, +)
return (total, completed)
}
}