3

我正在将一个 .usdz 模型(从 Apple 下载)加载到我ARSCNSceneView的工作中。但不幸的是,模型总是在没有任何纹理的情况下被渲染,并且看起来是黑色的。

// Get the url to the .usdz file
guard let usdzURL = Bundle.main.url(forResource:   "toy_robot_vintage", withExtension: "usdz")
else {
    return
}

// Load the SCNNode from file             
let referenceNode = SCNReferenceNode(url: usdzURL)!
referenceNode.load()

// Add node to scene
sceneView.scene.rootNode.addChildNode(referenceNode)

在此处输入图像描述

4

2 回答 2

4

你的场景没有光,这就是物体显示黑暗的原因。只需在场景中添加定向光:

let spotLight = SCNNode()
spotLight.light = SCNLight()
spotLight.light?.type = .directional

sceneView.scene.rootNode.addChildNode(spotLight)
于 2019-06-17T13:25:53.093 回答
1

如果您已经在 3D 场景中实现了灯光并且这些灯光具有必要的强度级别(默认为 1000 流明),那没关系。如果没有,只需使用以下代码来实现自动照明

let sceneView = ARSCNView()
sceneView.autoenablesDefaultLighting = true
sceneView.automaticallyUpdatesLighting = true

但是,如果您仍然看不到机器人模型的着色器

  • 在 Xcode 中,只需从下拉菜单中Scene Inspector打开属性Procedural Sky值。Environment

在此处输入图像描述

于 2019-06-17T13:09:55.027 回答