Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript

Try to allow all file extensions on iOS since that has weird rules

Scott Petrovic04481b7dedf8
diff --git a/src/lib/PlatformUtils.ts b/src/lib/PlatformUtils.ts
new file mode 100644
index 0000000..f1e7299
--- /dev/null
+++ b/src/lib/PlatformUtils.ts
@@ -0,0 +1,12 @@
+export class PlatformUtils {
+ /* originally created this since iOS has some weird rules about valid file extensions for
+ uploads. If we see the browser is iOS, we will allow all file extensions */
+ public static isIOS (): boolean {
+ // Check user agent for iOS devices
+ const isIOSUA = /iPad|iPhone|iPod/.test(navigator.userAgent)
+
+ // iPad on iOS 13+ detection (reports as Macintosh but has touch)
+ const isIPadOS = navigator.userAgent.includes("Mac") && "ontouchend" in document
+ return isIOSUA || isIPadOS
+ }
+}
diff --git a/src/lib/processes/load-model/StepLoadModel.ts b/src/lib/processes/load-model/StepLoadModel.ts
index 1dbbbcd..fea5810 100644
--- a/src/lib/processes/load-model/StepLoadModel.ts
+++ b/src/lib/processes/load-model/StepLoadModel.ts
@@ -9,6 +9,7 @@ import { MathUtils } from 'three/src/math/MathUtils.js'
import { BufferGeometry, Group, MeshPhongMaterial, Object3DEventMap, type Material, type Object3D } from 'three'
import { ModalDialog } from '../../ModalDialog.ts'
import { ModelCleanupUtility } from './ModelCleanupUtility.ts'
+import { PlatformUtils } from '../../PlatformUtils.ts'
// Note: EventTarget is a built-ininterface and do not need to import it
export class StepLoadModel extends EventTarget {
@@ -149,6 +150,7 @@ export class StepLoadModel extends EventTarget {
public add_event_listeners (): void {
if (this.ui.dom_upload_model_button !== null) {
+ // handle file upload
this.ui.dom_upload_model_button.addEventListener('change', (event: Event) => {
const file = event.target.files[0]
const file_extension: string = this.get_file_extension(file.name)
@@ -160,6 +162,12 @@ export class StepLoadModel extends EventTarget {
this.load_model_file(reader.result, file_extension)
}
})
+
+ // iOS has a weird issue with accepted file extensions, so we need to just
+ // accept everything for that platform
+ if (PlatformUtils.isIOS()) {
+ this.ui.dom_upload_model_button.setAttribute('accept', '*/*')
+ }
}
if (this.ui.dom_load_model_debug_checkbox !== null) {