#Load GLB file with input
12 messages · Page 1 of 1 (latest)
you just need to call a function
this is documentation on how to load glb https://threejs.org/docs/#examples/en/loaders/GLTFLoader
if you are using webpack or something similar there should be static folder, if you are using examples in three.js documentation just next to index.js add your model and just provide the path
I dont want to keep files as local or server. I want to add model from users.
Gltf loader can handle Data url as well
can you write sample code? how can I connect html input and three js function?
maybe this can get you started https://github.com/donmccurdy/three-gltf-viewer
I found this. this is like what I want but this can import only collada files. I will try convert to glb.
const handleFile = async (file: File) => {
if (file === null) {
return
} else {
//regex to check for file extension
if (isGlbOrGltf(file.name)) {
let reader = new FileReader()
reader.readAsArrayBuffer(file)
reader.onload = (gltfGlb: ProgressEvent<ArrayBuffer | any>) => {
if (gltfGlb.target === null) {
return
} else {
//loader.parse gltfGlb.target)
}
}
}
}```