Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

[FEATURE] VRML/WRL export #349

Closed
Haschtl opened this issue Dec 13, 2022 · 7 comments
Closed

[FEATURE] VRML/WRL export #349

Haschtl opened this issue Dec 13, 2022 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@Haschtl
Copy link

Haschtl commented Dec 13, 2022

It would be nice to have a VRML/WRL export option. Step is good for technical usage, but for visualizations vrml is better.

As KiCad is able to export a VRML model, wouldn't it be easy to have this feature in KiBot?

My plan is to automate the tool pcb2blender to export a GLTF model with blender. Therefore I want to rely on KiBot to export all the necessary stuff (layers as svg, pads, wrl of board and components)

This is the last missing step for a fully automated export of high resolution 3d models

@Haschtl Haschtl added the enhancement New feature or request label Dec 13, 2022
@set-soft set-soft changed the title [FEATURE] [FEATURE] VRML/WRL export Dec 14, 2022
@set-soft
Copy link
Member

Hi @Haschtl !
This sounds very interesting. Adding it to KiAuto/KiBot is not that hard.
But this will be after releasing 1.5.0.
BTW: could it be integrated with KiBot?

@set-soft
Copy link
Member

Hi @Haschtl !
If you want to experiment take a look at KiAuto repo, I added some preliminar VRML export option.

@Haschtl
Copy link
Author

Haschtl commented Dec 17, 2022

Nice! Thanks for the quick implementation.

Regarding the integration to KiBot.
I don't know much about the structure of KiBot, but I can tell, whats necessary for the export. First of all, thanks to @30350n for the PCB2Blender exporter.

The integration consists of two parts:

  1. All required data needs to be exported using KiBot
  2. The exporter step needs to be integrated as a submodule to KiBot

Used data

Required

  • WRL files of PCB and all components (basically the VRML-Export with relative-paths from KiCAD)
  • All layers as SVG

Optional

  • Definition of footprint-pads
  • Board definitions
  • KiCAD stackup

The pad definitions are used to add 3-dimensional solder and are exported in a custom file-format which includes information from each footprint's pads. The results are looking great!

The board definitions are useful, if there are multiple boards in one kicad_pcb file. It's used to multiple boards up. It requires to add some TextElements to split multiple boards, but this feature is completely optional.

The stackup of the board, which can be defined since KiCAD 6, is used to automatically detect the materials of the layers. This feature is not included in the current PCB2Blender repo, but I added it in my fork in a kind of hacky way... That's because I think there is currently no working Python-API to read the stackup with pcb_new, so I parsed the kicad_pcb file by hand.

Export

Blender is used here. All the steps here can run in the commandline. It's not only possible to export GLTF, but also OBJ, FBX, ... or simply save a BLEND file.
But there are still some things to consider:

  • pcb2blender creates some fancy materials in blender, which look amazing, but cannot be exported as GLTF or others. This should be used, if you need high defintion renderings. But this cannot be exported from blender
  • @30350n has another (deprecated) import-strategy which imports the layers as 3d-models. This looks less good, but can be exported as GLTF. But as there are a lot vertices in the 3d model, it's rather slow, when used in the browser (especially on the phone)
  • @30350n said, the best way would be to bake the materials into texture-maps, that can be exported.
  • In the meantime, I have created another import-strategy, which reads the layer-SVGs and saves texture-maps, which are then used. These look not as good as @3050n's solution, but are export-compatible

Long story short: It's possible to have one python-command to export all the different files (BLEND, GLTF, OBJ, FBX, ...) from a given KiCAD export.
I think, it's possible to run blender in a docker-container for this import-export task...
Blender can also be compiled as BlenderAsPyModule

It would definitely be a great addition to have the export as BLEND,GLTF,OBJ,FLX and others integrated in
KiBot!

@set-soft
Copy link
Member

set-soft commented Dec 17, 2022

Hi @Haschtl !
fafd5d2 adds VRML support using KiAuto 2.1.0, very experimental.

KiBot currently reads the stack-up and process pads. So these tasks can be done.
I have some plans to add support for kikit separate, but, to be honest, I think this is not a good solution. I explain it here.

@set-soft
Copy link
Member

Hi @Haschtl !
Now KiBot can separate multi-board projects using the mechanisms found in KiKit (rectangle and annotation).

@set-soft
Copy link
Member

set-soft commented Jan 6, 2023

Hi @Haschtl !
More advances. Now KiBot can also generate the pads and board boundary files.
I also added some options to the SVG output so you can change the viewBox in a similar way to the current export plug-in.
I'll take a look at the other things. Right now you can generate files that are quite close to what the @30350n v2.1 exporter generates (no support for board stacks).
I also added a mechanism in KiBot that allows importing some handy definitions included as KiBot imports.
So I created a template named PCB2Blender_2_1 that can be used to generate PCB3D files. Not yet fully tested, but generates something quite similar.
The pcb2blender_tools_2.kibot.yaml example shows how to use it.
Is quite trivial:

# Example KiBot config file
kibot:
  version: 1

import:
  - file: PCB2Blender_2_1

Then you can just use:

kibot -c pcb2blender_tools_2.kibot.yaml -b BOARD - d OUT_DIR

To get OUT_DIR/BOARD.pcb3d

@set-soft
Copy link
Member

set-soft commented Jan 7, 2023

Hi @Haschtl !
Ok, now KiBot can generate PCB3D files with the stack-up included.
The pcb2blender_tools_3.kibot.yaml example does it using the PCB2Blender_2_1_haschtl template.
I verified that the files generated by PCB2Blender_2_1 can be loaded using @30350n import plug-in. It was really hard because the current Blender on Debian stable is 2.83.5 and it uses the system level Python 3.9. Even after adapting the Python 3.10 dialect details it turns out that Blender 2.83 has a weaker X3D importer (VRML). So I had to use a docker image with Blender 3.4.
I'm closing this issue, not because I think we are done, but because the scope of the issue.
Now that we have PCB3D files, and that you can even add experimental files, like the gerbers (just editing the template) we should move to add automatic export, and perhaps some simple high quality renders.

@set-soft set-soft closed this as completed Jan 7, 2023
@INTI-CMNB INTI-CMNB locked and limited conversation to collaborators Jan 7, 2023
@set-soft set-soft converted this issue into discussion #358 Jan 7, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants