1、用blender把fbx改成 dae导出
2、在ios工程目录里随便建一个资源文件夹
3、代码
var gap = 0
let window = UIApplication.shared.windows.first
var topPadding = window?.safeAreaInsets.top ?? 0
topPadding += navigationController?.navigationBar.frame.height ?? 0
topPadding += (CGFloat)(gap);
var tabBarH:CGFloat = navigationController!.tabBarController!.tabBar.frame.height
var height = UIScreen.main.bounds.height - topPadding - tabBarH
let scene = SCNScene()
//let scene = SCNScene(named: "3DGameScene")
let sceneView = SCNView(frame:CGRect(x:0,y:topPadding,width:UIScreen.main.bounds.width,height:height))
sceneView.backgroundColor = UIColor.white
sceneView.scene = scene;
self.view.addSubview(sceneView)
let camera = SCNCamera()
let cameraNode = SCNNode()
cameraNode.camera = camera
cameraNode.position = SCNVector3(x: 0.0, y: 0.0, z: 3.0)
let light = SCNLight()
light.type = SCNLight.LightType.omni
let lightNode = SCNNode()
lightNode.light = light
lightNode.position = SCNVector3(x: 1.5, y: 1.5, z: 1.5)
let cubeGeometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0)
let cubeNode = SCNNode(geometry: cubeGeometry)
//scene.rootNode.addChildNode(cubeNode)
scene.rootNode.addChildNode(lightNode)
scene.rootNode.addChildNode(cameraNode)
guard let url = Bundle.main.url(forResource: "r2", withExtension: "dae") else {
fatalError("baby_groot.dae not exit.")
}
guard let customNode = SCNReferenceNode(url: url) else {
fatalError("load baby_groot error.")
}
customNode.load()
print(customNode)
customNode.position = SCNVector3(x: 0, y: 0, z: 0)
scene.rootNode.addChildNode(customNode)
5、重新绑定纹理
把纹理图放到dae文件所在目录下