| 399 | }; |
| 400 | |
| 401 | const exportGLB = () => { |
| 402 | const exportRoot = new THREE.Group(); |
| 403 | scene.traverse((child) => { |
| 404 | if (child.userData?.exportToGLB === true) { |
| 405 | exportRoot.add(child.clone(true)); |
| 406 | } |
| 407 | }); |
| 408 | const exporter = new GLTFExporter(); |
| 409 | const options = { binary: true, embedImages: true }; |
| 410 | exporter.parse( |
| 411 | exportRoot, |
| 412 | (result) => { |
| 413 | if (result instanceof ArrayBuffer) { |
| 414 | const blob = new Blob([result], { type: "model/gltf-binary" }); |
| 415 | |
| 416 | if (exportType == "glb") { |
| 417 | const link = document.createElement("a"); |
| 418 | link.style.display = "none"; |
| 419 | document.body.appendChild(link); |
| 420 | link.href = URL.createObjectURL(blob); |
| 421 | link.download = "scene.glb"; |
| 422 | link.click(); |
| 423 | document.body.removeChild(link); |
| 424 | } |
| 425 | |
| 426 | if (exportType == "fleet") { |
| 427 | uploadFleet(blob); |
| 428 | } |
| 429 | } else { |
| 430 | console.error("GLB export failed: unexpected result", result); |
| 431 | } |
| 432 | }, |
| 433 | (error) => { |
| 434 | console.error("An error occurred during export", error); |
| 435 | }, |
| 436 | options |
| 437 | ); |
| 438 | }; |
| 439 | return null; |
| 440 | } |
| 441 | |