pmndrs / three-stdlib

📚 Stand-alone library of threejs examples designed to run without transpilation in node & browser
https://npmjs.com/three-stdlib
MIT License
733 stars 119 forks source link

DRACOLoader: Property 'Worker' doesn't exist #349

Closed devirtua closed 9 months ago

devirtua commented 9 months ago

I am using threejs, @react-three/fiber, @react-three/drei on react native. Trying to load compressed gltf model but getting Reference Error: Property 'Worker' doesn't exist error.

Here is the related code:

import React from 'react';
import { useGLTF } from '@react-three/drei/native';

function A1() {
  const { scene } = useGLTF(require("./assets/a1_compressed.glb"));
  return <primitive object={scene} />
}

export default function Model(props) {
  return (
    <group>
      <A1 />
    </group>
  );
}

There are the dependencies:

  "dependencies": {
    "@react-three/drei": "^9.99.7",
    "@react-three/fiber": "^8.15.19",
    "expo": "^50.0.8",
    "expo-gl": "~13.6.0",
    "react": "18.2.0",
    "react-native": "0.73.5",
    "react-native-url-polyfill": "^2.0.0",
    "three": "^0.162.0"
  },

PHOTO-2024-03-05-17-09-58

CodyJasonBennett commented 9 months ago

DRACO can't be used with react-native, as it relies on both workers but importantly WASM/JIT (EU regulations on browser ban may enable this, since it's just iOS with this restriction). You'd need to implement http://github.com/google/draco over JSI and write the loader to interface with it. This is not something this library can support. I would suggest forgoing DRACO or meshopt on native, and/or rewriting the latter's encoders in JS or over JSI.

devirtua commented 9 months ago

Thank you for the clear explanation.