Skip to content

SVG export #787

Description

@kpreid

I would like to be able to put some depictions of blocks in the documentation. The most efficient (in complexity of the distributed packages) way to do this would be to add functionality to export scenes to SVG, which can be embedded as text. This export would also generally be a cool feature.

We already have some special-purpose SVG writing, but the new part here would be rendering 3D shapes. Specific tasks:

  • Generate polygons rather than triangles for block faces. (We can’t use reliably use triangles, because SVG rendering does not guarantee that abutting shapes have error-free contact like GPUs do.) These paths could be generated in one of two ways:
    1. Use the just-added Analysis::compute_edges(), and walk those edges to compile them into loops which make a polygon and its holes.
    2. Use the existing triangle mesh generation, then merge adjacent triangles iteratively. (This has the advantage that it can easily avoid generating polygons with holes in favor of leaving one seam, but it turns out that SVG does support paths with holes, so this is not needed.)
  • Make the polygons be depth-sorted. This might be most effectively done at the voxel level, because in the general case there exist overlapping shapes that can't be depth sorted without splitting them into parts (three perpendicular sticks), and it would be easier to decide that the polygons have to be separate before actually generating them.
  • (Not strictly needed) Generate wireframe lines for outlining shapes, preferably with hidden-line removal so the result is efficient. (Even without optimal hidden line removal we should still at least "cull back faces edges".)
    • Can we do hidden line removal by testing against voxels rather than polygons? This might have fewer numerical edge cases, but also require more tests.
  • (Not strictly needed) Generate 2D textures if needed, like the glTF export does but as separate images instead of an atlas. Depending on the texture complexity it might be better to store an image file or to generate many individual polygons.
  • In all-is-cubes-port, implement the concept of exports that have graphics options, which has not previously been a thing. (This may also help with unification of all-is-cubes-desktop’s “record” feature.)
  • Stitch all the above together into a SVG export feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: exportExporting and importing datakind: featureAdding user-facing/developer-facing functionality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions