pmndrs / gltfjsx

🎮 Turns GLTFs into JSX components
https://gltf.pmnd.rs
MIT License
4.5k stars 293 forks source link

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

Open MaxmaxmaximusAWS opened 3 years ago

MaxmaxmaximusAWS commented 3 years ago

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.

jl-n commented 3 years ago

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

drcmda commented 3 years ago

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.

jl-n commented 3 years ago

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).

drcmda commented 3 years ago

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.

jl-n commented 3 years ago

@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.

MaxmaxmaximusAWS commented 3 years ago

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"] />
drcmda commented 3 years ago

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.