Swift: Error changing aspect to an object

1

I'm trying to change the texture of an object, instead of giving it a solid color, for that I added a .jpg image to the assets.xcassets folder, and then from the code I gave it the texture but I did not have the option to select it said texture. Do you know if I will be skipping a step to add the texture or am I doing something wrong?

    super.viewDidAppear(animated)
    let sponge = SCNNode()
    sponge.geometry = SCNSphere(radius: 0.2)
    sponge.position = SCNVector3(-0.2,0,-0.5)
    sponge.geometry?.firstMaterial?.diffuse.contents = spongeDiffuse


    let rock = SCNNode()
    rock.geometry = SCNSphere(radius: 0.2)
    rock.position = SCNVector3(0.3,0,-0.5)
    rock.geometry?.firstMaterial?.diffuse.contents = rockDiffuse
    
asked by Jesus G 07.10.2018 в 22:58
source

2 answers

0

Hello the problem is that there is no spongeDiffuse or rockDiffuse as variables.

sponge.geometry?.firstMaterial?.diffuse.contents = UIImage(named: "spongeDiffuse")

I hope this works for you.

    
answered by 08.10.2018 / 16:51
source
0

In image 1, I show the images that I added in the assets.xcassets folder, where I also change the name to use them from the code. In image 2, there is the code that I use to change the texture of the object, but when I want to put the texture it does not appear inside the options, so it marks me an error.

    
answered by 07.10.2018 в 23:09