Closed chellem closed 3 years ago
@chellem can you post an example of what you've tried?
I have something like this. Am sure that polygons and scene are not empty
let mesh = Mesh(polygons)
let geometry = SCNGeometry(mesh)
let node = SCNNode(geometry: geometry)
scene.rootNode.addChildNode(node)
@nicklockwood you've completed ignored my other issue. (Big thanks for the support )
I didn't realize you were the same user since you opened a new ticket. I'm not sure the sarcasm was called for.
@nicklockwood can you help ?
@chellem Euclid has no code for loading models, so for that you'd need to use SceneKit or ModelIO, or something else. Here is some code to load the model using SceneKit, create a Euclid Mesh, and then convert back to SceneKit for display.
(I've used the .usdz version of the model since SceneKit didn't like the .obj).
// load scene
guard let url = Bundle.main.url(forResource: "T-shirt", withExtension: "usdz"),
let importedScene = try? SCNScene(url: url, options: [
.flattenScene: true,
.createNormalsIfAbsent: true,
.convertToYUp: true,
])
else {
preconditionFailure("Failed to load model")
}
// create Mesh
var importedNode = importedScene.rootNode
var mesh: Mesh!
while true {
if let geometry = importedNode.geometry {
mesh = Mesh(geometry)
break
}
guard let childNode = importedNode.childNodes.first else {
preconditionFailure("Model contained no geometry")
}
importedNode = childNode
}
// create SCNNode
let geometry = SCNGeometry(mesh)
let node = SCNNode(geometry: geometry)
scene.rootNode.addChildNode(node)
Can you please provide an example of this please ?
Am not seeing anything when trying to do this.