[Bf-blender-npr] Getting Line Style Curves?

Tamito KAJIYAMA rd6t-kjym at asahi-net.or.jp
Mon Aug 11 17:00:15 CEST 2014


Hi Margret,

Basically, you need to code your own curve mapping (or whatever
interpolation methods) by yourself in Freestyle for Blender. There is
no direct support for curve mapping in the Freestyle Python API.

It is possible in Freestyle to make use of existing CurveMap objects
defined somewhere in Blender data blocks. Taking your example of the
Along Stroke thickness modifier, curve mapping can be done using the
evaluate() method of a CurveMap object as follows:

   >>> bpy.data.linestyles["LineStyle"].thickness_modifiers["Along 
Stroke"].curve.curves[0].evaluate(0.0)

See the reference of the CurveMap object below for more detail:

http://www.blender.org/documentation/blender_python_api_2_71_release/bpy.types.CurveMap.html

It is not possible to create a new CurveMap object from within Python.
For instance you might want to have a UI panel for your own line
stylization module where a curve mapping window (as in the Along Stroke
thickness modifier) is used to stylize your strokes based on an
interactively defined curve mapping. That is actually not possible. In
Blender most data elements must be part of predefined data structures
(subclasses of ID or bpy_struct). The only exceptions are ID custom
properties whose values are limited to numbers and strings. At the
moment Blender does not allow curve maps to be values of ID custom
properties.

So, there is no easy way to have a curve map window for your style modules.

 From a programming perspective, interpolation is not a big deal if you
know how to do it. The best practice is then to hard-code your mapping
function in your style modules (as in pyNonLinearVaryingThicknessShader
you pointed out). I have done it in different occasions as shown below,
although there was no fancy UI window for the curves.

http://blenderyard.wordpress.com/2011/09/07/mesh-deform-with-non-uniform-perspective-projection/
See the sigmoid() function that defines a non-linear curve mapping.

http://blenderyard.wordpress.com/2014/02/04/anisotropic-line-thickness-in-freestyle/
In this case a linear interpolation is hard-code together with a set of
different mapping coefficients.

-- 
KAJIYAMA, Tamito <rd6t-kjym at asahi-net.or.jp>


On 11/08/2014 19:39, Margret Storm wrote:
> I really appreciate the ability to fine-tune line variation along the
> stroke with curves in parameter editing. However, there doesn't seem to
> be a way to import this into scripting -- calling that parameter
> (bpy.data.linestyles[LINESTYLENAME].thickness_modifiers["Along
> Stroke"].mapping) just returns "CURVE."
> Furthermore, it doesn't look like there's an existing stroke shader that
> can handle that kind of complexity. The closest I can see is
> pyNonLinearVaryingThicknessShader, and that only takes three parameters.
> Is this something I'll have to code on my own, or am I missing something?


More information about the Bf-blender-npr mailing list