3D rendering API

Generating 3D models from Gerber files is like generating C code from compiled machine code. Its possible, can look cool when you look at it from 3 meters distance, but it is a total mess when you try to analyze it.

Therefore, don’t expect generated 3D models to have great topology, or be dragged and dropped into 3D printer to get some plastic showcase model. (The later one can be achieved however, just requires some hand tweaking, try Remesh modifier in blender)

They are mend for virtual showcase only, and they do their job pretty well.

Single-file 3D rendering

Similarly to 2D API, 3D API also contains render_file() function, suitable for rendering standalone gerber files with minimal amount of configuration:

examples/blender/render_file.py
# -*- coding: utf-8 -*-
from PyR3.shortcut.io import export_to

from pygerber.API3D import render_file

render_file("tests/gerber/s5.grb")
export_to("render.glb")

You can achieve same result as above code using render_file_and_save() function:

examples/blender/render_file_and_save.py
# -*- coding: utf-8 -*-
from pygerber.API3D import render_file_and_save

render_file_and_save("tests/gerber/s5.grb", "render.glb")

Multi-file file 3D rendering

To render multiple files as one project you have to provide project specification, which can be done using dictionary in code or standalone config file written using JSON, YAML or TOML. Each specfile language has its own separate render function, render_from_json(), render_from_yaml(), render_from_toml()

Full explanation of configuration contents is described in Specfile for 3D rendering chapter.

Example usage of dictionary configuration looks like this:

examples/blender/render_from_spec.py
# -*- coding: utf-8 -*-
from pygerber.API3D import render_from_spec

render_from_spec(
    {
        "ignore_deprecated": True,
        "layers": [
            {
                "file_path": "./tests/gerber/set/top_copper.grb",
                "structure": {
                    "material": {
                        "color": [40, 143, 40, 255],
                        "metallic": 1.0,
                        "roughness": 0.8,
                    },
                    "thickness": 0.78,
                },
            },
            {
                "file_path": "./tests/gerber/set/top_solder_mask.grb",
                "structure": "solder_mask",
            },
            {"file_path": "./tests/gerber/set/top_paste_mask.grb"},
            {
                "file_path": "./tests/gerber/set/top_silk.grb",
                "structure": "silk",
            },
        ],
    }
)

As It was mentioned above, configuration can be also created in form of standalone so called specfile, and then it can be used following way:

examples/blender/render_from_yaml.py
# -*- coding: utf-8 -*-
from pygerber.API3D import render_from_yaml

render_from_yaml("tests/gerber/blender/specfile.yaml")

And coresponding source of YAML specfile looks like this:

tests/gerber/blender/specfile.yaml
ignore_deprecated: yes
layers:
  - file_path: ./tests/gerber/set/top_copper.grb
    structure:
      thickness: 0.78
      material:
        color: [40, 143, 40, 255]
  - file_path: ./tests/gerber/set/top_solder_mask.grb
    material: solder_mask
  - file_path: ./tests/gerber/set/top_paste_mask.grb
  - file_path: ./tests/gerber/set/top_silk.grb