After days of looking out for a solution, I found out that it seems that you must to manually copy files from
node_modules/three/examples/js/libs/draco/gltf
into your public path on server:
cp -r node_modules/three/examples/js/libs/draco/gltf HERE_YOUR_PUBLIC_PATH
You can do this using the cp
command native to Ubuntu, which is specifically intended for copying files and directories from one location to another.
cp -a /source/. /destination/
- Then you have to call
dracoLoader.setDecoderPath('PATH_TO_DRACO_LIBRARY')
The Code:
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
const loader = new GLTFLoader();
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath("myDecoder/gltf/");
loader.setDRACOLoader(dracoLoader);
//
//
loader.load(
"./models/beanstalk2_green-processed.gltf",
(d) => {
this.scene.add(d.scene);
},
null,
(e) => {
console.error(e);
}
);
// First compress it in Blender
// Then use the gltf-pipeline to compress it further (at your own risk)
// Beanstalk-compress.glb is the name of the file i want to compress
// You have to be in the right directory
// myProject/public/models$ gltf-pipeline -i Beanstalk-compress.glb -d
// result
// Beanstalk-processed.gltf or glb depending of your file
The Original post: