()
| 368 | } |
| 369 | |
| 370 | export function Export() { |
| 371 | const { scene } = useThree(); |
| 372 | const action = useActionStore((state) => state.action); |
| 373 | const fleetSpaceId = useActionStore((state) => state.fleetSpaceId); |
| 374 | |
| 375 | const exportType = useActionStore((state) => state.exportType); |
| 376 | |
| 377 | const setAction = useActionStore((state) => state.setAction); |
| 378 | |
| 379 | useEffect(() => { |
| 380 | if (action === true) { |
| 381 | setAction(false); |
| 382 | exportGLB(); |
| 383 | } |
| 384 | }, [action, setAction, scene]); |
| 385 | |
| 386 | const uploadFleet = async (blob) => { |
| 387 | const formData = new FormData(); |
| 388 | |
| 389 | formData.append("object", blob, "box3d.glb"); |
| 390 | formData.append("title", "New Object"); |
| 391 | formData.append("description", ""); |
| 392 | formData.append("spaceId", fleetSpaceId); |
| 393 | |
| 394 | await instanceFleet.post("space/file/mesh", formData, { |
| 395 | headers: { |
| 396 | "Content-Type": "multipart/form-data", |
| 397 | }, |
| 398 | }); |
| 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); |
nothing calls this directly
no test coverage detected