我正在尝试使用以下代码初始化或构造 SCNNode。它将从服务器中提取 SCN 文件并将其加载到代码中。但是,似乎我无法覆盖它一直在设备/本地目录中搜索我的纹理文件的资产 URL。我想知道我是否使用了正确的 SCNScene 语法和 URL
lazy var audiNode: SCNNode = {
//Endpoint for SCN file
let endpoint = URL(string: "http://jwt-auth-hosted.au-syd.mybluemix.net/hkdl-ar/tree.scn")
//Remote directory for texture PNG file for the SCN file
let texture = NSURL(string: "http://jwt-auth-hosted.au-syd.mybluemix.net/hkdl-ar")
//Declare scene options for initializing SCNScene
let assetDirURL = SCNSceneSource.LoadingOption.assetDirectoryURLs
let isOverrideAssetURL = SCNSceneSource.LoadingOption.overrideAssetURLs
do {
/*
- Declare scene with endpoint, is override asset URL = true, asset directory is texture
- However not sure if the options are being correctly called
*/
let scene = try SCNScene(url: endpoint!, options: [assetDirURL: [texture],isOverrideAssetURL:{1}])
//scene is not null
NSLog("audi scnscene: \(scene) with endpoint: \(String(describing: endpoint))")
}
catch let error {
NSLog("cannot load scnscene")
}
//Initialize parent node
let carNode = SCNNode()
//Get all child nodes of the SCNScene
let carSceneChildNodes = scene.rootNode.childNodes
//Loop through all child nodes and add them into the parent node
for childNode in carSceneChildNodes {
carNode.addChildNode(childNode)
}
//Set scale and position of the parent node
let scaleFactor = 0.05
carNode.position = SCNVector3(0,0,0)
carNode.scale = SCNVector3(scaleFactor, scaleFactor, scaleFactor)
NSLog("returning audi node")
//return node to another
return carNode
}()
所以我得到的错误是 2018-07-26 19:33:34.582848+0800 ARKit+CoreLocation[28182:11913775] [SceneKit] 错误:加载失败:C3DImage 0x1c08e1780 src:file:///var/containers/Bundle/Application /E103CC90-B45B-4111-885C-806328F27D93/ARKit+CoreLocation.app/tree.png [0.000000x0.000000]。我不确定如何正确覆盖资产 URL,很高兴您能提供帮助!