Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'loadSpineAsync: Please provide a valid resource for the `json` prop'
);
return null;
} else {
if (typeof json === 'number') {
_json = await jsonFromResourceAsync(json);
} else if (typeof json === 'object') {
if (json.bones) {
_json = json;
} else {
_json = await jsonFromResourceAsync(json);
}
}
}
// Downlaod the atlas file
const atlasUrl = await uriAsync(atlas);
const _atlas = await readAsStringAsync(atlasUrl);
if (!_json || typeof _atlas !== 'string') {
console.error(
'loadSpine: Invalid props. Please provide: `{ json: Object, atlas: string, assetProvider: Function }`'
);
}
const customAssetProvider = async (line, callback) => {
const getAsset = async () => {
if (isFunction(assetProvider)) {
return new Promise(async res => {
const resource = await assetProvider(line, res);
if (resource) {
res(resource);
}
(async () => {
const nativeAsset = await AssetUtils.resolveAsync(asset);
function parseAsset(image) {
texture.image = image;
// JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
texture.format = formatFromURI(nativeAsset.localUri);
texture.needsUpdate = true;
if (onLoad !== undefined) {
onLoad(texture);
}
}
if (Platform.OS === 'web') {
loader.load(
nativeAsset.localUri,
get files() {
return [
...AssetUtils.arrayFromObject(Assets.images || {}),
// ...AssetUtils.arrayFromObject(Assets.models || {})
];
}
async preloadAssets() {
await AssetUtils.cacheAssetsAsync({
// fonts: this.fonts,
files: this.files,
// audio: this.audio,
});
this.setState({ loading: false });
}
async function loadFileAsync({ asset, extension, funcName }: { asset?: string, extension: string, funcName: string }): Promise {
if (!asset) {
console.error(`ExpoTHREE.${funcName}: Cannot parse a null asset`);
return;
}
let uri;
try {
uri = await AssetUtils.uriAsync(asset);
} catch ({ message }) {
const customErrorMessage = provideBundlingExtensionErrorMessage({
extension,
funcName,
});
console.error(customErrorMessage, message);
}
if (uri == null || typeof uri !== 'string' || uri === '') {
console.error(
`ExpoTHREE.${funcName}: Invalid \`localUri\` was retrieved from \`asset\` prop:`,
uri
);
}
if (!uri.match(`/\.${extension}$/i`)) {
console.error(
`ExpoTHREE.${funcName}: the \`asset\` provided doesn't have the correct extension of: .${extension}. URI: ${uri}`
async function loadFileAsync({ asset, extension, funcName }) {
if (!asset) {
console.error(`ExpoTHREE.${funcName}: Cannot parse a null asset`);
return;
}
let uri;
try {
uri = await AssetUtils.uriAsync(asset);
}
catch ({ message }) {
const customErrorMessage = provideBundlingExtensionErrorMessage({
extension,
funcName,
});
console.error(customErrorMessage, message);
}
if (uri == null || typeof uri !== 'string' || uri === '') {
console.error(`ExpoTHREE.${funcName}: Invalid \`localUri\` was retrieved from \`asset\` prop:`, uri);
}
if (!uri.match(`/\.${extension}$/i`)) {
console.error(`ExpoTHREE.${funcName}: the \`asset\` provided doesn't have the correct extension of: .${extension}. URI: ${uri}`);
}
return;
}
private loadHTMLFile = async () => {
try {
let asset: Asset = await AssetUtils.resolveAsync(INDEX_FILE_PATH);
let fileString: string = await FileSystem.readAsStringAsync(
asset.localUri
);
this.setState({ webviewContent: fileString });
} catch (error) {
console.warn(error);
console.warn("Unable to resolve index file");
}
};
componentDidMount = async () => {
try {
const asset = await AssetUtils.resolveAsync(requiredAsset)
console.log({asset})
this.setState({ asset })
} catch (error) {
console.log({ error })
}
};
async function loadFileAsync({ asset, funcName }) {
if (!asset) {
throw new Error(`ExpoTHREE.${funcName}: Cannot parse a null asset`);
}
return await AssetUtils.uriAsync(asset);
}
export async function loadMtlAsync({ asset, onAssetRequested }) {
export default async function loadAsync(res, onProgress, onAssetRequested = function () { }) {
let urls = await resolveAsset(res);
if (!urls) {
throw new Error(`ExpoTHREE.loadAsync: Cannot parse undefined assets. Please pass valid resources for: ${res}.`);
}
const asset = urls[0];
let url = await uriAsync(asset);
if (url == null) {
throw new Error(`ExpoTHREE.loadAsync: this asset couldn't be downloaded. Be sure that your app.json contains the correct extensions.`);
}
if (urls.length == 1) {
if (url.match(/\.(jpeg|jpg|gif|png)$/)) {
return loadTextureAsync({ asset });
}
else if (url.match(/\.assimp$/i)) {
const arrayBuffer = await loadArrayBufferAsync({ uri: url, onProgress });
const AssimpLoader = loaderClassForExtension('assimp');
const loader = new AssimpLoader();
return loader.parse(arrayBuffer, onAssetRequested);
}
else if (url.match(/\.dae$/i)) {
return loadDaeAsync({
asset: url,