是否可以让相机看一下模特?这是我尝试过的:
// Add Character
func addModel(name:String)
{
// Remove old model
self.modelNode.removeFromParentNode()
modelNode = SCNNode()
// Load COLLADA Character
if let myScene = SCNScene(named: "Assets.scnassets/"+name+"/"+name+".dae")
{
// Recurse through all the child nodes in the Character and add to modelNode
for node in myScene.rootNode.childNodes as [SCNNode]
{
modelNode.addChildNode(node)
}
// Add modelNode to scene
self.rootNode.addChildNode(modelNode)
}
else
{
print("Error loading character: "+name)
}
}
// Add Camera
func addCamera()
{
// Remove old model
self.cameraNode.removeFromParentNode()
cameraNode = SCNNode()
// Set up a new camera
cameraNode.camera = SCNCamera()
// Set up LookAtConstraint
let constraint = SCNLookAtConstraint(target: modelNode)
cameraNode.constraints = [constraint]
self.rootNode.addChildNode(cameraNode)
}
这没有任何结果。意思是,我看不到模特。如果我没有运行 addCamera(),则会显示模型。但我不想看相机的模型。
答案 0 :(得分:0)
使用SCNLookAtConstraint(target: modelNode.childNodeWithName)
代替了我。我假设父节点没有持有子约束。