Replies: 2 comments 4 replies
-
If you need to change things after loading your gltf, consider converting it to jsx with gltfjsx https://github.com/pmndrs/gltfjsx |
Beta Was this translation helpful? Give feedback.
-
adding to what @gsimone said, GLTFLoader gives you an object that contains { scene, ... }, r3f adds { nodes, materials }. you're then trying to construct a mesh, which takes geometry and a material with that arbitrary loader object. you also do that smack in the middle of the render function which isn't good. Either color stuff in blender and use it as isCan be OK. const { scene } = useLoader(GLTFLoader, url)
return <primitive object={scene} /> Pick out stuff and render it any way you wantCan be OK, usually not recommended bc you loose transforms. const { nodes } = useLoader(GLTFLoader, url)
return (
<mesh geometry={nodes.robot.geometry}>
<meshStandardMaterial color="#ff0000" transparent opacity={0.5} />
</mesh>
) Mutate the material directlyMutation is usually bad, would not recommend. 👎 const { scene, materials } = useLoader(GLTFLoader, url)
useMemo(() => {
materials.someMaterial.color.set("#ff0000")
materials.someMaterial.transparent = true
materials.someMaterial.opacity = 0.5
}, [materials])
return <primitive object={scene} /> Use gltfjsx, everything is under your controlUsually your best option to always use it. 👍 |
Beta Was this translation helpful? Give feedback.
-
I have managed to load a gltf object into my react-three-fiber scene. Now I want to attach a material to my model. Is it possible to use standard material on this model? Here's what I tried:
Beta Was this translation helpful? Give feedback.
All reactions