Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_primitive.c
| Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| ED_workspace_status_text(C, status_str); | ED_workspace_status_text(C, status_str); | ||||
| } | } | ||||
| /* ----------------------- */ | /* ----------------------- */ | ||||
| /* create a rectangle */ | /* create a rectangle */ | ||||
| static void gp_primitive_rectangle(tGPDprimitive *tgpi, tPGPspoint *points2D) | static void gp_primitive_rectangle(tGPDprimitive *tgpi, tGPspoint *points2D) | ||||
| { | { | ||||
| BLI_assert(tgpi->tot_edges == 4); | BLI_assert(tgpi->tot_edges == 4); | ||||
| points2D[0].x = (float)tgpi->top[0]; | points2D[0].x = (float)tgpi->top[0]; | ||||
| points2D[0].y = (float)tgpi->top[1]; | points2D[0].y = (float)tgpi->top[1]; | ||||
| points2D[1].x = (float)tgpi->bottom[0]; | points2D[1].x = (float)tgpi->bottom[0]; | ||||
| points2D[1].y = (float)tgpi->top[1]; | points2D[1].y = (float)tgpi->top[1]; | ||||
| points2D[2].x = (float)tgpi->bottom[0]; | points2D[2].x = (float)tgpi->bottom[0]; | ||||
| points2D[2].y = (float)tgpi->bottom[1]; | points2D[2].y = (float)tgpi->bottom[1]; | ||||
| points2D[3].x = (float)tgpi->top[0]; | points2D[3].x = (float)tgpi->top[0]; | ||||
| points2D[3].y = (float)tgpi->bottom[1]; | points2D[3].y = (float)tgpi->bottom[1]; | ||||
| } | } | ||||
| /* create a line */ | /* create a line */ | ||||
| static void gp_primitive_line(tGPDprimitive *tgpi, tPGPspoint *points2D) | static void gp_primitive_line(tGPDprimitive *tgpi, tGPspoint *points2D) | ||||
| { | { | ||||
| BLI_assert(tgpi->tot_edges == 2); | BLI_assert(tgpi->tot_edges == 2); | ||||
| points2D[0].x = (float)tgpi->top[0]; | points2D[0].x = (float)tgpi->top[0]; | ||||
| points2D[0].y = (float)tgpi->top[1]; | points2D[0].y = (float)tgpi->top[1]; | ||||
| points2D[1].x = (float)tgpi->bottom[0]; | points2D[1].x = (float)tgpi->bottom[0]; | ||||
| points2D[1].y = (float)tgpi->bottom[1]; | points2D[1].y = (float)tgpi->bottom[1]; | ||||
| } | } | ||||
| /* create an arc */ | /* create an arc */ | ||||
| static void gp_primitive_arc(tGPDprimitive *tgpi, tPGPspoint *points2D) | static void gp_primitive_arc(tGPDprimitive *tgpi, tGPspoint *points2D) | ||||
| { | { | ||||
| const int totpoints = tgpi->tot_edges; | const int totpoints = tgpi->tot_edges; | ||||
| const float step = M_PI_2 / (float)(totpoints - 1); | const float step = M_PI_2 / (float)(totpoints - 1); | ||||
| float length[2]; | float length[2]; | ||||
| int start[2]; | int start[2]; | ||||
| int end[2]; | int end[2]; | ||||
| float a = 0.0f; | float a = 0.0f; | ||||
| start[0] = tgpi->top[0]; | start[0] = tgpi->top[0]; | ||||
| start[1] = tgpi->top[1]; | start[1] = tgpi->top[1]; | ||||
| end[0] = tgpi->bottom[0]; | end[0] = tgpi->bottom[0]; | ||||
| end[1] = tgpi->bottom[1]; | end[1] = tgpi->bottom[1]; | ||||
| if (tgpi->flip) { | if (tgpi->flip) { | ||||
| SWAP(int, end[0], start[0]); | SWAP(int, end[0], start[0]); | ||||
| SWAP(int, end[1], start[1]); | SWAP(int, end[1], start[1]); | ||||
| } | } | ||||
| length[0] = end[0] - start[0]; | length[0] = end[0] - start[0]; | ||||
| length[1] = end[1] - start[1]; | length[1] = end[1] - start[1]; | ||||
| for (int i = 0; i < totpoints; i++) { | for (int i = 0; i < totpoints; i++) { | ||||
| tPGPspoint *p2d = &points2D[i]; | tGPspoint *p2d = &points2D[i]; | ||||
| p2d->x = (start[0] + sinf(a) * length[0]); | p2d->x = (start[0] + sinf(a) * length[0]); | ||||
| p2d->y = (end[1] - cosf(a) * length[1]); | p2d->y = (end[1] - cosf(a) * length[1]); | ||||
| a += step; | a += step; | ||||
| } | } | ||||
| } | } | ||||
| /* create a circle */ | /* create a circle */ | ||||
| static void gp_primitive_circle(tGPDprimitive *tgpi, tPGPspoint *points2D) | static void gp_primitive_circle(tGPDprimitive *tgpi, tGPspoint *points2D) | ||||
| { | { | ||||
| const int totpoints = tgpi->tot_edges; | const int totpoints = tgpi->tot_edges; | ||||
| const float step = (2.0f * M_PI) / (float)(totpoints); | const float step = (2.0f * M_PI) / (float)(totpoints); | ||||
| float center[2]; | float center[2]; | ||||
| float radius[2]; | float radius[2]; | ||||
| float a = 0.0f; | float a = 0.0f; | ||||
| /* TODO: Use math-lib functions for these? */ | /* TODO: Use math-lib functions for these? */ | ||||
| center[0] = tgpi->top[0] + ((tgpi->bottom[0] - tgpi->top[0]) / 2.0f); | center[0] = tgpi->top[0] + ((tgpi->bottom[0] - tgpi->top[0]) / 2.0f); | ||||
| center[1] = tgpi->top[1] + ((tgpi->bottom[1] - tgpi->top[1]) / 2.0f); | center[1] = tgpi->top[1] + ((tgpi->bottom[1] - tgpi->top[1]) / 2.0f); | ||||
| radius[0] = fabsf(((tgpi->bottom[0] - tgpi->top[0]) / 2.0f)); | radius[0] = fabsf(((tgpi->bottom[0] - tgpi->top[0]) / 2.0f)); | ||||
| radius[1] = fabsf(((tgpi->bottom[1] - tgpi->top[1]) / 2.0f)); | radius[1] = fabsf(((tgpi->bottom[1] - tgpi->top[1]) / 2.0f)); | ||||
| for (int i = 0; i < totpoints; i++) { | for (int i = 0; i < totpoints; i++) { | ||||
| tPGPspoint *p2d = &points2D[i]; | tGPspoint *p2d = &points2D[i]; | ||||
| p2d->x = (center[0] + cosf(a) * radius[0]); | p2d->x = (center[0] + cosf(a) * radius[0]); | ||||
| p2d->y = (center[1] + sinf(a) * radius[1]); | p2d->y = (center[1] + sinf(a) * radius[1]); | ||||
| a += step; | a += step; | ||||
| } | } | ||||
| } | } | ||||
| /* Helper: Update shape of the stroke */ | /* Helper: Update shape of the stroke */ | ||||
| static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) | static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) | ||||
| { | { | ||||
| ToolSettings *ts = tgpi->scene->toolsettings; | ToolSettings *ts = tgpi->scene->toolsettings; | ||||
| bGPdata *gpd = tgpi->gpd; | bGPdata *gpd = tgpi->gpd; | ||||
| bGPDstroke *gps = tgpi->gpf->strokes.first; | bGPDstroke *gps = tgpi->gpf->strokes.first; | ||||
| /* realloc points to new size */ | /* realloc points to new size */ | ||||
| /* TODO: only do this if the size has changed? */ | /* TODO: only do this if the size has changed? */ | ||||
| gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * tgpi->tot_edges); | gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * tgpi->tot_edges); | ||||
| if (gps->dvert != NULL) { | if (gps->dvert != NULL) { | ||||
| gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * tgpi->tot_edges); | gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * tgpi->tot_edges); | ||||
| } | } | ||||
| gps->totpoints = tgpi->tot_edges; | gps->totpoints = tgpi->tot_edges; | ||||
| /* compute screen-space coordinates for points */ | /* compute screen-space coordinates for points */ | ||||
| tPGPspoint *points2D = MEM_callocN(sizeof(tPGPspoint) * tgpi->tot_edges, "gp primitive points2D"); | tGPspoint *points2D = MEM_callocN(sizeof(tGPspoint) * tgpi->tot_edges, "gp primitive points2D"); | ||||
| switch (tgpi->type) { | switch (tgpi->type) { | ||||
| case GP_STROKE_BOX: | case GP_STROKE_BOX: | ||||
| gp_primitive_rectangle(tgpi, points2D); | gp_primitive_rectangle(tgpi, points2D); | ||||
| break; | break; | ||||
| case GP_STROKE_LINE: | case GP_STROKE_LINE: | ||||
| gp_primitive_line(tgpi, points2D); | gp_primitive_line(tgpi, points2D); | ||||
| break; | break; | ||||
| case GP_STROKE_CIRCLE: | case GP_STROKE_CIRCLE: | ||||
| gp_primitive_circle(tgpi, points2D); | gp_primitive_circle(tgpi, points2D); | ||||
| break; | break; | ||||
| case GP_STROKE_ARC: | case GP_STROKE_ARC: | ||||
| gp_primitive_arc(tgpi, points2D); | gp_primitive_arc(tgpi, points2D); | ||||
| if (tgpi->cyclic) | if (tgpi->cyclic) | ||||
| gps->flag |= GP_STROKE_CYCLIC; | gps->flag |= GP_STROKE_CYCLIC; | ||||
| else | else | ||||
| gps->flag &= ~GP_STROKE_CYCLIC; | gps->flag &= ~GP_STROKE_CYCLIC; | ||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| /* convert screen-coordinates to 3D coordinates */ | /* convert screen-coordinates to 3D coordinates */ | ||||
| for (int i = 0; i < gps->totpoints; i++) { | for (int i = 0; i < gps->totpoints; i++) { | ||||
| bGPDspoint *pt = &gps->points[i]; | bGPDspoint *pt = &gps->points[i]; | ||||
| tPGPspoint *p2d = &points2D[i]; | tGPspoint *p2d = &points2D[i]; | ||||
| /* convert screen-coordinates to 3D coordinates */ | /* convert screen-coordinates to 3D coordinates */ | ||||
| gp_stroke_convertcoords_tpoint_primitive(tgpi->scene, tgpi->ar, tgpi->ob, tgpi->gpl, p2d, &pt->x); | gp_stroke_convertcoords_tpoint(tgpi->scene, tgpi->ar, tgpi->ob, tgpi->gpl, p2d, NULL, &pt->x); | ||||
| pt->pressure = 1.0f; | pt->pressure = 1.0f; | ||||
| pt->strength = tgpi->brush->gpencil_settings->draw_strength; | pt->strength = tgpi->brush->gpencil_settings->draw_strength; | ||||
| pt->time = 0.0f; | pt->time = 0.0f; | ||||
| if (gps->dvert != NULL) { | if (gps->dvert != NULL) { | ||||
| MDeformVert *dvert = &gps->dvert[i]; | MDeformVert *dvert = &gps->dvert[i]; | ||||
| dvert->totweight = 0; | dvert->totweight = 0; | ||||
| ▲ Show 20 Lines • Show All 466 Lines • Show Last 20 Lines | |||||