From 6c418fb56db14d01c265b1cd2d14bba84dcac334 Mon Sep 17 00:00:00 2001 From: kira924age Date: Mon, 14 Aug 2023 12:35:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20KTX2/Draco=20loade?= =?UTF-8?q?r=20to=20avatar-editor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #6209 --- src/react-components/avatar-editor.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/react-components/avatar-editor.js b/src/react-components/avatar-editor.js index edf4795fbc..974124360f 100644 --- a/src/react-components/avatar-editor.js +++ b/src/react-components/avatar-editor.js @@ -15,7 +15,10 @@ import { ensureAvatarMaterial } from "../utils/avatar-utils"; import AvatarPreview from "./avatar-preview"; import styles from "../assets/stylesheets/avatar-editor.scss"; +import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader"; import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader"; +import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader"; +import { getCustomGLTFParserURLResolver } from "../utils/media-url-utils"; import dropdownArrowUrl from "../assets/images/dropdown_arrow.png"; import dropdownArrow2xUrl from "../assets/images/dropdown_arrow@2x.png"; @@ -150,10 +153,23 @@ class AvatarEditor extends Component { e.preventDefault(); if (this.inputFiles.glb && this.inputFiles.glb instanceof File) { - const gltfLoader = new GLTFLoader().register(parser => new GLTFBinarySplitterPlugin(parser)); const gltfUrl = URL.createObjectURL(this.inputFiles.glb); + const loadingManager = new THREE.LoadingManager(); + loadingManager.setURLModifier(getCustomGLTFParserURLResolver(gltfUrl)); + + const gltfLoader = new GLTFLoader(loadingManager).register(parser => new GLTFBinarySplitterPlugin(parser)); const onProgress = console.log; + const ktxLoader = new KTX2Loader(loadingManager); + const dracoLoader = new DRACOLoader(loadingManager); + + if (ktxLoader) { + gltfLoader.setKTX2Loader(ktxLoader); + } + if (dracoLoader) { + gltfLoader.setDRACOLoader(dracoLoader); + } + await new Promise((resolve, reject) => { // GLTFBinarySplitterPlugin saves gltf and bin in gltf.files gltfLoader.load(