Skip to content

Commit

Permalink
Work on documentation and the Inkscape extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
cwant committed Jul 3, 2023
1 parent 150ec81 commit b35bcee
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Tessellate your favorite 3D surfaces (technically, 2D manifolds) with triangles,

## News

**Now works with Blender 2.8 (and still works with earlier versions). Todo: check if it works with Blender 3.x.**
**A nascent Inkscape extension to create tiling patterns: <https://github.com/cwant/inkscape-tiling-extension>**

**Check out my presentation on the creation of Tessagon as an open source Python project here: [https://cwant.github.io/python-os-presentation](https://cwant.github.io/python-os-presentation/#/)**
**You can find a Blender (3.6) pull request to add support for Tessagon in the "XYZ function" addon here:
<https://projects.blender.org/blender/blender-addons/pulls/104726>**

**A demo of using Tessagon with Inkscape can be found [here](https://gist.github.com/cwant/697f0c6ce07d9e14e710f5b80ca5eece).**
**Check out my presentation on the creation of Tessagon as an open source Python project here: <https://cwant.github.io/python-os-presentation>**

**~You can find a Blender pull request to add support for Tessagon in the "XYZ function" addon here:
[https://developer.blender.org/D3519](https://developer.blender.org/D3519)~** (This didn't really go anywhere, and was for Blender 2.x)
**A demo of using Tessagon with Inkscape Simple Scripting can be found [here](https://gist.github.com/cwant/697f0c6ce07d9e14e710f5b80ca5eece).**

## TL;DR

Expand All @@ -36,9 +36,10 @@ Three things are needed to use tessagon to tessellate the surface of a 2D-manifo

* Tessagon provides a bunch of classes (subclasses of a class called `Tessagon`) that will tessellate a portion of UV-space with mesh patterns. Parameters provide the details of the bounds in UV-space, the resolution of the tiling, whether the tiling is cyclic, whether a cyclic domain "twists" (think a topological identification space, like a Mobius strip or a Klein bottle), whether it is rotated, etc. These classes are in the `tessagon.types` module.
* The programmer must provide a formula that describes the shape of surface of the 3-dimensional object to create. This function maps two-dimensional space (also known as UV-space) into 3-dimensional space. The tiling happens in the input two dimensional space, and the function maps the tiling onto the surface of the 3-dimensional shape. There are some demo functions in `tessagon.misc.shapes`, such as torii (a.k.a. donuts), spheres, cylinders, etc.
* Finally, an adaptor is chosen to create a mesh in a supported 3D software package. Currently only Blender and VTK are supported, but there is also a generic `ListAdaptor` that does not depend on any external package, and can aid in the creation of importers (and is useful for testing/debugging):
* Finally, an adaptor is chosen to create a mesh in a supported 3D software package. Currently Blender and VTK are supported applications. There is an adaptor that writes an SVG group to a string, with various options (root SVG node, style options). There is also a generic `ListAdaptor` that does not depend on any external package, and can aid in the creation of importers (and is useful for testing/debugging):
* adaptor `BlenderAdaptor` from the module `tessagon.adaptors.blender_adaptor`. The output from the adaptor's `get_mesh` method is of type `BMesh`.
* adaptor `VtkAdaptor` from the module `tessagon.adaptors.vtk_adaptor`. The output from the adaptor's `get_mesh` method is of type `VtkPolydata`.
* adaptor `SvgAdaptor` from the module `tessagon.adaptors.svg_adaptor`. The output from the adaptor's `get_mesh` method is a string (by default, an SVG group of polygons).
* adaptor `ListAdaptor` from the module `tessagon.adaptors.list_adaptor`. The output from the adaptor's `get_mesh` method is a dict with keys `vert_list`, `face_list` and `color_list`, which point to lists of vertices, faces (as indices into the vertex list), and color indices for each face.

(Note that the `get_mesh` methods mentioned above are usually called indirectly through the `Tessagon` method `create_mesh`.)
Expand Down
40 changes: 40 additions & 0 deletions integrations/inkscape/generate_tiling_inx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
"""
Read in tiling.inx.in input file and inject Tessagon tiling types
(to stdout).
"""
import os
import sys

THIS_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.append(THIS_DIR + '/../..')

from tessagon.core.tessagon_discovery import TessagonDiscovery # noqa E402


class InxGenerate:
def run(self):
with open(THIS_DIR + '/tiling.inx.in') as f:
for line in f:
sys.stdout.write(line)
if "Autogenerated tiling types start" in line:
self.dump_tilings()

def dump_tilings(self):
# Create tiling menu with items in nice order
find_tilings = TessagonDiscovery()
tilings = find_tilings.with_classification('regular').to_list() + \
find_tilings.with_classification('archimedean').to_list() + \
find_tilings.with_classification('laves').to_list() + \
find_tilings.with_classification('non_edge').to_list() + \
find_tilings.with_classification('non_convex').to_list()

template = ' <option value="{}">{}</option>\n'
for tiling_class in tilings:
metadata = tiling_class.metadata
sys.stdout.write(template.format(tiling_class.__name__,
metadata.name))


if __name__ == "__main__":
InxGenerate().run()
82 changes: 82 additions & 0 deletions integrations/inkscape/tiling.inx.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Tiling</name>
<id>math.tiling</id>
<param name="tab" type="notebook">

<page name="basic" gui-text="Main options">
<param name="class_name" type="optiongroup" appearance="combo"
gui-text="Tiling type:">
<!-- Autogenerated tiling types start -->
<!-- Autogenerated tiling types end -->
</param>
<param name="x_num" type="int" min="1" max="10000"
gui-text="Number of tiles in the X direction:">4</param>
<param name="y_num" type="int" min="1" max="10000"
gui-text="Number of tiles in the Y direction:">4</param>
<param name="x_min" type="float" min="0.0" max="10000"
gui-text="Lower X bounding box:">50.0</param>
<param name="x_max" type="float" min="0.0" max="10000"
gui-text="Upper X bounding box:">150.0</param>
<param name="y_min" type="float" min="0.0" max="10000"
gui-text="Lower Y bounding box:">50.0</param>
<param name="y_max" type="float" min="0.0" max="10000"
gui-text="Upper Y bounding box:">150.0</param>
</page>

<page name="stroke_options" gui-text="Stroke Options">
<param name="stroke_type_unit" type="optiongroup"
appearance="combo"
gui-text="Stroke Type / Unit:">
<option translatable="no" value="px">px</option>
<option translatable="no" value="mm">mm</option>
<option translatable="no" value="cm">cm</option>
<option translatable="no" value="in">in</option>
<option translatable="no" value="none">None</option>
</param>
<param name="stroke_width" type="float" min="0" max="1000"
gui-text="Stroke Width:">1</param>
<param name="stroke_color" type="color" appearance="colorbutton"
gui-text="Stroke Color:">0x000000FF</param>
</page>

<page name="fill_options" gui-text="Fill Options">
<param name="fill_type" type="optiongroup"
appearance="combo"
gui-text="Fill Type:">
<option translatable="no" value="none">None</option>
<option translatable="no" value="color">Single color (Color 1)</option>
<option translatable="no" value="pattern">Color Pattern</option>
</param>

<param name="color_pattern" type="int" min="1" max="10"
gui-text="Which color pattern to use:">1</param>

<param name="color_1" type="color" appearance="colorbutton"
gui-text="Color 1:">0xD7E3F4FF</param>
<param name="color_2" type="color" appearance="colorbutton"
gui-text="Color 2:">0xAFC6E9FF</param>
<param name="color_3" type="color" appearance="colorbutton"
gui-text="Color 3:">0x87AADEFF</param>
<param name="color_4" type="color" appearance="colorbutton"
gui-text="Color 4:">0x5F8DD3FF</param>
<param name="color_5" type="color" appearance="colorbutton"
gui-text="Color 5:">0x3771C8FF</param>
<param name="color_6" type="color" appearance="colorbutton"
gui-text="Color 6:">0x2C5AA0FF</param>
<param name="color_7" type="color" appearance="colorbutton"
gui-text="Color 7:">0x214478FF</param>
<param name="color_8" type="color" appearance="colorbutton"
gui-text="Color 8:">0x162D50FF</param>
</page>
</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="Render"/>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">tiling.py</command>
</script>
</inkscape-extension>

0 comments on commit b35bcee

Please sign in to comment.