Giving unique attributes to a single model based component being re-used made with GLTFJSX #1673
-
Sorry if the title is confusing or wordy, kind of hard to put succinctly. Anyway, say for example, I am returning multiples of a single model that has been componentized with GLTFJSX, like so: below, Model12 is the GLTFJSX componentized model, and I am mapping over model state, setting unique props for each instance of the model based on the map.
In this case, it will render two instances of the model, with the position prop being respected, as well as the scale, but the modelColor prop is not. That is to say, the models always render with the same color (specifically the last color given). I am applying the colors in the component targeting each individual mesh. The meshes in both instances, of course, have the same names, which leads me to believe the problem lies here. Maybe there is an approach to applying a color across a model made up of multiple meshes within a group that I am unaware of, but I am starting to think the only way is to make separate components, like <Model12_1 />, <Model12_2 /> etc. which I feel is probably very incorrect. I was playing around and found if you manually assign the material in each individual mesh within the model component, you can reassign the color and it works, say for example with a meshStandardMaterial or meshPhysicalMaterial, though I would like to find out if you can do this with the materials destructured from the useGLTF hook somehow as some of the materials have normal maps applied already, and I would like to preserve those. I also noticed in the shoe example, that you can assign the material-color prop, which is awesome and so good to know! However, the material-color parameter still doesn't respect the individual color prop being passed to it for some reason or another. If anyone has any pointers as to why this may be happening, or why it's not possible, or any advice at all I would very much appreciate the insight! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
what useLoader does is it caches the models data. gltfjsx allows you to re-use it by covering geometries and materials into new meshes which now can receive their own positions and such, but you are using the same materials and geometries between instances still. you can clone the data you get from useGLTF, or give these meshes their own material, then it will work. |
Beta Was this translation helpful? Give feedback.
what useLoader does is it caches the models data. gltfjsx allows you to re-use it by covering geometries and materials into new meshes which now can receive their own positions and such, but you are using the same materials and geometries between instances still. you can clone the data you get from useGLTF, or give these meshes their own material, then it will work.