Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-02-07 20:55:54 +0300
committerHans Goudey <h.goudey@me.com>2022-02-07 20:56:48 +0300
commitfe1816f67fbc6aaf383ec77847d668367335d093 (patch)
treeb89fc16a38a498c8b8ca96f9c50ee1a765d167fe /source/blender/blenkernel
parentb8c764c5d1fa241a284b985936a96efe0ee23a0f (diff)
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use the name "Curves" to describe the data-block container for multiple curves. Eventually this will replace the existing "Curve" data-block. However, it will be a while before the curve data-block can be replaced so in order to distinguish the two curve types in the UI, "Hair Curves" will be used, but eventually changed back to "Curves". This patch renames "hair-related" files, functions, types, and variable names to this convention. A deep rename is preferred to keep code consistent and to avoid any "hair" terminology from leaking, since the new data-block is meant for all curve types, not just hair use cases. The downside of this naming is that the difference between "Curve" and "Curves" has become important. That was considered during design discussons and deemed acceptable, especially given the non-permanent nature of the somewhat common conflict. Some points of interest: - All DNA compatibility is lost, just like rBf59767ff9729. - I renamed `ID_HA` to `ID_CV` so there is no complete mismatch. - `hair_curves` is used where necessary to distinguish from the existing "curves" plural. - I didn't rename any of the cycles/rendering code function names, since that is also used by the old hair particle system. Differential Revision: https://developer.blender.org/D14007
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_attribute.h4
-rw-r--r--source/blender/blenkernel/BKE_curves.h68
-rw-r--r--source/blender/blenkernel/BKE_hair.h63
-rw-r--r--source/blender/blenkernel/BKE_idtype.h2
-rw-r--r--source/blender/blenkernel/BKE_main.h6
-rw-r--r--source/blender/blenkernel/CMakeLists.txt4
-rw-r--r--source/blender/blenkernel/intern/anim_data.c8
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c4
-rw-r--r--source/blender/blenkernel/intern/attribute.c24
-rw-r--r--source/blender/blenkernel/intern/curves.cc473
-rw-r--r--source/blender/blenkernel/intern/customdata.cc1
-rw-r--r--source/blender/blenkernel/intern/hair.cc474
-rw-r--r--source/blender/blenkernel/intern/idtype.c10
-rw-r--r--source/blender/blenkernel/intern/lib_query.c2
-rw-r--r--source/blender/blenkernel/intern/lib_remap.c2
-rw-r--r--source/blender/blenkernel/intern/main.c6
-rw-r--r--source/blender/blenkernel/intern/material.c26
-rw-r--r--source/blender/blenkernel/intern/object.cc30
-rw-r--r--source/blender/blenkernel/intern/object_update.c10
19 files changed, 612 insertions, 605 deletions
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index 6020da08f51..ff207997e79 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -40,11 +40,11 @@ struct ReportList;
/* Attribute.domain */
typedef enum AttributeDomain {
ATTR_DOMAIN_AUTO = -1, /* Use for nodes to choose automatically based on other data. */
- ATTR_DOMAIN_POINT = 0, /* Mesh, Hair or PointCloud Point */
+ ATTR_DOMAIN_POINT = 0, /* Mesh, Curve or Point Cloud Point */
ATTR_DOMAIN_EDGE = 1, /* Mesh Edge */
ATTR_DOMAIN_FACE = 2, /* Mesh Face */
ATTR_DOMAIN_CORNER = 3, /* Mesh Corner */
- ATTR_DOMAIN_CURVE = 4, /* Hair Curve */
+ ATTR_DOMAIN_CURVE = 4, /* A single curve in a larger curve data-block */
ATTR_DOMAIN_INSTANCE = 5, /* Instance */
ATTR_DOMAIN_NUM
diff --git a/source/blender/blenkernel/BKE_curves.h b/source/blender/blenkernel/BKE_curves.h
new file mode 100644
index 00000000000..99839b20121
--- /dev/null
+++ b/source/blender/blenkernel/BKE_curves.h
@@ -0,0 +1,68 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bke
+ * \brief Low-level operations for curves.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct BoundBox;
+struct CustomDataLayer;
+struct Depsgraph;
+struct Curves;
+struct Main;
+struct Object;
+struct Scene;
+
+void *BKE_curves_add(struct Main *bmain, const char *name);
+
+struct BoundBox *BKE_curves_boundbox_get(struct Object *ob);
+
+void BKE_curves_update_customdata_pointers(struct Curves *curves);
+bool BKE_curves_customdata_required(struct Curves *curves, struct CustomDataLayer *layer);
+
+/* Depsgraph */
+
+struct Curves *BKE_curves_new_for_eval(const struct Curves *curves_src,
+ int totpoint,
+ int totcurve);
+struct Curves *BKE_curves_copy_for_eval(struct Curves *curves_src, bool reference);
+
+void BKE_curves_data_update(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *object);
+
+/* Draw Cache */
+
+enum {
+ BKE_CURVES_BATCH_DIRTY_ALL = 0,
+};
+
+void BKE_curves_batch_cache_dirty_tag(struct Curves *curves, int mode);
+void BKE_curves_batch_cache_free(struct Curves *curves);
+
+extern void (*BKE_curves_batch_cache_dirty_tag_cb)(struct Curves *curves, int mode);
+extern void (*BKE_curves_batch_cache_free_cb)(struct Curves *curves);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
deleted file mode 100644
index 403e461a9dc..00000000000
--- a/source/blender/blenkernel/BKE_hair.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-/** \file
- * \ingroup bke
- * \brief General operations for hairs.
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct BoundBox;
-struct CustomDataLayer;
-struct Depsgraph;
-struct Hair;
-struct Main;
-struct Object;
-struct Scene;
-
-void *BKE_hair_add(struct Main *bmain, const char *name);
-
-struct BoundBox *BKE_hair_boundbox_get(struct Object *ob);
-
-void BKE_hair_update_customdata_pointers(struct Hair *hair);
-bool BKE_hair_customdata_required(struct Hair *hair, struct CustomDataLayer *layer);
-
-/* Depsgraph */
-
-struct Hair *BKE_hair_new_for_eval(const struct Hair *hair_src, int totpoint, int totcurve);
-struct Hair *BKE_hair_copy_for_eval(struct Hair *hair_src, bool reference);
-
-void BKE_hair_data_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *object);
-
-/* Draw Cache */
-
-enum {
- BKE_HAIR_BATCH_DIRTY_ALL = 0,
-};
-
-void BKE_hair_batch_cache_dirty_tag(struct Hair *hair, int mode);
-void BKE_hair_batch_cache_free(struct Hair *hair);
-
-extern void (*BKE_hair_batch_cache_dirty_tag_cb)(struct Hair *hair, int mode);
-extern void (*BKE_hair_batch_cache_free_cb)(struct Hair *hair);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index df50f773a46..e9e5b183e4a 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -278,7 +278,7 @@ extern IDTypeInfo IDType_ID_PC;
extern IDTypeInfo IDType_ID_CF;
extern IDTypeInfo IDType_ID_WS;
extern IDTypeInfo IDType_ID_LP;
-extern IDTypeInfo IDType_ID_HA;
+extern IDTypeInfo IDType_ID_CV;
extern IDTypeInfo IDType_ID_PT;
extern IDTypeInfo IDType_ID_VO;
extern IDTypeInfo IDType_ID_SIM;
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index 4c6eb31db4b..e4f94110eb1 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -182,7 +182,11 @@ typedef struct Main {
ListBase linestyles;
ListBase cachefiles;
ListBase workspaces;
- ListBase hairs;
+ /**
+ * \note The name `hair_curves` is chosen to be different than `curves`,
+ * but they are generic curve data-blocks, not just for hair.
+ */
+ ListBase hair_curves;
ListBase pointclouds;
ListBase volumes;
ListBase simulations;
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 55a68c1c5a0..efc9cd6e99f 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -119,6 +119,7 @@ set(SRC
intern/crazyspace.c
intern/cryptomatte.cc
intern/curve.cc
+ intern/curves.cc
intern/curve_bevel.c
intern/curve_convert.c
intern/curve_decimate.c
@@ -156,7 +157,6 @@ set(SRC
intern/gpencil_curve.c
intern/gpencil_geom.cc
intern/gpencil_modifier.c
- intern/hair.cc
intern/icons.cc
intern/icons_rasterize.c
intern/idprop.c
@@ -356,6 +356,7 @@ set(SRC
BKE_cryptomatte.h
BKE_cryptomatte.hh
BKE_curve.h
+ BKE_curves.h
BKE_curve_to_mesh.hh
BKE_curveprofile.h
BKE_customdata.h
@@ -384,7 +385,6 @@ set(SRC
BKE_gpencil_curve.h
BKE_gpencil_geom.h
BKE_gpencil_modifier.h
- BKE_hair.h
BKE_icons.h
BKE_idprop.h
BKE_idprop.hh
diff --git a/source/blender/blenkernel/intern/anim_data.c b/source/blender/blenkernel/intern/anim_data.c
index 42b72a7cd66..1c0b465d202 100644
--- a/source/blender/blenkernel/intern/anim_data.c
+++ b/source/blender/blenkernel/intern/anim_data.c
@@ -1284,8 +1284,8 @@ void BKE_animdata_main_cb(Main *bmain, ID_AnimData_Edit_Callback func, void *use
/* cache files */
ANIMDATA_IDS_CB(bmain->cachefiles.first);
- /* hairs */
- ANIMDATA_IDS_CB(bmain->hairs.first);
+ /* Hair Curves. */
+ ANIMDATA_IDS_CB(bmain->hair_curves.first);
/* pointclouds */
ANIMDATA_IDS_CB(bmain->pointclouds.first);
@@ -1413,8 +1413,8 @@ void BKE_animdata_fix_paths_rename_all_ex(Main *bmain,
/* cache files */
RENAMEFIX_ANIM_IDS(bmain->cachefiles.first);
- /* hairs */
- RENAMEFIX_ANIM_IDS(bmain->hairs.first);
+ /* Hair Curves. */
+ RENAMEFIX_ANIM_IDS(bmain->hair_curves.first);
/* pointclouds */
RENAMEFIX_ANIM_IDS(bmain->pointclouds.first);
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index b5ea68aaadc..c45856adbda 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -3382,8 +3382,8 @@ void BKE_animsys_evaluate_all_animation(Main *main, Depsgraph *depsgraph, float
/* cache files */
EVAL_ANIM_IDS(main->cachefiles.first, ADT_RECALC_ANIM);
- /* hairs */
- EVAL_ANIM_IDS(main->hairs.first, ADT_RECALC_ANIM);
+ /* Hair Curves. */
+ EVAL_ANIM_IDS(main->hair_curves.first, ADT_RECALC_ANIM);
/* pointclouds */
EVAL_ANIM_IDS(main->pointclouds.first, ADT_RECALC_ANIM);
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index 73e00398084..74eb95add51 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -29,8 +29,8 @@
#include "MEM_guardedalloc.h"
#include "DNA_ID.h"
+#include "DNA_curves_types.h"
#include "DNA_customdata_types.h"
-#include "DNA_hair_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_pointcloud_types.h"
@@ -38,9 +38,9 @@
#include "BLI_string_utf8.h"
#include "BKE_attribute.h"
+#include "BKE_curves.h"
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
-#include "BKE_hair.h"
#include "BKE_pointcloud.h"
#include "BKE_report.h"
@@ -88,12 +88,12 @@ static void get_domains(const ID *id, DomainInfo info[ATTR_DOMAIN_NUM])
}
break;
}
- case ID_HA: {
- Hair *hair = (Hair *)id;
- info[ATTR_DOMAIN_POINT].customdata = &hair->geometry.point_data;
- info[ATTR_DOMAIN_POINT].length = hair->geometry.point_size;
- info[ATTR_DOMAIN_CURVE].customdata = &hair->geometry.curve_data;
- info[ATTR_DOMAIN_CURVE].length = hair->geometry.curve_size;
+ case ID_CV: {
+ Curves *curves = (Curves *)id;
+ info[ATTR_DOMAIN_POINT].customdata = &curves->geometry.point_data;
+ info[ATTR_DOMAIN_POINT].length = curves->geometry.point_size;
+ info[ATTR_DOMAIN_CURVE].customdata = &curves->geometry.curve_data;
+ info[ATTR_DOMAIN_CURVE].length = curves->geometry.curve_size;
break;
}
default:
@@ -301,8 +301,8 @@ bool BKE_id_attribute_required(ID *id, CustomDataLayer *layer)
case ID_PT: {
return BKE_pointcloud_customdata_required((PointCloud *)id, layer);
}
- case ID_HA: {
- return BKE_hair_customdata_required((Hair *)id, layer);
+ case ID_CV: {
+ return BKE_curves_customdata_required((Curves *)id, layer);
}
default:
return false;
@@ -372,8 +372,8 @@ int *BKE_id_attributes_active_index_p(ID *id)
case ID_ME: {
return &((Mesh *)id)->attributes_active_index;
}
- case ID_HA: {
- return &((Hair *)id)->attributes_active_index;
+ case ID_CV: {
+ return &((Curves *)id)->attributes_active_index;
}
default:
return NULL;
diff --git a/source/blender/blenkernel/intern/curves.cc b/source/blender/blenkernel/intern/curves.cc
new file mode 100644
index 00000000000..f5672e9b288
--- /dev/null
+++ b/source/blender/blenkernel/intern/curves.cc
@@ -0,0 +1,473 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include <cmath>
+#include <cstring>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_curves_types.h"
+#include "DNA_defaults.h"
+#include "DNA_material_types.h"
+#include "DNA_object_types.h"
+
+#include "BLI_index_range.hh"
+#include "BLI_listbase.h"
+#include "BLI_math_base.h"
+#include "BLI_math_vec_types.hh"
+#include "BLI_rand.hh"
+#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_anim_data.h"
+#include "BKE_curves.h"
+#include "BKE_customdata.h"
+#include "BKE_global.h"
+#include "BKE_idtype.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_query.h"
+#include "BKE_lib_remap.h"
+#include "BKE_main.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+
+#include "BLT_translation.h"
+
+#include "DEG_depsgraph_query.h"
+
+#include "BLO_read_write.h"
+
+using blender::float3;
+using blender::IndexRange;
+using blender::MutableSpan;
+using blender::RandomNumberGenerator;
+
+static const char *ATTR_POSITION = "position";
+static const char *ATTR_RADIUS = "radius";
+
+static void curves_random(Curves *curves);
+
+static void curves_init_data(ID *id)
+{
+ Curves *curves = (Curves *)id;
+ BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(curves, id));
+
+ MEMCPY_STRUCT_AFTER(curves, DNA_struct_default_get(Curves), id);
+
+ CustomData_reset(&curves->geometry.point_data);
+ CustomData_reset(&curves->geometry.curve_data);
+
+ CustomData_add_layer_named(&curves->geometry.point_data,
+ CD_PROP_FLOAT3,
+ CD_CALLOC,
+ nullptr,
+ curves->geometry.point_size,
+ ATTR_POSITION);
+ CustomData_add_layer_named(&curves->geometry.point_data,
+ CD_PROP_FLOAT,
+ CD_CALLOC,
+ nullptr,
+ curves->geometry.point_size,
+ ATTR_RADIUS);
+
+ BKE_curves_update_customdata_pointers(curves);
+
+ curves_random(curves);
+}
+
+static void curves_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
+{
+ Curves *curves_dst = (Curves *)id_dst;
+ const Curves *curves_src = (const Curves *)id_src;
+ curves_dst->mat = static_cast<Material **>(MEM_dupallocN(curves_src->mat));
+
+ curves_dst->geometry.point_size = curves_src->geometry.point_size;
+ curves_dst->geometry.curve_size = curves_src->geometry.curve_size;
+
+ const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE;
+ CustomData_copy(&curves_src->geometry.point_data,
+ &curves_dst->geometry.point_data,
+ CD_MASK_ALL,
+ alloc_type,
+ curves_dst->geometry.point_size);
+ CustomData_copy(&curves_src->geometry.curve_data,
+ &curves_dst->geometry.curve_data,
+ CD_MASK_ALL,
+ alloc_type,
+ curves_dst->geometry.curve_size);
+ BKE_curves_update_customdata_pointers(curves_dst);
+
+ curves_dst->geometry.offsets = static_cast<int *>(MEM_dupallocN(curves_src->geometry.offsets));
+
+ curves_dst->batch_cache = nullptr;
+}
+
+static void curves_free_data(ID *id)
+{
+ Curves *curves = (Curves *)id;
+ BKE_animdata_free(&curves->id, false);
+
+ BKE_curves_batch_cache_free(curves);
+
+ CustomData_free(&curves->geometry.point_data, curves->geometry.point_size);
+ CustomData_free(&curves->geometry.curve_data, curves->geometry.curve_size);
+
+ MEM_SAFE_FREE(curves->geometry.offsets);
+
+ MEM_SAFE_FREE(curves->mat);
+}
+
+static void curves_foreach_id(ID *id, LibraryForeachIDData *data)
+{
+ Curves *curves = (Curves *)id;
+ for (int i = 0; i < curves->totcol; i++) {
+ BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, curves->mat[i], IDWALK_CB_USER);
+ }
+}
+
+static void curves_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+ Curves *curves = (Curves *)id;
+
+ CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
+ CustomDataLayer *clayers = nullptr, clayers_buff[CD_TEMP_CHUNK_SIZE];
+ CustomData_blend_write_prepare(
+ &curves->geometry.point_data, &players, players_buff, ARRAY_SIZE(players_buff));
+ CustomData_blend_write_prepare(
+ &curves->geometry.curve_data, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
+
+ /* Write LibData */
+ BLO_write_id_struct(writer, Curves, id_address, &curves->id);
+ BKE_id_blend_write(writer, &curves->id);
+
+ /* Direct data */
+ CustomData_blend_write(writer,
+ &curves->geometry.point_data,
+ players,
+ curves->geometry.point_size,
+ CD_MASK_ALL,
+ &curves->id);
+ CustomData_blend_write(writer,
+ &curves->geometry.curve_data,
+ clayers,
+ curves->geometry.curve_size,
+ CD_MASK_ALL,
+ &curves->id);
+
+ BLO_write_int32_array(writer, curves->geometry.curve_size + 1, curves->geometry.offsets);
+
+ BLO_write_pointer_array(writer, curves->totcol, curves->mat);
+ if (curves->adt) {
+ BKE_animdata_blend_write(writer, curves->adt);
+ }
+
+ /* Remove temporary data. */
+ if (players && players != players_buff) {
+ MEM_freeN(players);
+ }
+ if (clayers && clayers != clayers_buff) {
+ MEM_freeN(clayers);
+ }
+}
+
+static void curves_blend_read_data(BlendDataReader *reader, ID *id)
+{
+ Curves *curves = (Curves *)id;
+ BLO_read_data_address(reader, &curves->adt);
+ BKE_animdata_blend_read_data(reader, curves->adt);
+
+ /* Geometry */
+ CustomData_blend_read(reader, &curves->geometry.point_data, curves->geometry.point_size);
+ CustomData_blend_read(reader, &curves->geometry.curve_data, curves->geometry.point_size);
+ BKE_curves_update_customdata_pointers(curves);
+
+ BLO_read_int32_array(reader, curves->geometry.curve_size + 1, &curves->geometry.offsets);
+
+ /* Materials */
+ BLO_read_pointer_array(reader, (void **)&curves->mat);
+}
+
+static void curves_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+ Curves *curves = (Curves *)id;
+ for (int a = 0; a < curves->totcol; a++) {
+ BLO_read_id_address(reader, curves->id.lib, &curves->mat[a]);
+ }
+}
+
+static void curves_blend_read_expand(BlendExpander *expander, ID *id)
+{
+ Curves *curves = (Curves *)id;
+ for (int a = 0; a < curves->totcol; a++) {
+ BLO_expand(expander, curves->mat[a]);
+ }
+}
+
+IDTypeInfo IDType_ID_CV = {
+ /*id_code */ ID_CV,
+ /*id_filter */ FILTER_ID_CV,
+ /*main_listbase_index */ INDEX_ID_CV,
+ /*struct_size */ sizeof(Curves),
+ /*name */ "Hair Curves",
+ /*name_plural */ "Hair Curves",
+ /*translation_context */ BLT_I18NCONTEXT_ID_CURVES,
+ /*flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
+ /*asset_type_info */ nullptr,
+
+ /*init_data */ curves_init_data,
+ /*copy_data */ curves_copy_data,
+ /*free_data */ curves_free_data,
+ /*make_local */ nullptr,
+ /*foreach_id */ curves_foreach_id,
+ /*foreach_cache */ nullptr,
+ /*foreach_path */ nullptr,
+ /*owner_get */ nullptr,
+
+ /*blend_write */ curves_blend_write,
+ /*blend_read_data */ curves_blend_read_data,
+ /*blend_read_lib */ curves_blend_read_lib,
+ /*blend_read_expand */ curves_blend_read_expand,
+
+ /*blend_read_undo_preserve */ nullptr,
+
+ /*lib_override_apply_post */ nullptr,
+};
+
+static void curves_random(Curves *curves)
+{
+ CurvesGeometry &geometry = curves->geometry;
+ const int numpoints = 8;
+
+ geometry.curve_size = 500;
+
+ geometry.curve_size = 500;
+ geometry.point_size = geometry.curve_size * numpoints;
+
+ curves->geometry.offsets = (int *)MEM_calloc_arrayN(
+ curves->geometry.curve_size + 1, sizeof(int), __func__);
+ CustomData_realloc(&geometry.point_data, geometry.point_size);
+ CustomData_realloc(&geometry.curve_data, geometry.curve_size);
+ BKE_curves_update_customdata_pointers(curves);
+
+ MutableSpan<int> offsets{geometry.offsets, geometry.curve_size + 1};
+ MutableSpan<float3> positions{(float3 *)geometry.position, geometry.point_size};
+ MutableSpan<float> radii{geometry.radius, geometry.point_size};
+
+ for (const int i : offsets.index_range()) {
+ geometry.offsets[i] = numpoints * i;
+ }
+
+ RandomNumberGenerator rng;
+
+ for (int i = 0; i < geometry.curve_size; i++) {
+ const IndexRange curve_range(offsets[i], offsets[i + 1] - offsets[i]);
+ MutableSpan<float3> curve_positions = positions.slice(curve_range);
+ MutableSpan<float> curve_radii = radii.slice(curve_range);
+
+ const float theta = 2.0f * M_PI * rng.get_float();
+ const float phi = saacosf(2.0f * rng.get_float() - 1.0f);
+
+ float3 no = {std::sin(theta) * std::sin(phi), std::cos(theta) * std::sin(phi), std::cos(phi)};
+ no = blender::math::normalize(no);
+
+ float3 co = no;
+ for (int key = 0; key < numpoints; key++) {
+ float t = key / (float)(numpoints - 1);
+ curve_positions[key] = co;
+ curve_radii[key] = 0.02f * (1.0f - t);
+
+ float3 offset = float3(rng.get_float(), rng.get_float(), rng.get_float()) * 2.0f - 1.0f;
+ co += (offset + no) / numpoints;
+ }
+ }
+}
+
+void *BKE_curves_add(Main *bmain, const char *name)
+{
+ Curves *curves = static_cast<Curves *>(BKE_id_new(bmain, ID_CV, name));
+
+ return curves;
+}
+
+BoundBox *BKE_curves_boundbox_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_CURVES);
+ Curves *curves = static_cast<Curves *>(ob->data);
+
+ if (ob->runtime.bb != nullptr && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
+ return ob->runtime.bb;
+ }
+
+ if (ob->runtime.bb == nullptr) {
+ ob->runtime.bb = MEM_cnew<BoundBox>(__func__);
+
+ float min[3], max[3];
+ INIT_MINMAX(min, max);
+
+ float(*curves_co)[3] = curves->geometry.position;
+ float *curves_radius = curves->geometry.radius;
+ for (int a = 0; a < curves->geometry.point_size; a++) {
+ float *co = curves_co[a];
+ float radius = (curves_radius) ? curves_radius[a] : 0.0f;
+ const float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
+ const float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
+ DO_MIN(co_min, min);
+ DO_MAX(co_max, max);
+ }
+
+ BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
+ }
+
+ return ob->runtime.bb;
+}
+
+void BKE_curves_update_customdata_pointers(Curves *curves)
+{
+ curves->geometry.position = (float(*)[3])CustomData_get_layer_named(
+ &curves->geometry.point_data, CD_PROP_FLOAT3, ATTR_POSITION);
+ curves->geometry.radius = (float *)CustomData_get_layer_named(
+ &curves->geometry.point_data, CD_PROP_FLOAT, ATTR_RADIUS);
+}
+
+bool BKE_curves_customdata_required(Curves *UNUSED(curves), CustomDataLayer *layer)
+{
+ return layer->type == CD_PROP_FLOAT3 && STREQ(layer->name, ATTR_POSITION);
+}
+
+/* Dependency Graph */
+
+Curves *BKE_curves_new_for_eval(const Curves *curves_src, int totpoint, int totcurve)
+{
+ Curves *curves_dst = static_cast<Curves *>(BKE_id_new_nomain(ID_CV, nullptr));
+
+ STRNCPY(curves_dst->id.name, curves_src->id.name);
+ curves_dst->mat = static_cast<Material **>(MEM_dupallocN(curves_src->mat));
+ curves_dst->totcol = curves_src->totcol;
+
+ curves_dst->geometry.point_size = totpoint;
+ curves_dst->geometry.curve_size = totcurve;
+ CustomData_copy(&curves_src->geometry.point_data,
+ &curves_dst->geometry.point_data,
+ CD_MASK_ALL,
+ CD_CALLOC,
+ totpoint);
+ CustomData_copy(&curves_src->geometry.curve_data,
+ &curves_dst->geometry.curve_data,
+ CD_MASK_ALL,
+ CD_CALLOC,
+ totcurve);
+ BKE_curves_update_customdata_pointers(curves_dst);
+
+ return curves_dst;
+}
+
+Curves *BKE_curves_copy_for_eval(Curves *curves_src, bool reference)
+{
+ int flags = LIB_ID_COPY_LOCALIZE;
+
+ if (reference) {
+ flags |= LIB_ID_COPY_CD_REFERENCE;
+ }
+
+ Curves *result = (Curves *)BKE_id_copy_ex(nullptr, &curves_src->id, nullptr, flags);
+ return result;
+}
+
+static Curves *curves_evaluate_modifiers(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ Object *object,
+ Curves *curves_input)
+{
+ Curves *curves = curves_input;
+
+ /* Modifier evaluation modes. */
+ const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
+ const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime;
+ ModifierApplyFlag apply_flag = use_render ? MOD_APPLY_RENDER : MOD_APPLY_USECACHE;
+ const ModifierEvalContext mectx = {depsgraph, object, apply_flag};
+
+ /* Get effective list of modifiers to execute. Some effects like shape keys
+ * are added as virtual modifiers before the user created modifiers. */
+ VirtualModifierData virtualModifierData;
+ ModifierData *md = BKE_modifiers_get_virtual_modifierlist(object, &virtualModifierData);
+
+ /* Evaluate modifiers. */
+ for (; md; md = md->next) {
+ const ModifierTypeInfo *mti = BKE_modifier_get_info(static_cast<ModifierType>(md->type));
+
+ if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
+ continue;
+ }
+
+ if ((mti->type == eModifierTypeType_OnlyDeform) &&
+ (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) {
+ /* Ensure we are not modifying the input. */
+ if (curves == curves_input) {
+ curves = BKE_curves_copy_for_eval(curves, true);
+ }
+
+ /* Ensure we are not overwriting referenced data. */
+ CustomData_duplicate_referenced_layer_named(&curves->geometry.point_data,
+ CD_PROP_FLOAT3,
+ ATTR_POSITION,
+ curves->geometry.point_size);
+ BKE_curves_update_customdata_pointers(curves);
+
+ /* Created deformed coordinates array on demand. */
+ mti->deformVerts(
+ md, &mectx, nullptr, curves->geometry.position, curves->geometry.point_size);
+ }
+ }
+
+ return curves;
+}
+
+void BKE_curves_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Object *object)
+{
+ /* Free any evaluated data and restore original data. */
+ BKE_object_free_derived_caches(object);
+
+ /* Evaluate modifiers. */
+ Curves *curves = static_cast<Curves *>(object->data);
+ Curves *curves_eval = curves_evaluate_modifiers(depsgraph, scene, object, curves);
+
+ /* Assign evaluated object. */
+ const bool is_owned = (curves != curves_eval);
+ BKE_object_eval_assign_data(object, &curves_eval->id, is_owned);
+}
+
+/* Draw Cache */
+
+void (*BKE_curves_batch_cache_dirty_tag_cb)(Curves *curves, int mode) = nullptr;
+void (*BKE_curves_batch_cache_free_cb)(Curves *curves) = nullptr;
+
+void BKE_curves_batch_cache_dirty_tag(Curves *curves, int mode)
+{
+ if (curves->batch_cache) {
+ BKE_curves_batch_cache_dirty_tag_cb(curves, mode);
+ }
+}
+
+void BKE_curves_batch_cache_free(Curves *curves)
+{
+ if (curves->batch_cache) {
+ BKE_curves_batch_cache_free_cb(curves);
+ }
+}
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 36d511422aa..c5cc077c8ae 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -31,7 +31,6 @@
#include "DNA_ID.h"
#include "DNA_customdata_types.h"
-#include "DNA_hair_types.h"
#include "DNA_meshdata_types.h"
#include "BLI_bitmap.h"
diff --git a/source/blender/blenkernel/intern/hair.cc b/source/blender/blenkernel/intern/hair.cc
deleted file mode 100644
index bddadc3bcfd..00000000000
--- a/source/blender/blenkernel/intern/hair.cc
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup bke
- */
-
-#include <cmath>
-#include <cstring>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_defaults.h"
-#include "DNA_hair_types.h"
-#include "DNA_material_types.h"
-#include "DNA_object_types.h"
-
-#include "BLI_index_range.hh"
-#include "BLI_listbase.h"
-#include "BLI_math_base.h"
-#include "BLI_math_vec_types.hh"
-#include "BLI_rand.hh"
-#include "BLI_string.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_anim_data.h"
-#include "BKE_customdata.h"
-#include "BKE_global.h"
-#include "BKE_hair.h"
-#include "BKE_idtype.h"
-#include "BKE_lib_id.h"
-#include "BKE_lib_query.h"
-#include "BKE_lib_remap.h"
-#include "BKE_main.h"
-#include "BKE_modifier.h"
-#include "BKE_object.h"
-
-#include "BLT_translation.h"
-
-#include "DEG_depsgraph_query.h"
-
-#include "BLO_read_write.h"
-
-using blender::float3;
-using blender::IndexRange;
-using blender::MutableSpan;
-using blender::RandomNumberGenerator;
-
-static const char *HAIR_ATTR_POSITION = "position";
-static const char *HAIR_ATTR_RADIUS = "radius";
-
-/* Hair datablock */
-
-static void hair_random(Hair *hair);
-
-static void hair_init_data(ID *id)
-{
- Hair *hair = (Hair *)id;
- BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(hair, id));
-
- MEMCPY_STRUCT_AFTER(hair, DNA_struct_default_get(Hair), id);
-
- CustomData_reset(&hair->geometry.point_data);
- CustomData_reset(&hair->geometry.curve_data);
-
- CustomData_add_layer_named(&hair->geometry.point_data,
- CD_PROP_FLOAT3,
- CD_CALLOC,
- nullptr,
- hair->geometry.point_size,
- HAIR_ATTR_POSITION);
- CustomData_add_layer_named(&hair->geometry.point_data,
- CD_PROP_FLOAT,
- CD_CALLOC,
- nullptr,
- hair->geometry.point_size,
- HAIR_ATTR_RADIUS);
-
- BKE_hair_update_customdata_pointers(hair);
-
- hair_random(hair);
-}
-
-static void hair_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
-{
- Hair *hair_dst = (Hair *)id_dst;
- const Hair *hair_src = (const Hair *)id_src;
- hair_dst->mat = static_cast<Material **>(MEM_dupallocN(hair_src->mat));
-
- hair_dst->geometry.point_size = hair_src->geometry.point_size;
- hair_dst->geometry.curve_size = hair_src->geometry.curve_size;
-
- const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE;
- CustomData_copy(&hair_src->geometry.point_data,
- &hair_dst->geometry.point_data,
- CD_MASK_ALL,
- alloc_type,
- hair_dst->geometry.point_size);
- CustomData_copy(&hair_src->geometry.curve_data,
- &hair_dst->geometry.curve_data,
- CD_MASK_ALL,
- alloc_type,
- hair_dst->geometry.curve_size);
- BKE_hair_update_customdata_pointers(hair_dst);
-
- hair_dst->geometry.offsets = static_cast<int *>(MEM_dupallocN(hair_src->geometry.offsets));
-
- hair_dst->batch_cache = nullptr;
-}
-
-static void hair_free_data(ID *id)
-{
- Hair *hair = (Hair *)id;
- BKE_animdata_free(&hair->id, false);
-
- BKE_hair_batch_cache_free(hair);
-
- CustomData_free(&hair->geometry.point_data, hair->geometry.point_size);
- CustomData_free(&hair->geometry.curve_data, hair->geometry.curve_size);
-
- MEM_SAFE_FREE(hair->geometry.offsets);
-
- MEM_SAFE_FREE(hair->mat);
-}
-
-static void hair_foreach_id(ID *id, LibraryForeachIDData *data)
-{
- Hair *hair = (Hair *)id;
- for (int i = 0; i < hair->totcol; i++) {
- BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, hair->mat[i], IDWALK_CB_USER);
- }
-}
-
-static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address)
-{
- Hair *hair = (Hair *)id;
-
- CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
- CustomDataLayer *clayers = nullptr, clayers_buff[CD_TEMP_CHUNK_SIZE];
- CustomData_blend_write_prepare(
- &hair->geometry.point_data, &players, players_buff, ARRAY_SIZE(players_buff));
- CustomData_blend_write_prepare(
- &hair->geometry.curve_data, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
-
- /* Write LibData */
- BLO_write_id_struct(writer, Hair, id_address, &hair->id);
- BKE_id_blend_write(writer, &hair->id);
-
- /* Direct data */
- CustomData_blend_write(writer,
- &hair->geometry.point_data,
- players,
- hair->geometry.point_size,
- CD_MASK_ALL,
- &hair->id);
- CustomData_blend_write(writer,
- &hair->geometry.curve_data,
- clayers,
- hair->geometry.curve_size,
- CD_MASK_ALL,
- &hair->id);
-
- BLO_write_int32_array(writer, hair->geometry.curve_size + 1, hair->geometry.offsets);
-
- BLO_write_pointer_array(writer, hair->totcol, hair->mat);
- if (hair->adt) {
- BKE_animdata_blend_write(writer, hair->adt);
- }
-
- /* Remove temporary data. */
- if (players && players != players_buff) {
- MEM_freeN(players);
- }
- if (clayers && clayers != clayers_buff) {
- MEM_freeN(clayers);
- }
-}
-
-static void hair_blend_read_data(BlendDataReader *reader, ID *id)
-{
- Hair *hair = (Hair *)id;
- BLO_read_data_address(reader, &hair->adt);
- BKE_animdata_blend_read_data(reader, hair->adt);
-
- /* Geometry */
- CustomData_blend_read(reader, &hair->geometry.point_data, hair->geometry.point_size);
- CustomData_blend_read(reader, &hair->geometry.curve_data, hair->geometry.point_size);
- BKE_hair_update_customdata_pointers(hair);
-
- BLO_read_int32_array(reader, hair->geometry.curve_size + 1, &hair->geometry.offsets);
-
- /* Materials */
- BLO_read_pointer_array(reader, (void **)&hair->mat);
-}
-
-static void hair_blend_read_lib(BlendLibReader *reader, ID *id)
-{
- Hair *hair = (Hair *)id;
- for (int a = 0; a < hair->totcol; a++) {
- BLO_read_id_address(reader, hair->id.lib, &hair->mat[a]);
- }
-}
-
-static void hair_blend_read_expand(BlendExpander *expander, ID *id)
-{
- Hair *hair = (Hair *)id;
- for (int a = 0; a < hair->totcol; a++) {
- BLO_expand(expander, hair->mat[a]);
- }
-}
-
-IDTypeInfo IDType_ID_HA = {
- /*id_code */ ID_HA,
- /*id_filter */ FILTER_ID_HA,
- /*main_listbase_index */ INDEX_ID_HA,
- /*struct_size */ sizeof(Hair),
- /*name */ "Hair",
- /*name_plural */ "hairs",
- /*translation_context */ BLT_I18NCONTEXT_ID_HAIR,
- /*flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
- /*asset_type_info */ nullptr,
-
- /*init_data */ hair_init_data,
- /*copy_data */ hair_copy_data,
- /*free_data */ hair_free_data,
- /*make_local */ nullptr,
- /*foreach_id */ hair_foreach_id,
- /*foreach_cache */ nullptr,
- /*foreach_path */ nullptr,
- /*owner_get */ nullptr,
-
- /*blend_write */ hair_blend_write,
- /*blend_read_data */ hair_blend_read_data,
- /*blend_read_lib */ hair_blend_read_lib,
- /*blend_read_expand */ hair_blend_read_expand,
-
- /*blend_read_undo_preserve */ nullptr,
-
- /*lib_override_apply_post */ nullptr,
-};
-
-static void hair_random(Hair *hair)
-{
- CurvesGeometry &geometry = hair->geometry;
- const int numpoints = 8;
-
- geometry.curve_size = 500;
-
- geometry.curve_size = 500;
- geometry.point_size = geometry.curve_size * numpoints;
-
- hair->geometry.offsets = (int *)MEM_calloc_arrayN(
- hair->geometry.curve_size + 1, sizeof(int), __func__);
- CustomData_realloc(&geometry.point_data, geometry.point_size);
- CustomData_realloc(&geometry.curve_data, geometry.curve_size);
- BKE_hair_update_customdata_pointers(hair);
-
- MutableSpan<int> offsets{geometry.offsets, geometry.curve_size + 1};
- MutableSpan<float3> positions{(float3 *)geometry.position, geometry.point_size};
- MutableSpan<float> radii{geometry.radius, geometry.point_size};
-
- for (const int i : offsets.index_range()) {
- geometry.offsets[i] = numpoints * i;
- }
-
- RandomNumberGenerator rng;
-
- for (int i = 0; i < geometry.curve_size; i++) {
- const IndexRange curve_range(offsets[i], offsets[i + 1] - offsets[i]);
- MutableSpan<float3> curve_positions = positions.slice(curve_range);
- MutableSpan<float> curve_radii = radii.slice(curve_range);
-
- const float theta = 2.0f * M_PI * rng.get_float();
- const float phi = saacosf(2.0f * rng.get_float() - 1.0f);
-
- float3 no = {std::sin(theta) * std::sin(phi), std::cos(theta) * std::sin(phi), std::cos(phi)};
- no = blender::math::normalize(no);
-
- float3 co = no;
- for (int key = 0; key < numpoints; key++) {
- float t = key / (float)(numpoints - 1);
- curve_positions[key] = co;
- curve_radii[key] = 0.02f * (1.0f - t);
-
- float3 offset = float3(rng.get_float(), rng.get_float(), rng.get_float()) * 2.0f - 1.0f;
- co += (offset + no) / numpoints;
- }
- }
-}
-
-void *BKE_hair_add(Main *bmain, const char *name)
-{
- Hair *hair = static_cast<Hair *>(BKE_id_new(bmain, ID_HA, name));
-
- return hair;
-}
-
-BoundBox *BKE_hair_boundbox_get(Object *ob)
-{
- BLI_assert(ob->type == OB_HAIR);
- Hair *hair = static_cast<Hair *>(ob->data);
-
- if (ob->runtime.bb != nullptr && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
- return ob->runtime.bb;
- }
-
- if (ob->runtime.bb == nullptr) {
- ob->runtime.bb = MEM_cnew<BoundBox>(__func__);
-
- float min[3], max[3];
- INIT_MINMAX(min, max);
-
- float(*hair_co)[3] = hair->geometry.position;
- float *hair_radius = hair->geometry.radius;
- for (int a = 0; a < hair->geometry.point_size; a++) {
- float *co = hair_co[a];
- float radius = (hair_radius) ? hair_radius[a] : 0.0f;
- const float co_min[3] = {co[0] - radius, co[1] - radius, co[2] - radius};
- const float co_max[3] = {co[0] + radius, co[1] + radius, co[2] + radius};
- DO_MIN(co_min, min);
- DO_MAX(co_max, max);
- }
-
- BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
- }
-
- return ob->runtime.bb;
-}
-
-void BKE_hair_update_customdata_pointers(Hair *hair)
-{
- hair->geometry.position = (float(*)[3])CustomData_get_layer_named(
- &hair->geometry.point_data, CD_PROP_FLOAT3, HAIR_ATTR_POSITION);
- hair->geometry.radius = (float *)CustomData_get_layer_named(
- &hair->geometry.point_data, CD_PROP_FLOAT, HAIR_ATTR_RADIUS);
-}
-
-bool BKE_hair_customdata_required(Hair *UNUSED(hair), CustomDataLayer *layer)
-{
- return layer->type == CD_PROP_FLOAT3 && STREQ(layer->name, HAIR_ATTR_POSITION);
-}
-
-/* Dependency Graph */
-
-Hair *BKE_hair_new_for_eval(const Hair *hair_src, int totpoint, int totcurve)
-{
- Hair *hair_dst = static_cast<Hair *>(BKE_id_new_nomain(ID_HA, nullptr));
-
- STRNCPY(hair_dst->id.name, hair_src->id.name);
- hair_dst->mat = static_cast<Material **>(MEM_dupallocN(hair_src->mat));
- hair_dst->totcol = hair_src->totcol;
-
- hair_dst->geometry.point_size = totpoint;
- hair_dst->geometry.curve_size = totcurve;
- CustomData_copy(&hair_src->geometry.point_data,
- &hair_dst->geometry.point_data,
- CD_MASK_ALL,
- CD_CALLOC,
- totpoint);
- CustomData_copy(&hair_src->geometry.curve_data,
- &hair_dst->geometry.curve_data,
- CD_MASK_ALL,
- CD_CALLOC,
- totcurve);
- BKE_hair_update_customdata_pointers(hair_dst);
-
- return hair_dst;
-}
-
-Hair *BKE_hair_copy_for_eval(Hair *hair_src, bool reference)
-{
- int flags = LIB_ID_COPY_LOCALIZE;
-
- if (reference) {
- flags |= LIB_ID_COPY_CD_REFERENCE;
- }
-
- Hair *result = (Hair *)BKE_id_copy_ex(nullptr, &hair_src->id, nullptr, flags);
- return result;
-}
-
-static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph,
- struct Scene *scene,
- Object *object,
- Hair *hair_input)
-{
- Hair *hair = hair_input;
-
- /* Modifier evaluation modes. */
- const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
- const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime;
- ModifierApplyFlag apply_flag = use_render ? MOD_APPLY_RENDER : MOD_APPLY_USECACHE;
- const ModifierEvalContext mectx = {depsgraph, object, apply_flag};
-
- /* Get effective list of modifiers to execute. Some effects like shape keys
- * are added as virtual modifiers before the user created modifiers. */
- VirtualModifierData virtualModifierData;
- ModifierData *md = BKE_modifiers_get_virtual_modifierlist(object, &virtualModifierData);
-
- /* Evaluate modifiers. */
- for (; md; md = md->next) {
- const ModifierTypeInfo *mti = BKE_modifier_get_info(static_cast<ModifierType>(md->type));
-
- if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
- continue;
- }
-
- if ((mti->type == eModifierTypeType_OnlyDeform) &&
- (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) {
- /* Ensure we are not modifying the input. */
- if (hair == hair_input) {
- hair = BKE_hair_copy_for_eval(hair, true);
- }
-
- /* Ensure we are not overwriting referenced data. */
- CustomData_duplicate_referenced_layer_named(&hair->geometry.point_data,
- CD_PROP_FLOAT3,
- HAIR_ATTR_POSITION,
- hair->geometry.point_size);
- BKE_hair_update_customdata_pointers(hair);
-
- /* Created deformed coordinates array on demand. */
- mti->deformVerts(md, &mectx, nullptr, hair->geometry.position, hair->geometry.point_size);
- }
- }
-
- return hair;
-}
-
-void BKE_hair_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Object *object)
-{
- /* Free any evaluated data and restore original data. */
- BKE_object_free_derived_caches(object);
-
- /* Evaluate modifiers. */
- Hair *hair = static_cast<Hair *>(object->data);
- Hair *hair_eval = hair_evaluate_modifiers(depsgraph, scene, object, hair);
-
- /* Assign evaluated object. */
- const bool is_owned = (hair != hair_eval);
- BKE_object_eval_assign_data(object, &hair_eval->id, is_owned);
-}
-
-/* Draw Cache */
-
-void (*BKE_hair_batch_cache_dirty_tag_cb)(Hair *hair, int mode) = nullptr;
-void (*BKE_hair_batch_cache_free_cb)(Hair *hair) = nullptr;
-
-void BKE_hair_batch_cache_dirty_tag(Hair *hair, int mode)
-{
- if (hair->batch_cache) {
- BKE_hair_batch_cache_dirty_tag_cb(hair, mode);
- }
-}
-
-void BKE_hair_batch_cache_free(Hair *hair)
-{
- if (hair->batch_cache) {
- BKE_hair_batch_cache_free_cb(hair);
- }
-}
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index e6fd6c14d42..e9c8df76351 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -110,7 +110,7 @@ static void id_type_init(void)
INIT_TYPE(ID_CF);
INIT_TYPE(ID_WS);
INIT_TYPE(ID_LP);
- INIT_TYPE(ID_HA);
+ INIT_TYPE(ID_CV);
INIT_TYPE(ID_PT);
INIT_TYPE(ID_VO);
INIT_TYPE(ID_SIM);
@@ -237,7 +237,7 @@ uint64_t BKE_idtype_idcode_to_idfilter(const short idcode)
CASE_IDFILTER(CU);
CASE_IDFILTER(GD);
CASE_IDFILTER(GR);
- CASE_IDFILTER(HA);
+ CASE_IDFILTER(CV);
CASE_IDFILTER(IM);
CASE_IDFILTER(LA);
CASE_IDFILTER(LS);
@@ -286,7 +286,7 @@ short BKE_idtype_idcode_from_idfilter(const uint64_t idfilter)
CASE_IDFILTER(CU);
CASE_IDFILTER(GD);
CASE_IDFILTER(GR);
- CASE_IDFILTER(HA);
+ CASE_IDFILTER(CV);
CASE_IDFILTER(IM);
CASE_IDFILTER(LA);
CASE_IDFILTER(LS);
@@ -334,7 +334,7 @@ int BKE_idtype_idcode_to_index(const short idcode)
CASE_IDINDEX(CU);
CASE_IDINDEX(GD);
CASE_IDINDEX(GR);
- CASE_IDINDEX(HA);
+ CASE_IDINDEX(CV);
CASE_IDINDEX(IM);
CASE_IDINDEX(IP);
CASE_IDINDEX(KE);
@@ -393,7 +393,7 @@ short BKE_idtype_idcode_from_index(const int index)
CASE_IDCODE(CU);
CASE_IDCODE(GD);
CASE_IDCODE(GR);
- CASE_IDCODE(HA);
+ CASE_IDCODE(CV);
CASE_IDCODE(IM);
CASE_IDCODE(IP);
CASE_IDCODE(KE);
diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index e73b53c4bf8..f69fba5b540 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -471,7 +471,7 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
return ELEM(id_type_used, ID_MA);
case ID_WS:
return ELEM(id_type_used, ID_SCR, ID_SCE);
- case ID_HA:
+ case ID_CV:
return ELEM(id_type_used, ID_MA);
case ID_PT:
return ELEM(id_type_used, ID_MA);
diff --git a/source/blender/blenkernel/intern/lib_remap.c b/source/blender/blenkernel/intern/lib_remap.c
index e4e0466416a..a9de5b4a189 100644
--- a/source/blender/blenkernel/intern/lib_remap.c
+++ b/source/blender/blenkernel/intern/lib_remap.c
@@ -558,7 +558,7 @@ static void libblock_remap_foreach_idpair_cb(ID *old_id, ID *new_id, void *user_
case ID_ME:
case ID_CU:
case ID_MB:
- case ID_HA:
+ case ID_CV:
case ID_PT:
case ID_VO:
if (new_id) { /* Only affects us in case obdata was relinked (changed). */
diff --git a/source/blender/blenkernel/intern/main.c b/source/blender/blenkernel/intern/main.c
index 64731be57ac..53b1a9c9e16 100644
--- a/source/blender/blenkernel/intern/main.c
+++ b/source/blender/blenkernel/intern/main.c
@@ -643,8 +643,8 @@ ListBase *which_libbase(Main *bmain, short type)
return &(bmain->cachefiles);
case ID_WS:
return &(bmain->workspaces);
- case ID_HA:
- return &(bmain->hairs);
+ case ID_CV:
+ return &(bmain->hair_curves);
case ID_PT:
return &(bmain->pointclouds);
case ID_VO:
@@ -688,7 +688,7 @@ int set_listbasepointers(Main *bmain, ListBase *lb[/*INDEX_ID_MAX*/])
lb[INDEX_ID_ME] = &(bmain->meshes);
lb[INDEX_ID_CU] = &(bmain->curves);
lb[INDEX_ID_MB] = &(bmain->metaballs);
- lb[INDEX_ID_HA] = &(bmain->hairs);
+ lb[INDEX_ID_CV] = &(bmain->hair_curves);
lb[INDEX_ID_PT] = &(bmain->pointclouds);
lb[INDEX_ID_VO] = &(bmain->volumes);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 15469f910b4..1c1b2c2cd27 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -36,10 +36,10 @@
#include "DNA_anim_types.h"
#include "DNA_collection_types.h"
#include "DNA_curve_types.h"
+#include "DNA_curves_types.h"
#include "DNA_customdata_types.h"
#include "DNA_defaults.h"
#include "DNA_gpencil_types.h"
-#include "DNA_hair_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -341,9 +341,9 @@ Material ***BKE_object_material_array_p(Object *ob)
bGPdata *gpd = ob->data;
return &(gpd->mat);
}
- if (ob->type == OB_HAIR) {
- Hair *hair = ob->data;
- return &(hair->mat);
+ if (ob->type == OB_CURVES) {
+ Curves *curves = ob->data;
+ return &(curves->mat);
}
if (ob->type == OB_POINTCLOUD) {
PointCloud *pointcloud = ob->data;
@@ -374,9 +374,9 @@ short *BKE_object_material_len_p(Object *ob)
bGPdata *gpd = ob->data;
return &(gpd->totcol);
}
- if (ob->type == OB_HAIR) {
- Hair *hair = ob->data;
- return &(hair->totcol);
+ if (ob->type == OB_CURVES) {
+ Curves *curves = ob->data;
+ return &(curves->totcol);
}
if (ob->type == OB_POINTCLOUD) {
PointCloud *pointcloud = ob->data;
@@ -403,8 +403,8 @@ Material ***BKE_id_material_array_p(ID *id)
return &(((MetaBall *)id)->mat);
case ID_GD:
return &(((bGPdata *)id)->mat);
- case ID_HA:
- return &(((Hair *)id)->mat);
+ case ID_CV:
+ return &(((Curves *)id)->mat);
case ID_PT:
return &(((PointCloud *)id)->mat);
case ID_VO:
@@ -429,8 +429,8 @@ short *BKE_id_material_len_p(ID *id)
return &(((MetaBall *)id)->totcol);
case ID_GD:
return &(((bGPdata *)id)->totcol);
- case ID_HA:
- return &(((Hair *)id)->totcol);
+ case ID_CV:
+ return &(((Curves *)id)->totcol);
case ID_PT:
return &(((PointCloud *)id)->totcol);
case ID_VO:
@@ -454,7 +454,7 @@ static void material_data_index_remove_id(ID *id, short index)
BKE_curve_material_index_remove((Curve *)id, index);
break;
case ID_MB:
- case ID_HA:
+ case ID_CV:
case ID_PT:
case ID_VO:
/* No material indices for these object data types. */
@@ -509,7 +509,7 @@ static void material_data_index_clear_id(ID *id)
BKE_curve_material_index_clear((Curve *)id);
break;
case ID_MB:
- case ID_HA:
+ case ID_CV:
case ID_PT:
case ID_VO:
/* No material indices for these object data types. */
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 04d60c096f2..8faae6efb26 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -89,6 +89,7 @@
#include "BKE_constraint.h"
#include "BKE_crazyspace.h"
#include "BKE_curve.h"
+#include "BKE_curves.h"
#include "BKE_deform.h"
#include "BKE_displist.h"
#include "BKE_duplilist.h"
@@ -103,7 +104,6 @@
#include "BKE_gpencil.h"
#include "BKE_gpencil_geom.h"
#include "BKE_gpencil_modifier.h"
-#include "BKE_hair.h"
#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_idtype.h"
@@ -1415,7 +1415,7 @@ bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
}
/* Only geometry objects should be able to get modifiers T25291. */
- if (ELEM(ob->type, OB_POINTCLOUD, OB_VOLUME, OB_HAIR)) {
+ if (ELEM(ob->type, OB_POINTCLOUD, OB_VOLUME, OB_CURVES)) {
return (mti->modifyGeometrySet != nullptr);
}
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
@@ -2098,8 +2098,8 @@ static const char *get_obdata_defname(int type)
return DATA_("Armature");
case OB_SPEAKER:
return DATA_("Speaker");
- case OB_HAIR:
- return DATA_("Hair");
+ case OB_CURVES:
+ return DATA_("HairCurves");
case OB_POINTCLOUD:
return DATA_("PointCloud");
case OB_VOLUME:
@@ -2173,8 +2173,8 @@ void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
return BKE_lightprobe_add(bmain, name);
case OB_GPENCIL:
return BKE_gpencil_data_addnew(bmain, name);
- case OB_HAIR:
- return BKE_hair_add(bmain, name);
+ case OB_CURVES:
+ return BKE_curves_add(bmain, name);
case OB_POINTCLOUD:
return BKE_pointcloud_add_default(bmain, name);
case OB_VOLUME:
@@ -2211,8 +2211,8 @@ int BKE_object_obdata_to_type(const ID *id)
return OB_ARMATURE;
case ID_LP:
return OB_LIGHTPROBE;
- case ID_HA:
- return OB_HAIR;
+ case ID_CV:
+ return OB_CURVES;
case ID_PT:
return OB_POINTCLOUD;
case ID_VO:
@@ -2729,8 +2729,8 @@ Object *BKE_object_duplicate(Main *bmain, Object *ob, uint dupflag, uint duplica
id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
}
break;
- case OB_HAIR:
- if (dupflag & USER_DUP_HAIR) {
+ case OB_CURVES:
+ if (dupflag & USER_DUP_CURVES) {
id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
}
break;
@@ -3624,8 +3624,8 @@ BoundBox *BKE_object_boundbox_get(Object *ob)
case OB_GPENCIL:
bb = BKE_gpencil_boundbox_get(ob);
break;
- case OB_HAIR:
- bb = BKE_hair_boundbox_get(ob);
+ case OB_CURVES:
+ bb = BKE_curves_boundbox_get(ob);
break;
case OB_POINTCLOUD:
bb = BKE_pointcloud_boundbox_get(ob);
@@ -3826,8 +3826,8 @@ void BKE_object_minmax(Object *ob, float r_min[3], float r_max[3], const bool us
}
break;
}
- case OB_HAIR: {
- BoundBox bb = *BKE_hair_boundbox_get(ob);
+ case OB_CURVES: {
+ BoundBox bb = *BKE_curves_boundbox_get(ob);
BKE_boundbox_minmax(&bb, ob->obmat, r_min, r_max);
changed = true;
break;
@@ -4941,7 +4941,7 @@ bool BKE_object_supports_material_slots(struct Object *ob)
OB_SURF,
OB_FONT,
OB_MBALL,
- OB_HAIR,
+ OB_CURVES,
OB_POINTCLOUD,
OB_VOLUME,
OB_GPENCIL);
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 9c2b48303b2..803dde50d96 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -41,12 +41,12 @@
#include "BKE_armature.h"
#include "BKE_constraint.h"
#include "BKE_curve.h"
+#include "BKE_curves.h"
#include "BKE_displist.h"
#include "BKE_editmesh.h"
#include "BKE_effect.h"
#include "BKE_gpencil.h"
#include "BKE_gpencil_modifier.h"
-#include "BKE_hair.h"
#include "BKE_image.h"
#include "BKE_key.h"
#include "BKE_lattice.h"
@@ -214,8 +214,8 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *o
BKE_gpencil_update_layer_transforms(depsgraph, ob);
break;
}
- case OB_HAIR:
- BKE_hair_data_update(depsgraph, scene, ob);
+ case OB_CURVES:
+ BKE_curves_data_update(depsgraph, scene, ob);
break;
case OB_POINTCLOUD:
BKE_pointcloud_data_update(depsgraph, scene, ob);
@@ -326,8 +326,8 @@ void BKE_object_data_batch_cache_dirty_tag(ID *object_data)
case ID_GD:
BKE_gpencil_batch_cache_dirty_tag((struct bGPdata *)object_data);
break;
- case ID_HA:
- BKE_hair_batch_cache_dirty_tag((struct Hair *)object_data, BKE_HAIR_BATCH_DIRTY_ALL);
+ case ID_CV:
+ BKE_curves_batch_cache_dirty_tag((struct Curves *)object_data, BKE_CURVES_BATCH_DIRTY_ALL);
break;
case ID_PT:
BKE_pointcloud_batch_cache_dirty_tag((struct PointCloud *)object_data,