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AssetUtils from 'expo-asset-utils';\nimport { Platform } from 'react-native';\nimport { FileLoader } from 'three';\nimport { ColladaLoader } from 'three/examples/jsm/loaders/ColladaLoader';\nimport { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader';\nimport { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader';\n\nimport readAsStringAsync from './readAsStringAsync';\n\nasync function loadFileAsync({ asset, funcName }): Promise<string | null> {\n if (!asset) {\n throw new Error(`ExpoTHREE.${funcName}: Cannot parse a null asset`);\n }\n return await AssetUtils.uriAsync(asset);\n}\n\nexport async function loadMtlAsync({ asset, onAssetRequested }): Promise<any> {\n const uri = await loadFileAsync({\n asset,\n funcName: 'loadMtlAsync',\n });\n if (!uri) return;\n\n const loader = new MTLLoader();\n loader.setPath(onAssetRequested);\n\n if (Platform.OS === 'web') {\n return await new Promise((resolve, reject) =>\n loader.load(uri, resolve, () => {}, reject)\n );\n }\n\n return loadFileContentsAsync(loader, uri, 'loadMtlAsync');\n}\n\nexport async function loadObjAsync(options: {\n asset: any;\n onAssetRequested?: (...args: any[]) => any;\n onMtlAssetRequested?: (...args: any[]) => any;\n mtlAsset?: any;\n materials?: any;\n}): Promise<any> {\n const {\n asset,\n onAssetRequested,\n onMtlAssetRequested,\n mtlAsset,\n materials,\n } = options;\n let nextMaterials = materials;\n if (nextMaterials == null && mtlAsset != null) {\n nextMaterials = await loadMtlAsync({\n asset: mtlAsset,\n onAssetRequested: onMtlAssetRequested || onAssetRequested,\n });\n nextMaterials.preload();\n }\n\n const uri = await loadFileAsync({\n asset,\n funcName: 'loadObjAsync',\n });\n if (!uri) return;\n\n const loader = new OBJLoader();\n if (onAssetRequested) {\n loader.setPath(onAssetRequested as any);\n }\n if (nextMaterials != null) {\n loader.setMaterials(nextMaterials);\n }\n\n if (Platform.OS === 'web') {\n return await new Promise((resolve, reject) =>\n loader.load(uri, resolve, () => {}, reject)\n );\n }\n\n return loadFileContentsAsync(loader, uri, 'loadObjAsync');\n}\n\nexport async function loadDaeAsync({\n asset,\n onAssetRequested,\n onProgress,\n}): Promise<any> {\n const uri = await loadFileAsync({\n asset,\n funcName: 'loadDaeAsync',\n });\n if (typeof uri !== 'string' || uri == null) {\n return;\n }\n\n return new Promise((res, rej) =>\n new FileLoader().load(\n uri!,\n text => {\n // @ts-ignore\n const loader = new ColladaLoader();\n const parsedResult = (loader.parse as any)(text, onAssetRequested);\n res(parsedResult);\n },\n onProgress,\n rej\n )\n );\n}\n\nasync function loadFileContentsAsync(loader, uri, funcName): Promise<any> {\n try {\n const fileContents = await readAsStringAsync(uri);\n return loader.parse(fileContents);\n } catch ({ message }) {\n // Or model loader THREE.OBJLoader failed to parse fileContents\n throw new Error(\n `ExpoTHREE.${funcName}: Expo.FileSystem Failed to read uri: ${uri}. ${message}`\n );\n }\n}\n\nexport async function loadArrayBufferAsync({ uri, onProgress }): Promise<any> {\n const loader = new FileLoader();\n loader.setResponseType('arraybuffer');\n return new Promise((res, rej) => loader.load(uri, res, onProgress, rej));\n}\n"]} |