基于SceneKit的汽车改色,需要修改模型文件可以去 3D Models for Professionals :: TurboSquid自行下载,免费资源还挺多的。
先上个效果图吧:
核心代码:
let path = Bundle.main.path(forResource: "ks_car", ofType: "dae")!
let source = SCNSceneSource.init(url: URL(fileURLWithPath: path), options: nil)
let scene = source?.scene(options: nil)
//添加灯光效果 omni:点光源、方向360度,可衰减
let lightNode = SCNNode.init()
lightNode.light = SCNLight()
lightNode.light?.type = SCNLight.LightType.omni
lightNode.position = SCNVector3Make(0, 0, 300)
scene?.rootNode.addChildNode(lightNode)
scnView = SCNView.init(frame: CGRect(x: 0, y: 0, width: kswidth, height: 500))
scnView.allowsCameraControl = true
scnView.showsStatistics = true
scnView.backgroundColor = UIColor.white
scnView.scene = scene
self.view.addSubview(scnView)
demo地址: GitHub - Turboks/3DCar