99static int neighX[8] = {1, 1, 0, -1, -1, -1, 0, 1};
100static int neighY[8] = {0, 1, 1, 1, 0, -1, -1, -1};
107#define SUBFRAME_RECURSION OBJECT_MODIFIER_UPDATE_SUBFRAME_RECURSION_DEFAULT
109#define BRUSH_USES_VELOCITY (1 << 0)
112#define HIT_PROXIMITY 2
115#define ON_MESH_EDGE -2
116#define OUT_OF_TEXTURE -3
118#define EFF_MOVEMENT_PER_FRAME 0.05f
120#define WAVE_TIME_FAC (1.0f / 24.0f)
121#define CANVAS_REL_SIZE 5.0f
123#define MIN_WETNESS 0.001f
124#define MAX_WETNESS 5.0f
144 (*r_value) - 1.0f / time *
scale;
251#define ADJ_ON_MESH_EDGE (1 << 0)
252#define ADJ_BORDER_PIXEL (1 << 1)
275 if (runtime_data ==
nullptr) {
287 MEM_delete(runtime_data);
293 pmd->
modifier.
runtime = MEM_new<DynamicPaintRuntime>(
"dynamic paint runtime");
300 if (
canvas->pmd->modifier.runtime ==
nullptr) {
304 canvas->pmd->modifier.runtime);
327 return (canvas_mesh) ? canvas_mesh->
verts_num : 0;
357 const std::optional<AttributeMetaData> meta_data = attributes.
lookup_meta_data(name);
373 for (; surface; surface = surface->
next) {
374 if (surface != t_surface && surface->
type == t_surface->
type &&
409 for (; surface; surface = surface->
next) {
428 sizeof(surface->
name));
433 const char *name_prefix =
"";
434 const char *name_suffix_1 =
"";
435 const char *name_suffix_2 =
"";
450 name_suffix_1 =
"paintmap";
451 name_suffix_2 =
"wetmap";
454 name_suffix_1 = name_suffix_2 =
"displace";
457 name_suffix_1 = name_suffix_2 =
"weight";
460 name_suffix_1 = name_suffix_2 =
"wave";
468 if (!output_name_equal) {
489 const float s_color[3],
494 float i_alpha = 1.0f - s_alpha;
495 float f_alpha = t_alpha * i_alpha + s_alpha;
499 for (
int i = 0; i < 3; i++) {
500 result[i] = (t_color[i] * t_alpha * i_alpha + s_color[i] * s_alpha) / f_alpha;
512 float a_color[3],
float a_weight,
const float b_color[3],
float b_weight,
float ratio)
514 float weight_ratio, factor;
519 return b_weight * ratio;
521 weight_ratio = b_weight / (a_weight + b_weight);
524 return a_weight * (1.0f - ratio);
529 factor = weight_ratio * (ratio * 2.0f);
532 ratio = (ratio * 2.0f - 1.0f);
533 factor = weight_ratio * (1.0f - ratio) + ratio;
537 return (1.0f - factor) * a_weight + factor * b_weight;
555 for (
int i = 0; i < numobjects; i++) {
556 Object *brushObj = objects[i];
583 for (
int i = 2; i--;) {
584 if (!(b1->
min[i] <= b2->
max[i] && b1->
max[i] >= b2->
min[i])) {
597 for (
int i = 2; i--;) {
598 if (!(b1->
min[i] <= (b2->
max[i] + dist) && b1->
max[i] >= (b2->
min[i] - dist))) {
611 for (
int i = 2; i--;) {
612 if (!(
b->min[i] <= (point[i] + radius) &&
b->max[i] >= (point[i] - radius))) {
648 MEM_delete(grid->
s_pos);
651 MEM_delete(grid->
s_num);
657 MEM_delete(bData->
grid);
658 bData->
grid =
nullptr;
673 void *__restrict chunk_join,
674 void *__restrict chunk)
690 int *s_num =
static_cast<int *
>(tls->userdata_chunk);
694 for (
int j = 3; j--;) {
696 bData->
dim[j] * grid->
dim[j]));
700 temp_t_index[i] = co[0] + co[1] * grid->
dim[0] + co[2] * grid->
dim[0] * grid->
dim[1];
701 s_num[temp_t_index[i]]++;
705 void *__restrict chunk_join,
706 void *__restrict chunk)
710 const int grid_cells = grid->
dim[0] * grid->
dim[1] * grid->
dim[2];
712 int *join_s_num =
static_cast<int *
>(chunk_join);
713 int *s_num =
static_cast<int *
>(chunk);
716 for (
int i = 0; i < grid_cells; i++) {
717 join_s_num[i] += s_num[i];
727 float *dim = bData->
dim;
728 int *grid_dim = grid->
dim;
730 for (
int y = 0;
y < grid_dim[1];
y++) {
731 for (
int z = 0;
z < grid_dim[2];
z++) {
732 const int b_index =
x +
y * grid_dim[0] +
z * grid_dim[0] * grid_dim[1];
734 for (
int j = 3; j--;) {
735 const int s = (j == 0) ?
x : ((j == 1) ?
y :
z);
749 int grid_cells, axis = 3;
750 int *temp_t_index =
nullptr;
751 int *temp_s_num =
nullptr;
762 float dim_factor, volume, dim[3];
782 min_dim = std::max({td[0], td[1], td[2]}) / 1000.0f;
785 for (i = 0; i < 3; i++) {
786 if (td[i] < min_dim) {
792 if (axis == 0 || std::max({td[0], td[1], td[2]}) < 0.0001f) {
793 MEM_delete(bData->
grid);
794 bData->
grid =
nullptr;
799 volume = td[0] * td[1] * td[2];
803 pow(
double(volume) / (
double(sData->
total_points) / 10000.0), 1.0 /
double(axis)));
806 for (i = 0; i < 3; i++) {
807 grid->
dim[i] = int(
floor(td[i] / dim_factor));
808 CLAMP(grid->
dim[i], (dim[i] >= min_dim) ? 3 : 1, 100);
810 grid_cells = grid->
dim[0] * grid->
dim[1] * grid->
dim[2];
820 "Temp Surface Grid Target Ids");
842 for (i = 1; i < grid_cells; i++) {
848 int pos = grid->
s_pos[temp_t_index[i]] + temp_s_num[temp_t_index[i]];
851 temp_s_num[temp_t_index[i]]++;
864 MEM_delete(temp_s_num);
866 MEM_SAFE_DELETE(temp_t_index);
868 if (error || !grid->
s_num) {
887 MEM_delete(pmd->
brush);
888 pmd->
brush =
nullptr;
894 if (
data->adj_data) {
895 if (
data->adj_data->n_index) {
896 MEM_delete(
data->adj_data->n_index);
898 if (
data->adj_data->n_num) {
899 MEM_delete(
data->adj_data->n_num);
901 if (
data->adj_data->n_target) {
902 MEM_delete(
data->adj_data->n_target);
904 if (
data->adj_data->flags) {
905 MEM_delete(
data->adj_data->flags);
907 if (
data->adj_data->border) {
908 MEM_delete(
data->adj_data->border);
910 MEM_delete(
data->adj_data);
911 data->adj_data =
nullptr;
923 MEM_delete(bData->
s_pos);
926 MEM_delete(bData->
s_num);
947 MEM_delete(
data->bData);
948 data->bData =
nullptr;
955 if (!surface->
data) {
974 if (
data->format_data) {
978 if (format_data->
uv_p) {
979 MEM_delete(format_data->
uv_p);
985 MEM_delete(
data->format_data);
988 if (
data->type_data) {
989 switch (surface->
type) {
995 MEM_delete(
static_cast<float *
>(
data->type_data));
1006 MEM_delete(surface->
data);
1007 surface->
data =
nullptr;
1022 MEM_delete(surface);
1033 next_surface = surface->
next;
1035 surface = next_surface;
1045 if (pmd ==
nullptr) {
1141 canvas = pmd->
canvas = MEM_new<DynamicPaintCanvasSettings>(__func__);
1158 brush = pmd->
brush = MEM_new<DynamicPaintBrushSettings>(__func__);
1164 brush->psys =
nullptr;
1172 brush->alpha = 1.0f;
1173 brush->wetness = 1.0f;
1175 brush->paint_distance = 1.0f;
1178 brush->particle_radius = 0.2f;
1179 brush->particle_smooth = 0.05f;
1182 brush->wave_factor = 1.0f;
1183 brush->wave_clamp = 0.0f;
1184 brush->smudge_strength = 0.3f;
1185 brush->max_velocity = 1.0f;
1192 if (!
brush->paint_ramp) {
1195 ramp =
brush->paint_ramp->data;
1197 ramp[0].
r = ramp[0].
g = ramp[0].
b = ramp[0].
a = 1.0f;
1199 ramp[1].
r = ramp[1].
g = ramp[1].
b = ramp[1].
pos = 1.0f;
1209 if (!
brush->vel_ramp) {
1212 ramp =
brush->vel_ramp->data;
1213 ramp[0].
r = ramp[0].
g = ramp[0].
b = ramp[0].
a = ramp[0].
pos = 0.0f;
1214 ramp[1].
r = ramp[1].
g = ramp[1].
b = ramp[1].
a = ramp[1].
pos = 1.0f;
1215 brush->paint_ramp->tot = 2;
1316 t_brush->
pmd = tpmd;
1318 t_brush->flags =
brush->flags;
1319 t_brush->collision =
brush->collision;
1321 t_brush->r =
brush->r;
1322 t_brush->g =
brush->g;
1323 t_brush->b =
brush->b;
1324 t_brush->alpha =
brush->alpha;
1325 t_brush->wetness =
brush->wetness;
1327 t_brush->particle_radius =
brush->particle_radius;
1328 t_brush->particle_smooth =
brush->particle_smooth;
1329 t_brush->paint_distance =
brush->paint_distance;
1334 t_brush->psys =
brush->psys;
1336 if (
brush->paint_ramp) {
1337 memcpy(t_brush->paint_ramp,
brush->paint_ramp,
sizeof(
ColorBand));
1339 if (
brush->vel_ramp) {
1343 t_brush->proximity_falloff =
brush->proximity_falloff;
1344 t_brush->wave_type =
brush->wave_type;
1345 t_brush->ray_dir =
brush->ray_dir;
1347 t_brush->wave_factor =
brush->wave_factor;
1348 t_brush->wave_clamp =
brush->wave_clamp;
1349 t_brush->max_velocity =
brush->max_velocity;
1350 t_brush->smudge_strength =
brush->smudge_strength;
1359 switch (surface->
type) {
1362 "DynamicPaintSurface Data");
1366 "DynamicPaintSurface DepthData");
1370 "DynamicPaintSurface WeightData");
1374 "DynamicPaintSurface WaveData");
1402 int neigh_points = 0;
1410 neigh_points = 2 *
mesh->edges_num;
1416 if (!neigh_points) {
1438 MEM_delete(temp_data);
1446 int numOfEdges =
mesh->edges_num;
1447 int numOfPolys =
mesh->faces_num;
1453 for (
int i = 0; i < numOfEdges; i++) {
1454 ad->
n_num[edges[i][0]]++;
1455 ad->
n_num[edges[i][1]]++;
1457 temp_data[edges[i][0]]++;
1458 temp_data[edges[i][1]]++;
1463 for (
int i = 0; i < numOfPolys; i++) {
1464 for (
const int vert : corner_verts.
slice(faces[i])) {
1472 if ((temp_data[i] % 2) || (temp_data[i] < 4)) {
1484 n_pos += ad->
n_num[i];
1488 for (
int i = 0; i < numOfEdges; i++) {
1490 int index = edges[i][0];
1496 index = edges[i][1];
1507 MEM_delete(temp_data);
1533 Tex *tex =
data->surface->init_texture;
1535 float uv[3] = {0.0f};
1537 for (
int j = 3; j--;) {
1539 const int vert = corner_verts[corner_tris[i][j]];
1542 uv[0] = uv_map[corner_tris[i][j]][0] * 2.0f - 1.0f;
1543 uv[1] = uv_map[corner_tris[i][j]][1] * 2.0f - 1.0f;
1547 if (texres.
tin > pPoint[vert].
color[3]) {
1549 pPoint[vert].
color[3] = texres.
tin;
1565 Tex *tex =
data->surface->init_texture;
1569 float uv[9] = {0.0f};
1570 float uv_final[3] = {0.0f};
1575 for (
int j = 3; j--;) {
1582 uv_final[0] = uv_final[0] * 2.0f - 1.0f;
1583 uv_final[1] = uv_final[1] * 2.0f - 1.0f;
1593 void *__restrict userdata,
const int i,
const TaskParallelTLS *__restrict )
1607 float final_color[4];
1610 for (
int j = 3; j--;) {
1612 static_cast<const uchar *
>(&mloopcol[corner_tris[tri_idx][j]].r));
1657 mesh->active_uv_map_name();
1670 data.surface = surface;
1671 data.corner_verts = corner_verts;
1672 data.corner_tris = corner_tris;
1673 data.uv_map = uv_map;
1685 data.surface = surface;
1686 data.corner_tris = corner_tris;
1687 data.uv_map = uv_map;
1721 data.surface = surface;
1722 data.corner_tris = corner_tris;
1723 data.mloopcol = col;
1747 data_size =
sizeof(
float);
1767 if (surface->
data) {
1775 if (numOfPoints < 1) {
1781 if (!surface->
data) {
1833 const float *value =
static_cast<float *
>(surface->
data->
type_data);
1834 const float val = value[i] * surface->
disp_factor;
1851 data.surface = surface;
1852 data.vert_positions =
result->vert_positions_for_write();
1875 pPoint[i].
color, pPoint[i].
color[3], pPoint[i].e_color, pPoint[i].e_color[3], fcolor[i]);
1894 for (
const int l_index :
data->faces[p_index]) {
1895 const int v_index = corner_verts[l_index];
1905 mloopcol_wet[l_index].r = c;
1906 mloopcol_wet[l_index].g = c;
1907 mloopcol_wet[l_index].b = c;
1908 mloopcol_wet[l_index].a = 255;
1958 "Temp paint color");
1961 data.surface = surface;
1962 data.fcolor = fcolor;
2004 data.corner_verts = corner_verts;
2007 data.mloopcol_wet = mloopcol_wet.
span;
2025 float *weight =
static_cast<float *
>(sData->
type_data);
2029 if (defgrp_index != -1) {
2035 if ((def_weight !=
nullptr) || (weight[i] != 0.0f)) {
2037 if (def_weight ==
nullptr) {
2042 def_weight->
weight = weight[i];
2050 data.surface = surface;
2051 data.vert_positions =
result->vert_positions_for_write();
2059 result->tag_positions_changed();
2065 result->tag_positions_changed();
2122 for (; surface; surface = surface->
next) {
2123 int current_frame = scene->
r.
cfra;
2124 bool no_surface_data;
2137 no_surface_data = surface->
data ==
nullptr;
2145 if (no_surface_data || current_frame != surface->
current_frame ||
2172 else if (can_simulate) {
2208#define JITTER_SAMPLES \
2258 for (
int tx = 0; tx <
w; tx++) {
2259 const int index = tx +
w * ty;
2269 point[0][0] = (
float(tx) + 0.5f) /
w;
2270 point[0][1] = (
float(ty) + 0.5f) / h;
2276 point[1][0] =
float(tx) /
w;
2277 point[1][1] =
float(ty) / h;
2279 point[2][0] = (
float(tx) + 1) /
w;
2280 point[2][1] =
float(ty) / h;
2282 point[3][0] =
float(tx) /
w;
2283 point[3][1] = (
float(ty) + 1) / h;
2285 point[4][0] = (
float(tx) + 1) /
w;
2286 point[4][1] = (
float(ty) + 1) / h;
2295 if ((faceBB[i].
min[0] > point[
sample][0]) || (faceBB[i].
min[1] > point[
sample][1]) ||
2301 const float *uv1 = uv_map[corner_tris[i][0]];
2302 const float *uv2 = uv_map[corner_tris[i][1]];
2303 const float *uv3 = uv_map[corner_tris[i][2]];
2310 for (
int j = 0; j < aa_samples; j++) {
2311 uv[0] = point[0][0] + jitter5sample[j * 2] /
w;
2312 uv[1] = point[0][1] + jitter5sample[j * 2 + 1] / h;
2321 tPoint->
v1 = corner_verts[corner_tris[i][0]];
2322 tPoint->
v2 = corner_verts[corner_tris[i][1]];
2323 tPoint->
v3 = corner_verts[corner_tris[i][2]];
2355 for (
int tx = 0; tx <
w; tx++) {
2356 const int index = tx +
w * ty;
2364 const int u_min = (tx > 0) ? -1 : 0;
2365 const int u_max = (tx < (
w - 1)) ? 1 : 0;
2366 const int v_min = (ty > 0) ? -1 : 0;
2367 const int v_max = (ty < (h - 1)) ? 1 : 0;
2369 point[0] = (
float(tx) + 0.5f) /
w;
2370 point[1] = (
float(ty) + 0.5f) / h;
2373 for (
int ni = 0; ni < 8; ni++) {
2377 if (u >= u_min && u <= u_max && v >= v_min &&
v <= v_max) {
2379 if (u != 0 ||
v != 0) {
2380 const int ind = (tx + u) +
w * (ty +
v);
2383 if (tempPoints[ind].neighbor_pixel == -1 && tempPoints[ind].tri_index != -1) {
2385 const int i = tempPoints[ind].
tri_index;
2386 const float *uv1 = uv_map[corner_tris[i][0]];
2387 const float *uv2 = uv_map[corner_tris[i][1]];
2388 const float *uv3 = uv_map[corner_tris[i][2]];
2404 for (
int j = 0; j < aa_samples; j++) {
2405 uv[0] = point[0] + jitter5sample[j * 2] /
w;
2406 uv[1] = point[1] + jitter5sample[j * 2 + 1] / h;
2411 tPoint->
v1 = corner_verts[corner_tris[i][0]];
2412 tPoint->
v2 = corner_verts[corner_tris[i][1]];
2413 tPoint->
v3 = corner_verts[corner_tris[i][2]];
2429#undef JITTER_SAMPLES
2434 const float point[2])
2440 for (
int i = 0; i < 3; i++) {
2443 uv_map[corner_tris[tri_index][(i + 0)]],
2444 uv_map[corner_tris[tri_index][(i + 1) % 3]]);
2446 min_distance = std::min(dist_squared, min_distance);
2449 return min_distance;
2463 const float pixel[2],
2487 const int x = px +
neighX[n_index];
2488 const int y = py +
neighY[n_index];
2535 pixel[0] = (
float(px +
neighX[n_index]) + 0.5f) /
float(
w);
2536 pixel[1] = (
float(py +
neighY[n_index]) + 0.5f) /
float(h);
2548 const float pixel[2],
2556 const int3 loop_idx = corner_tris[tri_index];
2559 for (
int edge_idx = 0; edge_idx < 3; edge_idx++) {
2561 if (edge_idx == in_edge) {
2565 float uv0[2], uv1[2], uv2[2];
2567 copy_v2_v2(uv0, uv_map[loop_idx[(edge_idx + 0)]]);
2568 copy_v2_v2(uv1, uv_map[loop_idx[(edge_idx + 1) % 3]]);
2569 copy_v2_v2(uv2, uv_map[loop_idx[(edge_idx + 2) % 3]]);
2576 if (side2 == 0.0f) {
2581 const bool correct_side = (in_edge == -1) || (sidep < 0 && side2 > 0) ||
2582 (sidep > 0 && side2 < 0);
2585 if (!correct_side && sidep != 0.0f) {
2590 const int vert0 = corner_verts[loop_idx[(edge_idx + 0)]];
2591 const int vert1 = corner_verts[loop_idx[(edge_idx + 1) % 3]];
2597 bool found_other =
false;
2598 int target_tri = -1;
2599 int target_edge = -1;
2601 float ouv0[2], ouv1[2];
2603 for (
int i = 0; i < map->count && !found_other; i++) {
2604 const int tri_other_index = map->indices[i];
2606 if (tri_other_index == tri_index) {
2610 const int3 other_tri = corner_tris[tri_other_index];
2613 for (
int j = 0; j < 3; j++) {
2614 const int overt0 = corner_verts[other_tri[(j + 0)]];
2615 const int overt1 = corner_verts[other_tri[(j + 1) % 3]];
2618 if (overt0 == vert0 && overt1 == vert1) {
2620 copy_v2_v2(ouv0, uv_map[other_tri[(j + 0)]]);
2621 copy_v2_v2(ouv1, uv_map[other_tri[(j + 1) % 3]]);
2623 else if (overt0 == vert1 && overt1 == vert0) {
2625 copy_v2_v2(ouv1, uv_map[other_tri[(j + 0)]]);
2626 copy_v2_v2(ouv0, uv_map[other_tri[(j + 1) % 3]]);
2630 target_tri = tri_other_index;
2647 if (depth > 0 && correct_side) {
2666 float closest_point[2], dir_vec[2], tgt_pixel[2];
2669 CLAMP(lambda, 0.0f, 1.0f);
2674 int w = bdata->
w, h = bdata->
h, px = bdata->
px, py = bdata->
py;
2676 const int final_pixel[2] = {int(
floorf(tgt_pixel[0] *
w)), int(
floorf(tgt_pixel[1] * h))};
2679 if (final_pixel[0] < 0 || final_pixel[0] >=
w || final_pixel[1] < 0 || final_pixel[1] >= h) {
2688 int final_index = final_pixel[0] +
w * final_pixel[1];
2691 if (final_index == (px +
w * py)) {
2696 if (tempPoints[final_index].neighbor_pixel != -1) {
2700 if (final_index == (px +
w * py)) {
2705 const int final_tri_index = tempPoints[final_index].
tri_index;
2707 if (!
ELEM(final_tri_index, target_tri, -1)) {
2710 const float final_pt[2] = {((final_index %
w) + 0.5f) /
w, ((final_index /
w) + 0.5f) / h};
2711 const float threshold =
square_f(0.7f) / (
w * h);
2727 const int idx =
ed->n_index[
index];
2729 for (
int i = 0; i <
ed->n_num[
index]; i++) {
2730 if (
ed->n_target[idx + i] == neighbor) {
2745 if (new_n_num && new_n_index) {
2747 int total_targets = 0;
2750 total_targets +=
ed->n_num[
index];
2759 for (
int i = 0, idx =
ed->n_index[
index]; i < ed->n_num[
index]; i++) {
2760 const int target =
ed->n_target[idx + i];
2765 new_n_num[target]++;
2779 new_n_index[
index] = n_pos;
2780 memcpy(&new_n_target[n_pos],
2782 sizeof(
int) *
ed->n_num[
index]);
2785 n_pos += new_n_num[
index];
2797 for (
int i = 0, idx =
ed->n_index[
index]; i < ed->n_num[
index]; i++) {
2798 const int target =
ed->n_target[idx + i];
2801 const int num = new_n_num[target]++;
2802 new_n_target[new_n_index[target] +
num] =
index;
2808 MEM_delete(
ed->n_target);
2809 ed->n_target = new_n_target;
2811 MEM_delete(
ed->n_index);
2812 ed->n_index = new_n_index;
2814 MEM_delete(
ed->n_num);
2815 ed->n_num = new_n_num;
2817 ed->total_targets = total_targets;
2823 MEM_delete(new_n_index);
2826 MEM_delete(new_n_num);
2847 Vec3f *tempWeights =
nullptr;
2871 mesh->active_uv_map_name();
2891 &
LOG,
"Preparing UV surface of %ix%i pixels and %i tris.",
w, h,
int(corner_tris.
size()));
2894 if (surface->
data) {
2898 if (!surface->
data) {
2937 for (
int j = 1; j < 3; j++) {
2947 data.surface = surface;
2948 data.tempPoints = tempPoints;
2949 data.tempWeights = tempWeights;
2950 data.corner_tris = corner_tris;
2951 data.uv_map = uv_map;
2952 data.corner_verts = corner_verts;
2953 data.faceBB = faceBB;
2971 data.active_points = &active_points;
2988 for (
int i = 0; i <
w * h; i++) {
2989 if (tempPoints[i].tri_index != -1) {
2990 final_index[i] = cursor;
3003 int *vert_to_tri_map_mem;
3006 &vert_to_tri_map_mem,
3010 corner_verts.
data(),
3013 int total_border = 0;
3015 for (
int ty = 0; ty < h; ty++) {
3016 for (
int tx = 0; tx <
w; tx++) {
3017 const int index = tx +
w * ty;
3019 if (tempPoints[
index].tri_index != -1) {
3020 ed->n_index[final_index[
index]] = n_pos;
3021 ed->n_num[final_index[
index]] = 0;
3023 if (tempPoints[
index].neighbor_pixel != -1) {
3028 for (
int i = 0; i < 8; i++) {
3032 &
data, vert_to_tri_map,
w, h, tx, ty, i);
3034 if (n_target >= 0 && n_target !=
index) {
3036 ed, final_index[
index], final_index[n_target]))
3038 ed->n_target[n_pos] = final_index[n_target];
3039 ed->n_num[final_index[
index]]++;
3051 MEM_delete(vert_to_tri_map);
3052 MEM_delete(vert_to_tri_map_mem);
3063 ed->total_border = total_border;
3065 for (
int i = 0, next = 0; i < active_points; i++) {
3067 ed->border[next++] = i;
3076 FILE *dump_file = fopen(
"dynpaint-adj-data.txt",
"w");
3078 for (
int ty = 0; ty < h; ty++) {
3079 for (
int tx = 0; tx <
w; tx++) {
3080 const int index = tx +
w * ty;
3081 if (tempPoints[
index].tri_index != -1) {
3086 for (
int ty = 0; ty < h; ty++) {
3087 for (
int tx = 0; tx <
w; tx++) {
3088 const int index = tx +
w * ty;
3089 const int fidx = final_index[
index];
3091 if (tempPoints[
index].tri_index != -1) {
3094 "%d\t%d,%d\t%u\t%d,%d\t%d\t",
3098 tempPoints[
index].tri_index,
3099 nidx < 0 ? -1 : (nidx %
w),
3100 nidx < 0 ? -1 : h - 1 - (nidx /
w),
3102 for (
int i = 0; i <
ed->n_num[fidx]; i++) {
3103 int tgt = tmp[
ed->n_target[
ed->n_index[fidx] + i]];
3104 fprintf(dump_file,
"%s%d,%d", i ?
" " :
"", tgt %
w, h - 1 - tgt /
w);
3106 fprintf(dump_file,
"\n");
3138 MEM_delete(f_data->
uv_p);
3152 if (tempPoints[
index].tri_index != -1) {
3155 &tempWeights[
index * aa_samples],
3156 sizeof(*tempWeights) * aa_samples);
3170 MEM_delete(tempPoints);
3173 MEM_delete(tempWeights);
3176 MEM_delete(final_index);
3191 pPoint->alpha = 1.0f;
3195 pPoint->
color[2] = 1.0f;
3200 pPoint->
color[0] = 1.0f;
3212 return (error == 0);
3241 &
data->ibuf_float_data[pos]);
3266 depth = (0.5f - depth / 2.0f);
3269 CLAMP(depth, 0.0f, 1.0f);
3272 data->ibuf_float_data[pos + 3] = 1.0f;
3284 float depth = wPoint->
height;
3293 depth = (0.5f + depth / 2.0f);
3294 CLAMP(depth, 0.0f, 1.0f);
3297 data->ibuf_float_data[pos + 3] = 1.0f;
3314 data->ibuf_float_data[pos + 3] = 1.0f;
3318 const char *filepath,
3321 ImBuf *ibuf =
nullptr;
3332 STRNCPY(output_file, filepath);
3342 if (ibuf ==
nullptr) {
3343 setError(surface->
canvas,
N_(
"Image save failed: not enough free memory"));
3348 data.surface = surface;
3351 switch (surface->
type) {
3353 switch (output_layer) {
3382 switch (output_layer) {
3402 switch (output_layer) {
3458 const int paintFlags,
3459 const float paintColor[3],
3460 const float paintAlpha,
3461 const float paintWetness,
3462 const float timescale)
3482 float wetness = paintWetness;
3483 CLAMP(wetness, 0.0f, 1.0f);
3494 float a_ratio, a_highest;
3496 float invFact = 1.0f - paintAlpha;
3504 if (a_highest > invFact) {
3505 a_ratio = invFact / a_highest;
3507 pPoint->
e_color[3] *= a_ratio;
3508 pPoint->
color[3] *= a_ratio;
3512 pPoint->
e_color[3] -= paintAlpha * timescale;
3514 pPoint->
color[3] -= paintAlpha * timescale;
3518 wetness = (1.0f - paintWetness) * pPoint->
e_color[3];
3528 const float isect_change = isect_height - wPoint->
brush_isect;
3529 const float wave_factor =
brush->wave_factor;
3536 isect_height *= wave_factor;
3539 if (wave_factor > 0.0f && wPoint->
height > isect_height) {
3542 else if (wave_factor < 0.0f && wPoint->height < isect_height) {
3547 switch (
brush->wave_type) {
3549 wPoint->
height = isect_height;
3560 if (isect_change < 0.0f) {
3561 wPoint->
height += isect_change * wave_factor;
3581 const float timescale)
3590 strength = influence *
brush->alpha;
3591 CLAMP(strength, 0.0f, 1.0f);
3598 vel_factor /=
brush->max_velocity;
3599 CLAMP(vel_factor, 0.0f, 1.0f);
3606 strength *= coba_res[3];
3609 depth *= coba_res[3];
3616 float paintWetness =
brush->wetness * strength;
3617 float paintAlpha = strength;
3620 surface,
index,
brush->flags,
paint, paintAlpha, paintWetness, timescale);
3624 float *value =
static_cast<float *
>(sData->
type_data);
3627 depth = value[
index] + depth;
3635 value[
index] *= (1.0f - strength);
3644 float *value =
static_cast<float *
>(sData->
type_data);
3647 value[
index] *= (1.0f - strength);
3656 if (
brush->wave_clamp) {
3707 const float (*positions_p)[3] =
data->positions_p;
3708 const float (*positions_c)[3] =
data->positions_c;
3711 float (*prev_obmat)[4] =
data->prev_obmat;
3713 const float timescale =
data->timescale;
3734 float prev_obmat[4][4];
3735 Mesh *mesh_p, *mesh_c;
3736 int numOfVerts_p, numOfVerts_c;
3739 int cur_fra = scene->
r.
cfra;
3740 float prev_sfra = cur_sfra - timescale;
3741 int prev_fra = cur_fra;
3743 if (prev_sfra < 0.0f) {
3745 prev_fra = cur_fra - 1;
3749 scene->
r.
cfra = prev_fra;
3762 if (!runtime_data) {
3765 std::lock_guard
lock(runtime_data->brush_mutex);
3770 float (*positions_p)[3] =
reinterpret_cast<float (*)[3]
>(
3771 mesh_p->vert_positions_for_write().
data());
3772 copy_m4_m4(prev_obmat, ob->object_to_world().ptr());
3775 scene->
r.
cfra = cur_fra;
3786 if (!runtime_data) {
3789 std::lock_guard
lock(runtime_data->brush_mutex);
3790 mesh_c = runtime_data->brush_mesh;
3793 float (*positions_c)[3] =
reinterpret_cast<float (*)[3]
>(
3794 mesh_c->vert_positions_for_write().
data());
3797 "Dynamic Paint brush velocity");
3804 if (numOfVerts_p != numOfVerts_c) {
3805 positions_p = positions_c;
3810 data.brush_vel = *brushVel;
3811 data.positions_p = positions_p;
3812 data.positions_c = positions_c;
3813 data.obmat = ob->object_to_world().ptr();
3814 data.prev_obmat = prev_obmat;
3815 data.timescale = timescale;
3828 Depsgraph *depsgraph,
Scene *scene,
Object *ob,
Vec3f *brushVel,
float timescale)
3830 float prev_obmat[4][4];
3831 float cur_loc[3] = {0.0f}, prev_loc[3] = {0.0f};
3834 int cur_fra = scene->
r.
cfra;
3835 float prev_sfra = cur_sfra - timescale;
3836 int prev_fra = cur_fra;
3838 if (prev_sfra < 0.0f) {
3840 prev_fra = cur_fra - 1;
3844 scene->
r.
cfra = prev_fra;
3853 copy_m4_m4(prev_obmat, ob->object_to_world().ptr());
3856 scene->
r.
cfra = cur_fra;
3868 mul_m4_v3(ob->object_to_world().ptr(), cur_loc);
3914 const float timescale =
data->timescale;
3915 const int c_index =
data->c_index;
3920 const float brush_radius =
data->brush_radius;
3921 const float *avg_brushNor =
data->avg_brushNor;
3922 const Vec3f *brushVelocity =
data->brushVelocity;
3929 float total_sample =
float(samples);
3930 float brushStrength = 0.0f;
3932 float velocity_val = 0.0f;
3934 float paintColor[3] = {0.0f};
3943 for (ss = 0; ss < samples; ss++) {
3944 float3 ray_start, ray_dir;
3945 float sample_factor = 0.0f;
3946 float sampleStrength = 0.0f;
3947 short hit_found = 0;
3950 float volume_factor = 0.0f;
3952 float proximity_factor = 0.0f;
3953 float prox_colorband[4] = {0.0f};
3966 sample_factor = 1.0f;
3979 if (
const std::optional<bke::bvh::RayHit> hit = treeData.ray_intersect(ray)) {
3986 const float dist = hit->distance;
3987 const int f_index = hit->index;
3993 if (
const std::optional<bke::bvh::RayHit> hit_other = treeData.ray_intersect(other_ray))
3996 volume_factor = 1.0f;
4002 madd_v3_v3v3fl(hitCoord, ray_start, ray_dir, hit_other->distance);
4004 depth += dist * sample_factor;
4015 float proxDist = -1.0f;
4016 float hitCo[3] = {0.0f, 0.0f, 0.0f};
4020 if (inner_proximity && !hit_found) {
4026 if (
const std::optional<bke::bvh::ClosestPointResult> nearest = treeData.closest_point(
4027 ray_start, brush_radius))
4031 tri = nearest->index;
4035 float proj_ray[3] = {0.0f};
4050 if (
const std::optional<bke::bvh::RayHit> hit = treeData.ray_intersect(ray)) {
4051 proxDist = hit->distance;
4061 if (proxDist >= 0.0f && proxDist <= brush_radius) {
4062 proximity_factor = proxDist / brush_radius;
4063 CLAMP(proximity_factor, 0.0f, 1.0f);
4064 if (!inner_proximity) {
4065 proximity_factor = 1.0f - proximity_factor;
4082 volume_factor = 1.0f - volume_factor;
4083 if (inner_proximity) {
4084 proximity_factor = 1.0f - proximity_factor;
4090 sampleStrength = volume_factor;
4097 proximity_factor = prox_colorband[3];
4104 sampleStrength = proximity_factor;
4107 sampleStrength *= sample_factor;
4116 float brushPointVelocity[3];
4119 const int v1 = corner_verts[corner_tris[hitTri][0]];
4120 const int v2 = corner_verts[corner_tris[hitTri][1]];
4121 const int v3 = corner_verts[corner_tris[hitTri][2]];
4131 brushVelocity[v1].
v,
4132 brushVelocity[
v2].
v,
4133 brushVelocity[v3].
v,
4158 float sampleColor[3];
4159 float alpha_factor = 1.0f;
4161 sampleColor[0] =
brush->r;
4162 sampleColor[1] =
brush->g;
4163 sampleColor[2] =
brush->b;
4168 sampleColor[0] = prox_colorband[0];
4169 sampleColor[1] = prox_colorband[1];
4170 sampleColor[2] = prox_colorband[2];
4175 paintColor[0] += sampleColor[0];
4176 paintColor[1] += sampleColor[1];
4177 paintColor[2] += sampleColor[2];
4178 sampleStrength *= alpha_factor;
4183 brushStrength += sampleStrength;
4187 if (brushStrength > 0.0f || depth > 0.0f) {
4190 brushStrength /= total_sample;
4192 CLAMP(brushStrength, 0.0f, 1.0f);
4196 paintColor[0] /= numOfHits;
4197 paintColor[1] /= numOfHits;
4198 paintColor[2] /= numOfHits;
4206 surface,
index,
brush, paintColor, brushStrength, depth, velocity_val, timescale);
4220 Vec3f *brushVelocity =
nullptr;
4224 depsgraph, scene, brushOb,
brush, &brushVelocity, timescale);
4228 if (!runtime_data) {
4231 std::lock_guard
lock(runtime_data->brush_mutex);
4232 const Mesh *brush_mesh = runtime_data->brush_mesh;
4233 if (brush_mesh ==
nullptr) {
4238 float avg_brushNor[3] = {0.0f};
4250 numOfVerts =
mesh->verts_num;
4255 for (ii = 0; ii < numOfVerts; ii++) {
4256 mul_m4_v3(brushOb->object_to_world().ptr(), positions[ii]);
4270 mesh->tag_positions_changed();
4273 mul_v3_fl(avg_brushNor, 1.0f /
float(numOfVerts));
4276 avg_brushNor[2] = 1.0f;
4283 if (
mesh->faces_num != 0) {
4287 int total_cells = grid->
dim[0] * grid->
dim[1] * grid->
dim[2];
4290 for (c_index = 0; c_index < total_cells; c_index++) {
4292 if (!grid->
s_num[c_index] ||
4300 data.surface = surface;
4302 data.brushOb = brushOb;
4304 data.timescale = timescale;
4305 data.c_index = c_index;
4307 data.positions = positions;
4308 data.corner_verts = corner_verts;
4309 data.corner_tris = corner_tris;
4310 data.brush_radius = brush_radius;
4311 data.avg_brushNor = avg_brushNor;
4312 data.brushVelocity = brushVelocity;
4319 grid->
s_num[c_index],
4330 if (brushVelocity) {
4331 MEM_delete(brushVelocity);
4341 void *__restrict userdata,
const int id,
const TaskParallelTLS *__restrict )
4354 const float timescale =
data->timescale;
4355 const int c_index =
data->c_index;
4359 const float solidradius =
data->solidradius;
4361 const float range = solidradius +
smooth;
4362 const float particle_timestep = 0.04f * psys->
part->
timetweak;
4365 float disp_intersect = 0.0f;
4366 float radius = 0.0f;
4367 float strength = 0.0f;
4368 int part_index = -1;
4376 float smooth_range, part_solidradius;
4381 if (nearest.
dist > range) {
4388 part_solidradius = pa->
size;
4391 part_solidradius = solidradius;
4393 radius = part_solidradius +
smooth;
4394 if (nearest.
dist < radius) {
4396 smooth_range =
max_ff(0.0f, (nearest.
dist - part_solidradius));
4402 strength = 1.0f - smooth_range;
4403 disp_intersect = radius - nearest.
dist;
4404 part_index = nearest.
index;
4415 float smooth_range =
smooth * (1.0f - strength), dist;
4417 const float max_range =
smooth - strength *
smooth + solidradius;
4425 for (
int n = 0; n < particles; n++) {
4434 const float s_range = nearest[n].
dist - pa->
size;
4436 if (smooth_range < s_range) {
4441 smooth_range = s_range;
4442 dist = nearest[n].
dist;
4443 part_index = nearest[n].
index;
4446 if ((s_range < 0.0f) &&
4454 MEM_delete(nearest);
4458 const float rad = radius +
smooth;
4459 if ((rad - dist) > disp_intersect) {
4460 disp_intersect = radius - dist;
4470 const float str = 1.0f - smooth_range;
4472 strength = std::max(
str, strength);
4475 if (strength > 0.001f) {
4476 float paintColor[4] = {0.0f};
4478 float velocity_val = 0.0f;
4506 disp_intersect = (1.0f -
sqrtf(disp_intersect / radius)) * radius;
4511 surface,
index,
brush, paintColor, strength, depth, velocity_val, timescale);
4526 int particlesAdded = 0;
4527 int invalidParticles = 0;
4532 brush->particle_radius);
4535 const float range = solidradius +
smooth;
4560 if (
isnan(pa->state.co[0]) ||
isnan(pa->state.co[1]) ||
isnan(pa->state.co[2])) {
4577 if (invalidParticles) {
4582 if (particlesAdded < 1) {
4590 int total_cells = grid->
dim[0] * grid->
dim[1] * grid->
dim[2];
4596 for (c_index = 0; c_index < total_cells; c_index++) {
4604 data.surface = surface;
4607 data.solidradius = solidradius;
4608 data.timescale = timescale;
4609 data.c_index = c_index;
4610 data.treeData = tree;
4616 grid->
s_num[c_index],
4640 const float timescale =
data->timescale;
4642 const float brush_radius =
data->brush_radius;
4643 const Vec3f *brushVelocity =
data->brushVelocity;
4645 float *pointCoord =
data->pointCoord;
4648 float colorband[4] = {0.0f};
4657 strength = 1.0f -
distance / brush_radius;
4658 CLAMP(strength, 0.0f, 1.0f);
4664 if (strength >= 0.001f) {
4665 float paintColor[3] = {0.0f};
4667 float velocity_val = 0.0f;
4673 strength = colorband[3];
4686 velocity_val =
len_v3(velocity);
4701 paintColor[0] = colorband[0];
4702 paintColor[1] = colorband[1];
4703 paintColor[2] = colorband[2];
4706 paintColor[0] =
brush->r;
4707 paintColor[1] =
brush->g;
4708 paintColor[2] =
brush->b;
4713 const float disp_intersect = (1.0f -
sqrtf((brush_radius -
distance) / brush_radius)) *
4718 surface,
index,
brush, paintColor, strength, depth, velocity_val, timescale);
4723 Depsgraph *depsgraph,
4742 std::lock_guard
lock(runtime_data->brush_mutex);
4743 const Mesh *brush_mesh = runtime_data->brush_mesh;
4749 data.surface = surface;
4751 data.brushOb = brushOb;
4753 data.timescale = timescale;
4754 data.positions = brush_mesh->vert_positions();
4755 data.brush_radius = brush_radius;
4756 data.brushVelocity = &brushVel;
4757 data.pointCoord = pointCoord;
4784 const int num_neighs = adj_data->
n_num[
index];
4786 for (
int i = 0; i < num_neighs; i++) {
4788 const int t_index = adj_data->
n_target[n_index];
4792 realCoord[bData->
s_pos[t_index]].
v,
4834 for (
int i = 0; i < numOfNeighs; i++) {
4845 const float force[3],
4852 closest_id[0] = closest_id[1] = -1;
4853 closest_d[0] = closest_d[1] = -1.0f;
4856 for (
int i = 0; i < numOfNeighs; i++) {
4858 const float dir_dot =
dot_v3v3(bNeighs[n_index].dir, force);
4860 if (dir_dot > closest_d[0] && dir_dot > 0.0f) {
4861 closest_d[0] = dir_dot;
4862 closest_id[0] = n_index;
4866 if (closest_d[0] < 0.0f) {
4871 for (
int i = 0; i < numOfNeighs; i++) {
4874 if (n_index == closest_id[0]) {
4878 const float dir_dot =
dot_v3v3(bNeighs[n_index].dir, force);
4879 const float closest_dot =
dot_v3v3(bNeighs[n_index].dir, bNeighs[closest_id[0]].dir);
4883 if (dir_dot > closest_d[1] && closest_dot < closest_d[0] && dir_dot > 0.0f) {
4884 closest_d[1] = dir_dot;
4885 closest_id[1] = n_index;
4891 if (closest_id[1] != -1) {
4892 float force_proj[3];
4894 const float neigh_diff =
acosf(
4895 dot_v3v3(bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir));
4896 float force_intersect;
4901 cross_v3_v3v3(tangent, bNeighs[closest_id[0]].dir, bNeighs[closest_id[1]].dir);
4903 force_intersect =
dot_v3v3(force, tangent);
4904 madd_v3_v3v3fl(force_proj, force, tangent, (-1.0f) * force_intersect);
4908 temp =
dot_v3v3(bNeighs[closest_id[0]].dir, force_proj);
4909 CLAMP(temp, -1.0f, 1.0f);
4910 closest_d[1] =
acosf(temp) / neigh_diff;
4911 closest_d[0] = 1.0f - closest_d[1];
4914 temp =
fabsf(force_intersect);
4915 CLAMP(temp, 0.0f, 1.0f);
4931 float max_velocity = 0.0f;
4943 int steps = int(
ceil(
double(max_velocity) / bData->
average_dist *
double(timescale)));
4944 CLAMP(steps, 0, 12);
4945 float eff_scale =
brush->smudge_strength /
float(steps) * timescale;
4970 for (
int i = 0; i < 2; i++) {
4971 int n_index = closest_id[i];
4972 if (n_index != -1 && closest_d[i] > 0.0f) {
4973 float dir_dot = closest_d[i], dir_factor;
4974 float speed_scale = eff_scale * smudge_str / bNeighs[n_index].
dist;
4979 if (dir_dot <= 0.0f) {
4983 dir_factor = dir_dot * speed_scale;
4988 ePoint->
color[3] = ePoint->
color[3] * (1.0f - dir_factor) +
4989 pPoint->
color[3] * dir_factor;
4998 pPoint->
e_color[3] * dir_factor;
4999 pPoint->
wetness *= (1.0f - dir_factor);
5044 float *force =
data->force;
5045 ListBaseT<EffectorCache> *effectors =
data->effectors;
5047 float forc[3] = {0};
5056 effectors,
nullptr, surface->
effector_weights, &epoint, forc,
nullptr,
nullptr);
5095 double average_force = 0.0f;
5096 float shrink_speed = 0.0f, spread_speed = 0.0f;
5097 float fastest_effect, avg_dist;
5109 "PaintEffectForces");
5113 data.surface = surface;
5115 data.force = *force;
5116 data.effectors = effectors;
5126 average_force += double((*force)[
index * 4 + 3]);
5144 fastest_effect = std::max({spread_speed, shrink_speed,
float(average_force)});
5148 CLAMP(steps, 1, 20);
5173 const float eff_scale =
data->eff_scale;
5179 for (
int i = 0; i < numOfNeighs; i++) {
5180 const int n_idx = n_index[
index] + i;
5182 const PaintPoint *pPoint_prev = &prevPoint[n_target[n_idx]];
5183 const float speed_scale = (bNeighs[n_idx].
dist < eff_scale) ? 1.0f :
5184 eff_scale / bNeighs[n_idx].
dist;
5185 const float color_mix = std::min({pPoint_prev->
wetness, pPoint->
wetness, 1.0f}) * 0.25f *
5202 w_factor = 1.0f / numOfNeighs *
min_ff(pPoint_prev->
wetness, 1.0f) * speed_scale;
5203 CLAMP(w_factor, 0.0f, 1.0f);
5232 const float eff_scale =
data->eff_scale;
5238 for (
int i = 0; i < numOfNeighs; i++) {
5239 const int n_idx = n_index[
index] + i;
5240 const float speed_scale = (bNeighs[n_idx].
dist < eff_scale) ? 1.0f :
5241 eff_scale / bNeighs[n_idx].
dist;
5242 const PaintPoint *pPoint_prev = &prevPoint[n_target[n_idx]];
5243 float a_factor, ea_factor, w_factor;
5252 a_factor =
max_ff((1.0f - pPoint_prev->
color[3]) / numOfNeighs *
5253 (pPoint->
color[3] - pPoint_prev->
color[3]) * speed_scale,
5264 pPoint->
color[3] -= a_factor;
5266 pPoint->
e_color[3] -= ea_factor;
5290 const float *force =
data->force;
5291 const float eff_scale =
data->eff_scale;
5301 float w_factor = pPoint_prev->
wetness - 0.025f;
5302 if (w_factor <= 0) {
5305 CLAMP(w_factor, 0.0f, 1.0f);
5307 float ppoint_wetness_diff = 0.0f;
5313 for (
int i = 0; i < 2; i++) {
5314 const int n_idx = closest_id[i];
5315 if (n_idx != -1 && closest_d[i] > 0.0f) {
5316 const float dir_dot = closest_d[i];
5319 if (dir_dot <= 0.0f) {
5323 float dir_factor, a_factor;
5324 const float speed_scale = eff_scale * force[
index * 4 + 3] / bNeighs[n_idx].
dist;
5326 const uint n_trgt =
uint(n_target[n_idx]);
5331 const uint epointlock_idx = n_trgt / 8;
5332 const uint8_t epointlock_bitmask = 1 << (n_trgt & 7);
5340 const float e_wet = ePoint->
wetness;
5342 dir_factor =
min_ff(0.5f, dir_dot *
min_ff(speed_scale, 1.0f) * w_factor);
5345 ePoint->
wetness += dir_factor;
5349 a_factor = dir_factor / pPoint_prev->
wetness;
5350 CLAMP(a_factor, 0.0f, 1.0f);
5364 ppoint_wetness_diff += (ePoint->
wetness - e_wet);
5369 ~epointlock_bitmask);
5387 pPoint->
wetness -= ppoint_wetness_diff;
5430 data.surface = surface;
5431 data.prevPoint = prevPoint;
5432 data.eff_scale = eff_scale;
5452 data.surface = surface;
5453 data.prevPoint = prevPoint;
5454 data.eff_scale = eff_scale;
5470 const size_t point_locks_size = (sData->
total_points / 8) + 1;
5477 data.surface = surface;
5478 data.prevPoint = prevPoint;
5479 data.eff_scale = eff_scale;
5481 data.point_locks = point_locks;
5489 MEM_delete(point_locks);
5511 float mix_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
5512 float mix_e_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
5513 float mix_wetness = 0.0f;
5515 for (
int i = 0; i < numOfNeighs; i++) {
5516 const int n_idx = n_index[
index] + i;
5517 const int target = n_target[n_idx];
5527 mix_e_color[3] += pPoint2->
e_color[3];
5529 mix_wetness += pPoint2->
wetness;
5532 const float divisor = 1.0f / numOfNeighs;
5539 pPoint->
color[3] = 0.0f;
5542 if (mix_e_color[3]) {
5543 pPoint->
e_color[3] = mix_e_color[3] * divisor;
5550 pPoint->
wetness = mix_wetness / numOfNeighs;
5563 data.surface = surface;
5583 const float wave_speed =
data->wave_speed;
5584 const float wave_scale =
data->wave_scale;
5585 const float wave_max_slope =
data->wave_max_slope;
5587 const float dt =
data->dt;
5588 const float min_dist =
data->min_dist;
5589 const float damp_factor =
data->damp_factor;
5593 float force = 0.0f, avg_dist = 0.0f, avg_height = 0.0f, avg_n_height = 0.0f;
5594 int numOfN = 0, numOfRN = 0;
5596 if (wPoint->
state > 0) {
5605 for (
int i = 0; i < numOfNeighs; i++) {
5606 const int n_idx = n_index[
index] + i;
5607 float dist = bNeighs[n_idx].
dist * wave_scale;
5610 if (!dist || tPoint->
state > 0) {
5620 avg_n_height += tPoint->
height;
5624 force += (tPoint->
height - wPoint->
height) / (dist * dist);
5625 avg_height += tPoint->
height;
5627 avg_dist = (numOfN) ? avg_dist / numOfN : 0.0f;
5631 avg_n_height = (numOfRN) ? avg_n_height / numOfRN : 0.0f;
5632 wPoint->
height = (dt * wave_speed * avg_n_height + wPoint->
height * avg_dist) /
5633 (avg_dist + dt * wave_speed);
5639 force += (0.0f - wPoint->
height) * surface->
wave_spring / (avg_dist * avg_dist) / 2.0f;
5643 wPoint->
velocity += force * dt * wave_speed * wave_speed;
5650 if (wave_max_slope && avg_dist) {
5651 const float max_offset = wave_max_slope * avg_dist;
5652 const float offset = (numOfN) ? (avg_height / numOfN - wPoint->
height) : 0.0f;
5653 if (offset > max_offset) {
5654 wPoint->
height += offset - max_offset;
5656 else if (offset < -max_offset) {
5657 wPoint->
height += offset + max_offset;
5662 if (
data->reset_wave) {
5677 float dt, min_dist, damp_factor;
5678 const float wave_speed = surface->
wave_speed;
5682 double average_dist = 0.0f;
5697 for (
int i = 0; i < numOfNeighs; i++) {
5705 (average_dist /
double(wave_speed) / 3)));
5706 CLAMP(steps, 1, 20);
5711 min_dist = wave_speed * dt * 1.5f;
5714 for (ss = 0; ss < steps; ss++) {
5719 data.surface = surface;
5720 data.prevPoint = prevPoint;
5721 data.wave_speed = wave_speed;
5722 data.wave_scale = wave_scale;
5723 data.wave_max_slope = wave_max_slope;
5725 data.min_dist = min_dist;
5726 data.damp_factor = damp_factor;
5727 data.reset_wave = (ss == steps - 1);
5735 MEM_delete(prevPoint);
5761 const float timescale =
data->timescale;
5770 float p_wetness = pPoint->
wetness;
5779 float dry_ratio = pPoint->
wetness / p_wetness;
5792 pPoint->
e_color[3] *= dry_ratio;
5798 if (pPoint->
color[3]) {
5799 for (
int i = 0; i < 3; i++) {
5800 pPoint->
color[i] = (f_color[i] * f_color[3] -
5810 else if (pPoint->
state > 0) {
5854 int numOfVerts =
mesh->verts_num;
5866 for (
int i = 0; i < numOfVerts; i++) {
5902 const Vec3f *canvas_verts =
data->canvas_verts;
5904 const bool do_velocity_data =
data->do_velocity_data;
5905 const bool new_bdata =
data->new_bdata;
5907 float prev_point[3] = {0.0f, 0.0f, 0.0f};
5910 if (do_velocity_data && !new_bdata) {
5918 float n1[3], n2[3], n3[3];
5926 for (
int ss = 0; ss < bData->
s_num[
index]; ss++) {
5928 canvas_verts[tPoint->
v1].
v,
5929 canvas_verts[tPoint->
v2].
v,
5930 canvas_verts[tPoint->
v3].
v,
5945 float scaled_nor[3];
5965 for (ss = 0; ss < bData->
s_num[
index]; ss++) {
5973 canvas_verts[adj_data->
n_target[t_index]].
v,
5983 float scaled_nor[3];
5993 if (do_velocity_data && !new_bdata && !bData->
clear) {
5999 Depsgraph *depsgraph,
6006 bool new_bdata =
false;
6012 int canvasNumOfVerts =
mesh->verts_num;
6014 Vec3f *canvas_verts;
6025 if (do_velocity_data && bData->
velocity && (bData->
clear || !surface_moved)) {
6030 if (!surface_moved) {
6036 "Dynamic Paint transformed canvas verts");
6037 if (!canvas_verts) {
6046 MEM_delete(canvas_verts);
6053 "Dynamic Paint step data");
6055 "Dynamic Paint bData s_pos");
6057 "Dynamic Paint bData s_num");
6059 "Dynamic Paint point coords");
6061 size_t(canvasNumOfVerts),
"Dynamic Paint bData prev_positions");
6069 MEM_delete(bData->
s_pos);
6072 MEM_delete(bData->
s_num);
6078 MEM_delete(canvas_verts);
6087 if (do_velocity_data && !bData->
velocity) {
6092 "Dynamic Paint prev velocity");
6113 data.surface = surface;
6115 data.positions = positions;
6116 data.vert_normals =
mesh->vert_normals();
6117 data.canvas_verts = canvas_verts;
6118 data.do_velocity_data = do_velocity_data;
6119 data.new_bdata = new_bdata;
6127 MEM_delete(canvas_verts);
6136 memcpy(bData->
prev_positions, positions.
data(), canvasNumOfVerts *
sizeof(
float[3]));
6165 data.surface = surface;
6166 data.timescale = timescale;
6184 int scene_frame = scene->
r.
cfra;
6185 float scene_subframe = scene->
r.
subframe;
6187 for (
int i = 0; i < numobjects; i++) {
6188 Object *brushObj = objects[i];
6201 "Dynamic Paint brush velocity");
6245 depsgraph, surface, brushObj->
loc,
brush, brushObj, scene, timescale);
6248 else if (brushObj != ob) {
6254 scene->
r.
cfra = scene_frame;
6292 float *force =
nullptr;
6296 "PaintSurfaceDataCopy");
6303 for (s = 0; s < steps; s++) {
6309 MEM_delete(prevPoint);
6328 float timescale = 1.0f;
6341 timescale = 1.0f / (surface->
substeps + 1);
6343 for (st = 1; st <= surface->
substeps; st++) {
CustomData interface, see also DNA_customdata_types.h.
#define DPAINT_WAVE_ISECT_CHANGED
#define DPAINT_WAVE_REFLECT_ONLY
#define DPAINT_WAVE_OBSTACLE
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
#define PTCACHE_RESET_OUTDATED
File and directory operations.
A KD-tree for nearest neighbor search.
#define SNPRINTF(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define BLT_I18NCONTEXT_ID_BRUSH
#define CTX_DATA_(context, msgid)
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
#define CLOG_STR_ERROR(clg_ref, str)
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE uint8_t atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
ATOMIC_INLINE uint8_t atomic_fetch_and_or_uint8(uint8_t *p, uint8_t b)
ATOMIC_INLINE uint32_t atomic_add_and_fetch_uint32(uint32_t *p, uint32_t x)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr bool is_empty() const
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T * data() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr const char * c_str() const
bool contains(const Key &key) const
std::optional< AttributeMetaData > lookup_meta_data(StringRef name) const
GAttributeReader lookup(const StringRef name) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_for_write_span(StringRef name)
constexpr bool is_empty() const
#define EFF_MOVEMENT_PER_FRAME
#define SUBFRAME_RECURSION
#define BRUSH_USES_VELOCITY
void mix_color(float fac, float4 col1, float4 col2, float4 &outcol)
float dot(VecOp< float, D >, VecOp< float, D >) RET
float distance(float, float) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
T distance(const T &a, const T &b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
MINLINE float min_ff(float a, float b)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void dynamicPaint_brushMeshCalculateVelocity(Depsgraph *depsgraph, Scene *scene, Object *ob, DynamicPaintBrushSettings *brush, Vec3f **brushVel, float timescale)
int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old)
static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface)
MINLINE void negate_v3_v3(float r[3], const float a[3])
bool dynamicPaint_resetSurface(const struct Scene *scene, struct DynamicPaintSurface *surface)
void kdtree_balance(KDTree< CoordT > *tree)
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
static void dynamicPaint_allocateSurfaceType(DynamicPaintSurface *surface)
void dynamicPaint_freeSurface(const struct DynamicPaintModifierData *pmd, struct DynamicPaintSurface *surface)
static int dynamicPaint_doStep(Depsgraph *depsgraph, Scene *scene, Object *ob, DynamicPaintSurface *surface, float timescale, float subframe)
@ MOD_DPAINT_IMGFORMAT_PNG
@ MOD_DPAINT_IMGFORMAT_OPENEXR
char * STRNCPY(char(&dst)[N], const char *src)
static int surface_getBrushFlags(DynamicPaintSurface *surface, Depsgraph *depsgraph)
void dynamicPaint_outputSurfaceImage(struct DynamicPaintSurface *surface, const char *filepath, short output_layer)
static int neighStraightY[8]
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Mesh *result)
void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3])
void dynamicPaint_Modifier_copy(const struct DynamicPaintModifierData *pmd, struct DynamicPaintModifierData *tpmd, int flag)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
static void grid_bound_insert_cb_ex(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
MINLINE void copy_v3_v3(float r[3], const float a[3])
struct DynamicPaintSurface * dynamicPaint_createNewSurface(struct DynamicPaintCanvasSettings *canvas, struct Scene *scene)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void dynamicPaint_brushObjectCalculateVelocity(Depsgraph *depsgraph, Scene *scene, Object *ob, Vec3f *brushVel, float timescale)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
static void dynamic_paint_apply_surface_vpaint_blend_cb(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict)
static void dynamic_paint_create_uv_surface_direct_cb(void *__restrict userdata, const int ty, const TaskParallelTLS *__restrict)
static void dynamic_paint_apply_surface_vpaint_cb(void *__restrict userdata, const int p_index, const TaskParallelTLS *__restrict)
void dynamicPaint_clearSurface(const struct Scene *scene, struct DynamicPaintSurface *surface)
static void free_bakeData(PaintSurfaceData *data)
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
static void dynamic_paint_output_surface_image_wetmap_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static bool dynamicPaint_paintMesh(Depsgraph *depsgraph, DynamicPaintSurface *surface, DynamicPaintBrushSettings *brush, Object *brushOb, Scene *scene, float timescale)
static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static bool boundsIntersectDist(Bounds3D *b1, Bounds3D *b2, const float dist)
static void dynamic_paint_prepare_adjacency_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static void dynamic_paint_effect_spread_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
MINLINE void mul_v2_fl(float r[2], float f)
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, struct Object *ob, int output)
MINLINE void copy_v2_v2(float r[2], const float a[2])
void dynamicPaint_Modifier_free_runtime(struct DynamicPaintRuntime *runtime)
@ MOD_DPAINT_INITIAL_VERTEXCOLOR
@ MOD_DPAINT_INITIAL_NONE
@ MOD_DPAINT_INITIAL_COLOR
@ MOD_DPAINT_INITIAL_TEXTURE
void dynamicPaint_freeSurfaceData(struct DynamicPaintSurface *surface)
static void dynamicPaint_mixWaveHeight(PaintWavePoint *wPoint, const DynamicPaintBrushSettings *brush, float isect_height)
void dynamicPaint_freeBrush(struct DynamicPaintModifierData *pmd)
int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode)
static void dynamic_paint_wave_step_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static bool meshBrush_boundsIntersect(Bounds3D *b1, Bounds3D *b2, DynamicPaintBrushSettings *brush, float brush_radius)
static DynamicPaintRuntime * dynamicPaint_Modifier_runtime_ensure(DynamicPaintModifierData *pmd)
static void dynamic_paint_brush_velocity_compute_cb(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict)
@ eModifierType_DynamicPaint
static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *mesh)
static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, const bool force_init)
static const float gaussianFactors[5]
static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescale)
static void dynamic_paint_set_init_color_tex_to_imseq_cb(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict)
static void dynamicPaint_setInitialColor(const Scene *, DynamicPaintSurface *surface)
static void dynamicPaint_updatePointData(const DynamicPaintSurface *surface, const int index, const DynamicPaintBrushSettings *brush, float paint[3], float influence, float depth, float vel_factor, const float timescale)
static bool surface_usesAdjDistance(DynamicPaintSurface *surface)
MINLINE void add_v3_fl(float r[3], float f)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
void BKE_effectors_apply(ListBaseT< EffectorCache > *effectors, ListBaseT< ColliderCache > *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *wind_force, float *impulse)
ColorBand * BKE_colorband_add(bool rangetype)
const char * BKE_main_blendfile_path_from_global()
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
ATTR_WARN_UNUSED_RESULT const BMVert * v
@ PART_FLUID_SPRAYFOAMBUBBLE
@ MOD_DPAINT_PRFALL_SMOOTH
@ MOD_DPAINT_PRFALL_CONSTANT
int isect_point_tri_v2(const float pt[2], const float v1[2], const float v2[2], const float v3[2])
static void dynamic_paint_set_init_color_tex_to_vcol_cb(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict)
static Mesh * dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object *ob, Mesh *mesh)
static void surface_determineForceTargetPoints(const PaintSurfaceData *sData, const int index, const float force[3], float closest_d[2], int closest_id[2])
static void freeGrid(PaintSurfaceData *data)
@ LIB_ID_COPY_SET_COPIED_ON_WRITE
bool dynamicPaint_createType(struct DynamicPaintModifierData *pmd, int type, struct Scene *scene)
MINLINE void mul_v3_fl(float r[3], float f)
static bool boundIntersectPoint(Bounds3D *b, const float point[3], const float radius)
static Mesh * dynamicPaint_canvas_mesh_get(DynamicPaintCanvasSettings *canvas)
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
static bool dynamic_paint_surface_needs_dry_dissolve(DynamicPaintSurface *surface)
struct DynamicPaintSurface * get_activeSurface(struct DynamicPaintCanvasSettings *canvas)
MINLINE void sub_v3_v3(float r[3], const float a[3])
static bool setError(DynamicPaintCanvasSettings *canvas, const char *string)
KDTree< CoordT > * kdtree_new(uint nodes_len_capacity)
static void dynamic_paint_effect_shrink_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
void mul_m4_v3(const float M[4][4], float r[3])
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
bool IMB_save_image(ImBuf *ibuf, const char *filepath, ImBufFlags flags)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static int dynamic_paint_find_neighbor_pixel(const DynamicPaintCreateUVSurfaceData *data, const MeshElemMap *vert_to_tri_map, const int w, const int h, const int px, const int py, const int n_index)
static void dynamic_paint_apply_surface_displace_cb(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict)
static void grid_bound_insert_reduce(const void *__restrict, void *__restrict chunk_join, void *__restrict chunk)
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< float, 2 > float2
static void grid_cell_points_reduce(const void *__restrict userdata, void *__restrict chunk_join, void *__restrict chunk)
VecBase< int32_t, 3 > int3
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ MOD_DPAINT_PROX_PROJECT
@ MOD_DPAINT_INVERSE_PROX
@ MOD_DPAINT_VELOCITY_ALPHA
@ MOD_DPAINT_NEGATE_VOLUME
@ MOD_DPAINT_VELOCITY_COLOR
@ MOD_DPAINT_VELOCITY_DEPTH
@ MOD_DPAINT_USES_VELOCITY
static float getSurfaceDimension(PaintSurfaceData *sData)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void dynamicPaint_freeCanvas(struct DynamicPaintModifierData *pmd)
int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
static void dynamic_paint_set_init_color_vcol_to_imseq_cb(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict)
void minmax_v2v2_v2(float min[2], float max[2], const float vec[2])
BLI_INLINE void value_dissolve(float *r_value, const float time, const float scale, const bool is_log)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static void dynamic_paint_create_uv_surface_neighbor_cb(void *__restrict userdata, const int ty, const TaskParallelTLS *__restrict)
BMesh const char void * data
static void boundInsert(Bounds3D *b, const float point[3])
static void dynamicPaint_mixPaintColors(const DynamicPaintSurface *surface, const int index, const int paintFlags, const float paintColor[3], const float paintAlpha, const float paintWetness, const float timescale)
static void dynamic_paint_output_surface_image_paint_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
@ MOD_DYNAMICPAINT_TYPE_CANVAS
@ MOD_DYNAMICPAINT_TYPE_BRUSH
static bool dynamicPaint_paintSinglePoint(Depsgraph *depsgraph, DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush, Object *brushOb, Scene *scene, float timescale)
void interp_weights_tri_v3(float w[3], const float v1[3], const float v2[3], const float v3[3], const float co[3])
static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, float *force, PaintPoint *prevPoint, float timescale, float steps)
void kdtree_insert(KDTree< CoordT > *tree, int index, const CoordT &co)
void dynamicPaint_cacheUpdateFrames(struct DynamicPaintSurface *surface)
int kdtree_find_nearest(const KDTree< CoordT > *tree, const CoordT &co, KDTreeNearest< CoordT > *r_nearest)
MDeformWeight * BKE_defvert_ensure_index(MDeformVert *dv, int defgroup)
int BKE_object_defgroup_name_index(const Object *ob, StringRef name)
@ MOD_DPAINT_SURFACE_F_VERTEX
@ MOD_DPAINT_SURFACE_F_PTEX
@ MOD_DPAINT_SURFACE_F_IMAGESEQ
MINLINE void negate_v3(float r[3])
bool equals_m4m4(const float mat1[4][4], const float mat2[4][4])
void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
struct Mesh * dynamicPaint_Modifier_do(struct DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Mesh *mesh)
@ MOD_DPAINT_RAY_BRUSH_AVG
static void surface_freeUnusedData(DynamicPaintSurface *surface)
static bool dynamicPaint_checkSurfaceData(const Scene *scene, DynamicPaintSurface *surface)
static bool dynamicPaint_pointHasNeighbor(PaintAdjData *ed, int index, int neighbor)
ATTR_WARN_UNUSED_RESULT const size_t num
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void BKE_object_modifier_update_subframe(Depsgraph *depsgraph, Scene *scene, Object *ob, bool update_mesh, int parent_recursion_limit, float frame, int modifier_type)
void BKE_ptcache_id_from_dynamicpaint(PTCacheID *pid, struct Object *ob, struct DynamicPaintSurface *surface)
void BKE_image_pool_free(ImagePool *pool)
void BKE_id_free(Main *bmain, void *idv)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
void BKE_mesh_vert_corner_tri_map_create(MeshElemMap **r_map, int **r_mem, int totvert, const int3 *corner_tris, int tris_num, const int *corner_verts, int corners_num)
MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
static void dynamic_paint_generate_bake_data_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static bool surface_duplicateNameExists(DynamicPaintSurface *t_surface, const StringRefNull name)
static int dynamicPaint_prepareEffectStep(Depsgraph *depsgraph, DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale)
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
@ MOD_DPAINT_WAVEB_CHANGE
@ MOD_DPAINT_WAVEB_REFLECT
static int neighStraightX[8]
static float mixColors(float a_color[3], float a_weight, const float b_color[3], float b_weight, float ratio)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
static void dynamic_paint_apply_surface_wave_cb(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict)
void BKE_ptcache_validate(struct PointCache *cache, int framenr)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float n[3])
static bool surface_duplicateOutputExists(DynamicPaintSurface *t_surface, const StringRefNull name)
static bool boundsIntersect(Bounds3D *b1, Bounds3D *b2)
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
MINLINE void add_v3_v3(float r[3], const float a[3])
void kdtree_free(KDTree< CoordT > *tree)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void pd_point_from_loc(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
static void dynamic_paint_effect_drip_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
void BKE_ptcache_free_list(ListBaseT< PointCache > *ptcaches)
static bool dynamicPaint_paintParticles(DynamicPaintSurface *surface, ParticleSystem *psys, DynamicPaintBrushSettings *brush, float timescale)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static void dynamic_paint_prepare_effect_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static const float gaussianTotal
ATTR_WARN_UNUSED_RESULT const BMVert * v2
float BKE_scene_ctime_get(const Scene *scene)
MINLINE void copy_v3_fl(float r[3], float f)
struct Object ** BKE_collision_objects_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type)
static void surface_setUniqueOutputName(DynamicPaintSurface *surface, char *basename, int output)
static void dynamicPaint_freeAdjData(PaintSurfaceData *data)
int multitex_ext_safe(Tex *tex, const float texvec[3], TexResult *texres, ImagePool *pool, bool scene_color_manage, const bool skip_load_image)
static void scene_setSubframe(Scene *scene, float subframe)
static int surface_totalSamples(DynamicPaintSurface *surface)
MINLINE float max_ff(float a, float b)
static void blendColors(const float t_color[3], const float t_alpha, const float s_color[3], const float s_alpha, float result[4])
static void dynamic_paint_output_surface_image_displace_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceData *data, DynamicPaintFindIslandBorderData *bdata, int tri_index, const float pixel[2], int in_edge, int depth)
ListBaseT< EffectorCache > * BKE_effectors_create(struct Depsgraph *depsgraph, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool use_rotation)
static bool dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Depsgraph *depsgraph, Object *ob)
static void surfaceGenerateGrid(DynamicPaintSurface *surface)
int dynamicPaint_calculateFrame(struct DynamicPaintSurface *surface, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *cObject, int frame)
float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2])
static void canvas_copyMesh(DynamicPaintCanvasSettings *canvas, Mesh *mesh)
@ eModifierFlag_SharedCaches
struct PointCache * BKE_ptcache_add(ListBaseT< PointCache > *ptcaches)
static void dynamic_paint_output_surface_image_wave_cb(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, DynamicPaintBrushSettings *brush, float timescale)
MINLINE float square_f(float a)
@ MOD_DPAINT_DISP_DISPLACE
int kdtree_range_search(const KDTree< CoordT > *tree, const CoordT &co, KDTreeNearest< CoordT > **r_nearest, typename KDTree< CoordT >::ValueType range)
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) ATTR_WARN_UNUSED_RESULT
@ MOD_DPAINT_DISP_INCREMENTAL
@ MOD_DPAINT_WAVE_OPEN_BORDERS
@ MOD_DPAINT_DISSOLVE_LOG
static void dynamicPaint_doBorderStep(DynamicPaintSurface *surface)
MINLINE void copy_v4_v4(float r[4], const float a[4])
ImagePool * BKE_image_pool_new()
static void dynamic_paint_border_cb(void *__restrict userdata, const int b_index, const TaskParallelTLS *__restrict)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
void dynamicPaintSurface_setUniqueName(struct DynamicPaintSurface *surface, const char *basename)
void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3])
static void dynamic_paint_paint_single_point_cb_ex(void *__restrict userdata, const int index, const TaskParallelTLS *__restrict)
static bool dynamicPaint_symmetrizeAdjData(PaintAdjData *ed, int active_points)
static void dynamic_paint_paint_mesh_cell_point_cb_ex(void *__restrict userdata, const int id, const TaskParallelTLS *__restrict)
static bool surface_usesAdjData(DynamicPaintSurface *surface)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const bool force_init)
MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
static float dist_squared_to_corner_tris_uv_edges(const Span< int3 > corner_tris, const Span< float2 > uv_map, int tri_index, const float point[2])
void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3])
static void dynamic_paint_paint_particle_cell_point_cb_ex(void *__restrict userdata, const int id, const TaskParallelTLS *__restrict)
int BKE_image_path_ext_from_imtype_ensure(char *filepath, size_t filepath_maxncpy, char imtype)
struct EffectorWeights * BKE_effector_add_weights(struct Collection *collection)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void dynamicPaint_Modifier_free(struct DynamicPaintModifierData *pmd)
static void grid_cell_bounds_cb(void *__restrict userdata, const int x, const TaskParallelTLS *__restrict)
void BKE_modifier_path_init(char *path, int path_maxncpy, const char *name)
bool BLI_file_ensure_parent_dir_exists(const char *filepath) ATTR_NONNULL(1)
int dynamicPaint_createUVSurface(struct Scene *scene, struct DynamicPaintSurface *surface, float *progress, bool *do_update)
@ MOD_DPAINT_SURFACE_T_PAINT
@ MOD_DPAINT_SURFACE_T_WAVE
@ MOD_DPAINT_SURFACE_T_WEIGHT
@ MOD_DPAINT_SURFACE_T_DISPLACE
void BKE_collision_objects_free(struct Object **objects)
eDynamicPaint_EffectFlags
@ MOD_DPAINT_EFFECT_DO_DRIP
@ MOD_DPAINT_EFFECT_DO_SHRINK
@ MOD_DPAINT_EFFECT_DO_SPREAD
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
void BKE_effectors_free(ListBaseT< EffectorCache > *lb)
MDeformWeight * BKE_defvert_find_index(const MDeformVert *dv, int defgroup)
static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *ob)
static void grid_cell_points_cb_ex(void *__restrict userdata, const int i, const TaskParallelTLS *__restrict tls)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct DynamicPaintModifierData * pmd
struct ColorBand * paint_ramp
struct ColorBand * vel_ramp
const float(* positions_c)[3]
const float(* positions_p)[3]
ListBaseT< DynamicPaintSurface > surfaces
eDynamicPaint_CanvasFlags flags
struct DynamicPaintModifierData * pmd
const DynamicPaintSurface * surface
PaintUVPoint * tempPoints
const DynamicPaintSurface * surface
const DynamicPaintSurface * surface
ListBaseT< EffectorCache > * effectors
const MeshElemMap * vert_to_tri_map
const Vec3f * canvas_verts
const DynamicPaintSurface * surface
Span< float3 > vert_normals
const DynamicPaintSurface * surface
MutableSpan< ColorGeometry4b > mloopcol_wet
OffsetIndices< int > faces
MutableSpan< ColorGeometry4b > mloopcol
Span< float3 > vert_normals
MutableSpan< float3 > vert_positions
struct DynamicPaintBrushSettings * brush
struct DynamicPaintCanvasSettings * canvas
DynamicPaintModifierType type
const DynamicPaintSurface * surface
const DynamicPaintSurface * surface
const ParticleSystem * psys
const DynamicPaintBrushSettings * brush
const float * avg_brushNor
const Vec3f * brushVelocity
const DynamicPaintSurface * surface
Span< ColorGeometry4b > mloopcol
struct DynamicPaintCanvasSettings * canvas
struct Collection * brush_group
eDynamicPaint_EffectFlags effect
struct Tex * init_texture
ListBaseT< PointCache > ptcaches
eDynamicPaint_SurfaceFormat format
struct PaintSurfaceData * data
eDynamicPaint_ImageFormat image_fileformat
struct EffectorWeights * effector_weights
char image_output_path[1024]
eDynamicPaint_SurfaceFlags flags
eDynamicPaint_InitColorType init_color_type
eDynamicPaint_SurfaceType type
float color_dry_threshold
struct PointCache * pointcache
struct DynamicPaintSurface * next
eDynamicPaint_DispType disp_type
ImbFormatOptions foptions
float * float_data_for_write()
struct PointCache * cache
DynamicPaintVolumeGrid * grid
float(* prev_positions)[3]
PaintBakeNormal * bNormal
ImgSeqFormatData * format_data
struct PaintBakeData * bData
struct PhysicsSettings physics_settings
TaskParallelReduceFunc func_reduce
size_t userdata_chunk_size
MutableVArraySpan< T > span