I have the following code on the codesandbox below:
https://codesandbox.io/p/sandbox/model-loading-test-2ynlw9?file=%2Fsrc%2FApp.js%3A1%2C1-35%2C1
Where I attempt to import the ThreeMFLoader
import { Canvas } from "@react-three/fiber";
import { useEffect, useState, useRef } from "react";
import { ThreeMFLoader } from "three/addons/loaders/3MFLoader.js";
function Test({ savedFile }) {
// The file is then passed here
console.log("Test Is Rendered");
console.log(savedFile);
const [objectMesh, setObjectMesh] = useState();
useEffect(() => {
console.log("UseEffect Called");
let reader = new FileReader();
reader.addEventListener("loadend", (event) => {
let result = event.target.result;
let loader = new ThreeMFLoader();
let parsedResult = loader.parse(result);
setObjectMesh(parsedResult);
});
reader.readAsArrayBuffer(savedFile);
}, [savedFile]);
console.log("Rendering");
return <primitive object={objectMesh} />;
}
export default function App() {
const [savedFile, changeSavedFile] = useState(null);
// When the user uploads a file, it is saved tothe App State
return (
<div className="App">
<input type="file" onChange={(e) => changeSavedFile(e.target.files[0])} />
<Canvas>{savedFile && <Test savedFile={savedFile} />}</Canvas>
</div>
);
}
Why does it cause an import error:
ModuleNotFoundError: Could not find module in path: ‘three/addons/loaders/3MFLoader.js’ relative to ‘/src/App.js’