Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/dynamicpaint.c
| Show First 20 Lines • Show All 1,462 Lines • ▼ Show 20 Lines | static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const bool force_init) | ||||
| MEM_freeN(temp_data); | MEM_freeN(temp_data); | ||||
| } | } | ||||
| typedef struct DynamicPaintSetInitColorData { | typedef struct DynamicPaintSetInitColorData { | ||||
| const DynamicPaintSurface *surface; | const DynamicPaintSurface *surface; | ||||
| const MLoop *mloop; | const MLoop *mloop; | ||||
| const MLoopUV *mloopuv; | const float (*mloopuv)[2]; | ||||
| const MLoopTri *mlooptri; | const MLoopTri *mlooptri; | ||||
| const MLoopCol *mloopcol; | const MLoopCol *mloopcol; | ||||
| struct ImagePool *pool; | struct ImagePool *pool; | ||||
| const bool scene_color_manage; | const bool scene_color_manage; | ||||
| } DynamicPaintSetInitColorData; | } DynamicPaintSetInitColorData; | ||||
| static void dynamic_paint_set_init_color_tex_to_vcol_cb( | static void dynamic_paint_set_init_color_tex_to_vcol_cb( | ||||
| void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) | void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| const DynamicPaintSetInitColorData *data = userdata; | const DynamicPaintSetInitColorData *data = userdata; | ||||
| const PaintSurfaceData *sData = data->surface->data; | const PaintSurfaceData *sData = data->surface->data; | ||||
| PaintPoint *pPoint = (PaintPoint *)sData->type_data; | PaintPoint *pPoint = (PaintPoint *)sData->type_data; | ||||
| const MLoop *mloop = data->mloop; | const MLoop *mloop = data->mloop; | ||||
| const MLoopTri *mlooptri = data->mlooptri; | const MLoopTri *mlooptri = data->mlooptri; | ||||
| const MLoopUV *mloopuv = data->mloopuv; | const float(*mloopuv)[2] = data->mloopuv; | ||||
| struct ImagePool *pool = data->pool; | struct ImagePool *pool = data->pool; | ||||
| Tex *tex = data->surface->init_texture; | Tex *tex = data->surface->init_texture; | ||||
| const bool scene_color_manage = data->scene_color_manage; | const bool scene_color_manage = data->scene_color_manage; | ||||
| float uv[3] = {0.0f}; | float uv[3] = {0.0f}; | ||||
| for (int j = 3; j--;) { | for (int j = 3; j--;) { | ||||
| TexResult texres = {0}; | TexResult texres = {0}; | ||||
| const uint vert = mloop[mlooptri[i].tri[j]].v; | const uint vert = mloop[mlooptri[i].tri[j]].v; | ||||
| /* remap to [-1.0, 1.0] */ | /* remap to [-1.0, 1.0] */ | ||||
| uv[0] = mloopuv[mlooptri[i].tri[j]].uv[0] * 2.0f - 1.0f; | uv[0] = mloopuv[mlooptri[i].tri[j]][0] * 2.0f - 1.0f; | ||||
| uv[1] = mloopuv[mlooptri[i].tri[j]].uv[1] * 2.0f - 1.0f; | uv[1] = mloopuv[mlooptri[i].tri[j]][1] * 2.0f - 1.0f; | ||||
| multitex_ext_safe(tex, uv, &texres, pool, scene_color_manage, false); | multitex_ext_safe(tex, uv, &texres, pool, scene_color_manage, false); | ||||
| if (texres.tin > pPoint[vert].color[3]) { | if (texres.tin > pPoint[vert].color[3]) { | ||||
| copy_v3_v3(pPoint[vert].color, texres.trgba); | copy_v3_v3(pPoint[vert].color, texres.trgba); | ||||
| pPoint[vert].color[3] = texres.tin; | pPoint[vert].color[3] = texres.tin; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void dynamic_paint_set_init_color_tex_to_imseq_cb( | static void dynamic_paint_set_init_color_tex_to_imseq_cb( | ||||
| void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) | void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| const DynamicPaintSetInitColorData *data = userdata; | const DynamicPaintSetInitColorData *data = userdata; | ||||
| const PaintSurfaceData *sData = data->surface->data; | const PaintSurfaceData *sData = data->surface->data; | ||||
| PaintPoint *pPoint = (PaintPoint *)sData->type_data; | PaintPoint *pPoint = (PaintPoint *)sData->type_data; | ||||
| const MLoopTri *mlooptri = data->mlooptri; | const MLoopTri *mlooptri = data->mlooptri; | ||||
| const MLoopUV *mloopuv = data->mloopuv; | const float(*mloopuv)[2] = data->mloopuv; | ||||
| Tex *tex = data->surface->init_texture; | Tex *tex = data->surface->init_texture; | ||||
| ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; | ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data; | ||||
| const int samples = (data->surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; | const int samples = (data->surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; | ||||
| const bool scene_color_manage = data->scene_color_manage; | const bool scene_color_manage = data->scene_color_manage; | ||||
| float uv[9] = {0.0f}; | float uv[9] = {0.0f}; | ||||
| float uv_final[3] = {0.0f}; | float uv_final[3] = {0.0f}; | ||||
| TexResult texres = {0}; | TexResult texres = {0}; | ||||
| /* collect all uvs */ | /* collect all uvs */ | ||||
| for (int j = 3; j--;) { | for (int j = 3; j--;) { | ||||
| copy_v2_v2(&uv[j * 3], mloopuv[mlooptri[f_data->uv_p[i].tri_index].tri[j]].uv); | copy_v2_v2(&uv[j * 3], mloopuv[mlooptri[f_data->uv_p[i].tri_index].tri[j]]); | ||||
| } | } | ||||
| /* interpolate final uv pos */ | /* interpolate final uv pos */ | ||||
| interp_v3_v3v3v3(uv_final, &uv[0], &uv[3], &uv[6], f_data->barycentricWeights[i * samples].v); | interp_v3_v3v3v3(uv_final, &uv[0], &uv[3], &uv[6], f_data->barycentricWeights[i * samples].v); | ||||
| /* remap to [-1.0, 1.0] */ | /* remap to [-1.0, 1.0] */ | ||||
| uv_final[0] = uv_final[0] * 2.0f - 1.0f; | uv_final[0] = uv_final[0] * 2.0f - 1.0f; | ||||
| uv_final[1] = uv_final[1] * 2.0f - 1.0f; | uv_final[1] = uv_final[1] * 2.0f - 1.0f; | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | else if (surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) { | ||||
| char uvname[MAX_CUSTOMDATA_LAYER_NAME]; | char uvname[MAX_CUSTOMDATA_LAYER_NAME]; | ||||
| if (!tex) { | if (!tex) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* get uv map */ | /* get uv map */ | ||||
| CustomData_validate_layer_name(&mesh->ldata, CD_MLOOPUV, surface->init_layername, uvname); | CustomData_validate_layer_name(&mesh->ldata, CD_PROP_FLOAT2, surface->init_layername, uvname); | ||||
| const MLoopUV *mloopuv = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPUV, uvname); | const float(*mloopuv)[2] = CustomData_get_layer_named(&mesh->ldata, CD_PROP_FLOAT2, uvname); | ||||
| if (!mloopuv) { | if (!mloopuv) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* for vertex surface loop through tfaces and find uv color | /* for vertex surface loop through tfaces and find uv color | ||||
| * that provides highest alpha */ | * that provides highest alpha */ | ||||
| if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { | if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { | ||||
| struct ImagePool *pool = BKE_image_pool_new(); | struct ImagePool *pool = BKE_image_pool_new(); | ||||
| ▲ Show 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | |||||
| typedef struct DynamicPaintCreateUVSurfaceData { | typedef struct DynamicPaintCreateUVSurfaceData { | ||||
| const DynamicPaintSurface *surface; | const DynamicPaintSurface *surface; | ||||
| PaintUVPoint *tempPoints; | PaintUVPoint *tempPoints; | ||||
| Vec3f *tempWeights; | Vec3f *tempWeights; | ||||
| const MLoopTri *mlooptri; | const MLoopTri *mlooptri; | ||||
| const MLoopUV *mloopuv; | const float (*mloopuv)[2]; | ||||
| const MLoop *mloop; | const MLoop *mloop; | ||||
| const int tottri; | const int tottri; | ||||
| const Bounds2D *faceBB; | const Bounds2D *faceBB; | ||||
| uint32_t *active_points; | uint32_t *active_points; | ||||
| } DynamicPaintCreateUVSurfaceData; | } DynamicPaintCreateUVSurfaceData; | ||||
| static void dynamic_paint_create_uv_surface_direct_cb( | static void dynamic_paint_create_uv_surface_direct_cb( | ||||
| void *__restrict userdata, const int ty, const TaskParallelTLS *__restrict UNUSED(tls)) | void *__restrict userdata, const int ty, const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| const DynamicPaintCreateUVSurfaceData *data = userdata; | const DynamicPaintCreateUVSurfaceData *data = userdata; | ||||
| const DynamicPaintSurface *surface = data->surface; | const DynamicPaintSurface *surface = data->surface; | ||||
| PaintUVPoint *tempPoints = data->tempPoints; | PaintUVPoint *tempPoints = data->tempPoints; | ||||
| Vec3f *tempWeights = data->tempWeights; | Vec3f *tempWeights = data->tempWeights; | ||||
| const MLoopTri *mlooptri = data->mlooptri; | const MLoopTri *mlooptri = data->mlooptri; | ||||
| const MLoopUV *mloopuv = data->mloopuv; | const float(*mloopuv)[2] = data->mloopuv; | ||||
| const MLoop *mloop = data->mloop; | const MLoop *mloop = data->mloop; | ||||
| const int tottri = data->tottri; | const int tottri = data->tottri; | ||||
| const Bounds2D *faceBB = data->faceBB; | const Bounds2D *faceBB = data->faceBB; | ||||
| const float jitter5sample[10] = JITTER_SAMPLES; | const float jitter5sample[10] = JITTER_SAMPLES; | ||||
| const int aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; | const int aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; | ||||
| const int w = surface->image_resolution; | const int w = surface->image_resolution; | ||||
| Show All 36 Lines | for (int sample = 0; sample < 5; sample++) { | ||||
| */ | */ | ||||
| for (int i = 0; i < tottri; i++) { | for (int i = 0; i < tottri; i++) { | ||||
| /* Check uv bb */ | /* Check uv bb */ | ||||
| if ((faceBB[i].min[0] > point[sample][0]) || (faceBB[i].min[1] > point[sample][1]) || | if ((faceBB[i].min[0] > point[sample][0]) || (faceBB[i].min[1] > point[sample][1]) || | ||||
| (faceBB[i].max[0] < point[sample][0]) || (faceBB[i].max[1] < point[sample][1])) { | (faceBB[i].max[0] < point[sample][0]) || (faceBB[i].max[1] < point[sample][1])) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| const float *uv1 = mloopuv[mlooptri[i].tri[0]].uv; | const float *uv1 = mloopuv[mlooptri[i].tri[0]]; | ||||
| const float *uv2 = mloopuv[mlooptri[i].tri[1]].uv; | const float *uv2 = mloopuv[mlooptri[i].tri[1]]; | ||||
| const float *uv3 = mloopuv[mlooptri[i].tri[2]].uv; | const float *uv3 = mloopuv[mlooptri[i].tri[2]]; | ||||
| /* If point is inside the face */ | /* If point is inside the face */ | ||||
| if (isect_point_tri_v2(point[sample], uv1, uv2, uv3) != 0) { | if (isect_point_tri_v2(point[sample], uv1, uv2, uv3) != 0) { | ||||
| float uv[2]; | float uv[2]; | ||||
| /* Add b-weights per anti-aliasing sample */ | /* Add b-weights per anti-aliasing sample */ | ||||
| for (int j = 0; j < aa_samples; j++) { | for (int j = 0; j < aa_samples; j++) { | ||||
| uv[0] = point[0][0] + jitter5sample[j * 2] / w; | uv[0] = point[0][0] + jitter5sample[j * 2] / w; | ||||
| Show All 23 Lines | |||||
| { | { | ||||
| const DynamicPaintCreateUVSurfaceData *data = userdata; | const DynamicPaintCreateUVSurfaceData *data = userdata; | ||||
| const DynamicPaintSurface *surface = data->surface; | const DynamicPaintSurface *surface = data->surface; | ||||
| PaintUVPoint *tempPoints = data->tempPoints; | PaintUVPoint *tempPoints = data->tempPoints; | ||||
| Vec3f *tempWeights = data->tempWeights; | Vec3f *tempWeights = data->tempWeights; | ||||
| const MLoopTri *mlooptri = data->mlooptri; | const MLoopTri *mlooptri = data->mlooptri; | ||||
| const MLoopUV *mloopuv = data->mloopuv; | const float(*mloopuv)[2] = data->mloopuv; | ||||
| const MLoop *mloop = data->mloop; | const MLoop *mloop = data->mloop; | ||||
| uint32_t *active_points = data->active_points; | uint32_t *active_points = data->active_points; | ||||
| const float jitter5sample[10] = JITTER_SAMPLES; | const float jitter5sample[10] = JITTER_SAMPLES; | ||||
| const int aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; | const int aa_samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1; | ||||
| const int w = surface->image_resolution; | const int w = surface->image_resolution; | ||||
| const int h = w; | const int h = w; | ||||
| Show All 24 Lines | if (tPoint->tri_index == -1) { | ||||
| /* if not this pixel itself */ | /* if not this pixel itself */ | ||||
| if (u != 0 || v != 0) { | if (u != 0 || v != 0) { | ||||
| const int ind = (tx + u) + w * (ty + v); | const int ind = (tx + u) + w * (ty + v); | ||||
| /* if neighbor has index */ | /* if neighbor has index */ | ||||
| if (tempPoints[ind].neighbor_pixel == -1 && tempPoints[ind].tri_index != -1) { | if (tempPoints[ind].neighbor_pixel == -1 && tempPoints[ind].tri_index != -1) { | ||||
| float uv[2]; | float uv[2]; | ||||
| const int i = tempPoints[ind].tri_index; | const int i = tempPoints[ind].tri_index; | ||||
| const float *uv1 = mloopuv[mlooptri[i].tri[0]].uv; | const float *uv1 = mloopuv[mlooptri[i].tri[0]]; | ||||
| const float *uv2 = mloopuv[mlooptri[i].tri[1]].uv; | const float *uv2 = mloopuv[mlooptri[i].tri[1]]; | ||||
| const float *uv3 = mloopuv[mlooptri[i].tri[2]].uv; | const float *uv3 = mloopuv[mlooptri[i].tri[2]]; | ||||
| /* tri index */ | /* tri index */ | ||||
| /* There is a low possibility of actually having a neighbor point which tri is | /* There is a low possibility of actually having a neighbor point which tri is | ||||
| * already set from another neighbor in a separate thread here. | * already set from another neighbor in a separate thread here. | ||||
| * Checking for both tri_index and neighbor_pixel above reduces that probability | * Checking for both tri_index and neighbor_pixel above reduces that probability | ||||
| * but it remains possible. | * but it remains possible. | ||||
| * That atomic op (and its memory fence) ensures tPoint->neighbor_pixel is set | * That atomic op (and its memory fence) ensures tPoint->neighbor_pixel is set | ||||
| * to non--1 *before* its tri_index is set (i.e. that it cannot be used a neighbor). | * to non--1 *before* its tri_index is set (i.e. that it cannot be used a neighbor). | ||||
| Show All 27 Lines | if (tPoint->tri_index != -1) { | ||||
| atomic_add_and_fetch_uint32(active_points, 1); | atomic_add_and_fetch_uint32(active_points, 1); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #undef JITTER_SAMPLES | #undef JITTER_SAMPLES | ||||
| static float dist_squared_to_looptri_uv_edges(const MLoopTri *mlooptri, | static float dist_squared_to_looptri_uv_edges(const MLoopTri *mlooptri, | ||||
| const MLoopUV *mloopuv, | const float (*mloopuv)[2], | ||||
| int tri_index, | int tri_index, | ||||
| const float point[2]) | const float point[2]) | ||||
| { | { | ||||
| BLI_assert(tri_index >= 0); | BLI_assert(tri_index >= 0); | ||||
| float min_distance = FLT_MAX; | float min_distance = FLT_MAX; | ||||
| for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
| const float dist_squared = dist_squared_to_line_segment_v2( | const float dist_squared = dist_squared_to_line_segment_v2( | ||||
| point, | point, | ||||
| mloopuv[mlooptri[tri_index].tri[(i + 0)]].uv, | mloopuv[mlooptri[tri_index].tri[(i + 0)]], | ||||
| mloopuv[mlooptri[tri_index].tri[(i + 1) % 3]].uv); | mloopuv[mlooptri[tri_index].tri[(i + 1) % 3]]); | ||||
| if (dist_squared < min_distance) { | if (dist_squared < min_distance) { | ||||
| min_distance = dist_squared; | min_distance = dist_squared; | ||||
| } | } | ||||
| } | } | ||||
| return min_distance; | return min_distance; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceData *data, | ||||
| DynamicPaintFindIslandBorderData *bdata, | DynamicPaintFindIslandBorderData *bdata, | ||||
| int tri_index, | int tri_index, | ||||
| const float pixel[2], | const float pixel[2], | ||||
| int in_edge, | int in_edge, | ||||
| int depth) | int depth) | ||||
| { | { | ||||
| const MLoop *mloop = data->mloop; | const MLoop *mloop = data->mloop; | ||||
| const MLoopTri *mlooptri = data->mlooptri; | const MLoopTri *mlooptri = data->mlooptri; | ||||
| const MLoopUV *mloopuv = data->mloopuv; | const float(*mloopuv)[2] = data->mloopuv; | ||||
| const uint *loop_idx = mlooptri[tri_index].tri; | const uint *loop_idx = mlooptri[tri_index].tri; | ||||
| /* Enumerate all edges of the triangle, rotating the vertex list accordingly. */ | /* Enumerate all edges of the triangle, rotating the vertex list accordingly. */ | ||||
| for (int edge_idx = 0; edge_idx < 3; edge_idx++) { | for (int edge_idx = 0; edge_idx < 3; edge_idx++) { | ||||
| /* but not the edge we have just recursed through */ | /* but not the edge we have just recursed through */ | ||||
| if (edge_idx == in_edge) { | if (edge_idx == in_edge) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| float uv0[2], uv1[2], uv2[2]; | float uv0[2], uv1[2], uv2[2]; | ||||
| copy_v2_v2(uv0, mloopuv[loop_idx[(edge_idx + 0)]].uv); | copy_v2_v2(uv0, mloopuv[loop_idx[(edge_idx + 0)]]); | ||||
| copy_v2_v2(uv1, mloopuv[loop_idx[(edge_idx + 1) % 3]].uv); | copy_v2_v2(uv1, mloopuv[loop_idx[(edge_idx + 1) % 3]]); | ||||
| copy_v2_v2(uv2, mloopuv[loop_idx[(edge_idx + 2) % 3]].uv); | copy_v2_v2(uv2, mloopuv[loop_idx[(edge_idx + 2) % 3]]); | ||||
| /* Verify the target point is on the opposite side of the edge from the third triangle | /* Verify the target point is on the opposite side of the edge from the third triangle | ||||
| * vertex, to ensure that we always move closer to the goal point. */ | * vertex, to ensure that we always move closer to the goal point. */ | ||||
| const float sidep = line_point_side_v2(uv0, uv1, pixel); | const float sidep = line_point_side_v2(uv0, uv1, pixel); | ||||
| const float side2 = line_point_side_v2(uv0, uv1, uv2); | const float side2 = line_point_side_v2(uv0, uv1, uv2); | ||||
| if (side2 == 0.0f) { | if (side2 == 0.0f) { | ||||
| continue; | continue; | ||||
| Show All 34 Lines | for (int i = 0; i < map->count && !found_other; i++) { | ||||
| /* Check edges for match, looping in the same order as the outer loop. */ | /* Check edges for match, looping in the same order as the outer loop. */ | ||||
| for (int j = 0; j < 3; j++) { | for (int j = 0; j < 3; j++) { | ||||
| const int overt0 = mloop[other_loop_idx[(j + 0)]].v; | const int overt0 = mloop[other_loop_idx[(j + 0)]].v; | ||||
| const int overt1 = mloop[other_loop_idx[(j + 1) % 3]].v; | const int overt1 = mloop[other_loop_idx[(j + 1) % 3]].v; | ||||
| /* Allow for swapped vertex order */ | /* Allow for swapped vertex order */ | ||||
| if (overt0 == vert0 && overt1 == vert1) { | if (overt0 == vert0 && overt1 == vert1) { | ||||
| found_other = true; | found_other = true; | ||||
| copy_v2_v2(ouv0, mloopuv[other_loop_idx[(j + 0)]].uv); | copy_v2_v2(ouv0, mloopuv[other_loop_idx[(j + 0)]]); | ||||
| copy_v2_v2(ouv1, mloopuv[other_loop_idx[(j + 1) % 3]].uv); | copy_v2_v2(ouv1, mloopuv[other_loop_idx[(j + 1) % 3]]); | ||||
| } | } | ||||
| else if (overt0 == vert1 && overt1 == vert0) { | else if (overt0 == vert1 && overt1 == vert0) { | ||||
| found_other = true; | found_other = true; | ||||
| copy_v2_v2(ouv1, mloopuv[other_loop_idx[(j + 0)]].uv); | copy_v2_v2(ouv1, mloopuv[other_loop_idx[(j + 0)]]); | ||||
| copy_v2_v2(ouv0, mloopuv[other_loop_idx[(j + 1) % 3]].uv); | copy_v2_v2(ouv0, mloopuv[other_loop_idx[(j + 1) % 3]]); | ||||
| } | } | ||||
| if (found_other) { | if (found_other) { | ||||
| target_tri = lt_index; | target_tri = lt_index; | ||||
| target_edge = j; | target_edge = j; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | int dynamicPaint_createUVSurface(Scene *scene, | ||||
| PaintSurfaceData *sData; | PaintSurfaceData *sData; | ||||
| DynamicPaintCanvasSettings *canvas = surface->canvas; | DynamicPaintCanvasSettings *canvas = surface->canvas; | ||||
| Mesh *mesh = dynamicPaint_canvas_mesh_get(canvas); | Mesh *mesh = dynamicPaint_canvas_mesh_get(canvas); | ||||
| PaintUVPoint *tempPoints = NULL; | PaintUVPoint *tempPoints = NULL; | ||||
| Vec3f *tempWeights = NULL; | Vec3f *tempWeights = NULL; | ||||
| const MLoopTri *mlooptri = NULL; | const MLoopTri *mlooptri = NULL; | ||||
| const MLoopUV *mloopuv = NULL; | const float(*mloopuv)[2] = NULL; | ||||
| const MLoop *mloop = NULL; | const MLoop *mloop = NULL; | ||||
| Bounds2D *faceBB = NULL; | Bounds2D *faceBB = NULL; | ||||
| int *final_index; | int *final_index; | ||||
| *progress = 0.0f; | *progress = 0.0f; | ||||
| *do_update = true; | *do_update = true; | ||||
| if (!mesh) { | if (!mesh) { | ||||
| return setError(canvas, N_("Canvas mesh not updated")); | return setError(canvas, N_("Canvas mesh not updated")); | ||||
| } | } | ||||
| if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ) { | if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ) { | ||||
| return setError(canvas, N_("Cannot bake non-'image sequence' formats")); | return setError(canvas, N_("Cannot bake non-'image sequence' formats")); | ||||
| } | } | ||||
| mloop = BKE_mesh_loops(mesh); | mloop = BKE_mesh_loops(mesh); | ||||
| mlooptri = BKE_mesh_runtime_looptri_ensure(mesh); | mlooptri = BKE_mesh_runtime_looptri_ensure(mesh); | ||||
| const int tottri = BKE_mesh_runtime_looptri_len(mesh); | const int tottri = BKE_mesh_runtime_looptri_len(mesh); | ||||
| /* get uv map */ | /* get uv map */ | ||||
| if (CustomData_has_layer(&mesh->ldata, CD_MLOOPUV)) { | if (CustomData_has_layer(&mesh->ldata, CD_PROP_FLOAT2)) { | ||||
| CustomData_validate_layer_name(&mesh->ldata, CD_MLOOPUV, surface->uvlayer_name, uvname); | CustomData_validate_layer_name(&mesh->ldata, CD_PROP_FLOAT2, surface->uvlayer_name, uvname); | ||||
| mloopuv = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPUV, uvname); | mloopuv = CustomData_get_layer_named(&mesh->ldata, CD_PROP_FLOAT2, uvname); | ||||
| } | } | ||||
| /* Check for validity */ | /* Check for validity */ | ||||
| if (!mloopuv) { | if (!mloopuv) { | ||||
| return setError(canvas, N_("No UV data on canvas")); | return setError(canvas, N_("No UV data on canvas")); | ||||
| } | } | ||||
| if (surface->image_resolution < 16 || surface->image_resolution > 8192) { | if (surface->image_resolution < 16 || surface->image_resolution > 8192) { | ||||
| return setError(canvas, N_("Invalid resolution")); | return setError(canvas, N_("Invalid resolution")); | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (!error) { | ||||
| } | } | ||||
| } | } | ||||
| *progress = 0.01f; | *progress = 0.01f; | ||||
| *do_update = true; | *do_update = true; | ||||
| if (!error) { | if (!error) { | ||||
| for (int i = 0; i < tottri; i++) { | for (int i = 0; i < tottri; i++) { | ||||
| copy_v2_v2(faceBB[i].min, mloopuv[mlooptri[i].tri[0]].uv); | copy_v2_v2(faceBB[i].min, mloopuv[mlooptri[i].tri[0]]); | ||||
| copy_v2_v2(faceBB[i].max, mloopuv[mlooptri[i].tri[0]].uv); | copy_v2_v2(faceBB[i].max, mloopuv[mlooptri[i].tri[0]]); | ||||
| for (int j = 1; j < 3; j++) { | for (int j = 1; j < 3; j++) { | ||||
| minmax_v2v2_v2(faceBB[i].min, faceBB[i].max, mloopuv[mlooptri[i].tri[j]].uv); | minmax_v2v2_v2(faceBB[i].min, faceBB[i].max, mloopuv[mlooptri[i].tri[j]]); | ||||
| } | } | ||||
| } | } | ||||
| *progress = 0.02f; | *progress = 0.02f; | ||||
| *do_update = true; | *do_update = true; | ||||
| /* Loop through every pixel and check if pixel is uv-mapped on a canvas face. */ | /* Loop through every pixel and check if pixel is uv-mapped on a canvas face. */ | ||||
| DynamicPaintCreateUVSurfaceData data = { | DynamicPaintCreateUVSurfaceData data = { | ||||
| ▲ Show 20 Lines • Show All 3,460 Lines • Show Last 20 Lines | |||||