【问题标题】:Normal mapping in ScenekitScenekit 中的法线贴图
【发布时间】:2020-04-15 11:49:57
【问题描述】:

我正在尝试使用 SCNMaterial 属性快速为 3D 模型添加法线贴图。漫反射属性正在工作,但在屏幕上看不到包括正常属性在内的其他属性。当我调试以检查节点的材质是否包含正常属性时,它显示该属性与我添加的图像一起存在。 我还检查了我使用的正常图像在 SceneKit 编辑器中是否正确,它可以正常工作。 我已经添加了我正在使用的代码。

let node = SCNNode()
node.geometry = SCNSphere(radius: 0.1)
node.geometry!.firstMaterial!.diffuse.contents = UIColor.lightGray
node.geometry!.firstMaterial!.normal.contents = UIImage(named: "normal")
node.position = SCNVector3(0,0,0)
sceneView.scene.rootNode.addChildNode(node)

这是我得到的输出

我期待这样的事情

【问题讨论】:

    标签: ios swift xcode scenekit arkit


    【解决方案1】:

    我得到了解决方案。由于我没有启用 DefaultLighting,因此场景中没有照明。将此添加到代码中。

    sceneView.autoenablesDefaultLighting = true
    

    【讨论】:

      【解决方案2】:

      从截图来看,场景中似乎没有光照,或者材质对光照没有反应,因为球体没有着色。要使法线贴图起作用,必须考虑光照,因为它会响应光照方向。您是否尝试过创建一个全新的 SCNMaterial 并使用它的属性? (即https://developer.apple.com/documentation/scenekit/scnmaterial/lightingmodel 似乎很有趣)

      我会尝试设置

      node.geometry!.firstMaterial!.lightingModel = .physicallyBased
      

      【讨论】:

      • 谢谢凯文,照明是问题所在。我曾尝试添加照明模型,但它不起作用。我必须设置sceneView.autoenablesDefaultLighting=true,然后才起作用。
      【解决方案3】:

      试试这个。

      let scene =  SCNScene()
      let sphere = SCNSphere(radius: 0.1)
      let sphereMaterial = SCNMaterial()
      sphereMaterial.diffuse.contents = UIImage(named: "normal.png")
      
      let sphereNode = SCNNode()
      sphereNode.geometry = sphere
      sphereNode.geometry?.materials = [sphereMaterial]
      sphereNode.position = SCNVector3(0.5,0.1,-1)
      
      scene.rootNode.addChildNode(sphereNode)
      sceneView.scene = scene
      

      【讨论】:

      • 感谢您的回答,sphereMaterial.diffuse 工作正常,但 sphereMaterial.normal 在此代码中也不起作用。
      猜你喜欢
      • 2015-09-24
      • 2019-03-15
      • 1970-01-01
      • 2018-05-26
      • 2021-02-19
      • 1970-01-01
      • 2019-01-25
      • 2018-02-02
      • 1970-01-01
      相关资源
      最近更新 更多