这段代码摘录(场景、相机、灯光等)在 iOS 模拟器上的 Swift 中工作:
let boxNode = SCNNode()
// Create a box
boxNode.geometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0.1)
let numFaces = 6
scene.rootNode.addChildNode(boxNode)
// create and configure a material for each face
var materials: [SCNMaterial] = Array()
for i in 1...numFaces
{
let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "texture")
materials += material
}
// set the material to the 3d object geometry
boxNode.geometry.materials = materials
它生成一个框,每个面都是方格图像。
使用在 Wings3D 中创建、保存到 DAE 并加载到应用程序中的简单库存几何体尝试同样的事情,可以得到合适的形状,但脸上没有阴影和图像:
let boxNode = SCNNode()
// Load the geometry
let urlToColladaFile = NSBundle.mainBundle().URLForResource("Objects", withExtension:"dae")
let sceneSource = SCNSceneSource(URL:urlToColladaFile, options:nil)
boxNode.geometry = sceneSource.entryWithIdentifier("dodecahedron3-0", withClass:SCNGeometry.self) as SCNGeometry
let numFaces = 10
scene.rootNode.addChildNode(boxNode)
// create and configure a material for each face
var materials: [SCNMaterial] = Array()
for i in 1...numFaces
{
let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "texture")
materials += material
}
// set the material to the 3d object geometry
boxNode.geometry.materials = materials
我错过了什么?