-
-
Save yushimatenjin/2d67b739bd5a33604337b4b20d4172ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VRMLoader { | |
constructor(editor) { | |
this.editor = editor; | |
this.editor.on("assets:add", (asset) => { | |
const type = asset.get("type"); | |
const fileName = asset.get("name"); | |
const fileExtension = fileName.split(".").pop(); | |
if (type === "binary" && fileExtension === "vrm") { | |
setTimeout(async () => { | |
const name = this.replaceExtension(fileName, "glb"); | |
const assetUrl = asset.get("file").url; | |
const res = await fetch(assetUrl); | |
const glbData = await res.arrayBuffer(); | |
const blob = new Blob([glbData], { type: "model/gltf-binary" }); | |
const file = new File([blob], name, { type: "model/gltf-binary" }); | |
const dt = new DataTransfer(); | |
dt.items.add(file); | |
const list = dt.files; | |
this.editor.call("assets:upload:files", list); | |
}, 1000); | |
} | |
}); | |
} | |
replaceExtension(fileName, newExtension) { | |
const parts = fileName.split("."); | |
parts.pop(); | |
parts.push(newExtension); | |
return parts.join("."); | |
} | |
} | |
new VRMLoader(editor); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment