This code excerpt (scene, camera, light, etc. cut out of the code) works in Swift on an iOS simulator:
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
It generates a box with each face being the checkered image.
Trying the same thing with a simple stock geometry created in Wings3D, saved to a DAE, and loaded in the app gives me an appropriate shape, but no shading and image on the faces:
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
What am I missing?
does your geometry have texture coordinates? You can verify this programmatically (by checking if a source with the SCNGeometrySourceSemanticTexcoord semantic exists) or in the SceneKit editor built into Xcode.
Also note that you don't have to create one material per geometry element. If they are all the same, just build an array of one material and it will be used for the entire geometry.
Thanks, mnuages & rickster. Your deductions led me to researching my options within Wings3D, and I was able to solve the problem within Wings3D.
In short, I need to create a UV Mapping for each face of the solid.
For a regular polyhedra, I had multiple options:
This all becomes a little more complicated if I started adding bezels or smoother chamfers to the edges, for now I need to make sure that the UV Mapping makes sense for each set of faces I work on. Again, there are tutorials on this on the web.
Thanks again!
Cheers, Henry
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With