-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GLTFUnarchiver + GLTFSceneSource: add embedExternalImages option #34
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve self-reviewed with a few comments here. Please let me know if you have any additional feedback.
@@ -35,14 +35,16 @@ public class GLTFUnarchiver { | |||
private var buffers: [Data?] = [] | |||
private var materials: [SCNMaterial?] = [] | |||
private var textures: [SCNMaterialProperty?] = [] | |||
private var images: [Image?] = [] | |||
// An array of Image or URL types | |||
private var images: [Any?] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that I’m new to Swift, and my most recent experience with typed languages is TypeScript. Unfortunately I couldn’t declare this as an array of Image | URL
types. If Any
is unacceptable, I would consider this instead:
private var images: [Any?] = [] | |
private var images: [Image?] = [] | |
private var imageUrls: [URL?] = [] |
@@ -771,7 +775,8 @@ public class GLTFUnarchiver { | |||
return valueArray | |||
} | |||
|
|||
private func loadImage(index: Int) throws -> Image { | |||
// Returns either an Image or a URL | |||
private func loadImage(index: Int) throws -> Any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the above comment regarding Any
, I am willing to revise this part of the code to avoid Any
as the return type. I would consider factoring out the shared logic here in loadImage()
and then create a second private func loadImageUrl(index: Int) throws -> URL
method.
image = try loadImageFile(from: url) | ||
// Even if we shouldn't embed external images, try loading the image file for now | ||
// TODO: figure out how to check if `url` exists on-disk rather than using `loadImageFile()` to do this | ||
let loadedImage = try loadImageFile(from: url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most awkward part of this revision. As indicated in the comments, I’m essentially using loadImageFile()
as a test to see if the file exists on-disk. There are a few ways to improve this:
- Add a helper function to simply check if the image URL exists on-disk when
self.embedExternalImages
isfalse
- Call
loadImageFile()
only whenself.embedExternalImages
istrue
@@ -785,7 +790,8 @@ public class GLTFUnarchiver { | |||
} | |||
let glImage = images[index] | |||
|
|||
var image: Image? | |||
// An Image or a URL | |||
var image: Any? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment regarding Any
usage as the above comments (first comment, second comment).
During development on an internal tool, a colleague and I needed an option to suppress GLTFSceneKit’s default behavior of embedding external image data into a SceneKit file.
This PR achieves that by adding a
embedExternalImages
option toGTFSceneSource
constructor, which istrue
by default, thereby matching GLTFSceneKit’s current behavior.When the setting is
false
, aGLTFUnarchiver
class instance will return aURL
to an image, as extracted from a.gltf
file, rather thanImage
data.