Changing mesh texture/color on props reloading model #1825
Replies: 2 comments
-
moving this into a discussion for now. i think it is unlikely this is a bug. useLoader is cached, there is no way it can double load unless the url changes. but the render function is full of side effects, and that is not good. no idea what this is, but create sounds like it creates something, not good (looks like it needs to be inside useMemo) const model = Object.create(models['BaseConfigurator']); this executes "getMeshing()" on every render, not good. better make that useState(() => model.getMeshing()) const [meshMatrix, setConfigurator] = useState(model.getMeshing()) this looks like you're re-creating materials every render (needs to be inside a useMemo or useLayoutEffect) Object.keys(colorSelection['SelectedColors']).forEach((element, index) => {
... and this is probably your root issue return <primitive object={obj} scale={0.4} />; r3f won't touch primitives, it won't dispose of it after the component unmounts, because it is an external. it couldn't possibly reach into externals and destroy them. if you use primitive the object is yours to manage. keep in mind though, if you dispose (for instance in a useEffect) the cached item will still be there. useLoader has a i would recommend not using primitive and not obj/mtl. use gltf and gltfjsx, if possible.
|
Beta Was this translation helpful? Give feedback.
-
another one, and this could be the worst function App() {
function Scene() { ... }
return <Scene />
} this is an anti pattern. since this is how you form components: function App() { ... }
function Scene() { ... } |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
We have a model made on 3d Max with some Meshes, we have a RGB color picker, when we change the color we need to update the color texture of certain meshes, we have the color picker and the 3D Viewer on different components.
When we change the color state we pass the props to the component, our main issue is that for each change we made it appears that we model is loading multiple times so out memory goes up and then too slow.
Enviroment (please complete the following information):
Additional context
Code example:
Our main component:
return <ThumbnailScene colorSelection={props.others} size={'100%'}/>;
Our ThumbnailScene Component:
Are we missing something to avoid the performance issue, we read the documentation.
https://docs.pmnd.rs/react-three-fiber/advanced/pitfalls
Beta Was this translation helpful? Give feedback.
All reactions