Load STL File #1029
-
So for the past week I've been trying to load in a STL file and I can't get anything to work. When I don't import my file as an import statement, I get an error saying cannot load file.
Can someone help me figure out how to correctly load in a 3D object from an STL file and display it on a Canvas? I also create a StackOverFlow question but no hits. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
<bufferGeometry ref={geom} attach="geometry"/> This is your problem. The return from export const Model = ({url}) => {
const geom = useLoader(STLLoader, book)
return (
<Canvas>
<mesh>
<primitive object={geom} attach="geometry"/> // note I've used primitive.
<meshStandardMaterial color="hotpink"/>
</mesh>
<ambientLight/>
<pointLight position={[10, 10, 10]}/>
</Canvas>
)
} |
Beta Was this translation helpful? Give feedback.
-
You are using hooks outside of canvas. They are context related and can only be used within canvas. |
Beta Was this translation helpful? Give feedback.
This is your problem. The return from
useLoader
is typically an object, you should use it like this: