I want to create playable ads and integrate Draco libraries directly into the final bundle.js
. , I’ve converted draco_decoder.wasm
and draco_wasm_wrapper.js
into base64 strings, but I’m encountering the following error:
draco_wasm_wrapper.js net::ERR_ABORTED 404 (Not Found)
The application is trying to access it at: https://localhost:8080/draco_wasm_wrapper.js
. Can anyone help me resolve this issue?
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
// Base64 strings for the Draco files
const base64Wasm = '...'; // base64 string for draco_decoder.wasm
const base64Js = '...'; // base64 string for draco_wasm_wrapper.js
// Function to convert Base64 to Uint8Array for WASM
function base64ToUint8Array(base64) {
const binaryString = atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes;
}
// Function to create a Blob URL from Base64 for JS
function base64ToBlobUrl(base64) {
const binaryString = atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
const blob = new Blob([bytes], { type: 'application/javascript' });
return URL.createObjectURL(blob);
}
// Convert base64 strings
const wasmBinary = base64ToUint8Array(base64Wasm);
const jsBlobUrl = base64ToBlobUrl(base64Js);
// Set up DRACOLoader
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderConfig({
wasmBinary: wasmBinary,
jsPath: '', // Leave empty
jsSource: jsBlobUrl, // Use the Blob URL
});
// Set up GLTFLoader
const gltfLoader = new GLTFLoader();
gltfLoader.setDRACOLoader(dracoLoader);
// Load a GLTF model
const modelUrl = 'model.gltf';
gltfLoader.load(
modelUrl,
(gltf) => {
scene.add(gltf.scene);
},
(xhr) => {
console.log((xhr.loaded / xhr.total * 100) + '% loaded');
},
(error) => {
console.error('An error occurred while loading the GLTF model', error);
}
);