gltfjsx icon indicating copy to clipboard operation
gltfjsx copied to clipboard

[FEATURE] maybe we should add some decomposition to the generated code?

Open MaxmaxmaximusAWS opened this issue 3 years ago • 7 comments

maybe we should add some decomposition to the generated code?

for example, in addition to the default export, also export each model and texture separately, by name.

MaxmaxmaximusAWS avatar Oct 07 '20 05:10 MaxmaxmaximusAWS

This would be an incredible feature, especially when using with typescript.

jl-n avatar Nov 25 '20 20:11 jl-n

sounds interesting. so you mean something like this?

export function Arms() {
  const { nodes, material } = useGLTF("model.glb")
  return ...
}

export function Legs() {
  const { nodes, material } = useGLTF("model.glb")
  return ...
}

export default function Model() {
  return (
    <group>
      <Arms />
      <Legs />

just not sure about the specifics and if it's doable. lots of questions come to mind. for instance, names can easily break javascript conventions.

drcmda avatar Nov 25 '20 20:11 drcmda

Yes exactly. I can imagine there are lots of edge cases around doing this properly but it would be great to be able to run an exported scene from blender through gltfjsx and then selectively import objects into the scene (and get type errors if something has been changed).

jl-n avatar Nov 25 '20 21:11 jl-n

you can edit the main component though and make its parts conditional, isn't that enough? either way, you can make a pr and then we can review it. there is zero chance that i will have the time for that right now.

drcmda avatar Nov 25 '20 22:11 drcmda

@drcmda I'm doing that for now, if I find I encounter wanting to do this regularly I'll make a PR. Thanks for your work on this.

jl-n avatar Nov 25 '20 22:11 jl-n

so you mean something like this?

exactly =)

names can easily break javascript conventions.

export const models = {
  Arms: () => { const { nodes, material } = useGLTF("model.glb") },
  "dffg gf  fd  gf": = () => { const { nodes, material } = useGLTF("model.glb") }
}

export default function Model() {
  return (
    <group>
      <models.Arms />
      <models["dffg gf  fd  gf"] />

MaxmaxmaximusAWS avatar Nov 25 '20 22:11 MaxmaxmaximusAWS

one more concern would be how to treat n levels of nesting. if it's all about exposing "nodes" then each would just contain the mesh with the linked up geometry and material, but groups and their positioning would be lost in the named export. but yeah, make a flag and wire it into the code - i would probably accept it.

drcmda avatar Nov 25 '20 23:11 drcmda