Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/armature/editarmature_sketch.c
| Context not available. | |||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "BIF_gl.h" | #include "BIF_glutil.h" | ||||
merwin: Can remove this BIF_gl.h include. | |||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "armature_intern.h" | #include "armature_intern.h" | ||||
| #include "BIF_retarget.h" | #include "BIF_retarget.h" | ||||
| Context not available. | |||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "GPU_select.h" | #include "GPU_select.h" | ||||
| #include "GPU_matrix.h" | |||||
| #include "GPU_batch.h" | |||||
| #include "GPU_immediate.h" | |||||
| typedef int (*GestureDetectFct)(bContext *, SK_Gesture *, SK_Sketch *); | typedef int (*GestureDetectFct)(bContext *, SK_Gesture *, SK_Sketch *); | ||||
| typedef void (*GestureApplyFct)(bContext *, SK_Gesture *, SK_Sketch *); | typedef void (*GestureApplyFct)(bContext *, SK_Gesture *, SK_Sketch *); | ||||
| Context not available. | |||||
| } | } | ||||
| /**************************************************************/ | /**************************************************************/ | ||||
| static void sk_cancelStroke(SK_Sketch *sketch) | static void sk_cancelStroke(SK_Sketch *sketch) | ||||
| { | { | ||||
| if (sketch->active_stroke != NULL) { | if (sketch->active_stroke != NULL) { | ||||
Not Done Inline ActionsThis belongs to glutil.c. Create imm_cylinder below imm_cylinder_nor. fclem: This belongs to glutil.c. Create imm_cylinder below imm_cylinder_nor. | |||||
| Context not available. | |||||
| return max_ff(size * pt->size, size / 2); | return max_ff(size * pt->size, size / 2); | ||||
| } | } | ||||
| static void sk_drawPoint(GLUquadric *quad, SK_Point *pt, float size) | static void sk_drawPoint(SK_Point *pt, float size, const float color[4]) | ||||
| { | { | ||||
Not Done Inline ActionsMake this const float color[4] so we can pass in const colors. Not that it really matters but it's good practice. merwin: Make this `const float color[4]` so we can pass in const colors. Not that it //really// matters… | |||||
| glTranslate3fv(pt->p); | Batch *batch = Batch_get_sphere(0); | ||||
| gluSphere(quad, sk_clampPointSize(pt, size), 8, 8); | |||||
| gpuTranslate3fv(pt->p); | |||||
| gpuPushMatrix(); | |||||
| gpuScaleUniform(sk_clampPointSize(pt, size)); | |||||
| Batch_set_builtin_program(batch, GPU_SHADER_3D_UNIFORM_COLOR); | |||||
| Batch_Uniform4fv(batch, "color", color); | |||||
Not Done Inline ActionsSmall change, but makes it easier to read & understand: Batch *batch = Batch_get_sphere(0); And remove the "= NULL" above. Here & the other places. merwin: Small change, but makes it easier to read & understand:
```lang=c
Batch *batch =… | |||||
| Batch_draw(batch); | |||||
| gpuPopMatrix(); | |||||
| } | } | ||||
| static void sk_drawEdge(GLUquadric *quad, SK_Point *pt0, SK_Point *pt1, float size) | static void sk_drawEdge(SK_Point *pt0, SK_Point *pt1, float size, const float color[4]) | ||||
| { | { | ||||
| float vec1[3], vec2[3] = {0, 0, 1}, axis[3]; | float vec1[3], vec2[3] = { 0, 0, 1 }, axis[3]; | ||||
Not Done Inline ActionsSame here, make it const color. merwin: Same here, make it const color. | |||||
| float angle, length; | float angle, length; | ||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| sub_v3_v3v3(vec1, pt1->p, pt0->p); | sub_v3_v3v3(vec1, pt1->p, pt0->p); | ||||
| length = normalize_v3(vec1); | length = normalize_v3(vec1); | ||||
| cross_v3_v3v3(axis, vec2, vec1); | cross_v3_v3v3(axis, vec2, vec1); | ||||
| Context not available. | |||||
| axis[1] = 1; | axis[1] = 1; | ||||
| } | } | ||||
| angle = angle_normalized_v3v3(vec2, vec1); | immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| immUniformColor4fv(color); | |||||
| glRotate3fv(angle * (float)(180.0 / M_PI) + 180.0f, axis); | angle = angle_normalized_v3v3(vec2, vec1); | ||||
| gpuRotate3fv(angle * (float)(180.0 / M_PI) + 180.0f, axis); | |||||
| imm_cylinder(pos, sk_clampPointSize(pt1, size), sk_clampPointSize(pt0, size), length, 8, 8); | |||||
| gluCylinder(quad, sk_clampPointSize(pt1, size), sk_clampPointSize(pt0, size), length, 8, 8); | immUnbindProgram(); | ||||
| } | } | ||||
| static void sk_drawNormal(GLUquadric *quad, SK_Point *pt, float size, float height) | static void sk_drawNormal(SK_Point *pt, float size, float height) | ||||
| { | { | ||||
| float vec2[3] = {0, 0, 1}, axis[3]; | float vec2[3] = { 0, 0, 1 }, axis[3]; | ||||
| float angle; | float angle; | ||||
| const float color[3] = { 0.0f, 1.0f, 1.0f }; | |||||
| glPushMatrix(); | |||||
| VertexFormat *format = immVertexFormat(); | |||||
| unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT); | |||||
| gpuPushMatrix(); | |||||
| cross_v3_v3v3(axis, vec2, pt->no); | cross_v3_v3v3(axis, vec2, pt->no); | ||||
| Context not available. | |||||
| axis[1] = 1; | axis[1] = 1; | ||||
| } | } | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | |||||
| immUniformColor4fv(color); | |||||
| angle = angle_normalized_v3v3(vec2, pt->no); | angle = angle_normalized_v3v3(vec2, pt->no); | ||||
| gpuRotate3fv(angle * (float)(180.0 / M_PI), axis); | |||||
| glRotate3fv(angle * (float)(180.0 / M_PI), axis); | imm_cylinder(pos, sk_clampPointSize(pt, size), 0, sk_clampPointSize(pt, height), 10, 2); | ||||
| glColor3f(0, 1, 1); | immUnbindProgram(); | ||||
| gluCylinder(quad, sk_clampPointSize(pt, size), 0, sk_clampPointSize(pt, height), 10, 2); | |||||
| glPopMatrix(); | gpuPopMatrix(); | ||||
| } | } | ||||
| static void sk_drawStroke(SK_Stroke *stk, int id, float color[3], int start, int end) | static void sk_drawStroke(SK_Stroke *stk, int id, const float color[3], int start, int end) | ||||
| { | { | ||||
| float rgb[3]; | float rgb[3]; | ||||
| float zero_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; | |||||
| int i; | int i; | ||||
| GLUquadric *quad = gluNewQuadric(); | |||||
| gluQuadricNormals(quad, GLU_SMOOTH); | |||||
| if (id != -1) { | if (id != -1) { | ||||
| GPU_select_load_id(id); | GPU_select_load_id(id); | ||||
| for (i = 0; i < stk->nb_points; i++) { | for (i = 0; i < stk->nb_points; i++) { | ||||
| glPushMatrix(); | gpuPushMatrix(); | ||||
| sk_drawPoint(quad, stk->points + i, 0.1); | sk_drawPoint(stk->points + i, 0.1, zero_color); | ||||
| if (i > 0) { | if (i > 0) { | ||||
| sk_drawEdge(quad, stk->points + i - 1, stk->points + i, 0.1); | sk_drawEdge(stk->points + i - 1, stk->points + i, 0.1, zero_color); | ||||
| } | } | ||||
| glPopMatrix(); | gpuPopMatrix(); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| float d_rgb[3] = {1, 1, 1}; | float d_rgb[3] = { 1, 1, 1 }; | ||||
| float tmp_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; | |||||
| copy_v3_v3(rgb, color); | copy_v3_v3(rgb, color); | ||||
| sub_v3_v3(d_rgb, rgb); | sub_v3_v3(d_rgb, rgb); | ||||
| Context not available. | |||||
| for (i = 0; i < stk->nb_points; i++) { | for (i = 0; i < stk->nb_points; i++) { | ||||
| SK_Point *pt = stk->points + i; | SK_Point *pt = stk->points + i; | ||||
| glPushMatrix(); | gpuPushMatrix(); | ||||
| if (pt->type == PT_EXACT) { | if (pt->type == PT_EXACT) { | ||||
| glColor3f(0, 0, 0); | sk_drawPoint(pt, 0.15, zero_color); | ||||
| sk_drawPoint(quad, pt, 0.15); | sk_drawNormal(pt, 0.05, 0.9); | ||||
| sk_drawNormal(quad, pt, 0.05, 0.9); | |||||
| } | } | ||||
| if (i >= start && i <= end) { | if (i >= start && i <= end) { | ||||
| glColor3f(0.3, 0.3, 0.3); | copy_v4_fl4(tmp_color, 0.3f, 0.3f, 0.3f, 1.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| glColor3fv(rgb); | copy_v4_fl4(tmp_color, rgb[0], rgb[1], rgb[2], 1.0f); | ||||
| } | } | ||||
| if (pt->type != PT_EXACT) { | if (pt->type != PT_EXACT) { | ||||
| sk_drawPoint(pt, 0.1, tmp_color); | |||||
| sk_drawPoint(quad, pt, 0.1); | |||||
| } | } | ||||
| if (i > 0) { | if (i > 0) { | ||||
| sk_drawEdge(quad, pt - 1, pt, 0.1); | sk_drawEdge(pt - 1, pt, 0.1, tmp_color); | ||||
| } | } | ||||
| glPopMatrix(); | gpuPopMatrix(); | ||||
| add_v3_v3(rgb, d_rgb); | add_v3_v3(rgb, d_rgb); | ||||
| } | } | ||||
| } | } | ||||
| gluDeleteQuadric(quad); | |||||
| } | } | ||||
| static void drawSubdividedStrokeBy(ToolSettings *toolsettings, BArcIterator *iter, NextSubdivisionFunc next_subdividion) | static void drawSubdividedStrokeBy(ToolSettings *toolsettings, BArcIterator *iter, NextSubdivisionFunc next_subdividion) | ||||
| { | { | ||||
| SK_Stroke *stk = ((SK_StrokeIterator *)iter)->stroke; | SK_Stroke *stk = ((SK_StrokeIterator *)iter)->stroke; | ||||
| float head[3], tail[3]; | float head[3], tail[3]; | ||||
| float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; | |||||
| int bone_start = 0; | int bone_start = 0; | ||||
| int end = iter->length; | int end = iter->length; | ||||
| int index; | int index; | ||||
| GLUquadric *quad = gluNewQuadric(); | |||||
| gluQuadricNormals(quad, GLU_SMOOTH); | |||||
| iter->head(iter); | iter->head(iter); | ||||
| copy_v3_v3(head, iter->p); | copy_v3_v3(head, iter->p); | ||||
| Context not available. | |||||
| while (index != -1) { | while (index != -1) { | ||||
| SK_Point *pt = stk->points + index; | SK_Point *pt = stk->points + index; | ||||
| glPushMatrix(); | gpuPushMatrix(); | ||||
| glColor3f(0, 1, 0); | sk_drawPoint(pt, 0.15, color); | ||||
| sk_drawPoint(quad, pt, 0.15); | |||||
| sk_drawNormal(quad, pt, 0.05, 0.9); | sk_drawNormal(pt, 0.05, 0.9); | ||||
| glPopMatrix(); | gpuPopMatrix(); | ||||
| copy_v3_v3(head, tail); | copy_v3_v3(head, tail); | ||||
| bone_start = index; // start next bone from current index | bone_start = index; // start next bone from current index | ||||
| index = next_subdividion(toolsettings, iter, bone_start, end, head, tail); | index = next_subdividion(toolsettings, iter, bone_start, end, head, tail); | ||||
| } | } | ||||
| gluDeleteQuadric(quad); | |||||
| } | } | ||||
| static void sk_drawStrokeSubdivision(ToolSettings *toolsettings, SK_Stroke *stk) | static void sk_drawStrokeSubdivision(ToolSettings *toolsettings, SK_Stroke *stk) | ||||
| Context not available. | |||||
| glClear(GL_DEPTH_BUFFER_BIT); | glClear(GL_DEPTH_BUFFER_BIT); | ||||
| glEnable(GL_DEPTH_TEST); | glEnable(GL_DEPTH_TEST); | ||||
| gpuMatrixBegin3D_legacy(); | |||||
| if (with_names) { | if (with_names) { | ||||
| int id; | int id; | ||||
| for (id = 1, stk = sketch->strokes.first; stk; id++, stk = stk->next) { | for (id = 1, stk = sketch->strokes.first; stk; id++, stk = stk->next) { | ||||
| Context not available. | |||||
| GPU_select_load_id(-1); | GPU_select_load_id(-1); | ||||
| } | } | ||||
| else { | else { | ||||
| float selected_rgb[3] = {1, 0, 0}; | float selected_rgb[3] = { 1, 0, 0 }; | ||||
| float unselected_rgb[3] = {1, 0.5, 0}; | float unselected_rgb[3] = { 1, 0.5, 0 }; | ||||
| float tmp_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; | |||||
| for (stk = sketch->strokes.first; stk; stk = stk->next) { | for (stk = sketch->strokes.first; stk; stk = stk->next) { | ||||
| int start = -1; | int start = -1; | ||||
| int end = -1; | int end = -1; | ||||
| Context not available. | |||||
| } | } | ||||
| if (last != NULL) { | if (last != NULL) { | ||||
| GLUquadric *quad = gluNewQuadric(); | gpuPushMatrix(); | ||||
| gluQuadricNormals(quad, GLU_SMOOTH); | |||||
| glPushMatrix(); | |||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||
| switch (sketch->next_point.mode) { | switch (sketch->next_point.mode) { | ||||
| case PT_SNAP: | case PT_SNAP: | ||||
| glColor3f(0, 1, 0); | copy_v4_fl4(tmp_color, 0.0f, 1.0f, 0.0f, 1.0f); | ||||
| break; | break; | ||||
| case PT_PROJECT: | case PT_PROJECT: | ||||
| glColor3f(0, 0, 0); | copy_v4_fl4(tmp_color, 0.0f, 0.0f, 0.0f, 1.0f); | ||||
| break; | break; | ||||
| } | } | ||||
| sk_drawPoint(quad, &sketch->next_point, 0.1); | sk_drawPoint(&sketch->next_point, 0.1, tmp_color); | ||||
| glColor4f(selected_rgb[0], selected_rgb[1], selected_rgb[2], 0.3); | copy_v4_fl4(tmp_color, selected_rgb[0], selected_rgb[1], selected_rgb[2], 0.3); | ||||
| sk_drawEdge(last, &sketch->next_point, 0.1f, tmp_color); | |||||
| sk_drawEdge(quad, last, &sketch->next_point, 0.1); | |||||
| glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
| glPopMatrix(); | gpuPopMatrix(); | ||||
| gluDeleteQuadric(quad); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| #if 0 | #if 0 | ||||
| if (BLI_listbase_is_empty(&sketch->depth_peels) == false) { | if (BLI_listbase_is_empty(&sketch->depth_peels) == false) { | ||||
| float colors[8][3] = { | float colors[8][3] = { | ||||
| {1, 0, 0}, | { 1, 0, 0 }, | ||||
| {0, 1, 0}, | { 0, 1, 0 }, | ||||
| {0, 0, 1}, | { 0, 0, 1 }, | ||||
| {1, 1, 0}, | { 1, 1, 0 }, | ||||
| {1, 0, 1}, | { 1, 0, 1 }, | ||||
| {0, 1, 1}, | { 0, 1, 1 }, | ||||
| {1, 1, 1}, | { 1, 1, 1 }, | ||||
| {0, 0, 0} | { 0, 0, 0 } | ||||
| }; | }; | ||||
| DepthPeel *p; | DepthPeel *p; | ||||
| GLUquadric *quad = gluNewQuadric(); | GLUquadric *quad = gluNewQuadric(); | ||||
Not Done Inline ActionsI agree we should keep this disabled code even though it uses GLU. It is an example of what could be done here. merwin: I agree we should keep this disabled code even though it uses GLU. It is an example of what… | |||||
| Context not available. | |||||
| /* only draw gesture in active area */ | /* only draw gesture in active area */ | ||||
| if (sketch->gesture != NULL /* && area_is_active_area(G.vd->area) */) { | if (sketch->gesture != NULL /* && area_is_active_area(G.vd->area) */) { | ||||
| float gesture_rgb[3] = {0, 0.5, 1}; | float gesture_rgb[3] = { 0, 0.5, 1 }; | ||||
| sk_drawStroke(sketch->gesture, -1, gesture_rgb, -1, -1); | sk_drawStroke(sketch->gesture, -1, gesture_rgb, -1, -1); | ||||
| } | } | ||||
| gpuMatrixEnd(); | |||||
| } | } | ||||
| static int sk_finish_stroke(bContext *C, SK_Sketch *sketch) | static int sk_finish_stroke(bContext *C, SK_Sketch *sketch) | ||||
| Context not available. | |||||
Can remove this BIF_gl.h include.