feat: some tweaks
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m41s

This commit is contained in:
2024-05-03 01:33:55 +02:00
parent 4c235fe24a
commit cf5b36490f
8 changed files with 235 additions and 211 deletions

View File

@ -1,37 +1,36 @@
<script lang="ts">
import type { Scene } from "three";
import { OBJExporter } from "three/addons/exporters/OBJExporter.js";
import { GLTFExporter } from "three/addons/exporters/GLTFExporter.js";
import type { Group } from "three";
import type { OBJExporter } from "three/addons/exporters/OBJExporter.js";
import type { GLTFExporter } from "three/addons/exporters/GLTFExporter.js";
import FileSaver from "file-saver";
// Download
const download = (
data: string,
data: ArrayBuffer | string,
name: string,
mimetype: string,
extension: string,
) => {
if (typeof data !== "string") data = JSON.stringify(data);
const blob = new Blob([data], { type: mimetype + ";charset=utf-8" });
FileSaver.saveAs(blob, name + "." + extension);
};
// export const json = (data, name = 'default') => {
// download(JSON.stringify(data), name, 'application/json', 'json');
// };
//
// export const obj = (data, name = 'default') => {
// };
export let scene: Group;
export let scene: Scene;
let gltfExporter: GLTFExporter;
async function exportGltf() {
const exporter =
gltfExporter ||
(await import("three/addons/exporters/GLTFExporter.js").then((m) => {
gltfExporter = new m.GLTFExporter();
return gltfExporter;
}));
function exportGltf() {
const exporter = new GLTFExporter();
exporter.parse(
scene,
(gltf) => {
// download .gltf file
download(gltf, "plant", "text/plain", "gltf");
download(gltf as ArrayBuffer, "plant", "text/plain", "gltf");
},
(err) => {
console.log(err);
@ -39,8 +38,15 @@
);
}
function exportObj() {
const exporter = new OBJExporter();
let objExporter: OBJExporter;
async function exportObj() {
const exporter =
objExporter ||
(await import("three/addons/exporters/OBJExporter.js").then((m) => {
objExporter = new m.OBJExporter();
return objExporter;
}));
const result = exporter.parse(scene);
// download .obj file
download(result, "plant", "text/plain", "obj");