Coder Social home page Coder Social logo

freestyle-svg-exporter's Introduction

Freestyle SVG Exporter

A Blender addon for exporting stylized lines created by the Freestyle render engine to an SVG format. This is the development version: More features, more bugs!

Model by Blendergoodies

To use (for now):

  • Overwrite the current addon file with the one in this repository.
  • Enable the addon via User Preferences > Addons > SVG

The GUI for the exporter should now be visible in the render tab of the properties window. The exported .svg file is written to the default output path (Properties > Render > Output). If you experience any problems with the exporter please let me know.

Options

  • Mode
    Option between Frame and Animation. Frame will render a single frame, Animation will bundle all rendered frames into a single .svg file.

  • Split at Invisible
    By default the exporter won't take invisible vertices into account and export them like they are visible. Some stroke modifiers, like Blueprint, mark vertices as invisible to achieve a certain effect. Enabling this option will make the paths split when encountering an invisible vertex, which leads to a better result.

  • Fill Contours
    The contour of objects is filled with their material color. Note that this features is somewhat unstable - especially with animations.

  • Stroke Cap Style
    Defines the style the stroke caps will have in the SVG output.

Exportable Properties

Because the representation of Freestyle strokes and SVG path objects is fundamentally different, a one on one translation between Freestyle and SVG is not possible. The main shortcoming of SVG compared to Freestyle is that Freestyle defines style per-point, where SVG defines it per-path. This means that Freestyle can produce much more complex results that are impossible to achieve in SVG.

The properties that can be exported are:

  • Base color
  • Base alpha
  • Base thickness
  • Dashes

Animations

The exporter supports the creation of SVG animations. When the Mode is set to Animation, all frames from a render - one when rendering a frame (f12) or all when rendering an animation (shift f12) - into a single file. Most modern browsers support the rendering of SVG animations.

Exporting Fills

Fills are colored areas extracted from a Freestyle render result. Specifically, they are defined by a combination of the Contour and External Contour edge type, combined with some predicates. The fill result can be unexpected, when the SVG renderer cannot correctly draw the path that the exporter has generated. This problem is extra apparent in animations.

Model by Julien Deswaef

Fills support holes and layering. When using layers, the exporter tries to render objects with the same material as the same patch. The exporting of fills and especially the order in which they are layered is by no means perfect. In most cases, these problems can be easily solved in Inkscape or a text editor.

freestyle-svg-exporter's People

Contributors

folkertdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

freestyle-svg-exporter's Issues

Is exporting open paths possible?

Hi, thank you for creating this addon! :)

I'm currently loading an SVG file into Blender, manipulating it, and exporting it back to SVG.

It works great with closed paths, but open paths are not rendered, so they are lost.
A work around is to add a tiny extrude value to the path (0.0001 works).
But then two identical paths are exported overlapping each other.

Is there any way to enable exporting open paths from Blender?
Or to remove duplicate lines?

Fill contours is generated for every lineset

Hello @folkertdev

It seems that there is a fill generated for every Lineset defined in Freestyle. And I'm not really sure this is intended behavior.

In this particular case where I'm trying to have external contour lines that are different from the inside lines, if I have the "Fill Contours" option enabled, it renders fills for both lineset and so it "hides" the fill of one lineset hides the lines from the other lineset.

Here are is a practical example.
uhbench-debug-fillcontour

(Sorry, Github does not want me to upload SVG. So this is SVG rendered in PNG from Inkscape ;) )
I can send you the SVG files if you want them.

As I see it, for each lineset, the exporter creates a incorporating a for fills and a for strokes.

Maybe, if that's possible, it would be nice to (de-)activate the fill contours per lineset.
Or just generate it once in it's own tag, that is always beneath all the other strokes.

Edit: Maybe a "quick hack" would be to compute the fills only on the first lineset and ignore for the following ones.

What do you think?

Freestyle feature request

Hi.
I'm almost sure this is not the best place to ask. But I'd like to contact a freestyle dev. about a request....
I'd love to have line with correspond with local grey/light values of a model. The effect would be thick lines on the shadow side and thin lines on the light side of a model. And over all thicker lines on a model with a dark material and thinner lines on a model with a light material.
This would result in line drawings like I learned to make with Rotring pens.

Where does it export to again? Not able to find an exported svg.

Made sure I have the latest version from this repository, made sure I have the default output path set in "user preferences > file > render output". Made sure the plugin is enabled and checked in the render tab.
Have restarted blender to make sure all settings apply.
Still, when rendering, only getting the png's had set to render but no svg anywhere I can find it.

Using blender on Windows 10.

How to export?

