2017-03-23 3 views
0

Können Sie mir erklären - warum meine Texturen nicht in 3D-Ansicht von Scene Kit angezeigt wird?SCENE KIT: Laden Materialfehler

Ich versuche, diffuse Farbe und Ambient hinzuzufügen - aber es funktioniert nicht.

Also hier ist meine Frage - warum?

Angezeigt werden nur grau-Material Farbe: enter image description here Hier ist Beispiel meines GameViewController Code in swift:

import UIKit 
import QuartzCore 
import SceneKit 
import SpriteKit 

class GameViewController: UIViewController { 

var sceneView: SCNView! 
var scene: SCNScene! 
var label: UILabel! 
var timer: Timer! 
var time: Int = 0 
var globeNode: SCNNode! 

override func viewDidLoad() { 
    super.viewDidLoad() 

    sceneView = self.view as! SCNView 
    sceneView.allowsCameraControl = true 
    scene = SCNScene() 
    sceneView.scene = scene 

    let camera = SCNCamera() 
    let cameraNode = SCNNode() 
    cameraNode.camera = camera 
    cameraNode.position = SCNVector3(x: -3.0, y: 3.0, z: 3.0) 

    let ambientLight = SCNLight() 
    ambientLight.type = SCNLight.LightType.ambient 
    ambientLight.color = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1.0) 
    cameraNode.light = ambientLight 

    let light = SCNLight() 
    light.type = SCNLight.LightType.spot 
    light.spotInnerAngle = 30.0 
    light.spotOuterAngle = 80.0 
    light.castsShadow = true 
    let lightNode = SCNNode() 
    lightNode.light = light 
    lightNode.position = SCNVector3(x: 1.5, y: 1.5, z: 1.5) 

    let cubeGeometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0) 
    let cubeNode = SCNNode(geometry: cubeGeometry) 

    let planeGeometry = SCNPlane(width: 100.0, height: 100.0) 
    let planeNode = SCNNode(geometry: planeGeometry) 
    planeNode.eulerAngles = SCNVector3(x: GLKMathDegreesToRadians(-90), y: 0, z: 0) 
    planeNode.position = SCNVector3(x: 0, y: -0.5, z: 0) 

    self.globeNode = SCNNode() 
    let theGlobeGeometry = SCNSphere(radius: 110) 
    theGlobeGeometry.firstMaterial?.diffuse.contents = UIImage(named:"earth_diffuse.jpg") 
    theGlobeGeometry.firstMaterial?.ambient.contents = UIImage(named:"earth_ambient2.jpeg") 
    //  theGlobeGeometry.firstMaterial.ambient.contents = UIImage(named:"earth_ambient.jpg") 
    theGlobeGeometry.firstMaterial?.specular.contents = UIImage(named:"earth_specular.jpg") 
    theGlobeGeometry.firstMaterial?.emission.contents = nil 
    theGlobeGeometry.firstMaterial?.transparent.contents = nil 
    theGlobeGeometry.firstMaterial?.reflective.contents = nil 
    theGlobeGeometry.firstMaterial?.multiply.contents = nil 
    theGlobeGeometry.firstMaterial?.normal.contents = UIImage(named:"earth_normal.jpg") 

    let theGlobeModelNode = SCNNode(geometry: theGlobeGeometry) 
    self.globeNode.addChildNode(theGlobeModelNode) 

    let theCloudGeometry = SCNSphere(radius:0.501) 
    theCloudGeometry.firstMaterial?.diffuse.contents = nil 
    theCloudGeometry.firstMaterial?.ambient.contents = nil 
    theCloudGeometry.firstMaterial?.specular.contents = nil 
    theCloudGeometry.firstMaterial?.emission.contents = nil 
    theCloudGeometry.firstMaterial?.transparent.contents = UIImage(named:"earth_clouds.png") 
    theCloudGeometry.firstMaterial?.reflective.contents = nil 
    theCloudGeometry.firstMaterial?.multiply.contents = nil 
    theCloudGeometry.firstMaterial?.normal.contents = nil 

    let theCloudModelNode = SCNNode(geometry: theCloudGeometry) 
    self.globeNode.addChildNode(theCloudModelNode) 

    // animate the 3d object 
    let animation: CABasicAnimation = CABasicAnimation(keyPath: "rotation") 
    animation.toValue = NSValue(scnVector4: SCNVector4(x: 1, y: 1, z: 0, w: Float(M_PI)*2)) 
    animation.duration = 5 
    animation.repeatCount = MAXFLOAT //repeat forever 
    globeNode.addAnimation(animation, forKey: nil) 

    let redMaterial = SCNMaterial() 
    redMaterial.diffuse.contents = UIColor.red 
    cubeGeometry.materials = [redMaterial] 

    let greenMaterial = SCNMaterial() 
    greenMaterial.diffuse.contents = UIColor.green 
    planeGeometry.materials = [greenMaterial] 

    let constraint = SCNLookAtConstraint(target: cubeNode) 
    constraint.isGimbalLockEnabled = true 
    cameraNode.constraints = [constraint] 
    lightNode.constraints = [constraint] 

    scene.rootNode.addChildNode(lightNode) 
    scene.rootNode.addChildNode(cameraNode) 
    //scene.rootNode.addChildNode(cubeNode) 
    scene.rootNode.addChildNode(planeNode) 
    scene.rootNode.addChildNode(globeNode) 

} 

func addSceneToScene() { 
    let geoScene = SCNScene(named: "art.scnassets/driod.dae") 
    scene.rootNode.addChildNode((geoScene?.rootNode.childNode(withName: "Head_009", recursively: true))!) 

} 

override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 
    // UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation") 

    return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.landscapeLeft.rawValue) 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 
} 

Vielen Dank im Voraus!

Antwort

0

Das liegt wahrscheinlich daran, dass die Texturbilder nicht gefunden werden. Sind die Bilder in Ihrem bundle?

Oder haben Sie vergessen, die Bilder in Ihr Ziel aufzunehmen?

+0

Zum zweiten Sambro, wo hast du die Textur Bilder? Im Asset-Katalog scnassets, in einem anderen Asset-Katalog oder anderswo? –

+0

Ich habe dieses Problem behoben, indem ich Bilder zu Assets.xassets hinzufüge und Bilder von Floor.geometry aufruft? .firstMaterial? .diffuse.contents \t \t \t = UIImage (benannt: "metallic") –

Verwandte Themen