Skip to content

Commit

Permalink
feat: 🎸 add KTX2/Draco loader to avatar-editor
Browse files Browse the repository at this point in the history
✅ Closes: Hubs-Foundation#6209
  • Loading branch information
kira924age committed Aug 14, 2023
1 parent 1907267 commit 6c418fb
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/react-components/avatar-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6c418fb

Please sign in to comment.