Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to export glTF 2.0 #28

Open
N0cynym opened this issue Jul 5, 2023 · 10 comments
Open

How to export glTF 2.0 #28

N0cynym opened this issue Jul 5, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@N0cynym
Copy link

N0cynym commented Jul 5, 2023

I just have a question:

How can I export from my blender project a .glb with rendered surface texture?

I want to create a file for https://modelviewer.dev/editor/

Thanks for this tool 🙏

@30350n
Copy link
Owner

30350n commented Jul 6, 2023

That's not easily possible atm, alteast not with the current Cycles shaders. The 3D (deprecated) material mode might work, but won't look nearly as good. Solutions for this have been discussed before in #8 and also #24 kinda.

@N0cynym
Copy link
Author

N0cynym commented Jul 7, 2023

@30350n did you test how it looks like if you render top and bottom image and put it as image texture on the surface of the blank imported glb body?

@30350n
Copy link
Owner

30350n commented Jul 7, 2023

No, but what your suggesting is more or less a very naive version of texture baking.
The problem is that this doesn't really work (or atleast isn't optimal) with the pcb mesh the addon produces. I spent some time on working around this on the baking branch, but don't have time to further persue this atm.

@30350n 30350n added the enhancement New feature or request label Jul 7, 2023
@30350n 30350n self-assigned this Jul 7, 2023
@N0cynym
Copy link
Author

N0cynym commented Jan 19, 2024

Dear @30350n,

I hope you started well into the new year!?

Do you have any news/updates about this feature?

@30350n
Copy link
Owner

30350n commented Jan 19, 2024

I hope you started well into the new year!?

Yes, thanks, hope you did too.

Do you have any news/updates about this feature?

No, not really and it wouldn't really be the main priority either. The main thing that needs to be done is a rework of all the materials, to improve performance (and visuals). Though this could also atleast simplify the export problem ...

Regardless, I can't really invest the time that would take atm.

@N0cynym
Copy link
Author

N0cynym commented Jan 19, 2024

Thank you very much for your time and for updating this amazing project. 👍

Well for now I'll see how I can embed a VRML export from KiCad to my web presentation. But I think using a glTF 2.0 export with your material finish in a model viewer would be much nicer ☺️

@crazy-hair
Copy link

crazy-hair commented Jul 31, 2024

You can bake the textures out with the Blender passes (the ones you will need are Diffuse Color, Glossy Color, Roughness, Normal, and optionally Ambient Occlusion) onto a secondary UV map (you can use the integrated Smart UV Project function for this, it doesn't need to be fancy). Unfortunately Blender doesn't support exporting with the KHR_materials_pbrSpecularGlossiness extension though, so you'll have to export it as glTF and then edit the JSON with the proper specular setup:
Code_2024-07-31_00-40-54_c
You can find more documentation on the extension here.

If you want the solder mask to show up in the normal map, you'll need to bake the normal map pass (and AO, if you want it to show up there as well) with a modified shader setup like this:
image
(Blender doesn't show past 3 digits but the Bump node's distance field is set to 0.0001).

Attached is an example glTF file:
glTF_compressed.zip

Make sure that the viewer you're using has support for SpecularGlossiness though, it looks like <model-viewer> might not support it. I know Babylon.js and PlayCanvas do.

TLDR: Not impossible, but certainly not a single button press. If you're familiar with Blender and the glTF standard it shouldn't be too difficult though.

@crazy-hair
Copy link

Small update: It appears that with the Blender 4.2 update, you can export spec-gloss materials with a node setup like this:
blender_2024-08-10_20-26-05
It works by setting the IOR to a very high index and then plugging the specular texture into the specular tint input. It actually doesn't utilize the KHR_materials_pbrSpecularGlossiness extension at all, instead just using KHR_materials_ior and KHR_materials_specular extensions, both of which appear to be supported by <model-viewer>.
Code_2024-08-10_20-52-57

With manual glTF editing out of the way, the only hurdle to exporting as glTF is now just baking the materials down to textures, and it's not that hard if you understand how rendering in Blender works. Here's an example glB file for reference: compressed.zip

@N0cynym If you still need a pcb3d file converted to glTF, I can take a crack at it if you want to send it my way.

@30350n
Copy link
Owner

30350n commented Aug 11, 2024

Thanks a lot for looking into this and for sharing your findings! Ideally this would probably be automated, either by selecting a special "GLTF Export" material mode in the importer or by having a special "Export PCB to GLTF" operator somewhere, which could then also handle the baking as well as possibleGLTF post processing.

Regarding the "baking" part of this, I tried looking into this quite a while ago. WIP is available on the baking branch.

@crazy-hair
Copy link

It would probably be easiest to have a button labeled something like Bake to exportable mesh in the sidebar that clones the object, applies all the needed actions (make single user, apply modifiers, create a secondary UV map, auto-unwrap, etc,) and then bakes the materials to it. It would leave the user with a secondary mesh in the viewport that can be exported with the native glTF exporter. I unfortunately am not a dev, so I'm not really able to automate anything or make a PR, and I know you're busy with other things so I'm not expecting this to get implemented anytime soon, but on the face of it, it should be pretty doable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants