2012-12-11 23:00:22 +01:00
|
|
|
/*
|
2010-06-26 00:45:42 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2010 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2012-12-11 23:00:22 +01:00
|
|
|
*/
|
|
|
|
|
2010-06-26 00:45:42 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-10-24 18:10:45 +02:00
|
|
|
#include <string.h>
|
2010-06-26 00:45:42 +02:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
#include "DNA_object_types.h"
|
2010-07-20 19:57:33 +02:00
|
|
|
#include "DNA_material_types.h" /* for ramp blend */
|
2010-09-18 02:31:22 +02:00
|
|
|
#include "DNA_texture_types.h"
|
2019-09-11 20:34:55 +02:00
|
|
|
#include "DNA_defaults.h"
|
2010-07-20 19:57:33 +02:00
|
|
|
|
2013-03-18 01:48:59 +01:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_math.h"
|
2017-01-16 17:33:34 +01:00
|
|
|
#include "BLI_string_utils.h"
|
2013-03-18 01:48:59 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2020-03-09 16:56:12 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
2017-12-07 05:36:26 +01:00
|
|
|
#include "BKE_colorband.h"
|
2014-07-16 08:25:10 +02:00
|
|
|
#include "BKE_context.h"
|
2014-07-16 06:36:39 +02:00
|
|
|
#include "BKE_freestyle.h"
|
2020-03-09 16:56:12 +01:00
|
|
|
#include "BKE_idtype.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2010-06-26 00:45:42 +02:00
|
|
|
#include "BKE_linestyle.h"
|
2020-03-09 16:56:12 +01:00
|
|
|
#include "BKE_main.h"
|
2014-05-03 11:51:53 +02:00
|
|
|
#include "BKE_node.h"
|
2010-07-20 19:57:33 +02:00
|
|
|
#include "BKE_colortools.h"
|
2010-09-18 02:31:22 +02:00
|
|
|
#include "BKE_animsys.h"
|
2010-07-20 19:57:33 +02:00
|
|
|
|
2020-03-09 16:56:12 +01:00
|
|
|
static void linestyle_init_data(ID *id)
|
|
|
|
{
|
|
|
|
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
|
|
|
|
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(linestyle, id));
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(linestyle, DNA_struct_default_get(FreestyleLineStyle), id);
|
|
|
|
|
|
|
|
BKE_linestyle_geometry_modifier_add(linestyle, NULL, LS_MODIFIER_SAMPLING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void linestyle_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
|
|
|
|
{
|
|
|
|
FreestyleLineStyle *linestyle_dst = (FreestyleLineStyle *)id_dst;
|
|
|
|
const FreestyleLineStyle *linestyle_src = (const FreestyleLineStyle *)id_src;
|
|
|
|
|
|
|
|
/* We never handle usercount here for own data. */
|
|
|
|
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
|
|
|
|
/* We always need allocation of our private ID data. */
|
|
|
|
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
|
|
|
|
|
|
|
|
for (int a = 0; a < MAX_MTEX; a++) {
|
|
|
|
if (linestyle_src->mtex[a]) {
|
|
|
|
linestyle_dst->mtex[a] = MEM_mallocN(sizeof(*linestyle_dst->mtex[a]), __func__);
|
|
|
|
*linestyle_dst->mtex[a] = *linestyle_src->mtex[a];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linestyle_src->nodetree) {
|
|
|
|
BKE_id_copy_ex(bmain,
|
|
|
|
(ID *)linestyle_src->nodetree,
|
|
|
|
(ID **)&linestyle_dst->nodetree,
|
|
|
|
flag_private_id_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
LineStyleModifier *linestyle_modifier;
|
|
|
|
BLI_listbase_clear(&linestyle_dst->color_modifiers);
|
|
|
|
for (linestyle_modifier = (LineStyleModifier *)linestyle_src->color_modifiers.first;
|
|
|
|
linestyle_modifier;
|
|
|
|
linestyle_modifier = linestyle_modifier->next) {
|
|
|
|
BKE_linestyle_color_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&linestyle_dst->alpha_modifiers);
|
|
|
|
for (linestyle_modifier = (LineStyleModifier *)linestyle_src->alpha_modifiers.first;
|
|
|
|
linestyle_modifier;
|
|
|
|
linestyle_modifier = linestyle_modifier->next) {
|
|
|
|
BKE_linestyle_alpha_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&linestyle_dst->thickness_modifiers);
|
|
|
|
for (linestyle_modifier = (LineStyleModifier *)linestyle_src->thickness_modifiers.first;
|
|
|
|
linestyle_modifier;
|
|
|
|
linestyle_modifier = linestyle_modifier->next) {
|
|
|
|
BKE_linestyle_thickness_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&linestyle_dst->geometry_modifiers);
|
|
|
|
for (linestyle_modifier = (LineStyleModifier *)linestyle_src->geometry_modifiers.first;
|
|
|
|
linestyle_modifier;
|
|
|
|
linestyle_modifier = linestyle_modifier->next) {
|
|
|
|
BKE_linestyle_geometry_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void linestyle_free_data(ID *id)
|
|
|
|
{
|
|
|
|
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
|
|
|
|
LineStyleModifier *linestyle_modifier;
|
|
|
|
|
|
|
|
for (int material_slot_index = 0; material_slot_index < MAX_MTEX; material_slot_index++) {
|
|
|
|
MEM_SAFE_FREE(linestyle->mtex[material_slot_index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is no lib link block, but linestyle extension */
|
|
|
|
if (linestyle->nodetree) {
|
|
|
|
ntreeFreeNestedTree(linestyle->nodetree);
|
|
|
|
MEM_freeN(linestyle->nodetree);
|
|
|
|
linestyle->nodetree = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((linestyle_modifier = (LineStyleModifier *)linestyle->color_modifiers.first)) {
|
|
|
|
BKE_linestyle_color_modifier_remove(linestyle, linestyle_modifier);
|
|
|
|
}
|
|
|
|
while ((linestyle_modifier = (LineStyleModifier *)linestyle->alpha_modifiers.first)) {
|
|
|
|
BKE_linestyle_alpha_modifier_remove(linestyle, linestyle_modifier);
|
|
|
|
}
|
|
|
|
while ((linestyle_modifier = (LineStyleModifier *)linestyle->thickness_modifiers.first)) {
|
|
|
|
BKE_linestyle_thickness_modifier_remove(linestyle, linestyle_modifier);
|
|
|
|
}
|
|
|
|
while ((linestyle_modifier = (LineStyleModifier *)linestyle->geometry_modifiers.first)) {
|
|
|
|
BKE_linestyle_geometry_modifier_remove(linestyle, linestyle_modifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDTypeInfo IDType_ID_LS = {
|
|
|
|
.id_code = ID_LS,
|
|
|
|
.id_filter = FILTER_ID_LS,
|
|
|
|
.main_listbase_index = INDEX_ID_LS,
|
|
|
|
.struct_size = sizeof(FreestyleLineStyle),
|
|
|
|
.name = "FreestyleLineStyle",
|
|
|
|
.name_plural = "linestyles",
|
|
|
|
.translation_context = BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE,
|
|
|
|
.flags = 0,
|
|
|
|
|
|
|
|
.init_data = linestyle_init_data,
|
|
|
|
.copy_data = linestyle_copy_data,
|
|
|
|
.free_data = linestyle_free_data,
|
|
|
|
.make_local = NULL,
|
|
|
|
};
|
|
|
|
|
2012-12-08 23:24:41 +01:00
|
|
|
static const char *modifier_name[LS_MODIFIER_NUM] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
NULL,
|
|
|
|
"Along Stroke",
|
|
|
|
"Distance from Camera",
|
|
|
|
"Distance from Object",
|
|
|
|
"Material",
|
|
|
|
"Sampling",
|
|
|
|
"Bezier Curve",
|
|
|
|
"Sinus Displacement",
|
|
|
|
"Spatial Noise",
|
|
|
|
"Perlin Noise 1D",
|
|
|
|
"Perlin Noise 2D",
|
|
|
|
"Backbone Stretcher",
|
|
|
|
"Tip Remover",
|
|
|
|
"Calligraphy",
|
|
|
|
"Polygonalization",
|
|
|
|
"Guiding Lines",
|
|
|
|
"Blueprint",
|
|
|
|
"2D Offset",
|
|
|
|
"2D Transform",
|
|
|
|
"Tangent",
|
|
|
|
"Noise",
|
|
|
|
"Crease Angle",
|
|
|
|
"Simplification",
|
|
|
|
"3D Curvature",
|
2012-12-11 23:00:22 +01:00
|
|
|
};
|
2010-06-26 00:45:42 +02:00
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
void BKE_linestyle_init(FreestyleLineStyle *linestyle)
|
2010-06-27 02:03:34 +02:00
|
|
|
{
|
2020-03-09 16:56:12 +01:00
|
|
|
linestyle_init_data(&linestyle->id);
|
2010-06-27 02:03:34 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 04:33:05 +01:00
|
|
|
FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name)
|
2010-06-26 00:45:42 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
FreestyleLineStyle *linestyle;
|
2010-06-26 00:45:42 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
linestyle = (FreestyleLineStyle *)BKE_libblock_alloc(bmain, ID_LS, name, 0);
|
2012-12-11 23:00:22 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_linestyle_init(linestyle);
|
2010-06-26 00:45:42 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return linestyle;
|
2010-06-26 00:45:42 +02:00
|
|
|
}
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineStyle *linestyle)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
FreestyleLineStyle *linestyle_copy;
|
|
|
|
BKE_id_copy(bmain, &linestyle->id, (ID **)&linestyle_copy);
|
|
|
|
return linestyle_copy;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2018-04-24 15:20:17 +02:00
|
|
|
FreestyleLineStyle *BKE_linestyle_active_from_view_layer(ViewLayer *view_layer)
|
2014-07-16 06:36:39 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
FreestyleConfig *config = &view_layer->freestyle_config;
|
|
|
|
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
|
|
|
|
return (lineset) ? lineset->linestyle : NULL;
|
2014-07-16 06:36:39 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
static LineStyleModifier *new_modifier(const char *name, int type, size_t size)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *m;
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
name = modifier_name[type];
|
|
|
|
}
|
|
|
|
m = (LineStyleModifier *)MEM_callocN(size, "line style modifier");
|
|
|
|
m->type = type;
|
|
|
|
BLI_strncpy(m->name, name, sizeof(m->name));
|
|
|
|
m->influence = 1.0f;
|
|
|
|
m->flags = LS_MODIFIER_ENABLED | LS_MODIFIER_EXPANDED;
|
|
|
|
|
|
|
|
return m;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_to_modifier_list(ListBase *lb, LineStyleModifier *m)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_addtail(lb, (void *)m);
|
|
|
|
BLI_uniquename(
|
|
|
|
lb, m, modifier_name[m->type], '.', offsetof(LineStyleModifier, name), sizeof(m->name));
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
static LineStyleModifier *alloc_color_modifier(const char *name, int type)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t size;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
size = sizeof(LineStyleColorModifier_AlongStroke);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
size = sizeof(LineStyleColorModifier_DistanceFromCamera);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
size = sizeof(LineStyleColorModifier_DistanceFromObject);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
size = sizeof(LineStyleColorModifier_Material);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
size = sizeof(LineStyleColorModifier_Tangent);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
size = sizeof(LineStyleColorModifier_Noise);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
size = sizeof(LineStyleColorModifier_CreaseAngle);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
size = sizeof(LineStyleColorModifier_Curvature_3D);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_modifier(name, type, size);
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle,
|
|
|
|
const char *name,
|
|
|
|
int type)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *m;
|
|
|
|
|
|
|
|
m = alloc_color_modifier(name, type);
|
|
|
|
if (UNLIKELY(m == NULL)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
m->blend = MA_RAMP_BLEND;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
((LineStyleColorModifier_AlongStroke *)m)->color_ramp = BKE_colorband_add(true);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp = BKE_colorband_add(true);
|
|
|
|
((LineStyleColorModifier_DistanceFromCamera *)m)->range_min = 0.0f;
|
|
|
|
((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL;
|
|
|
|
((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = BKE_colorband_add(true);
|
|
|
|
((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f;
|
|
|
|
((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
((LineStyleColorModifier_Material *)m)->color_ramp = BKE_colorband_add(true);
|
|
|
|
((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_LINE;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
((LineStyleColorModifier_Tangent *)m)->color_ramp = BKE_colorband_add(true);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
((LineStyleColorModifier_Noise *)m)->color_ramp = BKE_colorband_add(true);
|
|
|
|
((LineStyleColorModifier_Noise *)m)->amplitude = 10.0f;
|
|
|
|
((LineStyleColorModifier_Noise *)m)->period = 10.0f;
|
|
|
|
((LineStyleColorModifier_Noise *)m)->seed = 512;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
((LineStyleColorModifier_CreaseAngle *)m)->color_ramp = BKE_colorband_add(true);
|
|
|
|
((LineStyleColorModifier_CreaseAngle *)m)->min_angle = 0.0f;
|
|
|
|
((LineStyleColorModifier_CreaseAngle *)m)->max_angle = DEG2RADF(180.0f);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
((LineStyleColorModifier_Curvature_3D *)m)->color_ramp = BKE_colorband_add(true);
|
|
|
|
((LineStyleColorModifier_Curvature_3D *)m)->min_curvature = 0.0f;
|
|
|
|
((LineStyleColorModifier_Curvature_3D *)m)->max_curvature = 0.5f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->color_modifiers, m);
|
|
|
|
|
|
|
|
return m;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linestyle,
|
|
|
|
const LineStyleModifier *m,
|
|
|
|
const int flag)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *new_m;
|
|
|
|
|
|
|
|
new_m = alloc_color_modifier(m->name, m->type);
|
|
|
|
if (UNLIKELY(new_m == NULL)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
new_m->influence = m->influence;
|
|
|
|
new_m->flags = m->flags;
|
|
|
|
new_m->blend = m->blend;
|
|
|
|
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
|
|
|
LineStyleColorModifier_AlongStroke *p = (LineStyleColorModifier_AlongStroke *)m;
|
|
|
|
LineStyleColorModifier_AlongStroke *q = (LineStyleColorModifier_AlongStroke *)new_m;
|
|
|
|
q->color_ramp = MEM_dupallocN(p->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
|
|
|
LineStyleColorModifier_DistanceFromCamera *p = (LineStyleColorModifier_DistanceFromCamera *)
|
|
|
|
m;
|
|
|
|
LineStyleColorModifier_DistanceFromCamera *q = (LineStyleColorModifier_DistanceFromCamera *)
|
|
|
|
new_m;
|
|
|
|
q->color_ramp = MEM_dupallocN(p->color_ramp);
|
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
|
|
|
LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)
|
|
|
|
m;
|
|
|
|
LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *)
|
|
|
|
new_m;
|
|
|
|
q->target = p->target;
|
|
|
|
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
|
|
|
|
id_us_plus((ID *)q->target);
|
|
|
|
}
|
|
|
|
q->color_ramp = MEM_dupallocN(p->color_ramp);
|
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_MATERIAL: {
|
|
|
|
LineStyleColorModifier_Material *p = (LineStyleColorModifier_Material *)m;
|
|
|
|
LineStyleColorModifier_Material *q = (LineStyleColorModifier_Material *)new_m;
|
|
|
|
q->color_ramp = MEM_dupallocN(p->color_ramp);
|
|
|
|
q->flags = p->flags;
|
|
|
|
q->mat_attr = p->mat_attr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleColorModifier_Tangent *p = (LineStyleColorModifier_Tangent *)m;
|
|
|
|
LineStyleColorModifier_Tangent *q = (LineStyleColorModifier_Tangent *)new_m;
|
|
|
|
q->color_ramp = MEM_dupallocN(p->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_NOISE: {
|
|
|
|
LineStyleColorModifier_Noise *p = (LineStyleColorModifier_Noise *)m;
|
|
|
|
LineStyleColorModifier_Noise *q = (LineStyleColorModifier_Noise *)new_m;
|
|
|
|
q->color_ramp = MEM_dupallocN(p->color_ramp);
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->period = p->period;
|
|
|
|
q->seed = p->seed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE: {
|
|
|
|
LineStyleColorModifier_CreaseAngle *p = (LineStyleColorModifier_CreaseAngle *)m;
|
|
|
|
LineStyleColorModifier_CreaseAngle *q = (LineStyleColorModifier_CreaseAngle *)new_m;
|
|
|
|
q->color_ramp = MEM_dupallocN(p->color_ramp);
|
|
|
|
q->min_angle = p->min_angle;
|
|
|
|
q->max_angle = p->max_angle;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CURVATURE_3D: {
|
|
|
|
LineStyleColorModifier_Curvature_3D *p = (LineStyleColorModifier_Curvature_3D *)m;
|
|
|
|
LineStyleColorModifier_Curvature_3D *q = (LineStyleColorModifier_Curvature_3D *)new_m;
|
|
|
|
q->color_ramp = MEM_dupallocN(p->color_ramp);
|
|
|
|
q->min_curvature = p->min_curvature;
|
|
|
|
q->max_curvature = p->max_curvature;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->color_modifiers, new_m);
|
|
|
|
|
|
|
|
return new_m;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
|
2014-07-17 02:23:30 +02:00
|
|
|
int BKE_linestyle_color_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-22 01:39:35 +02:00
|
|
|
if (BLI_findindex(&linestyle->color_modifiers, m) == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
MEM_freeN(((LineStyleColorModifier_AlongStroke *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
MEM_freeN(((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
MEM_freeN(((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
MEM_freeN(((LineStyleColorModifier_Material *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
MEM_freeN(((LineStyleColorModifier_Tangent *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
MEM_freeN(((LineStyleColorModifier_Noise *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
MEM_freeN(((LineStyleColorModifier_CreaseAngle *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
MEM_freeN(((LineStyleColorModifier_Curvature_3D *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BLI_freelinkN(&linestyle->color_modifiers, m);
|
|
|
|
return 0;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
static LineStyleModifier *alloc_alpha_modifier(const char *name, int type)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t size;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
size = sizeof(LineStyleAlphaModifier_AlongStroke);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
size = sizeof(LineStyleAlphaModifier_DistanceFromCamera);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
size = sizeof(LineStyleAlphaModifier_DistanceFromObject);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
size = sizeof(LineStyleAlphaModifier_Material);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
size = sizeof(LineStyleAlphaModifier_Tangent);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
size = sizeof(LineStyleAlphaModifier_Noise);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
size = sizeof(LineStyleAlphaModifier_CreaseAngle);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
size = sizeof(LineStyleAlphaModifier_Curvature_3D);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
return new_modifier(name, type, size);
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyle,
|
|
|
|
const char *name,
|
|
|
|
int type)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *m;
|
|
|
|
|
|
|
|
m = alloc_alpha_modifier(name, type);
|
|
|
|
m->blend = LS_VALUE_BLEND;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
|
|
|
LineStyleAlphaModifier_AlongStroke *p = (LineStyleAlphaModifier_AlongStroke *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
|
|
|
LineStyleAlphaModifier_DistanceFromCamera *p = (LineStyleAlphaModifier_DistanceFromCamera *)
|
|
|
|
m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->range_min = 0.0f;
|
|
|
|
p->range_max = 10000.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
|
|
|
LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)
|
|
|
|
m;
|
|
|
|
p->target = NULL;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->range_min = 0.0f;
|
|
|
|
p->range_max = 10000.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_MATERIAL: {
|
|
|
|
LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->mat_attr = LS_MODIFIER_MATERIAL_LINE_A;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleAlphaModifier_Tangent *p = (LineStyleAlphaModifier_Tangent *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_NOISE: {
|
|
|
|
LineStyleAlphaModifier_Noise *p = (LineStyleAlphaModifier_Noise *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
((LineStyleAlphaModifier_Noise *)m)->amplitude = 10.0f;
|
|
|
|
((LineStyleAlphaModifier_Noise *)m)->period = 10.0f;
|
|
|
|
((LineStyleAlphaModifier_Noise *)m)->seed = 512;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE: {
|
|
|
|
LineStyleAlphaModifier_CreaseAngle *p = (LineStyleAlphaModifier_CreaseAngle *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
((LineStyleAlphaModifier_CreaseAngle *)m)->min_angle = 0.0f;
|
|
|
|
((LineStyleAlphaModifier_CreaseAngle *)m)->max_angle = DEG2RADF(180.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CURVATURE_3D: {
|
|
|
|
LineStyleAlphaModifier_Curvature_3D *p = (LineStyleAlphaModifier_Curvature_3D *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
((LineStyleAlphaModifier_Curvature_3D *)m)->min_curvature = 0.0f;
|
|
|
|
((LineStyleAlphaModifier_Curvature_3D *)m)->max_curvature = 0.5f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->alpha_modifiers, m);
|
|
|
|
|
|
|
|
return m;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linestyle,
|
|
|
|
const LineStyleModifier *m,
|
|
|
|
const int UNUSED(flag))
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *new_m;
|
|
|
|
|
|
|
|
new_m = alloc_alpha_modifier(m->name, m->type);
|
|
|
|
new_m->influence = m->influence;
|
|
|
|
new_m->flags = m->flags;
|
|
|
|
new_m->blend = m->blend;
|
|
|
|
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
|
|
|
LineStyleAlphaModifier_AlongStroke *p = (LineStyleAlphaModifier_AlongStroke *)m;
|
|
|
|
LineStyleAlphaModifier_AlongStroke *q = (LineStyleAlphaModifier_AlongStroke *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
|
|
|
LineStyleAlphaModifier_DistanceFromCamera *p = (LineStyleAlphaModifier_DistanceFromCamera *)
|
|
|
|
m;
|
|
|
|
LineStyleAlphaModifier_DistanceFromCamera *q = (LineStyleAlphaModifier_DistanceFromCamera *)
|
|
|
|
new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
|
|
|
LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)
|
|
|
|
m;
|
|
|
|
LineStyleAlphaModifier_DistanceFromObject *q = (LineStyleAlphaModifier_DistanceFromObject *)
|
|
|
|
new_m;
|
2019-04-22 01:39:35 +02:00
|
|
|
if (p->target) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_plus(&p->target->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
q->target = p->target;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_MATERIAL: {
|
|
|
|
LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m;
|
|
|
|
LineStyleAlphaModifier_Material *q = (LineStyleAlphaModifier_Material *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->mat_attr = p->mat_attr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleAlphaModifier_Tangent *p = (LineStyleAlphaModifier_Tangent *)m;
|
|
|
|
LineStyleAlphaModifier_Tangent *q = (LineStyleAlphaModifier_Tangent *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_NOISE: {
|
|
|
|
LineStyleAlphaModifier_Noise *p = (LineStyleAlphaModifier_Noise *)m;
|
|
|
|
LineStyleAlphaModifier_Noise *q = (LineStyleAlphaModifier_Noise *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->period = p->period;
|
|
|
|
q->seed = p->seed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE: {
|
|
|
|
LineStyleAlphaModifier_CreaseAngle *p = (LineStyleAlphaModifier_CreaseAngle *)m;
|
|
|
|
LineStyleAlphaModifier_CreaseAngle *q = (LineStyleAlphaModifier_CreaseAngle *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->min_angle = p->min_angle;
|
|
|
|
q->max_angle = p->max_angle;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CURVATURE_3D: {
|
|
|
|
LineStyleAlphaModifier_Curvature_3D *p = (LineStyleAlphaModifier_Curvature_3D *)m;
|
|
|
|
LineStyleAlphaModifier_Curvature_3D *q = (LineStyleAlphaModifier_Curvature_3D *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->min_curvature = p->min_curvature;
|
|
|
|
q->max_curvature = p->max_curvature;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->alpha_modifiers, new_m);
|
|
|
|
|
|
|
|
return new_m;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
|
2014-07-17 02:23:30 +02:00
|
|
|
int BKE_linestyle_alpha_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-22 01:39:35 +02:00
|
|
|
if (BLI_findindex(&linestyle->alpha_modifiers, m) == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_AlongStroke *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_DistanceFromObject *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_Material *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_Tangent *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_Noise *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_CreaseAngle *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_Curvature_3D *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
BLI_freelinkN(&linestyle->alpha_modifiers, m);
|
|
|
|
return 0;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
static LineStyleModifier *alloc_thickness_modifier(const char *name, int type)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t size;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_AlongStroke);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_DistanceFromCamera);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_DistanceFromObject);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_Material);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CALLIGRAPHY:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_Calligraphy);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_Tangent);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_Noise);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_CreaseAngle);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
size = sizeof(LineStyleThicknessModifier_Curvature_3D);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_modifier(name, type, size);
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *linestyle,
|
|
|
|
const char *name,
|
|
|
|
int type)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *m;
|
|
|
|
|
|
|
|
m = alloc_thickness_modifier(name, type);
|
|
|
|
m->blend = LS_VALUE_BLEND;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
|
|
|
LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->value_min = 0.0f;
|
|
|
|
p->value_max = 1.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
|
|
|
LineStyleThicknessModifier_DistanceFromCamera *p =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromCamera *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->range_min = 0.0f;
|
|
|
|
p->range_max = 1000.0f;
|
|
|
|
p->value_min = 0.0f;
|
|
|
|
p->value_max = 1.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
|
|
|
LineStyleThicknessModifier_DistanceFromObject *p =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromObject *)m;
|
|
|
|
p->target = NULL;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->range_min = 0.0f;
|
|
|
|
p->range_max = 1000.0f;
|
|
|
|
p->value_min = 0.0f;
|
|
|
|
p->value_max = 1.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_MATERIAL: {
|
|
|
|
LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->mat_attr = LS_MODIFIER_MATERIAL_LINE;
|
|
|
|
p->value_min = 0.0f;
|
|
|
|
p->value_max = 1.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CALLIGRAPHY: {
|
|
|
|
LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m;
|
|
|
|
p->min_thickness = 1.0f;
|
|
|
|
p->max_thickness = 10.0f;
|
|
|
|
p->orientation = DEG2RADF(60.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleThicknessModifier_Tangent *p = (LineStyleThicknessModifier_Tangent *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->min_thickness = 1.0f;
|
|
|
|
p->max_thickness = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_NOISE: {
|
|
|
|
LineStyleThicknessModifier_Noise *p = (LineStyleThicknessModifier_Noise *)m;
|
|
|
|
p->period = 10.0f;
|
|
|
|
p->amplitude = 10.0f;
|
|
|
|
p->seed = 512;
|
|
|
|
p->flags = LS_THICKNESS_ASYMMETRIC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE: {
|
|
|
|
LineStyleThicknessModifier_CreaseAngle *p = (LineStyleThicknessModifier_CreaseAngle *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->min_angle = 0.0f;
|
|
|
|
p->max_angle = DEG2RADF(180.0f);
|
|
|
|
p->min_thickness = 1.0f;
|
|
|
|
p->max_thickness = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CURVATURE_3D: {
|
|
|
|
LineStyleThicknessModifier_Curvature_3D *p = (LineStyleThicknessModifier_Curvature_3D *)m;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
p->min_curvature = 0.0f;
|
|
|
|
p->max_curvature = 0.5f;
|
|
|
|
p->min_thickness = 1.0f;
|
|
|
|
p->max_thickness = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->thickness_modifiers, m);
|
|
|
|
|
|
|
|
return m;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *linestyle,
|
|
|
|
const LineStyleModifier *m,
|
|
|
|
const int flag)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *new_m;
|
|
|
|
|
|
|
|
new_m = alloc_thickness_modifier(m->name, m->type);
|
2019-04-22 01:39:35 +02:00
|
|
|
if (!new_m) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
new_m->influence = m->influence;
|
|
|
|
new_m->flags = m->flags;
|
|
|
|
new_m->blend = m->blend;
|
|
|
|
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
|
|
|
LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m;
|
|
|
|
LineStyleThicknessModifier_AlongStroke *q = (LineStyleThicknessModifier_AlongStroke *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->value_min = p->value_min;
|
|
|
|
q->value_max = p->value_max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
|
|
|
LineStyleThicknessModifier_DistanceFromCamera *p =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromCamera *)m;
|
|
|
|
LineStyleThicknessModifier_DistanceFromCamera *q =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromCamera *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
|
|
|
q->value_min = p->value_min;
|
|
|
|
q->value_max = p->value_max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
|
|
|
LineStyleThicknessModifier_DistanceFromObject *p =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromObject *)m;
|
|
|
|
LineStyleThicknessModifier_DistanceFromObject *q =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromObject *)new_m;
|
|
|
|
q->target = p->target;
|
|
|
|
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
|
|
|
|
id_us_plus((ID *)q->target);
|
|
|
|
}
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
|
|
|
q->value_min = p->value_min;
|
|
|
|
q->value_max = p->value_max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_MATERIAL: {
|
|
|
|
LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m;
|
|
|
|
LineStyleThicknessModifier_Material *q = (LineStyleThicknessModifier_Material *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->mat_attr = p->mat_attr;
|
|
|
|
q->value_min = p->value_min;
|
|
|
|
q->value_max = p->value_max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CALLIGRAPHY: {
|
|
|
|
LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m;
|
|
|
|
LineStyleThicknessModifier_Calligraphy *q = (LineStyleThicknessModifier_Calligraphy *)new_m;
|
|
|
|
q->min_thickness = p->min_thickness;
|
|
|
|
q->max_thickness = p->max_thickness;
|
|
|
|
q->orientation = p->orientation;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleThicknessModifier_Tangent *p = (LineStyleThicknessModifier_Tangent *)m;
|
|
|
|
LineStyleThicknessModifier_Tangent *q = (LineStyleThicknessModifier_Tangent *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->min_thickness = p->min_thickness;
|
|
|
|
q->max_thickness = p->max_thickness;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_NOISE: {
|
|
|
|
LineStyleThicknessModifier_Noise *p = (LineStyleThicknessModifier_Noise *)m;
|
|
|
|
LineStyleThicknessModifier_Noise *q = (LineStyleThicknessModifier_Noise *)new_m;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->period = p->period;
|
|
|
|
q->seed = p->seed;
|
|
|
|
q->flags = p->flags;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CURVATURE_3D: {
|
|
|
|
LineStyleThicknessModifier_Curvature_3D *p = (LineStyleThicknessModifier_Curvature_3D *)m;
|
|
|
|
LineStyleThicknessModifier_Curvature_3D *q = (LineStyleThicknessModifier_Curvature_3D *)
|
|
|
|
new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->min_curvature = p->min_curvature;
|
|
|
|
q->max_curvature = p->max_curvature;
|
|
|
|
q->min_thickness = p->min_thickness;
|
|
|
|
q->max_thickness = p->max_thickness;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE: {
|
|
|
|
LineStyleThicknessModifier_CreaseAngle *p = (LineStyleThicknessModifier_CreaseAngle *)m;
|
|
|
|
LineStyleThicknessModifier_CreaseAngle *q = (LineStyleThicknessModifier_CreaseAngle *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->min_angle = p->min_angle;
|
|
|
|
q->max_angle = p->max_angle;
|
|
|
|
q->min_thickness = p->min_thickness;
|
|
|
|
q->max_thickness = p->max_thickness;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->thickness_modifiers, new_m);
|
|
|
|
|
|
|
|
return new_m;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
2010-06-26 00:45:42 +02:00
|
|
|
|
2014-07-17 02:23:30 +02:00
|
|
|
int BKE_linestyle_thickness_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-22 01:39:35 +02:00
|
|
|
if (BLI_findindex(&linestyle->thickness_modifiers, m) == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_AlongStroke *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_DistanceFromObject *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_Material *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CALLIGRAPHY:
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_Tangent *)m)->curve);
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BLI_freelinkN(&linestyle->thickness_modifiers, m);
|
|
|
|
return 0;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
static LineStyleModifier *alloc_geometry_modifier(const char *name, int type)
|
2011-08-19 16:05:11 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t size;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LS_MODIFIER_SAMPLING:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_Sampling);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_BEZIER_CURVE:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_BezierCurve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_SINUS_DISPLACEMENT:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_SinusDisplacement);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_SPATIAL_NOISE:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_SpatialNoise);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_PERLIN_NOISE_1D:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_PerlinNoise1D);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_PERLIN_NOISE_2D:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_PerlinNoise2D);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_BACKBONE_STRETCHER:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_BackboneStretcher);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TIP_REMOVER:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_TipRemover);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_POLYGONIZATION:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_Polygonalization);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_GUIDING_LINES:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_GuidingLines);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_BLUEPRINT:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_Blueprint);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_2D_OFFSET:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_2DOffset);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_2D_TRANSFORM:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_2DTransform);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_SIMPLIFICATION:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_Simplification);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_modifier(name, type, size);
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_geometry_modifier_add(FreestyleLineStyle *linestyle,
|
|
|
|
const char *name,
|
|
|
|
int type)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *m;
|
|
|
|
|
|
|
|
m = alloc_geometry_modifier(name, type);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LS_MODIFIER_SAMPLING: {
|
|
|
|
LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m;
|
|
|
|
p->sampling = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_BEZIER_CURVE: {
|
|
|
|
LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m;
|
|
|
|
p->error = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_SINUS_DISPLACEMENT: {
|
|
|
|
LineStyleGeometryModifier_SinusDisplacement *p =
|
|
|
|
(LineStyleGeometryModifier_SinusDisplacement *)m;
|
|
|
|
p->wavelength = 20.0f;
|
|
|
|
p->amplitude = 5.0f;
|
|
|
|
p->phase = 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_SPATIAL_NOISE: {
|
|
|
|
LineStyleGeometryModifier_SpatialNoise *p = (LineStyleGeometryModifier_SpatialNoise *)m;
|
|
|
|
p->amplitude = 5.0f;
|
|
|
|
p->scale = 20.0f;
|
|
|
|
p->octaves = 4;
|
|
|
|
p->flags = LS_MODIFIER_SPATIAL_NOISE_SMOOTH | LS_MODIFIER_SPATIAL_NOISE_PURERANDOM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_PERLIN_NOISE_1D: {
|
|
|
|
LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m;
|
|
|
|
p->frequency = 10.0f;
|
|
|
|
p->amplitude = 10.0f;
|
|
|
|
p->octaves = 4;
|
|
|
|
p->angle = DEG2RADF(45.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_PERLIN_NOISE_2D: {
|
|
|
|
LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m;
|
|
|
|
p->frequency = 10.0f;
|
|
|
|
p->amplitude = 10.0f;
|
|
|
|
p->octaves = 4;
|
|
|
|
p->angle = DEG2RADF(45.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_BACKBONE_STRETCHER: {
|
|
|
|
LineStyleGeometryModifier_BackboneStretcher *p =
|
|
|
|
(LineStyleGeometryModifier_BackboneStretcher *)m;
|
|
|
|
p->backbone_length = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TIP_REMOVER: {
|
|
|
|
LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m;
|
|
|
|
p->tip_length = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_POLYGONIZATION: {
|
|
|
|
LineStyleGeometryModifier_Polygonalization *p =
|
|
|
|
(LineStyleGeometryModifier_Polygonalization *)m;
|
|
|
|
p->error = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_GUIDING_LINES: {
|
|
|
|
LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m;
|
|
|
|
p->offset = 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_BLUEPRINT: {
|
|
|
|
LineStyleGeometryModifier_Blueprint *p = (LineStyleGeometryModifier_Blueprint *)m;
|
|
|
|
p->flags = LS_MODIFIER_BLUEPRINT_CIRCLES;
|
|
|
|
p->rounds = 1;
|
|
|
|
p->backbone_length = 10.0f;
|
|
|
|
p->random_radius = 3;
|
|
|
|
p->random_center = 5;
|
|
|
|
p->random_backbone = 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_2D_OFFSET: {
|
|
|
|
LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m;
|
|
|
|
p->start = 0.0f;
|
|
|
|
p->end = 0.0f;
|
|
|
|
p->x = 0.0f;
|
|
|
|
p->y = 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_2D_TRANSFORM: {
|
|
|
|
LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m;
|
|
|
|
p->pivot = LS_MODIFIER_2D_TRANSFORM_PIVOT_CENTER;
|
|
|
|
p->scale_x = 1.0f;
|
|
|
|
p->scale_y = 1.0f;
|
|
|
|
p->angle = DEG2RADF(0.0f);
|
|
|
|
p->pivot_u = 0.5f;
|
|
|
|
p->pivot_x = 0.0f;
|
|
|
|
p->pivot_y = 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_SIMPLIFICATION: {
|
|
|
|
LineStyleGeometryModifier_Simplification *p = (LineStyleGeometryModifier_Simplification *)m;
|
|
|
|
p->tolerance = 0.1f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->geometry_modifiers, m);
|
|
|
|
|
|
|
|
return m;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_geometry_modifier_copy(FreestyleLineStyle *linestyle,
|
|
|
|
const LineStyleModifier *m,
|
|
|
|
const int UNUSED(flag))
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *new_m;
|
|
|
|
|
|
|
|
new_m = alloc_geometry_modifier(m->name, m->type);
|
|
|
|
new_m->flags = m->flags;
|
|
|
|
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_SAMPLING: {
|
|
|
|
LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m;
|
|
|
|
LineStyleGeometryModifier_Sampling *q = (LineStyleGeometryModifier_Sampling *)new_m;
|
|
|
|
q->sampling = p->sampling;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_BEZIER_CURVE: {
|
|
|
|
LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m;
|
|
|
|
LineStyleGeometryModifier_BezierCurve *q = (LineStyleGeometryModifier_BezierCurve *)new_m;
|
|
|
|
q->error = p->error;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_SINUS_DISPLACEMENT: {
|
|
|
|
LineStyleGeometryModifier_SinusDisplacement *p =
|
|
|
|
(LineStyleGeometryModifier_SinusDisplacement *)m;
|
|
|
|
LineStyleGeometryModifier_SinusDisplacement *q =
|
|
|
|
(LineStyleGeometryModifier_SinusDisplacement *)new_m;
|
|
|
|
q->wavelength = p->wavelength;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->phase = p->phase;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_SPATIAL_NOISE: {
|
|
|
|
LineStyleGeometryModifier_SpatialNoise *p = (LineStyleGeometryModifier_SpatialNoise *)m;
|
|
|
|
LineStyleGeometryModifier_SpatialNoise *q = (LineStyleGeometryModifier_SpatialNoise *)new_m;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->scale = p->scale;
|
|
|
|
q->octaves = p->octaves;
|
|
|
|
q->flags = p->flags;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_PERLIN_NOISE_1D: {
|
|
|
|
LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m;
|
|
|
|
LineStyleGeometryModifier_PerlinNoise1D *q = (LineStyleGeometryModifier_PerlinNoise1D *)
|
|
|
|
new_m;
|
|
|
|
q->frequency = p->frequency;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->angle = p->angle;
|
|
|
|
q->octaves = p->octaves;
|
|
|
|
q->seed = p->seed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_PERLIN_NOISE_2D: {
|
|
|
|
LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m;
|
|
|
|
LineStyleGeometryModifier_PerlinNoise2D *q = (LineStyleGeometryModifier_PerlinNoise2D *)
|
|
|
|
new_m;
|
|
|
|
q->frequency = p->frequency;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->angle = p->angle;
|
|
|
|
q->octaves = p->octaves;
|
|
|
|
q->seed = p->seed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_BACKBONE_STRETCHER: {
|
|
|
|
LineStyleGeometryModifier_BackboneStretcher *p =
|
|
|
|
(LineStyleGeometryModifier_BackboneStretcher *)m;
|
|
|
|
LineStyleGeometryModifier_BackboneStretcher *q =
|
|
|
|
(LineStyleGeometryModifier_BackboneStretcher *)new_m;
|
|
|
|
q->backbone_length = p->backbone_length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TIP_REMOVER: {
|
|
|
|
LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m;
|
|
|
|
LineStyleGeometryModifier_TipRemover *q = (LineStyleGeometryModifier_TipRemover *)new_m;
|
|
|
|
q->tip_length = p->tip_length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_POLYGONIZATION: {
|
|
|
|
LineStyleGeometryModifier_Polygonalization *p =
|
|
|
|
(LineStyleGeometryModifier_Polygonalization *)m;
|
|
|
|
LineStyleGeometryModifier_Polygonalization *q =
|
|
|
|
(LineStyleGeometryModifier_Polygonalization *)new_m;
|
|
|
|
q->error = p->error;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_GUIDING_LINES: {
|
|
|
|
LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m;
|
|
|
|
LineStyleGeometryModifier_GuidingLines *q = (LineStyleGeometryModifier_GuidingLines *)new_m;
|
|
|
|
q->offset = p->offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_BLUEPRINT: {
|
|
|
|
LineStyleGeometryModifier_Blueprint *p = (LineStyleGeometryModifier_Blueprint *)m;
|
|
|
|
LineStyleGeometryModifier_Blueprint *q = (LineStyleGeometryModifier_Blueprint *)new_m;
|
|
|
|
q->flags = p->flags;
|
|
|
|
q->rounds = p->rounds;
|
|
|
|
q->backbone_length = p->backbone_length;
|
|
|
|
q->random_radius = p->random_radius;
|
|
|
|
q->random_center = p->random_center;
|
|
|
|
q->random_backbone = p->random_backbone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_2D_OFFSET: {
|
|
|
|
LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m;
|
|
|
|
LineStyleGeometryModifier_2DOffset *q = (LineStyleGeometryModifier_2DOffset *)new_m;
|
|
|
|
q->start = p->start;
|
|
|
|
q->end = p->end;
|
|
|
|
q->x = p->x;
|
|
|
|
q->y = p->y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_2D_TRANSFORM: {
|
|
|
|
LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m;
|
|
|
|
LineStyleGeometryModifier_2DTransform *q = (LineStyleGeometryModifier_2DTransform *)new_m;
|
|
|
|
q->pivot = p->pivot;
|
|
|
|
q->scale_x = p->scale_x;
|
|
|
|
q->scale_y = p->scale_y;
|
|
|
|
q->angle = p->angle;
|
|
|
|
q->pivot_u = p->pivot_u;
|
|
|
|
q->pivot_x = p->pivot_x;
|
|
|
|
q->pivot_y = p->pivot_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_SIMPLIFICATION: {
|
|
|
|
LineStyleGeometryModifier_Simplification *p = (LineStyleGeometryModifier_Simplification *)m;
|
|
|
|
LineStyleGeometryModifier_Simplification *q = (LineStyleGeometryModifier_Simplification *)
|
|
|
|
new_m;
|
|
|
|
q->tolerance = p->tolerance;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL; /* unknown modifier type */
|
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->geometry_modifiers, new_m);
|
|
|
|
|
|
|
|
return new_m;
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
|
|
|
|
2014-07-17 02:23:30 +02:00
|
|
|
int BKE_linestyle_geometry_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m)
|
2011-08-19 16:05:11 +02:00
|
|
|
{
|
2019-04-22 01:39:35 +02:00
|
|
|
if (BLI_findindex(&linestyle->geometry_modifiers, m) == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_freelinkN(&linestyle->geometry_modifiers, m);
|
|
|
|
return 0;
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 21:36:34 +02:00
|
|
|
/**
|
|
|
|
* Reinsert \a modifier in modifier list with an offset of \a direction.
|
|
|
|
* \return if position of \a modifier has changed.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BKE_linestyle_color_modifier_move(FreestyleLineStyle *linestyle,
|
|
|
|
LineStyleModifier *modifier,
|
|
|
|
int direction)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_listbase_link_move(&linestyle->color_modifiers, modifier, direction);
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BKE_linestyle_alpha_modifier_move(FreestyleLineStyle *linestyle,
|
|
|
|
LineStyleModifier *modifier,
|
|
|
|
int direction)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_listbase_link_move(&linestyle->alpha_modifiers, modifier, direction);
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BKE_linestyle_thickness_modifier_move(FreestyleLineStyle *linestyle,
|
|
|
|
LineStyleModifier *modifier,
|
|
|
|
int direction)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_listbase_link_move(&linestyle->thickness_modifiers, modifier, direction);
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle,
|
|
|
|
LineStyleModifier *modifier,
|
|
|
|
int direction)
|
2011-08-19 16:05:11 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_listbase_link_move(&linestyle->geometry_modifiers, modifier, direction);
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
|
|
|
|
2014-07-16 07:13:40 +02:00
|
|
|
void BKE_linestyle_modifier_list_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase)
|
2010-09-18 02:31:22 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *m;
|
|
|
|
ColorBand *color_ramp;
|
|
|
|
LinkData *link;
|
|
|
|
|
|
|
|
BLI_listbase_clear(listbase);
|
|
|
|
|
|
|
|
for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
color_ramp = ((LineStyleColorModifier_AlongStroke *)m)->color_ramp;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
color_ramp = ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
color_ramp = ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
color_ramp = ((LineStyleColorModifier_Material *)m)->color_ramp;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
link = (LinkData *)MEM_callocN(sizeof(LinkData), "link to color ramp");
|
|
|
|
link->data = color_ramp;
|
|
|
|
BLI_addtail(listbase, link);
|
|
|
|
}
|
2010-09-18 02:31:22 +02:00
|
|
|
}
|
|
|
|
|
2014-07-16 07:13:40 +02:00
|
|
|
char *BKE_linestyle_path_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *color_ramp)
|
2010-09-18 02:31:22 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LineStyleModifier *m;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_AlongStroke *)m)->color_ramp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_Material *)m)->color_ramp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_Tangent *)m)->color_ramp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_Noise *)m)->color_ramp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
char name_esc[sizeof(m->name) * 2];
|
|
|
|
BLI_strescape(name_esc, m->name, sizeof(name_esc));
|
|
|
|
return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", name_esc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("BKE_linestyle_path_to_color_ramp: No color ramps correspond to the given pointer.\n");
|
|
|
|
return NULL;
|
2010-09-18 02:31:22 +02:00
|
|
|
}
|
2010-11-29 22:24:55 +01:00
|
|
|
|
2014-07-19 08:33:15 +02:00
|
|
|
bool BKE_linestyle_use_textures(FreestyleLineStyle *linestyle, const bool use_shading_nodes)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (use_shading_nodes) {
|
|
|
|
if (linestyle && linestyle->use_nodes && linestyle->nodetree) {
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
for (node = linestyle->nodetree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (linestyle && (linestyle->flag & LS_TEXTURE)) {
|
|
|
|
return (linestyle->mtex[0] != NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-19 08:33:15 +02:00
|
|
|
}
|
2014-07-16 08:25:10 +02:00
|
|
|
|
|
|
|
void BKE_linestyle_default_shader(const bContext *C, FreestyleLineStyle *linestyle)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *uv_along_stroke, *input_texure, *output_linestyle;
|
|
|
|
bNodeSocket *fromsock, *tosock;
|
|
|
|
bNodeTree *ntree;
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(linestyle->nodetree == NULL);
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2019-08-22 16:00:59 +02:00
|
|
|
ntree = ntreeAddTree(NULL, "stroke_shader", "ShaderNodeTree");
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
linestyle->nodetree = ntree;
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uv_along_stroke = nodeAddStaticNode(C, ntree, SH_NODE_UVALONGSTROKE);
|
|
|
|
uv_along_stroke->locx = 0.0f;
|
|
|
|
uv_along_stroke->locy = 300.0f;
|
|
|
|
uv_along_stroke->custom1 = 0; // use_tips
|
2014-07-20 05:17:22 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
input_texure = nodeAddStaticNode(C, ntree, SH_NODE_TEX_IMAGE);
|
|
|
|
input_texure->locx = 200.0f;
|
|
|
|
input_texure->locy = 300.0f;
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
output_linestyle = nodeAddStaticNode(C, ntree, SH_NODE_OUTPUT_LINESTYLE);
|
|
|
|
output_linestyle->locx = 400.0f;
|
|
|
|
output_linestyle->locy = 300.0f;
|
|
|
|
output_linestyle->custom1 = MA_RAMP_BLEND;
|
|
|
|
output_linestyle->custom2 = 0; // use_clamp
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
nodeSetActive(ntree, input_texure);
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
fromsock = BLI_findlink(&uv_along_stroke->outputs, 0); // UV
|
|
|
|
tosock = BLI_findlink(&input_texure->inputs, 0); // UV
|
|
|
|
nodeAddLink(ntree, uv_along_stroke, fromsock, input_texure, tosock);
|
2014-07-20 05:17:22 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
fromsock = BLI_findlink(&input_texure->outputs, 0); // Color
|
|
|
|
tosock = BLI_findlink(&output_linestyle->inputs, 0); // Color
|
|
|
|
nodeAddLink(ntree, input_texure, fromsock, output_linestyle, tosock);
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), ntree);
|
2014-07-16 08:25:10 +02:00
|
|
|
}
|