From 850b1b35881c0d8c557c7306c1cdc7ebecad69fb Mon Sep 17 00:00:00 2001 From: Deirdre Saoirse Moen Date: Sat, 30 Mar 2024 14:22:34 -0700 Subject: [PATCH] Add test for watchOS, which can import SceneKit, but has no SCNScene write method. --- Sources/Mesh+IO.swift | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Sources/Mesh+IO.swift b/Sources/Mesh+IO.swift index 198b6970..123d3672 100644 --- a/Sources/Mesh+IO.swift +++ b/Sources/Mesh+IO.swift @@ -75,22 +75,26 @@ public extension Mesh { try string.write(to: url, atomically: true, encoding: .utf8) #endif default: - #if canImport(SceneKit) - let scnScene = SCNScene() - let materialLookup = materialLookup.map { lookup in { defaultMaterialLookup(lookup($0)) } } - let geometry = SCNGeometry(polygons: self, materialLookup: materialLookup) - scnScene.rootNode.addChildNode(SCNNode(geometry: geometry)) - guard scnScene.write( - to: url, - options: [:], - delegate: nil, - progressHandler: nil - ) else { - throw IOError("Failed to export file") - } - #else - throw IOError("Unsupported mesh file format '\(url.pathExtension)'") - #endif + #if os(watchOS) + throw IOError("Cannot export '\(url.pathExtension)' on watchOS.") + #else + #if canImport(SceneKit) + let scnScene = SCNScene() + let materialLookup = materialLookup.map { lookup in { defaultMaterialLookup(lookup($0)) } } + let geometry = SCNGeometry(polygons: self, materialLookup: materialLookup) + scnScene.rootNode.addChildNode(SCNNode(geometry: geometry)) + guard scnScene.write( + to: url, + options: [:], + delegate: nil, + progressHandler: nil + ) else { + throw IOError("Failed to export file") + } + #else + throw IOError("Unsupported mesh file format '\(url.pathExtension)'") + #endif + #endif } } }