Cleanup: Move hair object type files to C++
Differential Revision: https://developer.blender.org/D13657
This commit is contained in:
parent
05f900e346
commit
582f6032fc
|
@ -156,7 +156,7 @@ set(SRC
|
|||
intern/gpencil_curve.c
|
||||
intern/gpencil_geom.cc
|
||||
intern/gpencil_modifier.c
|
||||
intern/hair.c
|
||||
intern/hair.cc
|
||||
intern/icons.cc
|
||||
intern/icons_rasterize.c
|
||||
intern/idprop.c
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
* \ingroup bke
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_defaults.h"
|
||||
|
@ -25,8 +28,9 @@
|
|||
#include "DNA_material_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "BLI_float3.hh"
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_math_base.h"
|
||||
#include "BLI_rand.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
@ -49,6 +53,8 @@
|
|||
|
||||
#include "BLO_read_write.h"
|
||||
|
||||
using blender::float3;
|
||||
|
||||
static const char *HAIR_ATTR_POSITION = "position";
|
||||
static const char *HAIR_ATTR_RADIUS = "radius";
|
||||
|
||||
|
@ -67,10 +73,10 @@ static void hair_init_data(ID *id)
|
|||
CustomData_reset(&hair->cdata);
|
||||
|
||||
CustomData_add_layer_named(
|
||||
&hair->pdata, CD_PROP_FLOAT3, CD_CALLOC, NULL, hair->totpoint, HAIR_ATTR_POSITION);
|
||||
&hair->pdata, CD_PROP_FLOAT3, CD_CALLOC, nullptr, hair->totpoint, HAIR_ATTR_POSITION);
|
||||
CustomData_add_layer_named(
|
||||
&hair->pdata, CD_PROP_FLOAT, CD_CALLOC, NULL, hair->totpoint, HAIR_ATTR_RADIUS);
|
||||
CustomData_add_layer(&hair->cdata, CD_HAIRCURVE, CD_CALLOC, NULL, hair->totcurve);
|
||||
&hair->pdata, CD_PROP_FLOAT, CD_CALLOC, nullptr, hair->totpoint, HAIR_ATTR_RADIUS);
|
||||
CustomData_add_layer(&hair->cdata, CD_HAIRCURVE, CD_CALLOC, nullptr, hair->totcurve);
|
||||
BKE_hair_update_customdata_pointers(hair);
|
||||
|
||||
hair_random(hair);
|
||||
|
@ -80,14 +86,14 @@ static void hair_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, co
|
|||
{
|
||||
Hair *hair_dst = (Hair *)id_dst;
|
||||
const Hair *hair_src = (const Hair *)id_src;
|
||||
hair_dst->mat = MEM_dupallocN(hair_src->mat);
|
||||
hair_dst->mat = static_cast<Material **>(MEM_dupallocN(hair_src->mat));
|
||||
|
||||
const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE;
|
||||
CustomData_copy(&hair_src->pdata, &hair_dst->pdata, CD_MASK_ALL, alloc_type, hair_dst->totpoint);
|
||||
CustomData_copy(&hair_src->cdata, &hair_dst->cdata, CD_MASK_ALL, alloc_type, hair_dst->totcurve);
|
||||
BKE_hair_update_customdata_pointers(hair_dst);
|
||||
|
||||
hair_dst->batch_cache = NULL;
|
||||
hair_dst->batch_cache = nullptr;
|
||||
}
|
||||
|
||||
static void hair_free_data(ID *id)
|
||||
|
@ -115,8 +121,8 @@ static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address
|
|||
{
|
||||
Hair *hair = (Hair *)id;
|
||||
|
||||
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
|
||||
CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
|
||||
CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
|
||||
CustomDataLayer *clayers = nullptr, clayers_buff[CD_TEMP_CHUNK_SIZE];
|
||||
CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
|
||||
CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
|
||||
|
||||
|
@ -174,33 +180,33 @@ static void hair_blend_read_expand(BlendExpander *expander, ID *id)
|
|||
}
|
||||
|
||||
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 = NULL,
|
||||
/*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 = NULL,
|
||||
.foreach_id = hair_foreach_id,
|
||||
.foreach_cache = NULL,
|
||||
.foreach_path = NULL,
|
||||
.owner_get = NULL,
|
||||
/*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_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 = NULL,
|
||||
/*blend_read_undo_preserve */ nullptr,
|
||||
|
||||
.lib_override_apply_post = NULL,
|
||||
/*lib_override_apply_post */ nullptr,
|
||||
};
|
||||
|
||||
static void hair_random(Hair *hair)
|
||||
|
@ -250,7 +256,7 @@ static void hair_random(Hair *hair)
|
|||
|
||||
void *BKE_hair_add(Main *bmain, const char *name)
|
||||
{
|
||||
Hair *hair = BKE_id_new(bmain, ID_HA, name);
|
||||
Hair *hair = static_cast<Hair *>(BKE_id_new(bmain, ID_HA, name));
|
||||
|
||||
return hair;
|
||||
}
|
||||
|
@ -258,14 +264,14 @@ void *BKE_hair_add(Main *bmain, const char *name)
|
|||
BoundBox *BKE_hair_boundbox_get(Object *ob)
|
||||
{
|
||||
BLI_assert(ob->type == OB_HAIR);
|
||||
Hair *hair = ob->data;
|
||||
Hair *hair = static_cast<Hair *>(ob->data);
|
||||
|
||||
if (ob->runtime.bb != NULL && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
|
||||
if (ob->runtime.bb != nullptr && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
|
||||
return ob->runtime.bb;
|
||||
}
|
||||
|
||||
if (ob->runtime.bb == NULL) {
|
||||
ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "hair boundbox");
|
||||
if (ob->runtime.bb == nullptr) {
|
||||
ob->runtime.bb = MEM_cnew<BoundBox>(__func__);
|
||||
|
||||
float min[3], max[3];
|
||||
INIT_MINMAX(min, max);
|
||||
|
@ -289,10 +295,12 @@ BoundBox *BKE_hair_boundbox_get(Object *ob)
|
|||
|
||||
void BKE_hair_update_customdata_pointers(Hair *hair)
|
||||
{
|
||||
hair->co = CustomData_get_layer_named(&hair->pdata, CD_PROP_FLOAT3, HAIR_ATTR_POSITION);
|
||||
hair->radius = CustomData_get_layer_named(&hair->pdata, CD_PROP_FLOAT, HAIR_ATTR_RADIUS);
|
||||
hair->curves = CustomData_get_layer(&hair->cdata, CD_HAIRCURVE);
|
||||
hair->mapping = CustomData_get_layer(&hair->cdata, CD_HAIRMAPPING);
|
||||
hair->co = (float(*)[3])CustomData_get_layer_named(
|
||||
&hair->pdata, CD_PROP_FLOAT3, HAIR_ATTR_POSITION);
|
||||
hair->radius = (float *)CustomData_get_layer_named(
|
||||
&hair->pdata, CD_PROP_FLOAT, HAIR_ATTR_RADIUS);
|
||||
hair->curves = (HairCurve *)CustomData_get_layer(&hair->cdata, CD_HAIRCURVE);
|
||||
hair->mapping = (HairMaping *)CustomData_get_layer(&hair->cdata, CD_HAIRMAPPING);
|
||||
}
|
||||
|
||||
bool BKE_hair_customdata_required(Hair *UNUSED(hair), CustomDataLayer *layer)
|
||||
|
@ -304,10 +312,10 @@ bool BKE_hair_customdata_required(Hair *UNUSED(hair), CustomDataLayer *layer)
|
|||
|
||||
Hair *BKE_hair_new_for_eval(const Hair *hair_src, int totpoint, int totcurve)
|
||||
{
|
||||
Hair *hair_dst = BKE_id_new_nomain(ID_HA, NULL);
|
||||
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 = MEM_dupallocN(hair_src->mat);
|
||||
hair_dst->mat = static_cast<Material **>(MEM_dupallocN(hair_src->mat));
|
||||
hair_dst->totcol = hair_src->totcol;
|
||||
|
||||
hair_dst->totpoint = totpoint;
|
||||
|
@ -327,7 +335,7 @@ Hair *BKE_hair_copy_for_eval(Hair *hair_src, bool reference)
|
|||
flags |= LIB_ID_COPY_CD_REFERENCE;
|
||||
}
|
||||
|
||||
Hair *result = (Hair *)BKE_id_copy_ex(NULL, &hair_src->id, NULL, flags);
|
||||
Hair *result = (Hair *)BKE_id_copy_ex(nullptr, &hair_src->id, nullptr, flags);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -351,7 +359,7 @@ static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph,
|
|||
|
||||
/* Evaluate modifiers. */
|
||||
for (; md; md = md->next) {
|
||||
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
||||
const ModifierTypeInfo *mti = BKE_modifier_get_info(static_cast<ModifierType>(md->type));
|
||||
|
||||
if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
|
||||
continue;
|
||||
|
@ -370,7 +378,7 @@ static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph,
|
|||
BKE_hair_update_customdata_pointers(hair);
|
||||
|
||||
/* Created deformed coordinates array on demand. */
|
||||
mti->deformVerts(md, &mectx, NULL, hair->co, hair->totpoint);
|
||||
mti->deformVerts(md, &mectx, nullptr, hair->co, hair->totpoint);
|
||||
}
|
||||
else if (mti->modifyHair) {
|
||||
/* Ensure we are not modifying the input. */
|
||||
|
@ -383,7 +391,7 @@ static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph,
|
|||
if (hair_next && hair_next != hair) {
|
||||
/* If the modifier returned a new hair, release the old one. */
|
||||
if (hair != hair_input) {
|
||||
BKE_id_free(NULL, hair);
|
||||
BKE_id_free(nullptr, hair);
|
||||
}
|
||||
hair = hair_next;
|
||||
}
|
||||
|
@ -399,7 +407,7 @@ void BKE_hair_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Obje
|
|||
BKE_object_free_derived_caches(object);
|
||||
|
||||
/* Evaluate modifiers. */
|
||||
Hair *hair = object->data;
|
||||
Hair *hair = static_cast<Hair *>(object->data);
|
||||
Hair *hair_eval = hair_evaluate_modifiers(depsgraph, scene, object, hair);
|
||||
|
||||
/* Assign evaluated object. */
|
||||
|
@ -409,8 +417,8 @@ void BKE_hair_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Obje
|
|||
|
||||
/* Draw Cache */
|
||||
|
||||
void (*BKE_hair_batch_cache_dirty_tag_cb)(Hair *hair, int mode) = NULL;
|
||||
void (*BKE_hair_batch_cache_free_cb)(Hair *hair) = NULL;
|
||||
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)
|
||||
{
|
|
@ -85,7 +85,7 @@ set(SRC
|
|||
intern/draw_cache_impl_curve.cc
|
||||
intern/draw_cache_impl_displist.c
|
||||
intern/draw_cache_impl_gpencil.c
|
||||
intern/draw_cache_impl_hair.c
|
||||
intern/draw_cache_impl_hair.cc
|
||||
intern/draw_cache_impl_lattice.c
|
||||
intern/draw_cache_impl_mesh.c
|
||||
intern/draw_cache_impl_metaball.c
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
* \brief Hair API for render engines
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
|
@ -49,27 +49,28 @@ static void hair_batch_cache_clear(Hair *hair);
|
|||
/* ---------------------------------------------------------------------- */
|
||||
/* Hair GPUBatch Cache */
|
||||
|
||||
typedef struct HairBatchCache {
|
||||
struct HairBatchCache {
|
||||
ParticleHairCache hair;
|
||||
|
||||
/* settings to determine if cache is invalid */
|
||||
bool is_dirty;
|
||||
} HairBatchCache;
|
||||
};
|
||||
|
||||
/* GPUBatch cache management. */
|
||||
|
||||
static bool hair_batch_cache_valid(Hair *hair)
|
||||
{
|
||||
HairBatchCache *cache = hair->batch_cache;
|
||||
HairBatchCache *cache = static_cast<HairBatchCache *>(hair->batch_cache);
|
||||
return (cache && cache->is_dirty == false);
|
||||
}
|
||||
|
||||
static void hair_batch_cache_init(Hair *hair)
|
||||
{
|
||||
HairBatchCache *cache = hair->batch_cache;
|
||||
HairBatchCache *cache = static_cast<HairBatchCache *>(hair->batch_cache);
|
||||
|
||||
if (!cache) {
|
||||
cache = hair->batch_cache = MEM_callocN(sizeof(*cache), __func__);
|
||||
cache = MEM_cnew<HairBatchCache>(__func__);
|
||||
hair->batch_cache = cache;
|
||||
}
|
||||
else {
|
||||
memset(cache, 0, sizeof(*cache));
|
||||
|
@ -89,13 +90,13 @@ void DRW_hair_batch_cache_validate(Hair *hair)
|
|||
static HairBatchCache *hair_batch_cache_get(Hair *hair)
|
||||
{
|
||||
DRW_hair_batch_cache_validate(hair);
|
||||
return hair->batch_cache;
|
||||
return static_cast<HairBatchCache *>(hair->batch_cache);
|
||||
}
|
||||
|
||||
void DRW_hair_batch_cache_dirty_tag(Hair *hair, int mode)
|
||||
{
|
||||
HairBatchCache *cache = hair->batch_cache;
|
||||
if (cache == NULL) {
|
||||
HairBatchCache *cache = static_cast<HairBatchCache *>(hair->batch_cache);
|
||||
if (cache == nullptr) {
|
||||
return;
|
||||
}
|
||||
switch (mode) {
|
||||
|
@ -109,7 +110,7 @@ void DRW_hair_batch_cache_dirty_tag(Hair *hair, int mode)
|
|||
|
||||
static void hair_batch_cache_clear(Hair *hair)
|
||||
{
|
||||
HairBatchCache *cache = hair->batch_cache;
|
||||
HairBatchCache *cache = static_cast<HairBatchCache *>(hair->batch_cache);
|
||||
if (!cache) {
|
||||
return;
|
||||
}
|
||||
|
@ -125,8 +126,8 @@ void DRW_hair_batch_cache_free(Hair *hair)
|
|||
|
||||
static void ensure_seg_pt_count(Hair *hair, ParticleHairCache *hair_cache)
|
||||
{
|
||||
if ((hair_cache->pos != NULL && hair_cache->indices != NULL) ||
|
||||
(hair_cache->proc_point_buf != NULL)) {
|
||||
if ((hair_cache->pos != nullptr && hair_cache->indices != nullptr) ||
|
||||
(hair_cache->proc_point_buf != nullptr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -153,7 +154,7 @@ static void hair_batch_cache_fill_segments_proc_pos(Hair *hair,
|
|||
for (int i = 0; i < num_curves; i++, curve++) {
|
||||
float(*curve_co)[3] = hair->co + curve->firstpoint;
|
||||
float total_len = 0.0f;
|
||||
float *co_prev = NULL, *seg_data_first;
|
||||
float *co_prev = nullptr, *seg_data_first;
|
||||
for (int j = 0; j < curve->numpoints; j++) {
|
||||
float *seg_data = (float *)GPU_vertbuf_raw_step(attr_step);
|
||||
copy_v3_v3(seg_data, curve_co[j]);
|
||||
|
@ -181,7 +182,7 @@ static void hair_batch_cache_ensure_procedural_pos(Hair *hair,
|
|||
ParticleHairCache *cache,
|
||||
GPUMaterial *gpu_material)
|
||||
{
|
||||
if (cache->proc_point_buf == NULL) {
|
||||
if (cache->proc_point_buf == nullptr) {
|
||||
/* initialize vertex format */
|
||||
GPUVertFormat format = {0};
|
||||
uint pos_id = GPU_vertformat_attr_add(&format, "posTime", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
|
||||
|
@ -209,7 +210,7 @@ static void hair_batch_cache_ensure_procedural_pos(Hair *hair,
|
|||
cache->point_tex = GPU_texture_create_from_vertbuf("hair_point", cache->proc_point_buf);
|
||||
}
|
||||
|
||||
if (gpu_material && cache->proc_length_buf != NULL && cache->length_tex) {
|
||||
if (gpu_material && cache->proc_length_buf != nullptr && cache->length_tex) {
|
||||
ListBase gpu_attrs = GPU_material_attributes(gpu_material);
|
||||
LISTBASE_FOREACH (GPUMaterialAttribute *, attr, &gpu_attrs) {
|
||||
if (attr->type == CD_HAIRLENGTH) {
|
||||
|
@ -306,7 +307,7 @@ static void hair_batch_cache_ensure_procedural_indices(Hair *hair,
|
|||
{
|
||||
BLI_assert(thickness_res <= MAX_THICKRES); /* Cylinder strip not currently supported. */
|
||||
|
||||
if (cache->final[subdiv].proc_hairs[thickness_res - 1] != NULL) {
|
||||
if (cache->final[subdiv].proc_hairs[thickness_res - 1] != nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -340,7 +341,7 @@ bool hair_ensure_procedural_data(Object *object,
|
|||
int thickness_res)
|
||||
{
|
||||
bool need_ft_update = false;
|
||||
Hair *hair = object->data;
|
||||
Hair *hair = static_cast<Hair *>(object->data);
|
||||
|
||||
HairBatchCache *cache = hair_batch_cache_get(hair);
|
||||
*r_hair_cache = &cache->hair;
|
||||
|
@ -349,23 +350,23 @@ bool hair_ensure_procedural_data(Object *object,
|
|||
(*r_hair_cache)->final[subdiv].strands_res = 1 << (steps + subdiv);
|
||||
|
||||
/* Refreshed on combing and simulation. */
|
||||
if ((*r_hair_cache)->proc_point_buf == NULL) {
|
||||
if ((*r_hair_cache)->proc_point_buf == nullptr) {
|
||||
ensure_seg_pt_count(hair, &cache->hair);
|
||||
hair_batch_cache_ensure_procedural_pos(hair, &cache->hair, gpu_material);
|
||||
need_ft_update = true;
|
||||
}
|
||||
|
||||
/* Refreshed if active layer or custom data changes. */
|
||||
if ((*r_hair_cache)->strand_tex == NULL) {
|
||||
if ((*r_hair_cache)->strand_tex == nullptr) {
|
||||
hair_batch_cache_ensure_procedural_strand_data(hair, &cache->hair);
|
||||
}
|
||||
|
||||
/* Refreshed only on subdiv count change. */
|
||||
if ((*r_hair_cache)->final[subdiv].proc_buf == NULL) {
|
||||
if ((*r_hair_cache)->final[subdiv].proc_buf == nullptr) {
|
||||
hair_batch_cache_ensure_procedural_final_points(&cache->hair, subdiv);
|
||||
need_ft_update = true;
|
||||
}
|
||||
if ((*r_hair_cache)->final[subdiv].proc_hairs[thickness_res - 1] == NULL) {
|
||||
if ((*r_hair_cache)->final[subdiv].proc_hairs[thickness_res - 1] == nullptr) {
|
||||
hair_batch_cache_ensure_procedural_indices(hair, &cache->hair, thickness_res, subdiv);
|
||||
}
|
||||
|
Loading…
Reference in New Issue