2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2010 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2010-06-26 00:45:42 +02:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2012-12-11 23:00:22 +01:00
|
|
|
*/
|
|
|
|
|
2022-12-29 18:01:32 +01:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2010-06-26 00:45:42 +02:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_defaults.h"
|
2010-07-20 19:57:33 +02:00
|
|
|
#include "DNA_material_types.h" /* for ramp blend */
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
2010-09-18 02:31:22 +02:00
|
|
|
#include "DNA_texture_types.h"
|
2010-07-20 19:57:33 +02:00
|
|
|
|
2013-03-18 01:48:59 +01:00
|
|
|
#include "BLI_blenlib.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 10:39:20 +02:00
|
|
|
#include "BLI_math_rotation.h"
|
2023-10-18 17:15:30 +02:00
|
|
|
#include "BLI_string_utils.hh"
|
2013-03-18 01:48:59 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2020-03-09 16:56:12 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
2020-09-10 13:50:03 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2017-12-07 05:36:26 +01:00
|
|
|
#include "BKE_colorband.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_colortools.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
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"
|
2020-05-15 18:45:54 +02:00
|
|
|
#include "BKE_lib_query.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"
|
2023-05-15 15:14:22 +02:00
|
|
|
#include "BKE_node.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_node_tree_update.hh"
|
2020-05-15 18:45:54 +02:00
|
|
|
#include "BKE_texture.h"
|
2010-07-20 19:57:33 +02:00
|
|
|
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_read_write.hh"
|
2020-09-10 13:50:03 +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);
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_linestyle_geometry_modifier_add(linestyle, nullptr, LS_MODIFIER_SAMPLING);
|
2020-03-09 16:56:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-06-07 06:53:20 +02:00
|
|
|
/* We never handle user-count here for own data. */
|
2020-03-09 16:56:12 +01:00
|
|
|
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]) {
|
2022-11-18 11:08:39 +01:00
|
|
|
linestyle_dst->mtex[a] = MEM_new<MTex>(__func__);
|
|
|
|
*linestyle_dst->mtex[a] = blender::dna::shallow_copy(*linestyle_src->mtex[a]);
|
2020-03-09 16:56:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linestyle_src->nodetree) {
|
|
|
|
BKE_id_copy_ex(bmain,
|
|
|
|
(ID *)linestyle_src->nodetree,
|
|
|
|
(ID **)&linestyle_dst->nodetree,
|
|
|
|
flag_private_id_data);
|
2022-09-06 14:57:44 +02:00
|
|
|
linestyle_dst->nodetree->owner_id = &linestyle_dst->id;
|
2020-03-09 16:56:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&linestyle_dst->color_modifiers);
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, linestyle_modifier, &linestyle_src->color_modifiers) {
|
2020-03-09 16:56:12 +01:00
|
|
|
BKE_linestyle_color_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&linestyle_dst->alpha_modifiers);
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, linestyle_modifier, &linestyle_src->alpha_modifiers) {
|
2020-03-09 16:56:12 +01:00
|
|
|
BKE_linestyle_alpha_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&linestyle_dst->thickness_modifiers);
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, linestyle_modifier, &linestyle_src->thickness_modifiers) {
|
2020-03-09 16:56:12 +01:00
|
|
|
BKE_linestyle_thickness_modifier_copy(linestyle_dst, linestyle_modifier, flag_subdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&linestyle_dst->geometry_modifiers);
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, linestyle_modifier, &linestyle_src->geometry_modifiers) {
|
2020-03-09 16:56:12 +01:00
|
|
|
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) {
|
2020-04-20 16:14:45 +02:00
|
|
|
ntreeFreeEmbeddedTree(linestyle->nodetree);
|
2020-03-09 16:56:12 +01:00
|
|
|
MEM_freeN(linestyle->nodetree);
|
2022-11-18 11:08:39 +01:00
|
|
|
linestyle->nodetree = nullptr;
|
2020-03-09 16:56:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 18:45:54 +02:00
|
|
|
static void linestyle_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
{
|
|
|
|
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_MTEX; i++) {
|
|
|
|
if (linestyle->mtex[i]) {
|
2021-10-27 11:30:43 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(
|
|
|
|
data, BKE_texture_mtex_foreach_id(data, linestyle->mtex[i]));
|
2020-05-15 18:45:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (linestyle->nodetree) {
|
|
|
|
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
|
2021-10-27 11:30:43 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(
|
|
|
|
data, BKE_library_foreach_ID_embedded(data, (ID **)&linestyle->nodetree));
|
2020-05-15 18:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->color_modifiers) {
|
|
|
|
if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
|
|
|
|
LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)
|
|
|
|
lsm;
|
2023-08-17 19:19:05 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, p->target, IDWALK_CB_NOP);
|
2020-05-15 18:45:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->alpha_modifiers) {
|
|
|
|
if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
|
|
|
|
LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)
|
|
|
|
lsm;
|
2023-08-17 19:19:05 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, p->target, IDWALK_CB_NOP);
|
2020-05-15 18:45:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->thickness_modifiers) {
|
|
|
|
if (lsm->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
|
|
|
|
LineStyleThicknessModifier_DistanceFromObject *p =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromObject *)lsm;
|
2023-08-17 19:19:05 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, p->target, IDWALK_CB_NOP);
|
2020-05-15 18:45:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 13:50:03 +02:00
|
|
|
static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers)
|
|
|
|
{
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) {
|
2020-09-10 13:50:03 +02:00
|
|
|
int struct_nr;
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */
|
|
|
|
}
|
|
|
|
BLO_write_struct_by_id(writer, struct_nr, m);
|
|
|
|
}
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) {
|
2020-09-10 13:50:03 +02:00
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
BLO_write_struct(
|
|
|
|
writer, ColorBand, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
BLO_write_struct(
|
|
|
|
writer, ColorBand, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Material *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Tangent *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Noise *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
BLO_write_struct(
|
|
|
|
writer, ColorBand, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers)
|
|
|
|
{
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) {
|
2020-09-10 13:50:03 +02:00
|
|
|
int struct_nr;
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */
|
|
|
|
}
|
|
|
|
BLO_write_struct_by_id(writer, struct_nr, m);
|
|
|
|
}
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) {
|
2020-09-10 13:50:03 +02:00
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
BKE_curvemapping_blend_write(writer,
|
|
|
|
((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
BKE_curvemapping_blend_write(writer,
|
|
|
|
((LineStyleAlphaModifier_DistanceFromObject *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Material *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Tangent *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Noise *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers)
|
|
|
|
{
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) {
|
2020-09-10 13:50:03 +02:00
|
|
|
int struct_nr;
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CALLIGRAPHY:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */
|
|
|
|
}
|
|
|
|
BLO_write_struct_by_id(writer, struct_nr, m);
|
|
|
|
}
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) {
|
2020-09-10 13:50:03 +02:00
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
|
|
|
BKE_curvemapping_blend_write(writer,
|
|
|
|
((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
|
|
|
BKE_curvemapping_blend_write(writer,
|
|
|
|
((LineStyleThicknessModifier_DistanceFromObject *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Material *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TANGENT:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Tangent *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
BKE_curvemapping_blend_write(writer,
|
|
|
|
((LineStyleThicknessModifier_Curvature_3D *)m)->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers)
|
|
|
|
{
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, modifiers) {
|
2020-09-10 13:50:03 +02:00
|
|
|
int struct_nr;
|
|
|
|
switch (m->type) {
|
|
|
|
case LS_MODIFIER_SAMPLING:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_BEZIER_CURVE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_SINUS_DISPLACEMENT:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_SPATIAL_NOISE:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_PERLIN_NOISE_1D:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_PERLIN_NOISE_2D:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_BACKBONE_STRETCHER:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_TIP_REMOVER:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_POLYGONIZATION:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_GUIDING_LINES:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_BLUEPRINT:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_2D_OFFSET:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_2D_TRANSFORM:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_SIMPLIFICATION:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */
|
|
|
|
}
|
|
|
|
BLO_write_struct_by_id(writer, struct_nr, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void linestyle_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
|
|
|
{
|
|
|
|
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
|
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id);
|
|
|
|
BKE_id_blend_write(writer, &linestyle->id);
|
2020-09-10 13:50:03 +02:00
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
write_linestyle_color_modifiers(writer, &linestyle->color_modifiers);
|
|
|
|
write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers);
|
|
|
|
write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers);
|
|
|
|
write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers);
|
|
|
|
for (int a = 0; a < MAX_MTEX; a++) {
|
|
|
|
if (linestyle->mtex[a]) {
|
|
|
|
BLO_write_struct(writer, MTex, linestyle->mtex[a]);
|
2020-09-10 13:50:03 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-19 11:13:55 +02:00
|
|
|
if (linestyle->nodetree) {
|
2023-04-14 10:35:31 +02:00
|
|
|
BLO_Write_IDBuffer *temp_embedded_id_buffer = BLO_write_allocate_id_buffer();
|
|
|
|
BLO_write_init_id_buffer_from_id(
|
|
|
|
temp_embedded_id_buffer, &linestyle->nodetree->id, BLO_write_is_undo(writer));
|
|
|
|
BLO_write_struct_at_address(writer,
|
|
|
|
bNodeTree,
|
|
|
|
linestyle->nodetree,
|
|
|
|
BLO_write_get_id_buffer_temp_id(temp_embedded_id_buffer));
|
|
|
|
ntreeBlendWrite(
|
|
|
|
writer,
|
|
|
|
reinterpret_cast<bNodeTree *>(BLO_write_get_id_buffer_temp_id(temp_embedded_id_buffer)));
|
|
|
|
BLO_write_destroy_id_buffer(&temp_embedded_id_buffer);
|
2021-08-19 11:13:55 +02:00
|
|
|
}
|
2020-09-10 13:50:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void direct_link_linestyle_color_modifier(BlendDataReader *reader,
|
|
|
|
LineStyleModifier *modifier)
|
|
|
|
{
|
|
|
|
switch (modifier->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
|
|
|
LineStyleColorModifier_AlongStroke *m = (LineStyleColorModifier_AlongStroke *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
|
|
|
LineStyleColorModifier_DistanceFromCamera *m = (LineStyleColorModifier_DistanceFromCamera *)
|
|
|
|
modifier;
|
|
|
|
BLO_read_data_address(reader, &m->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
|
|
|
LineStyleColorModifier_DistanceFromObject *m = (LineStyleColorModifier_DistanceFromObject *)
|
|
|
|
modifier;
|
|
|
|
BLO_read_data_address(reader, &m->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_MATERIAL: {
|
|
|
|
LineStyleColorModifier_Material *m = (LineStyleColorModifier_Material *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleColorModifier_Tangent *m = (LineStyleColorModifier_Tangent *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_NOISE: {
|
|
|
|
LineStyleColorModifier_Noise *m = (LineStyleColorModifier_Noise *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE: {
|
|
|
|
LineStyleColorModifier_CreaseAngle *m = (LineStyleColorModifier_CreaseAngle *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CURVATURE_3D: {
|
|
|
|
LineStyleColorModifier_Curvature_3D *m = (LineStyleColorModifier_Curvature_3D *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->color_ramp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void direct_link_linestyle_alpha_modifier(BlendDataReader *reader,
|
|
|
|
LineStyleModifier *modifier)
|
|
|
|
{
|
|
|
|
switch (modifier->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
|
|
|
LineStyleAlphaModifier_AlongStroke *m = (LineStyleAlphaModifier_AlongStroke *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
|
|
|
LineStyleAlphaModifier_DistanceFromCamera *m = (LineStyleAlphaModifier_DistanceFromCamera *)
|
|
|
|
modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
|
|
|
LineStyleAlphaModifier_DistanceFromObject *m = (LineStyleAlphaModifier_DistanceFromObject *)
|
|
|
|
modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_MATERIAL: {
|
|
|
|
LineStyleAlphaModifier_Material *m = (LineStyleAlphaModifier_Material *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleAlphaModifier_Tangent *m = (LineStyleAlphaModifier_Tangent *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_NOISE: {
|
|
|
|
LineStyleAlphaModifier_Noise *m = (LineStyleAlphaModifier_Noise *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE: {
|
|
|
|
LineStyleAlphaModifier_CreaseAngle *m = (LineStyleAlphaModifier_CreaseAngle *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CURVATURE_3D: {
|
|
|
|
LineStyleAlphaModifier_Curvature_3D *m = (LineStyleAlphaModifier_Curvature_3D *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void direct_link_linestyle_thickness_modifier(BlendDataReader *reader,
|
|
|
|
LineStyleModifier *modifier)
|
|
|
|
{
|
|
|
|
switch (modifier->type) {
|
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
|
|
|
LineStyleThicknessModifier_AlongStroke *m = (LineStyleThicknessModifier_AlongStroke *)
|
|
|
|
modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
|
|
|
LineStyleThicknessModifier_DistanceFromCamera *m =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromCamera *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
|
|
|
LineStyleThicknessModifier_DistanceFromObject *m =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromObject *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_MATERIAL: {
|
|
|
|
LineStyleThicknessModifier_Material *m = (LineStyleThicknessModifier_Material *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleThicknessModifier_Tangent *m = (LineStyleThicknessModifier_Tangent *)modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE: {
|
|
|
|
LineStyleThicknessModifier_CreaseAngle *m = (LineStyleThicknessModifier_CreaseAngle *)
|
|
|
|
modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_CURVATURE_3D: {
|
|
|
|
LineStyleThicknessModifier_Curvature_3D *m = (LineStyleThicknessModifier_Curvature_3D *)
|
|
|
|
modifier;
|
|
|
|
BLO_read_data_address(reader, &m->curve);
|
|
|
|
BKE_curvemapping_blend_read(reader, m->curve);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 19:51:47 +01:00
|
|
|
static void direct_link_linestyle_geometry_modifier(BlendDataReader * /*reader*/,
|
|
|
|
LineStyleModifier * /*modifier*/)
|
2020-09-10 13:50:03 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void linestyle_blend_read_data(BlendDataReader *reader, ID *id)
|
|
|
|
{
|
|
|
|
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
|
|
|
|
|
|
|
|
BLO_read_list(reader, &linestyle->color_modifiers);
|
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->color_modifiers) {
|
|
|
|
direct_link_linestyle_color_modifier(reader, modifier);
|
|
|
|
}
|
|
|
|
BLO_read_list(reader, &linestyle->alpha_modifiers);
|
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->alpha_modifiers) {
|
|
|
|
direct_link_linestyle_alpha_modifier(reader, modifier);
|
|
|
|
}
|
|
|
|
BLO_read_list(reader, &linestyle->thickness_modifiers);
|
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->thickness_modifiers) {
|
|
|
|
direct_link_linestyle_thickness_modifier(reader, modifier);
|
|
|
|
}
|
|
|
|
BLO_read_list(reader, &linestyle->geometry_modifiers);
|
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->geometry_modifiers) {
|
|
|
|
direct_link_linestyle_geometry_modifier(reader, modifier);
|
|
|
|
}
|
|
|
|
for (int a = 0; a < MAX_MTEX; a++) {
|
|
|
|
BLO_read_data_address(reader, &linestyle->mtex[a]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 16:56:12 +01:00
|
|
|
IDTypeInfo IDType_ID_LS = {
|
2023-01-16 02:41:11 +01:00
|
|
|
/*id_code*/ ID_LS,
|
|
|
|
/*id_filter*/ FILTER_ID_LS,
|
|
|
|
/*main_listbase_index*/ INDEX_ID_LS,
|
|
|
|
/*struct_size*/ sizeof(FreestyleLineStyle),
|
|
|
|
/*name*/ "FreestyleLineStyle",
|
2023-10-22 08:47:26 +02:00
|
|
|
/*name_plural*/ N_("linestyles"),
|
2023-01-16 02:41:11 +01:00
|
|
|
/*translation_context*/ BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE,
|
|
|
|
/*flags*/ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
|
|
|
|
/*asset_type_info*/ nullptr,
|
|
|
|
|
|
|
|
/*init_data*/ linestyle_init_data,
|
|
|
|
/*copy_data*/ linestyle_copy_data,
|
|
|
|
/*free_data*/ linestyle_free_data,
|
|
|
|
/*make_local*/ nullptr,
|
|
|
|
/*foreach_id*/ linestyle_foreach_id,
|
|
|
|
/*foreach_cache*/ nullptr,
|
|
|
|
/*foreach_path*/ nullptr,
|
|
|
|
/*owner_pointer_get*/ nullptr,
|
|
|
|
|
|
|
|
/*blend_write*/ linestyle_blend_write,
|
|
|
|
/*blend_read_data*/ linestyle_blend_read_data,
|
2023-03-11 18:07:59 +01:00
|
|
|
/*blend_read_after_liblink*/ nullptr,
|
2023-01-16 02:41:11 +01:00
|
|
|
|
|
|
|
/*blend_read_undo_preserve*/ nullptr,
|
|
|
|
|
|
|
|
/*lib_override_apply_post*/ nullptr,
|
2020-03-09 16:56:12 +01:00
|
|
|
};
|
|
|
|
|
2012-12-08 23:24:41 +01:00
|
|
|
static const char *modifier_name[LS_MODIFIER_NUM] = {
|
2022-11-18 11:08:39 +01:00
|
|
|
nullptr, "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", "Curvature 3D",
|
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
|
|
|
}
|
|
|
|
|
2023-06-03 00:36:28 +02:00
|
|
|
FreestyleLineStyle *BKE_linestyle_new(Main *bmain, const char *name)
|
2010-06-26 00:45:42 +02:00
|
|
|
{
|
|
|
|
FreestyleLineStyle *linestyle;
|
|
|
|
|
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
|
|
|
linestyle = (FreestyleLineStyle *)BKE_libblock_alloc(bmain, ID_LS, name, 0);
|
2012-12-11 23:00:22 +01: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
|
|
|
BKE_linestyle_init(linestyle);
|
2010-06-26 00:45:42 +02:00
|
|
|
|
|
|
|
return linestyle;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-04-24 15:20:17 +02:00
|
|
|
FreestyleConfig *config = &view_layer->freestyle_config;
|
|
|
|
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
|
2022-11-18 11:08:39 +01:00
|
|
|
return (lineset) ? lineset->linestyle : nullptr;
|
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
|
|
|
{
|
|
|
|
LineStyleModifier *m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
if (!name) {
|
|
|
|
name = modifier_name[type];
|
|
|
|
}
|
2010-07-20 19:57:33 +02:00
|
|
|
m = (LineStyleModifier *)MEM_callocN(size, "line style modifier");
|
2013-03-20 00:54:14 +01:00
|
|
|
m->type = type;
|
2023-09-04 16:16:26 +02:00
|
|
|
STRNCPY(m->name, DATA_(name));
|
2013-03-20 00:54:14 +01:00
|
|
|
m->influence = 1.0f;
|
|
|
|
m->flags = LS_MODIFIER_ENABLED | LS_MODIFIER_EXPANDED;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-20 19:57:33 +02:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_to_modifier_list(ListBase *lb, LineStyleModifier *m)
|
|
|
|
{
|
|
|
|
BLI_addtail(lb, (void *)m);
|
2011-10-29 17:46:14 +02:00
|
|
|
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
|
|
|
{
|
2011-08-19 16:05:11 +02:00
|
|
|
size_t size;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-19 16:05:11 +02:00
|
|
|
switch (type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
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;
|
2015-07-10 14:57:23 +02:00
|
|
|
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;
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
return new_modifier(name, type, size);
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2014-07-17 02:23:30 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle,
|
|
|
|
const char *name,
|
|
|
|
int type)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
|
|
|
LineStyleModifier *m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
m = alloc_color_modifier(name, type);
|
2022-11-18 11:08:39 +01:00
|
|
|
if (UNLIKELY(m == nullptr)) {
|
|
|
|
return nullptr;
|
2015-02-20 07:17:36 +01:00
|
|
|
}
|
2011-08-19 16:05:11 +02:00
|
|
|
m->blend = MA_RAMP_BLEND;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-20 19:57:33 +02:00
|
|
|
switch (type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
2017-12-07 05:52:59 +01:00
|
|
|
((LineStyleColorModifier_AlongStroke *)m)->color_ramp = BKE_colorband_add(true);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
2017-12-07 05:52:59 +01:00
|
|
|
((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp = BKE_colorband_add(true);
|
2013-07-19 17:23:42 +02:00
|
|
|
((LineStyleColorModifier_DistanceFromCamera *)m)->range_min = 0.0f;
|
|
|
|
((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
2022-11-18 11:08:39 +01:00
|
|
|
((LineStyleColorModifier_DistanceFromObject *)m)->target = nullptr;
|
2017-12-07 05:52:59 +01:00
|
|
|
((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = BKE_colorband_add(true);
|
2013-07-19 17:23:42 +02:00
|
|
|
((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f;
|
|
|
|
((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
2017-12-07 05:52:59 +01:00
|
|
|
((LineStyleColorModifier_Material *)m)->color_ramp = BKE_colorband_add(true);
|
2014-07-07 08:54:46 +02:00
|
|
|
((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_LINE;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2015-07-10 14:57:23 +02:00
|
|
|
case LS_MODIFIER_TANGENT:
|
2017-12-07 05:52:59 +01:00
|
|
|
((LineStyleColorModifier_Tangent *)m)->color_ramp = BKE_colorband_add(true);
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
2017-12-07 05:52:59 +01:00
|
|
|
((LineStyleColorModifier_Noise *)m)->color_ramp = BKE_colorband_add(true);
|
2015-07-10 14:57:23 +02:00
|
|
|
((LineStyleColorModifier_Noise *)m)->amplitude = 10.0f;
|
|
|
|
((LineStyleColorModifier_Noise *)m)->period = 10.0f;
|
|
|
|
((LineStyleColorModifier_Noise *)m)->seed = 512;
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
2017-12-07 05:52:59 +01:00
|
|
|
((LineStyleColorModifier_CreaseAngle *)m)->color_ramp = BKE_colorband_add(true);
|
2015-07-10 14:57:23 +02:00
|
|
|
((LineStyleColorModifier_CreaseAngle *)m)->min_angle = 0.0f;
|
|
|
|
((LineStyleColorModifier_CreaseAngle *)m)->max_angle = DEG2RADF(180.0f);
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
2017-12-07 05:52:59 +01:00
|
|
|
((LineStyleColorModifier_Curvature_3D *)m)->color_ramp = BKE_colorband_add(true);
|
2015-07-10 14:57:23 +02:00
|
|
|
((LineStyleColorModifier_Curvature_3D *)m)->min_curvature = 0.0f;
|
|
|
|
((LineStyleColorModifier_Curvature_3D *)m)->max_curvature = 0.5f;
|
|
|
|
break;
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->color_modifiers, m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linestyle,
|
|
|
|
const LineStyleModifier *m,
|
|
|
|
const int flag)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
|
|
|
LineStyleModifier *new_m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
new_m = alloc_color_modifier(m->name, m->type);
|
2022-11-18 11:08:39 +01:00
|
|
|
if (UNLIKELY(new_m == nullptr)) {
|
|
|
|
return nullptr;
|
2015-02-20 07:17:36 +01:00
|
|
|
}
|
2011-11-14 01:43:37 +01:00
|
|
|
new_m->influence = m->influence;
|
|
|
|
new_m->flags = m->flags;
|
|
|
|
new_m->blend = m->blend;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
switch (m->type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleColorModifier_AlongStroke *p = (LineStyleColorModifier_AlongStroke *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleColorModifier_AlongStroke *q = (LineStyleColorModifier_AlongStroke *)new_m;
|
2022-11-18 11:08:39 +01:00
|
|
|
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleColorModifier_DistanceFromCamera *p = (LineStyleColorModifier_DistanceFromCamera *)
|
|
|
|
m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleColorModifier_DistanceFromCamera *q = (LineStyleColorModifier_DistanceFromCamera *)
|
|
|
|
new_m;
|
2022-11-18 11:08:39 +01:00
|
|
|
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
|
2013-03-20 00:54:14 +01:00
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)
|
2013-03-20 00:54:14 +01:00
|
|
|
m;
|
|
|
|
LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *)
|
|
|
|
new_m;
|
|
|
|
q->target = p->target;
|
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
|
|
|
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
|
|
|
|
id_us_plus((ID *)q->target);
|
|
|
|
}
|
2022-11-18 11:08:39 +01:00
|
|
|
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
|
2013-03-20 00:54:14 +01:00
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_MATERIAL: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleColorModifier_Material *p = (LineStyleColorModifier_Material *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleColorModifier_Material *q = (LineStyleColorModifier_Material *)new_m;
|
2022-11-18 11:08:39 +01:00
|
|
|
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-03-20 00:54:14 +01:00
|
|
|
q->mat_attr = p->mat_attr;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
case LS_MODIFIER_TANGENT: {
|
|
|
|
LineStyleColorModifier_Tangent *p = (LineStyleColorModifier_Tangent *)m;
|
|
|
|
LineStyleColorModifier_Tangent *q = (LineStyleColorModifier_Tangent *)new_m;
|
2022-11-18 11:08:39 +01:00
|
|
|
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LS_MODIFIER_NOISE: {
|
|
|
|
LineStyleColorModifier_Noise *p = (LineStyleColorModifier_Noise *)m;
|
|
|
|
LineStyleColorModifier_Noise *q = (LineStyleColorModifier_Noise *)new_m;
|
2022-11-18 11:08:39 +01:00
|
|
|
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
|
2015-07-10 14:57:23 +02:00
|
|
|
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;
|
2022-11-18 11:08:39 +01:00
|
|
|
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
|
2015-07-10 14:57:23 +02:00
|
|
|
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;
|
2022-11-18 11:08:39 +01:00
|
|
|
q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp));
|
2015-07-10 14:57:23 +02:00
|
|
|
q->min_curvature = p->min_curvature;
|
|
|
|
q->max_curvature = p->max_curvature;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->color_modifiers, new_m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
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) {
|
2014-05-13 02:15:12 +02:00
|
|
|
return -1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2010-07-20 19:57:33 +02:00
|
|
|
switch (m->type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
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;
|
2015-07-10 14:57:23 +02:00
|
|
|
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;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
BLI_freelinkN(&linestyle->color_modifiers, m);
|
2014-05-13 02:15:12 +02:00
|
|
|
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
|
|
|
{
|
2011-08-19 16:05:11 +02:00
|
|
|
size_t size;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-19 16:05:11 +02:00
|
|
|
switch (type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
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;
|
2015-07-10 14:57:23 +02:00
|
|
|
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;
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
2014-05-13 02:15:12 +02:00
|
|
|
return new_modifier(name, type, size);
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2014-07-17 02:23:30 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyle,
|
|
|
|
const char *name,
|
|
|
|
int type)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
|
|
|
LineStyleModifier *m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
m = alloc_alpha_modifier(name, type);
|
2011-08-19 16:05:11 +02:00
|
|
|
m->blend = LS_VALUE_BLEND;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-20 19:57:33 +02:00
|
|
|
switch (type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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);
|
2013-03-20 00:54:14 +01:00
|
|
|
p->range_min = 0.0f;
|
|
|
|
p->range_max = 10000.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)
|
|
|
|
m;
|
2022-11-18 11:08:39 +01:00
|
|
|
p->target = nullptr;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2013-03-20 00:54:14 +01:00
|
|
|
p->range_min = 0.0f;
|
|
|
|
p->range_max = 10000.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_MATERIAL: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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);
|
2014-10-13 17:53:08 +02:00
|
|
|
p->mat_attr = LS_MODIFIER_MATERIAL_LINE_A;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +02:00
|
|
|
((LineStyleAlphaModifier_Curvature_3D *)m)->min_curvature = 0.0f;
|
|
|
|
((LineStyleAlphaModifier_Curvature_3D *)m)->max_curvature = 0.5f;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->alpha_modifiers, m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
LineStyleModifier *BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linestyle,
|
|
|
|
const LineStyleModifier *m,
|
2022-12-20 19:51:47 +01:00
|
|
|
const int /*flag*/)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
|
|
|
LineStyleModifier *new_m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
new_m = alloc_alpha_modifier(m->name, m->type);
|
2011-11-14 01:43:37 +01:00
|
|
|
new_m->influence = m->influence;
|
|
|
|
new_m->flags = m->flags;
|
|
|
|
new_m->blend = m->blend;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
switch (m->type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleAlphaModifier_AlongStroke *p = (LineStyleAlphaModifier_AlongStroke *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleAlphaModifier_AlongStroke *q = (LineStyleAlphaModifier_AlongStroke *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleAlphaModifier_DistanceFromCamera *p = (LineStyleAlphaModifier_DistanceFromCamera *)
|
|
|
|
m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleAlphaModifier_DistanceFromCamera *q = (LineStyleAlphaModifier_DistanceFromCamera *)
|
|
|
|
new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-03-20 00:54:14 +01:00
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)
|
2013-03-20 00:54:14 +01:00
|
|
|
m;
|
|
|
|
LineStyleAlphaModifier_DistanceFromObject *q = (LineStyleAlphaModifier_DistanceFromObject *)
|
|
|
|
new_m;
|
2019-04-22 01:39:35 +02:00
|
|
|
if (p->target) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&p->target->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2013-03-20 00:54:14 +01:00
|
|
|
q->target = p->target;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-03-20 00:54:14 +01:00
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_MATERIAL: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleAlphaModifier_Material *q = (LineStyleAlphaModifier_Material *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-03-20 00:54:14 +01:00
|
|
|
q->mat_attr = p->mat_attr;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +02:00
|
|
|
q->flags = p->flags;
|
|
|
|
q->min_curvature = p->min_curvature;
|
|
|
|
q->max_curvature = p->max_curvature;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->alpha_modifiers, new_m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
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) {
|
2014-05-13 02:15:12 +02:00
|
|
|
return -1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2010-07-20 19:57:33 +02:00
|
|
|
switch (m->type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_AlongStroke *)m)->curve);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_DistanceFromObject *)m)->curve);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_Material *)m)->curve);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2015-07-10 14:57:23 +02:00
|
|
|
case LS_MODIFIER_TANGENT:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_Tangent *)m)->curve);
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_Noise *)m)->curve);
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_CreaseAngle *)m)->curve);
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleAlphaModifier_Curvature_3D *)m)->curve);
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
BLI_freelinkN(&linestyle->alpha_modifiers, m);
|
2014-05-13 02:15:12 +02:00
|
|
|
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
|
|
|
{
|
2011-08-19 16:05:11 +02:00
|
|
|
size_t size;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-19 16:05:11 +02:00
|
|
|
switch (type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
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;
|
2015-07-10 14:57:23 +02:00
|
|
|
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;
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
return new_modifier(name, type, size);
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2014-07-17 02:23:30 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *linestyle,
|
|
|
|
const char *name,
|
|
|
|
int type)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
|
|
|
LineStyleModifier *m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
m = alloc_thickness_modifier(name, type);
|
2011-08-19 16:05:11 +02:00
|
|
|
m->blend = LS_VALUE_BLEND;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-20 19:57:33 +02:00
|
|
|
switch (type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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);
|
2013-03-20 00:54:14 +01:00
|
|
|
p->value_min = 0.0f;
|
|
|
|
p->value_max = 1.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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);
|
2013-03-20 00:54:14 +01:00
|
|
|
p->range_min = 0.0f;
|
|
|
|
p->range_max = 1000.0f;
|
|
|
|
p->value_min = 0.0f;
|
|
|
|
p->value_max = 1.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleThicknessModifier_DistanceFromObject *p =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromObject *)m;
|
2022-11-18 11:08:39 +01:00
|
|
|
p->target = nullptr;
|
2019-08-06 19:21:55 +02:00
|
|
|
p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
2013-03-20 00:54:14 +01:00
|
|
|
p->range_min = 0.0f;
|
|
|
|
p->range_max = 1000.0f;
|
|
|
|
p->value_min = 0.0f;
|
|
|
|
p->value_max = 1.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_MATERIAL: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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);
|
2014-07-07 08:54:46 +02:00
|
|
|
p->mat_attr = LS_MODIFIER_MATERIAL_LINE;
|
2013-03-20 00:54:14 +01:00
|
|
|
p->value_min = 0.0f;
|
|
|
|
p->value_max = 1.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_CALLIGRAPHY: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m;
|
|
|
|
p->min_thickness = 1.0f;
|
|
|
|
p->max_thickness = 10.0f;
|
|
|
|
p->orientation = DEG2RADF(60.0f);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +02:00
|
|
|
p->min_curvature = 0.0f;
|
|
|
|
p->max_curvature = 0.5f;
|
|
|
|
p->min_thickness = 1.0f;
|
|
|
|
p->max_thickness = 10.0f;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->thickness_modifiers, m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
LineStyleModifier *BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *linestyle,
|
|
|
|
const LineStyleModifier *m,
|
|
|
|
const int flag)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
|
|
|
LineStyleModifier *new_m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
new_m = alloc_thickness_modifier(m->name, m->type);
|
2019-04-22 01:39:35 +02:00
|
|
|
if (!new_m) {
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-11-14 01:43:37 +01:00
|
|
|
new_m->influence = m->influence;
|
|
|
|
new_m->flags = m->flags;
|
|
|
|
new_m->blend = m->blend;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
switch (m->type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleThicknessModifier_AlongStroke *q = (LineStyleThicknessModifier_AlongStroke *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-03-20 00:54:14 +01:00
|
|
|
q->value_min = p->value_min;
|
|
|
|
q->value_max = p->value_max;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleThicknessModifier_DistanceFromCamera *p =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromCamera *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleThicknessModifier_DistanceFromCamera *q =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromCamera *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-03-20 00:54:14 +01:00
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
|
|
|
q->value_min = p->value_min;
|
|
|
|
q->value_max = p->value_max;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleThicknessModifier_DistanceFromObject *p =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromObject *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleThicknessModifier_DistanceFromObject *q =
|
|
|
|
(LineStyleThicknessModifier_DistanceFromObject *)new_m;
|
|
|
|
q->target = p->target;
|
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
|
|
|
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);
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-03-20 00:54:14 +01:00
|
|
|
q->range_min = p->range_min;
|
|
|
|
q->range_max = p->range_max;
|
|
|
|
q->value_min = p->value_min;
|
|
|
|
q->value_max = p->value_max;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_MATERIAL: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleThicknessModifier_Material *q = (LineStyleThicknessModifier_Material *)new_m;
|
2019-08-06 19:21:55 +02:00
|
|
|
q->curve = BKE_curvemapping_copy(p->curve);
|
2013-04-25 18:23:23 +02:00
|
|
|
q->flags = p->flags;
|
2013-03-20 00:54:14 +01:00
|
|
|
q->mat_attr = p->mat_attr;
|
|
|
|
q->value_min = p->value_min;
|
|
|
|
q->value_max = p->value_max;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_CALLIGRAPHY: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleThicknessModifier_Calligraphy *q = (LineStyleThicknessModifier_Calligraphy *)new_m;
|
|
|
|
q->min_thickness = p->min_thickness;
|
|
|
|
q->max_thickness = p->max_thickness;
|
|
|
|
q->orientation = p->orientation;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +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);
|
2015-07-10 14:57:23 +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;
|
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->thickness_modifiers, new_m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
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) {
|
2014-05-13 02:15:12 +02:00
|
|
|
return -1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2010-07-20 19:57:33 +02:00
|
|
|
switch (m->type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_AlongStroke *)m)->curve);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_CAMERA:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_DISTANCE_FROM_OBJECT:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_DistanceFromObject *)m)->curve);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_Material *)m)->curve);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CALLIGRAPHY:
|
|
|
|
break;
|
2015-07-10 14:57:23 +02:00
|
|
|
case LS_MODIFIER_TANGENT:
|
2019-08-06 19:21:55 +02:00
|
|
|
BKE_curvemapping_free(((LineStyleThicknessModifier_Tangent *)m)->curve);
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CURVATURE_3D:
|
|
|
|
break;
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
|
|
|
BLI_freelinkN(&linestyle->thickness_modifiers, m);
|
2014-05-13 02:15:12 +02:00
|
|
|
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
|
|
|
{
|
|
|
|
size_t size;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-19 16:05:11 +02:00
|
|
|
switch (type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
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;
|
2015-07-10 14:57:23 +02:00
|
|
|
case LS_MODIFIER_SIMPLIFICATION:
|
|
|
|
size = sizeof(LineStyleGeometryModifier_Simplification);
|
|
|
|
break;
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
return new_modifier(name, type, size);
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2014-07-17 02:23:30 +02:00
|
|
|
LineStyleModifier *BKE_linestyle_geometry_modifier_add(FreestyleLineStyle *linestyle,
|
|
|
|
const char *name,
|
|
|
|
int type)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
|
|
|
LineStyleModifier *m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
m = alloc_geometry_modifier(name, type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-19 16:05:11 +02:00
|
|
|
switch (type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_SAMPLING: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m;
|
|
|
|
p->sampling = 10.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_BEZIER_CURVE: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m;
|
|
|
|
p->error = 10.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_SINUS_DISPLACEMENT: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_SinusDisplacement *p =
|
|
|
|
(LineStyleGeometryModifier_SinusDisplacement *)m;
|
|
|
|
p->wavelength = 20.0f;
|
|
|
|
p->amplitude = 5.0f;
|
|
|
|
p->phase = 0.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_SPATIAL_NOISE: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_PERLIN_NOISE_1D: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m;
|
|
|
|
p->frequency = 10.0f;
|
|
|
|
p->amplitude = 10.0f;
|
|
|
|
p->octaves = 4;
|
|
|
|
p->angle = DEG2RADF(45.0f);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_PERLIN_NOISE_2D: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m;
|
|
|
|
p->frequency = 10.0f;
|
|
|
|
p->amplitude = 10.0f;
|
|
|
|
p->octaves = 4;
|
|
|
|
p->angle = DEG2RADF(45.0f);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_BACKBONE_STRETCHER: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_BackboneStretcher *p =
|
|
|
|
(LineStyleGeometryModifier_BackboneStretcher *)m;
|
|
|
|
p->backbone_length = 10.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_TIP_REMOVER: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m;
|
|
|
|
p->tip_length = 10.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_POLYGONIZATION: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_Polygonalization *p =
|
|
|
|
(LineStyleGeometryModifier_Polygonalization *)m;
|
|
|
|
p->error = 10.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_GUIDING_LINES: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m;
|
|
|
|
p->offset = 0.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_BLUEPRINT: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_2D_OFFSET: {
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m;
|
|
|
|
p->start = 0.0f;
|
|
|
|
p->end = 0.0f;
|
|
|
|
p->x = 0.0f;
|
|
|
|
p->y = 0.0f;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_2D_TRANSFORM: {
|
2013-03-20 00:54:14 +01:00
|
|
|
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;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2013-03-20 00:54:14 +01:00
|
|
|
}
|
2015-07-12 19:48:08 +02:00
|
|
|
case LS_MODIFIER_SIMPLIFICATION: {
|
|
|
|
LineStyleGeometryModifier_Simplification *p = (LineStyleGeometryModifier_Simplification *)m;
|
|
|
|
p->tolerance = 0.1f;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->geometry_modifiers, m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
LineStyleModifier *BKE_linestyle_geometry_modifier_copy(FreestyleLineStyle *linestyle,
|
|
|
|
const LineStyleModifier *m,
|
2022-12-20 19:51:47 +01:00
|
|
|
const int /*flag*/)
|
2011-11-14 01:43:37 +01:00
|
|
|
{
|
|
|
|
LineStyleModifier *new_m;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-13 02:15:12 +02:00
|
|
|
new_m = alloc_geometry_modifier(m->name, m->type);
|
2011-11-14 01:43:37 +01:00
|
|
|
new_m->flags = m->flags;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
switch (m->type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_SAMPLING: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_Sampling *q = (LineStyleGeometryModifier_Sampling *)new_m;
|
|
|
|
q->sampling = p->sampling;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_BEZIER_CURVE: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_BezierCurve *q = (LineStyleGeometryModifier_BezierCurve *)new_m;
|
|
|
|
q->error = p->error;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_SINUS_DISPLACEMENT: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_SinusDisplacement *p =
|
|
|
|
(LineStyleGeometryModifier_SinusDisplacement *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_SinusDisplacement *q =
|
|
|
|
(LineStyleGeometryModifier_SinusDisplacement *)new_m;
|
|
|
|
q->wavelength = p->wavelength;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->phase = p->phase;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_SPATIAL_NOISE: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_SpatialNoise *p = (LineStyleGeometryModifier_SpatialNoise *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_SpatialNoise *q = (LineStyleGeometryModifier_SpatialNoise *)new_m;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->scale = p->scale;
|
|
|
|
q->octaves = p->octaves;
|
|
|
|
q->flags = p->flags;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_PERLIN_NOISE_1D: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_PerlinNoise1D *q = (LineStyleGeometryModifier_PerlinNoise1D *)
|
|
|
|
new_m;
|
|
|
|
q->frequency = p->frequency;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->angle = p->angle;
|
2013-04-25 18:23:23 +02:00
|
|
|
q->octaves = p->octaves;
|
|
|
|
q->seed = p->seed;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_PERLIN_NOISE_2D: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_PerlinNoise2D *q = (LineStyleGeometryModifier_PerlinNoise2D *)
|
|
|
|
new_m;
|
|
|
|
q->frequency = p->frequency;
|
|
|
|
q->amplitude = p->amplitude;
|
|
|
|
q->angle = p->angle;
|
2013-04-25 18:23:23 +02:00
|
|
|
q->octaves = p->octaves;
|
|
|
|
q->seed = p->seed;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_BACKBONE_STRETCHER: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_BackboneStretcher *p =
|
|
|
|
(LineStyleGeometryModifier_BackboneStretcher *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_BackboneStretcher *q =
|
|
|
|
(LineStyleGeometryModifier_BackboneStretcher *)new_m;
|
|
|
|
q->backbone_length = p->backbone_length;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_TIP_REMOVER: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_TipRemover *q = (LineStyleGeometryModifier_TipRemover *)new_m;
|
|
|
|
q->tip_length = p->tip_length;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_POLYGONIZATION: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_Polygonalization *p =
|
|
|
|
(LineStyleGeometryModifier_Polygonalization *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_Polygonalization *q =
|
|
|
|
(LineStyleGeometryModifier_Polygonalization *)new_m;
|
|
|
|
q->error = p->error;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_GUIDING_LINES: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_GuidingLines *q = (LineStyleGeometryModifier_GuidingLines *)new_m;
|
|
|
|
q->offset = p->offset;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_BLUEPRINT: {
|
2011-11-14 01:43:37 +01:00
|
|
|
LineStyleGeometryModifier_Blueprint *p = (LineStyleGeometryModifier_Blueprint *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
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;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_2D_OFFSET: {
|
2012-01-04 01:23:34 +01:00
|
|
|
LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
LineStyleGeometryModifier_2DOffset *q = (LineStyleGeometryModifier_2DOffset *)new_m;
|
|
|
|
q->start = p->start;
|
|
|
|
q->end = p->end;
|
|
|
|
q->x = p->x;
|
|
|
|
q->y = p->y;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2012-01-04 01:23:34 +01:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
case LS_MODIFIER_2D_TRANSFORM: {
|
2012-01-04 01:23:34 +01:00
|
|
|
LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m;
|
2013-03-20 00:54:14 +01:00
|
|
|
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;
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2012-01-04 01:23:34 +01:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
case LS_MODIFIER_SIMPLIFICATION: {
|
|
|
|
LineStyleGeometryModifier_Simplification *p = (LineStyleGeometryModifier_Simplification *)m;
|
|
|
|
LineStyleGeometryModifier_Simplification *q = (LineStyleGeometryModifier_Simplification *)
|
|
|
|
new_m;
|
|
|
|
q->tolerance = p->tolerance;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
default:
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr; /* unknown modifier type */
|
2011-11-14 01:43:37 +01:00
|
|
|
}
|
|
|
|
add_to_modifier_list(&linestyle->geometry_modifiers, new_m);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 01:43:37 +01:00
|
|
|
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) {
|
2014-05-13 02:15:12 +02:00
|
|
|
return -1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-08-19 16:05:11 +02:00
|
|
|
BLI_freelinkN(&linestyle->geometry_modifiers, m);
|
2014-05-13 02:15:12 +02:00
|
|
|
return 0;
|
2011-08-19 16:05:11 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 21:36:34 +02:00
|
|
|
bool BKE_linestyle_color_modifier_move(FreestyleLineStyle *linestyle,
|
|
|
|
LineStyleModifier *modifier,
|
|
|
|
int direction)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2016-09-18 21:36:34 +02:00
|
|
|
return BLI_listbase_link_move(&linestyle->color_modifiers, modifier, direction);
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
2016-09-18 21:36:34 +02:00
|
|
|
bool BKE_linestyle_alpha_modifier_move(FreestyleLineStyle *linestyle,
|
|
|
|
LineStyleModifier *modifier,
|
|
|
|
int direction)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2016-09-18 21:36:34 +02:00
|
|
|
return BLI_listbase_link_move(&linestyle->alpha_modifiers, modifier, direction);
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
2016-09-18 21:36:34 +02:00
|
|
|
bool BKE_linestyle_thickness_modifier_move(FreestyleLineStyle *linestyle,
|
|
|
|
LineStyleModifier *modifier,
|
|
|
|
int direction)
|
2010-07-20 19:57:33 +02:00
|
|
|
{
|
2016-09-18 21:36:34 +02:00
|
|
|
return BLI_listbase_link_move(&linestyle->thickness_modifiers, modifier, direction);
|
2010-07-20 19:57:33 +02:00
|
|
|
}
|
2016-09-18 21:36:34 +02:00
|
|
|
bool BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle,
|
|
|
|
LineStyleModifier *modifier,
|
|
|
|
int direction)
|
2011-08-19 16:05:11 +02:00
|
|
|
{
|
2016-09-18 21:36:34 +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
|
|
|
{
|
|
|
|
ColorBand *color_ramp;
|
|
|
|
LinkData *link;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-07 20:07:10 +01:00
|
|
|
BLI_listbase_clear(listbase);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) {
|
2010-09-18 02:31:22 +02:00
|
|
|
switch (m->type) {
|
2013-07-19 17:23:42 +02:00
|
|
|
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;
|
2010-09-18 02:31:22 +02:00
|
|
|
}
|
2014-04-09 22:24:33 +02:00
|
|
|
link = (LinkData *)MEM_callocN(sizeof(LinkData), "link to color ramp");
|
2010-09-18 02:31:22 +02:00
|
|
|
link->data = color_ramp;
|
|
|
|
BLI_addtail(listbase, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-03-20 01:08:42 +01:00
|
|
|
bool found = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) {
|
2010-09-18 02:31:22 +02:00
|
|
|
switch (m->type) {
|
2013-04-23 22:10:22 +02:00
|
|
|
case LS_MODIFIER_ALONG_STROKE:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_AlongStroke *)m)->color_ramp) {
|
2013-04-23 22:10:22 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2013-04-23 22:10:22 +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) {
|
2013-04-23 22:10:22 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2013-04-23 22:10:22 +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) {
|
2013-04-23 22:10:22 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2013-04-23 22:10:22 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_MATERIAL:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_Material *)m)->color_ramp) {
|
2013-04-23 22:10:22 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2013-04-23 22:10:22 +02:00
|
|
|
break;
|
2015-07-10 14:57:23 +02:00
|
|
|
case LS_MODIFIER_TANGENT:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_Tangent *)m)->color_ramp) {
|
2015-07-10 14:57:23 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_NOISE:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_Noise *)m)->color_ramp) {
|
2015-07-10 14:57:23 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
|
|
|
case LS_MODIFIER_CREASE_ANGLE:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (color_ramp == ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp) {
|
2015-07-10 14:57:23 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2015-07-10 14:57:23 +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) {
|
2015-07-10 14:57:23 +02:00
|
|
|
found = true;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2015-07-10 14:57:23 +02:00
|
|
|
break;
|
2013-04-23 22:10:22 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-23 22:10:22 +02:00
|
|
|
if (found) {
|
|
|
|
char name_esc[sizeof(m->name) * 2];
|
2020-12-10 03:25:49 +01:00
|
|
|
BLI_str_escape(name_esc, m->name, sizeof(name_esc));
|
2013-04-23 22:10:22 +02:00
|
|
|
return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", name_esc);
|
2010-09-18 02:31:22 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-16 07:13:40 +02:00
|
|
|
printf("BKE_linestyle_path_to_color_ramp: No color ramps correspond to the given pointer.\n");
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
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)
|
|
|
|
{
|
|
|
|
if (use_shading_nodes) {
|
|
|
|
if (linestyle && linestyle->use_nodes && linestyle->nodetree) {
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &linestyle->nodetree->nodes) {
|
2014-07-19 08:33:15 +02:00
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (linestyle && (linestyle->flag & LS_TEXTURE)) {
|
2022-11-18 11:08:39 +01:00
|
|
|
return (linestyle->mtex[0] != nullptr);
|
2014-07-19 08:33:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-16 08:25:10 +02:00
|
|
|
|
|
|
|
void BKE_linestyle_default_shader(const bContext *C, FreestyleLineStyle *linestyle)
|
|
|
|
{
|
2022-03-09 15:02:04 +01:00
|
|
|
bNode *uv_along_stroke, *input_texture, *output_linestyle;
|
2014-07-16 08:25:10 +02:00
|
|
|
bNodeSocket *fromsock, *tosock;
|
|
|
|
bNodeTree *ntree;
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
BLI_assert(linestyle->nodetree == nullptr);
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2023-05-15 15:14:22 +02:00
|
|
|
ntree = blender::bke::ntreeAddTreeEmbedded(
|
|
|
|
nullptr, &linestyle->id, "stroke_shader", "ShaderNodeTree");
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2014-07-20 05:17:22 +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 */
|
|
|
|
|
2022-03-09 15:02:04 +01:00
|
|
|
input_texture = nodeAddStaticNode(C, ntree, SH_NODE_TEX_IMAGE);
|
|
|
|
input_texture->locx = 200.0f;
|
|
|
|
input_texture->locy = 300.0f;
|
2014-07-16 08:25:10 +02:00
|
|
|
|
|
|
|
output_linestyle = nodeAddStaticNode(C, ntree, SH_NODE_OUTPUT_LINESTYLE);
|
2014-07-20 05:17:22 +02:00
|
|
|
output_linestyle->locx = 400.0f;
|
2014-07-16 08:25:10 +02:00
|
|
|
output_linestyle->locy = 300.0f;
|
2014-07-16 15:25:37 +02:00
|
|
|
output_linestyle->custom1 = MA_RAMP_BLEND;
|
|
|
|
output_linestyle->custom2 = 0; /* use_clamp */
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2022-03-09 15:02:04 +01:00
|
|
|
nodeSetActive(ntree, input_texture);
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
fromsock = static_cast<bNodeSocket *>(BLI_findlink(&uv_along_stroke->outputs, 0)); /* UV */
|
|
|
|
tosock = static_cast<bNodeSocket *>(BLI_findlink(&input_texture->inputs, 0)); /* UV */
|
2022-03-09 15:02:04 +01:00
|
|
|
nodeAddLink(ntree, uv_along_stroke, fromsock, input_texture, tosock);
|
2014-07-20 05:17:22 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
fromsock = static_cast<bNodeSocket *>(BLI_findlink(&input_texture->outputs, 0)); /* Color */
|
|
|
|
tosock = static_cast<bNodeSocket *>(BLI_findlink(&output_linestyle->inputs, 0)); /* Color */
|
2022-03-09 15:02:04 +01:00
|
|
|
nodeAddLink(ntree, input_texture, fromsock, output_linestyle, tosock);
|
2014-07-16 08:25:10 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_ntree_update_main_tree(CTX_data_main(C), ntree, nullptr);
|
2014-07-16 08:25:10 +02:00
|
|
|
}
|