pmndrs / gltfjsx

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

[EXAMPLE NEEDED] Using the parser stand-alone #95

Closed quacrobat closed 3 years ago

quacrobat commented 3 years ago

Hello, great collection of react/three tools - thanks so much @pmndrs.

How to do direct piping/parsing of gltf into a react component without CLI?

Can someone please provide a working sandbox of "Using the parser stand-alone" - i can't figure it out at all from the snippet!

Thank you

drcmda commented 3 years ago

the parser creates plain text, this has nothing to do with components: https://github.com/pmndrs/gltf-react-three/blob/main/utils/store.js#L7-L29 the main page also has an example: https://github.com/pmndrs/gltfjsx#using-the-parser-stand-alone

but i think you are mixing something up. the text generated from the parser is nothing you can feed react runtime other than just displaying it. if you have a gltf, then run npx gltfjsx over it, then copy the file into your project, then you can render it. you can't create the jsx runtime and that would defeat the entire purpose. if you have a remote gltf you want to render then just use primitive object={scene} without gltfjsx being involved.

quacrobat commented 3 years ago

Ah, i was wondering if that was the case, thanks for the clarification.

Indeed I was hoping to be able to just pipe the jsx into a Model component - or a state even.

I did see the main page example but I can't figure out how to make it work as I am hitting an error when importing parse, i reported it in #96 .

drcmda commented 3 years ago

everything in that issue you opened was wrong, from creating objects in the render function to everything else. the example on the main page is how you do it. but again, this is only for creating text content for printing out and looking at it, it serves no other purpose. i don't know if that's really what you want to do. when you drag a glb into https://gltf.pmnd.rs the left side is using the stand alone parser, it prints out text into a <pre> tag that's all. if you want real components that you can render and see, then use gltfjsx from the command line and generate them.

quacrobat commented 3 years ago

Thanks for taking the time to follow up and apologies if i am not expressing myself clearly - yes i do understand now exactly what gltfjsx does.

My use case was about end users uploading their own models and being able to list the meshes that make them up (like a gltf content explorer tree). I do know how to do it without gltfjsx.

Regardless, if i want to try out the parse example for a different use case, and indeed just print out a pre tag with the text, but I am getting an error when i try to import it. Is that a bug or am i doing something completely wrong? the sandbox in #96 is updated without the mess i was trying to do before.