# gds3xtrude
A simple layout to 3D converter.
gds3xtrude takes the layers of your layout and converts them into 3D volumes by extrusion.
`gds3xtrude` is intended to be used in two different ways:
* as KLayout extension: Show 3D model of the active view.
* as standalone tool: Convert GDS to OpenSCAD/Blender from the command line.
![Screenshot](./examples/freepdk45_screenshot.png "Screenshot")
## Dependencies
* OpenSCAD: 3D modelling tool. Can be installed using the package manager of most linux distributions.
* solidpython: Python library for creating OpenSCAD models.
* klayout: Python module of KLayout used for GDS input/output and polygon operations.
## Install (Linux)
### As KLayout package
Use the KLayout package manager to install `gds3xtrude`.
Dependencies (gds3xtrude python package, OpenSCAD) must be installed manually:
```sh
apt install openscad
pip3 install --user gds3xtrude[standalone]
```
### As standalone tool
When used as a standalone tool `gds3xtrude` additionally depends on the klayout Python package.
```sh
pip3 install --user gds3xtrude
pip3 install --user klayout
```
### Install from Git (instead of installing using pip)
```sh
git clone [this repo]
cd gds3xtrude
pip install --user .
```
## Install (Windows)
Windows is currently not supported but very likely you can get gds3xtrude running there with some tweaks.
Here are some ideas how to install it:
* Install Python and pip
* Get OpenSCAD: http://www.openscad.org/downloads.html
* Rest should be similar to the Linux install instructions.
## Usage
### As KLayout module
* Open a layout.
* Zoom in to the region you want to pass to gds3xtrude.
* Select `Tools -> gds3xtrude -> run script`
* Select the layerstack file for your technology. (Example for FreePDK45 can be found in `examples/freepdk45.layerstack`)
### As standalone tool
Example usage:
```sh
# Get layerstack file for FreePDK45.
wget https://codeberg.org/tok/gds3xtrude/raw/branch/master/examples/freepdk45.layerstack
# Get a GDS file.
wget https://codeberg.org/tok/gds3xtrude/raw/branch/master/examples/NAND2X1.gds
# Run gds3xtrude
gds3xtrude --tech freepdk45.layerstack --input NAND2X1.gds --view
```
If you get an error like `gds3xtrude: command not found` the program is probably not in your `PATH` environment variable.
Try to add the pip binary directory to the PATH variable first:
```sh
PATH=$PATH:$HOME/.local/bin
# And now again: gds3xtrude ...
```
### Layer stack definition
To convert a 2D layout into a 3D model some information about the physical layer stack is necessary.
This information must be passed to gds3xtrude as a file. An example of a simple layer stack description
for the FreePDK45 can be found in `examples/freepdk45.layerstack`. Use this file as a starting point and adapt it to your needs.
Essentially a layerstack file is just a python script that defines some data structures.
Example:
```python
from gds3xtrude.include import layer, Material
# Define layers
poly = layer(15)
contact = layer(16)
metal1 = layer(21)
# Define materials and colors
m_poly = Material('poly', color=(0.8, 0.2, 0.2))
m_metal1 = Material('metal1', color=(0.8, 0.2, 0.2))
# Assign materials
poly.material = m_poly
metal1.material = m_metal1
# Define additional layers from boolean operation
contact_to_silicon = contact - poly
# Define layer stack structure as a list of `(layer thickness, [masks, ...])`.
# and/or `([mask, ...], z_start, z_end)`.
# The 3D model is created layer by layer from bottom to top.
layerstack = [
(10, contact_to_silicon), # Start at 0 and create a slice of thickness 10.
(20, [contact, poly]), # Put a slice of thickness 20 on top of the previous slice.
(50, contact), # Put a slice of thickness 5 on top of the previous slice.
(50, metal1),
# You can also use absolute z-coordinates by using the following syntax:
(metal1, 200, 220), # Create a slice from z=200 to z=220 based on the metal1 mask.
]
```
The crossection of the layer stack described in the example above is shown here. Note that the contact from metal1 down to silicon (which is not shown nor included in the example) consists of three parts. This is only due to the layer by layer creation of the 3D model but it is important to understand for writing the layerstack definition. For instance on the lowest layer there is only a piece of contact down to silicon. Contacts wich have polysilicon below do not reach this lowest layer. This is modelled as the boolean difference `contact_to_silicon = contact - poly`.
Masks can be merged by putting them into a list as used for the second layer (`[contact, poly]`).
![layer stack illustration](./doc/layerstack_doc.png "layer stack")
## Blender
3D models can also be generated in blender. Use the command line tool for this:
```sh
gds3xtrude --tech freepdk45.layerstack --input NAND2X1.gds --cad blender
```
Note that the current implementation over the Blender scripting API is very slow and therefore only small things such as standard cells can be visualized.
Also make sure to use Blender 2.82 or higher.
## FreeCAD
The generated OpenSCAD models (.scad) can be imported into FreeCAD.
### Color Issue
When applying a boolean union FreeCAD strips away colors. Therefore an exported .obj model will by totally gray. There is a workaround:
* Open the OpenSCAD model in FreeCAD
* Open the `Model` tab in `Combo View`
* Expand the list of the imported model which is likely to be named `Unnamed`
* Find a child node labelled `union`, select and delete it
* Select the full model to be exported (Ctrl-A)
* Now you can export to .obj without loosing color information
Additionally to the .obj file FreeCAD will also create a .mtl file containing material/color information. Blender will automatically read it when importing the .obj file.
Raw data
{
"_id": null,
"home_page": "https://codeberg.org/tok/gds3xtrude",
"name": "gds3xtrude",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "gds openscad 3d viewer layout klayout",
"author": "T. Kramer",
"author_email": "code@tkramer.ch",
"download_url": "https://files.pythonhosted.org/packages/e9/11/683cee1ad6e7927005400477b8c5ceeee3dab004f51349467cb3f9280ad0/gds3xtrude-0.0.13.tar.gz",
"platform": null,
"description": "# gds3xtrude\nA simple layout to 3D converter.\n\ngds3xtrude takes the layers of your layout and converts them into 3D volumes by extrusion.\n\n`gds3xtrude` is intended to be used in two different ways:\n* as KLayout extension: Show 3D model of the active view.\n* as standalone tool: Convert GDS to OpenSCAD/Blender from the command line.\n\n![Screenshot](./examples/freepdk45_screenshot.png \"Screenshot\")\n\n## Dependencies\n* OpenSCAD: 3D modelling tool. Can be installed using the package manager of most linux distributions.\n* solidpython: Python library for creating OpenSCAD models.\n* klayout: Python module of KLayout used for GDS input/output and polygon operations.\n\n## Install (Linux)\n\n### As KLayout package\nUse the KLayout package manager to install `gds3xtrude`.\nDependencies (gds3xtrude python package, OpenSCAD) must be installed manually:\n\n```sh\napt install openscad\npip3 install --user gds3xtrude[standalone]\n```\n\n### As standalone tool\nWhen used as a standalone tool `gds3xtrude` additionally depends on the klayout Python package.\n\n```sh\npip3 install --user gds3xtrude\npip3 install --user klayout\n```\n\n### Install from Git (instead of installing using pip)\n```sh\ngit clone [this repo]\ncd gds3xtrude\npip install --user .\n```\n\n## Install (Windows)\nWindows is currently not supported but very likely you can get gds3xtrude running there with some tweaks.\nHere are some ideas how to install it:\n* Install Python and pip\n* Get OpenSCAD: http://www.openscad.org/downloads.html\n* Rest should be similar to the Linux install instructions.\n\n## Usage\n\n### As KLayout module\n\n* Open a layout.\n* Zoom in to the region you want to pass to gds3xtrude.\n* Select `Tools -> gds3xtrude -> run script`\n* Select the layerstack file for your technology. (Example for FreePDK45 can be found in `examples/freepdk45.layerstack`)\n\n\n### As standalone tool\nExample usage:\n```sh\n# Get layerstack file for FreePDK45.\nwget https://codeberg.org/tok/gds3xtrude/raw/branch/master/examples/freepdk45.layerstack\n\n# Get a GDS file.\nwget https://codeberg.org/tok/gds3xtrude/raw/branch/master/examples/NAND2X1.gds\n\n# Run gds3xtrude\ngds3xtrude --tech freepdk45.layerstack --input NAND2X1.gds --view\n```\n\nIf you get an error like `gds3xtrude: command not found` the program is probably not in your `PATH` environment variable.\nTry to add the pip binary directory to the PATH variable first:\n```sh\nPATH=$PATH:$HOME/.local/bin\n# And now again: gds3xtrude ...\n```\n\n### Layer stack definition\nTo convert a 2D layout into a 3D model some information about the physical layer stack is necessary.\nThis information must be passed to gds3xtrude as a file. An example of a simple layer stack description\nfor the FreePDK45 can be found in `examples/freepdk45.layerstack`. Use this file as a starting point and adapt it to your needs.\n\nEssentially a layerstack file is just a python script that defines some data structures.\n\nExample:\n```python\nfrom gds3xtrude.include import layer, Material\n\n# Define layers\npoly = layer(15)\ncontact = layer(16)\nmetal1 = layer(21)\n\n# Define materials and colors\nm_poly = Material('poly', color=(0.8, 0.2, 0.2))\nm_metal1 = Material('metal1', color=(0.8, 0.2, 0.2))\n\n# Assign materials\npoly.material = m_poly\nmetal1.material = m_metal1\n\n# Define additional layers from boolean operation\ncontact_to_silicon = contact - poly\n\n# Define layer stack structure as a list of `(layer thickness, [masks, ...])`.\n# and/or `([mask, ...], z_start, z_end)`.\n# The 3D model is created layer by layer from bottom to top.\nlayerstack = [\n (10, contact_to_silicon), # Start at 0 and create a slice of thickness 10.\n (20, [contact, poly]), # Put a slice of thickness 20 on top of the previous slice.\n (50, contact), # Put a slice of thickness 5 on top of the previous slice.\n (50, metal1),\n\n # You can also use absolute z-coordinates by using the following syntax:\n (metal1, 200, 220), # Create a slice from z=200 to z=220 based on the metal1 mask.\n]\n```\n\nThe crossection of the layer stack described in the example above is shown here. Note that the contact from metal1 down to silicon (which is not shown nor included in the example) consists of three parts. This is only due to the layer by layer creation of the 3D model but it is important to understand for writing the layerstack definition. For instance on the lowest layer there is only a piece of contact down to silicon. Contacts wich have polysilicon below do not reach this lowest layer. This is modelled as the boolean difference `contact_to_silicon = contact - poly`.\nMasks can be merged by putting them into a list as used for the second layer (`[contact, poly]`).\n\n![layer stack illustration](./doc/layerstack_doc.png \"layer stack\")\n\n## Blender\n3D models can also be generated in blender. Use the command line tool for this:\n```sh\ngds3xtrude --tech freepdk45.layerstack --input NAND2X1.gds --cad blender\n```\nNote that the current implementation over the Blender scripting API is very slow and therefore only small things such as standard cells can be visualized.\nAlso make sure to use Blender 2.82 or higher.\n\n## FreeCAD\nThe generated OpenSCAD models (.scad) can be imported into FreeCAD.\n\n### Color Issue\nWhen applying a boolean union FreeCAD strips away colors. Therefore an exported .obj model will by totally gray. There is a workaround:\n* Open the OpenSCAD model in FreeCAD\n* Open the `Model` tab in `Combo View`\n* Expand the list of the imported model which is likely to be named `Unnamed`\n* Find a child node labelled `union`, select and delete it\n* Select the full model to be exported (Ctrl-A)\n* Now you can export to .obj without loosing color information\n\nAdditionally to the .obj file FreeCAD will also create a .mtl file containing material/color information. Blender will automatically read it when importing the .obj file.",
"bugtrack_url": null,
"license": "AGPL",
"summary": "3D GDS viewer based on OpenSCAD",
"version": "0.0.13",
"project_urls": {
"Homepage": "https://codeberg.org/tok/gds3xtrude"
},
"split_keywords": [
"gds",
"openscad",
"3d",
"viewer",
"layout",
"klayout"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e911683cee1ad6e7927005400477b8c5ceeee3dab004f51349467cb3f9280ad0",
"md5": "8755ad97da2a6d080aff10c35380c270",
"sha256": "6c0ada06e20f65a40006dde720dafcaa433f51397f9caf0732d7674b507a1919"
},
"downloads": -1,
"filename": "gds3xtrude-0.0.13.tar.gz",
"has_sig": false,
"md5_digest": "8755ad97da2a6d080aff10c35380c270",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 29773,
"upload_time": "2023-05-17T21:07:02",
"upload_time_iso_8601": "2023-05-17T21:07:02.462691Z",
"url": "https://files.pythonhosted.org/packages/e9/11/683cee1ad6e7927005400477b8c5ceeee3dab004f51349467cb3f9280ad0/gds3xtrude-0.0.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-17 21:07:02",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": true,
"codeberg_user": "tok",
"codeberg_project": "gds3xtrude",
"lcname": "gds3xtrude"
}