Cra*_*lot 4 3d ios scenekit modelio
目标是重新创建此OBJ文件的照明:https : //poly.google.com/view/cKryD9VnDEZ
将OBJ文件加载到SceneKit中的代码(可以从上面的链接下载文件):
let modelPath = "model.obj"
let url = NSURL(string: modelPath)
let scene = SCNScene(named: modelPath)!
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
sceneView.scene = scene
sceneView.backgroundColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)
到目前为止尝试过的选项:
1)默认的环境照明要比Google Poly照明更恶劣。移除环境照明会使一切变得太平坦。
2)使用四个定向灯:模型前面,后面,后面一个,上面一个。所有灯光都倾斜以指向模型。这是最好的,但仍然留下了一些阴影和更粗糙的区域,这些在Google Polymer上是看不到的。
3)在选项2中又增加了两个灯,这次在左右增加了灯。这个选项比选项2差,因为多余的灯光与四个现有的灯光组合在一起,并粉刷了模型。
建议后更新:
该代码现在实现了环境光和定向光。
由于某些原因,向摄像机节点(相对于场景根节点)添加定向光没有区别。
指示灯代码如下。
有两个问题:
1)在屏幕截图1中,胸部的右侧太亮并且没有边缘。胸部最左侧的脸太暗。光线最佳的脸位于中间。如何获得适合所有面部的照明(或更适合Google Poly照明)?
2)在屏幕截图2中,方向灯似乎无效。如何通过建议的一种环境光和一种定向光的架构来确保模型的背面与正面一样轻?
码:
// Create ambient light
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = .ambient
ambientLightNode.light!.color = UIColor(white: 0.50, alpha: 1.0)
// Add ambient light to scene
scene.rootNode.addChildNode(ambientLightNode)
// Create directional light
let directionalLight = SCNNode()
directionalLight.light = SCNLight()
directionalLight.light!.type = .directional
directionalLight.light!.color = UIColor(white: 0.40, alpha: 1.0)
directionalLight.eulerAngles = SCNVector3(x: Float.pi, y: 0, z: 0)
// Add directional light
scene.rootNode.addChildNode(directionalLight)
Run Code Online (Sandbox Code Playgroud)