Hi,
I really appreciate your work about this addon but (sorry for the dumb question) I don't find how to export.
I installed the plugin and it appears correctly. I checked it and made a rendering with freestyle.
After that I don't know how to get a svg file (I tried to save the result as image but there is no svg option among available formats).
Thanks,
Marco

fill contour doesn't work and throws errors

Hello @folkertdev

Just tried the latest version and it doesn't work with "contour fill" option enabled. Throws errors:

found bundled python: ~/blender-2.74-linux-glibc211-i686/2.74/python
SVG Export: writing to /tmp/0001.svg
Traceback (most recent call last):
  File "/LineSet", line 1, in <module>
  File "~/blender-2.74-linux-glibc211-i686/2.74/scripts/freestyle/modules/parameter_editor.py", line 1221, in process
    fn(scene, layer, lineset)
  File "~/blender-2.74-linux-glibc211-i686/2.74/scripts/addons/render_freestyle_svg.py", line 591, in lineset_post
    NotBP1D(pyZDiscontinuityBP1D())
  File "~/blender-2.74-linux-glibc211-i686/2.74/scripts/freestyle/modules/freestyle/predicates.py", line 567, in __init__
    if len(self.predicates) < 2:
AttributeError: 'AndBP1D' object has no attribute 'predicates'

location: <unknown location>:-1

location: <unknown location>:-1

Error executing Python script from PythonInterpreter::interpretText
Name: LineSet
Errors: 
Error: Traceback (most recent call last):
  File "/LineSet", line 1, in <module>
  File "~/blender-2.74-linux-glibc211-i686/2.74/scripts/freestyle/modules/parameter_editor.py", line 1221, in process
    fn(scene, layer, lineset)
  File "~/blender-2.74-linux-glibc211-i686/2.74/scripts/addons/render_freestyle_svg.py", line 591, in lineset_post
    NotBP1D(pyZDiscontinuityBP1D())
  File "~/blender-2.74-linux-glibc211-i686/2.74/scripts/freestyle/modules/freestyle/predicates.py", line 567, in __init__
    if len(self.predicates) < 2:
AttributeError: 'AndBP1D' object has no attribute 'predicates'

location: <unknown location>:-1


Error: interpretation failed

SVG file format not visible

Hello,
After installing the addon, I shoud see the SVG file format in "Properties/Render/Output" under the dropdown menu, but any SVG format is available. see the screen capture attached
Capture d’écran 2020-12-18 à 15 03 54

Thanks in advance :)

DXF Exporter

I want to generate 2D DXF drawings from my Blender models.

Currently I use a "visible" linetype and a "hidden" linetype, which I save as SVG and then use Inkscape to convert to DXF. Unfortunately both linetypes end up on the same layer "strokes" and I need them on separate layers to edit them.

Also, would it be possible to convert directly to DXF? It handles circles and arcs so much better than SVG.

I know a bit of python (although I'm not sure if I'm up to this as I doubt it would be trivial) and am familiar with the DXF file format. While files would I need to edit?

File naming for a still or frame

I've noticed that when you render a single frame, it adds a number to the filename.
Although this might be interesting if you have an animation (of which you just want to render one frame), it's a bit "annoying" when just rendering a single illustration (not part of an animation).
Don't know if that can be an easy fix.

FreeStyle SVG fills

Hello everyone. As requested, I'm posted a less-cluttered issue for this.
Basically, what I'd like to do is export fills correctly from FreeStyle SVG exporter.
I done a simple scene with Blender 2.49c and VRM (Vector Rendering Method), here it is:

https://drive.google.com/open?id=1r5LY-3KlHjQ42ZPsYt0SHTYRnWdTDF3A

Here is the VRM extension for Blender 2.4x: https://vrm.ao2.it/section/en/files/download.html

Note I guess you need the old Blender version to open the .blend

Edit: Check out the website for examples and more: https://vrm.ao2.it/

Blender 2.8 compatibility

With the release of blender 2.8 this plugin seems to break. The script itself should be ported to work with the new blender release.

I started a fork over at https://github.com/JanWerder/freestyle-svg-exporter

The current problem seems to be that the RenderSettings object no longer offers the layers attribute
freestyle = scene.render.layers.active.freestyle_settings AttributeError: 'RenderSettings' object has no attribute 'layers'
(https://github.com/folkertdev/freestyle-svg-exporter/blob/master/render_freestyle_svg.py#L243)

FreeStyle SVG Exporter - colors

Dear developer, I'd like if the SVG exporter could take into account vertex coloring from geometry (instead of material's color) and turns it into an SVG gradient.
I don't know how complex or simple this could be, but please share your toughts.

Error on loading addon

Hello @folkertdev

I've just downloaded the latest version of the script and I run into an error.
The addon does not want to load. Here is the error:

Traceback (most recent call last):
  File "/usr/share/blender/2.74/scripts/modules/addon_utils.py", line 306, in enable
    mod = __import__(module_name)
  File "/usr/share/blender/2.74/scripts/addons/render_freestyle_svg.py", line 52, in <module>
    from freestyle.utils import (
ImportError: cannot import name 'BoundingBox'

Maybe it was a bad call for me to pull it from the repo again.

Here is my version of Blender:

Blender 2.74 (sub 0)
    build date: 2015-05-08
    build time: 19:30:03
    build commit date: 2015-03-31
    build commit time: 13:39
    build hash: 000dfc0
    build platform: Linux
    build type: Release
    build c flags:  -Wall -Wcast-align -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=return-type -Wstrict-prototypes -Wmissing-prototypes -Wno-char-subscripts -Wno-unknown-pragmas -Wpointer-arith -Wunused-parameter -Wwrite-strings -Wlogical-op -Wundef -Winit-self -Wnonnull -Wmissing-include-dirs -Wno-div-by-zero -Wtype-limits -Wuninitialized -Wredundant-decls -Wno-error=unused-but-set-variable -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4  -fopenmp  -msse2  -msse -pipe -fPIC -funsigned-char -fno-strict-aliasing
    build c++ flags:  -Wredundant-decls -Wall -Wno-invalid-offsetof -Wno-sign-compare -Wlogical-op -Winit-self -Wmissing-include-dirs -Wno-div-by-zero -Wtype-limits -Wuninitialized -Wundef -Wmissing-declarations -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4  -fopenmp  -msse2  -msse -pipe -fPIC -funsigned-char -fno-strict-aliasing
    build link flags:  -Wl,--version-script=/build/blender/src/blender-2.74/source/creator/blender.map
    build system: CMake

Edit: Reversed back to the commit 5f31911 and still works fine. Have not tried the inbetween versions.

Can't activate plugin in Blender 3.6

When I try to activate the addon in settings I get:

Traceback (most recent call last):
  File "/home/neopostmodern/Applications/blender-3.6.2-linux-x64/3.6/scripts/modules/addon_utils.py", line 333, in enable
    mod = __import__(module_name)
  File "/home/neopostmodern/Applications/blender-3.6.2-linux-x64/3.6/scripts/addons/render_freestyle_svg.py", line 17, in <module>
    import parameter_editor
  File "/home/neopostmodern/Applications/blender-3.6.2-linux-x64/3.6/scripts/freestyle/modules/parameter_editor.py", line 55, in <module>
    from freestyle.shaders import (
ImportError: cannot import name 'StrokeShader' from 'freestyle.shaders' (/home/neopostmodern/.local/lib/python3.10/site-packages/freestyle/shaders.py)

How to set stroke colors?

Hello, Thanks for the wonderful plugin. It is just awesome and very useful for technical documentation. Would it be possible to add the possibility to let the strokes inherit the vertex color? Or set some color for part of the strokes. At the moment i can only change the color of all the strokes together. Meaning i have to retouch every graphic with Inkscape to get the desired result. According to the plugin menues it appears that this is already possible. What did i miss, or is it a bug?

EDIT: Nevermind, i found it. Plugins stroke color has to be set via
image

Select object or part of object and assign the material like usual. Line color is in the material settings scroll down a bit.

Man, i am happy now. Missed that for years. Great, really great plugin. You are the man.
image

4col_strokes.blend.zip

You may close the issue. Solved.

Naming feature request

I need the SVG exporter can assign names for pathes and collections (or only for collections will be good too).
My .blender files has a deep nested collections, I give a name to collections, and when I export it I need SVG to have <g> tags with the attribute data-name with the name I gave.
It is like in Adobe Illistrator, I assign the name [car, transport] to a layer or to an object, and <g> or <path> tag has a data-name attribute data-name='[car, transport]'. It works with objects names the same way.

Why I need this feature? I want't to make some kids educational website with illustrated dictionaries. E.g. render some bitmap , and above them put svg transparent pictures with <g> tags with data-name attributes, and these attributes are connected to my JS scripts to fetch information.

I need it extremely soon. How can we come to an agreement?

Output SVG's have many open paths

Hello,

I try to use Freestyle SVG Exporter to create SVGs for my models and then paint them in another program. Unfortunately, every single output file exported via Freestyle is a mess of open paths, so it's almost impossible to paint these SVG without leaving some tiny white stripes, curves, etc.

Should I change exporting settings or something?

Examples (blend + output SVG): https://ufile.io/snfeq

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.