Commit: 42467c884f0056657c8fe0786c0c26da70ad60dd
Author: Campbell Barton
Date:   Thu Apr 6 20:21:07 2017 +1000
Branches: custom-manipulators
https://developer.blender.org/rB42467c884f0056657c8fe0786c0c26da70ad60dd

Merge branch 'blender2.8' into custom-manipulators

===================================================================



===================================================================

diff --cc 
source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
index 3f99918c227,00000000000..3fb5059cae5
mode 100644,000000..100644
--- 
a/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
+++ 
b/source/blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
@@@ -1,561 -1,0 +1,561 @@@
 +/*
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * The Original Code is Copyright (C) 2014 Blender Foundation.
 + * All rights reserved.
 + *
 + * Contributor(s): Blender Foundation
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +
 +/** \file 
blender/windowmanager/manipulators/intern/manipulator_library/arrow_manipulator.c
 + *  \ingroup wm
 + *
 + * \name Arrow Manipulator
 + *
 + * 3D Manipulator
 + *
 + * \brief Simple arrow manipulator which is dragged into a certain direction.
 + * The arrow head can have varying shapes, e.g. cone, box, etc.
 + */
 +
 +#include "BIF_gl.h"
 +
 +#include "BKE_context.h"
 +
 +#include "BLI_math.h"
 +
 +#include "DNA_manipulator_types.h"
 +#include "DNA_view3d_types.h"
 +
 +#include "ED_view3d.h"
 +#include "ED_screen.h"
 +
 +#include "GPU_draw.h"
 +#include "GPU_immediate.h"
 +#include "GPU_immediate_util.h"
 +#include "GPU_matrix.h"
 +#include "GPU_select.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "RNA_access.h"
 +
 +#include "WM_types.h"
 +#include "WM_api.h"
 +
 +/* own includes */
 +#include "wm_manipulator_wmapi.h"
 +#include "wm_manipulator_intern.h"
 +#include "manipulator_geometry.h"
 +#include "manipulator_library_intern.h"
 +
 +/* to use custom arrows exported to geom_arrow_manipulator.c */
 +//#define USE_MANIPULATOR_CUSTOM_ARROWS
 +
 +/* ArrowManipulator->flag */
 +enum {
 +      ARROW_UP_VECTOR_SET    = (1 << 0),
 +      ARROW_CUSTOM_RANGE_SET = (1 << 1),
 +};
 +
 +typedef struct ArrowManipulator {
 +      wmManipulator manipulator;
 +
 +      ManipulatorCommonData data;
 +
 +      int style;
 +      int flag;
 +
 +      float len;          /* arrow line length */
 +      float direction[3];
 +      float up[3];
 +      float aspect[2];    /* cone style only */
 +} ArrowManipulator;
 +
 +
 +/* -------------------------------------------------------------------- */
 +
 +static void manipulator_arrow_get_final_pos(wmManipulator *manipulator, float 
r_pos[3])
 +{
 +      ArrowManipulator *arrow = (ArrowManipulator *)manipulator;
 +
 +      mul_v3_v3fl(r_pos, arrow->direction, arrow->data.offset);
 +      add_v3_v3(r_pos, arrow->manipulator.origin);
 +}
 +
 +static void arrow_draw_geom(const ArrowManipulator *arrow, const bool select, 
const float color[4])
 +{
 +      /* USE_IMM for other arrow types */
 +      glColor4fv(color);
 +
 +      if (arrow->style & MANIPULATOR_ARROW_STYLE_CROSS) {
 +              glPushAttrib(GL_ENABLE_BIT);
 +              glDisable(GL_LIGHTING);
 +              glBegin(GL_LINES);
 +              glVertex2f(-1.0, 0.f);
 +              glVertex2f(1.0, 0.f);
 +              glVertex2f(0.f, -1.0);
 +              glVertex2f(0.f, 1.0);
 +              glEnd();
 +
 +              glPopAttrib();
 +      }
 +      else if (arrow->style & MANIPULATOR_ARROW_STYLE_CONE) {
 +              const float unitx = arrow->aspect[0];
 +              const float unity = arrow->aspect[1];
 +              const float vec[4][3] = {
 +                      {-unitx, -unity, 0},
 +                      { unitx, -unity, 0},
 +                      { unitx,  unity, 0},
 +                      {-unitx,  unity, 0},
 +              };
 +
 +              glLineWidth(arrow->manipulator.line_width);
 +              glEnableClientState(GL_VERTEX_ARRAY);
 +              glVertexPointer(3, GL_FLOAT, 0, vec);
 +              glDrawArrays(GL_LINE_LOOP, 0, ARRAY_SIZE(vec));
 +              glDisableClientState(GL_VERTEX_ARRAY);
 +              glLineWidth(1.0);
 +      }
 +      else {
 +#ifdef USE_MANIPULATOR_CUSTOM_ARROWS
 +              
wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_arrow, select);
 +#else
 +              const float vec[2][3] = {
 +                      {0.0f, 0.0f, 0.0f},
 +                      {0.0f, 0.0f, arrow->len},
 +              };
 +
 +              glLineWidth(arrow->manipulator.line_width);
 +              glEnableClientState(GL_VERTEX_ARRAY);
 +              glVertexPointer(3, GL_FLOAT, 0, vec);
 +              glDrawArrays(GL_LINE_STRIP, 0, ARRAY_SIZE(vec));
 +              glDisableClientState(GL_VERTEX_ARRAY);
 +              glLineWidth(1.0);
 +
 +
 +              /* *** draw arrow head *** */
 +
 +              gpuPushMatrix();
 +
 +              if (arrow->style & MANIPULATOR_ARROW_STYLE_BOX) {
 +                      const float size = 0.05f;
 +
 +                      /* translate to line end with some extra offset so box 
starts exactly where line ends */
 +                      gpuTranslate3f(0.0f, 0.0f, arrow->len + size);
 +                      /* scale down to box size */
 +                      gpuScale3f(size, size, size);
 +
 +                      /* draw cube */
 +                      
wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_cube, select);
 +              }
 +              else {
 +                      const float len = 0.25f;
 +                      const float width = 0.06f;
 +                      const bool use_lighting = select == false && 
((U.manipulator_flag & V3D_SHADED_MANIPULATORS) != 0);
 +
 +                      /* translate to line end */
-                       unsigned int pos = add_attrib(immVertexFormat(), "pos", 
GL_FLOAT, 3, KEEP_FLOAT);
++                      unsigned int pos = 
VertexFormat_add_attrib(immVertexFormat(), "pos", GL_FLOAT, 3, KEEP_FLOAT);
 +                      gpuTranslate3f(0.0f, 0.0f, arrow->len);
 +
 +                      immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
 +                      immUniformColor4fv(color);
 +
 +                      if (use_lighting) {
 +                              glShadeModel(GL_SMOOTH);
 +                      }
 +
 +                      imm_draw_circle_fill_3d(pos, 0.0, 0.0, width, 8);
 +                      imm_draw_cylinder_fill_3d(pos, width, 0.0, len, 8, 1);
 +
 +                      immUnbindProgram();
 +
 +                      if (use_lighting) {
 +                              glShadeModel(GL_FLAT);
 +                      }
 +              }
 +
 +              gpuPopMatrix();
 +
 +#endif  /* USE_MANIPULATOR_CUSTOM_ARROWS */
 +      }
 +}
 +
 +static void arrow_draw_intern(ArrowManipulator *arrow, const bool select, 
const bool highlight)
 +{
 +      const float up[3] = {0.0f, 0.0f, 1.0f};
 +      float col[4];
 +      float rot[3][3];
 +      float mat[4][4];
 +      float final_pos[3];
 +
 +      manipulator_color_get(&arrow->manipulator, highlight, col);
 +      manipulator_arrow_get_final_pos(&arrow->manipulator, final_pos);
 +
 +      if (arrow->flag & ARROW_UP_VECTOR_SET) {
 +              copy_v3_v3(rot[2], arrow->direction);
 +              copy_v3_v3(rot[1], arrow->up);
 +              cross_v3_v3v3(rot[0], arrow->up, arrow->direction);
 +      }
 +      else {
 +              rotation_between_vecs_to_mat3(rot, up, arrow->direction);
 +      }
 +      copy_m4_m3(mat, rot);
 +      copy_v3_v3(mat[3], final_pos);
 +      mul_mat3_m4_fl(mat, arrow->manipulator.scale);
 +
 +      gpuPushMatrix();
 +      gpuMultMatrix3D(mat);
 +
 +      gpuTranslate3fv(arrow->manipulator.offset);
 +
 +      glEnable(GL_BLEND);
 +      arrow_draw_geom(arrow, select, col);
 +      glDisable(GL_BLEND);
 +
 +      gpuPopMatrix();
 +
 +      if (arrow->manipulator.interaction_data) {
 +              ManipulatorInteraction *inter = 
arrow->manipulator.interaction_data;
 +
 +              copy_m4_m3(mat, rot);
 +              copy_v3_v3(mat[3], inter->init_origin);
 +              mul_mat3_m4_fl(mat, inter->init_scale);
 +
 +              gpuPushMatrix();
 +              gpuMultMatrix3D(mat);
 +              gpuTranslate3fv(arrow->manipulator.offset);
 +
 +              glEnable(GL_BLEND);
 +              arrow_draw_geom(arrow, select, (const float [4]){0.5f, 0.5f, 
0.5f, 0.5f});
 +              glDisable(GL_BLEND);
 +
 +              gpuPopMatrix();
 +      }
 +}
 +
 +static void manipulator_arrow_render_3d_intersect(
 +        const bContext *UNUSED(C), wmManipulator *manipulator,
 +        int selectionbase)
 +{
 +      GPU_select_load_id(selectionbase);
 +      arrow_draw_intern((ArrowManipulator *)manipulator, true, false);
 +}
 +
 +static void manipulator_arrow_draw(const bContext *UNUSED(C), wmManipulator 
*manipulator)
 +{
 +      arrow_draw_intern((ArrowManipulator *)manipulator, false, 
(manipulator->state & WM_MANIPULATOR_HIGHLIGHT) != 0);
 +}
 +
 +/**
 + * Calculate arrow offset independent from prop min value,
 + * meaning the range will not be offset by min value first.
 + */
 +#define USE_ABS_HANDLE_RANGE
 +
 +static int manipulator_arrow_handler(bContext *C, const wmEvent *event, 
wmManipulator *manipulator, const int flag)
 +{
 +      ArrowManipulator *arrow = (ArrowManipulator *)manipulator;
 +      ManipulatorInteraction *inter = manipulator->interaction_data;
 +      ARegion *ar = CTX_wm_region(C);
 +      RegionView3D *rv3d = ar->regiondata;
 +
 +      float orig_origin[4];
 +      float viewvec[3], tangent[3], plane[3];
 +      float offset[4];
 +      float m_diff[2];
 +      float dir_2d[2], dir2d_final[2];
 +      float facdir = 1.0f;
 +      bool use_vertical = false;
 +
 +
 +      copy_v3_v3(orig_origin, inter->init_origin);
 +      orig_origin[3] = 1.0f;
 +      add_v3_v3v3(offset, orig_origin, arrow->direction);
 +      offset[3] = 1.0f;
 +
 +      /* calculate view vector */
 +      if (rv3d->is_persp) {
 +              sub_v3_v3v3(viewvec, orig_origin, rv3d->viewinv[3]);
 +      }
 +      else {
 +              copy_v3_v3(viewvec, rv3d->viewinv[2]);
 +      }
 +      normalize_v3(viewvec);
 +
 +      /* first determine if view vector is really close to the direction. If 
it is, we use
 +       * vertical movement to determine offset, just like transform system 
does */
 +      if (RAD2DEG(acos(dot_v3v3(viewvec, arrow->direction))) > 5.0f) {
 +              /* multiply to projection space */
 +              mul_m4_v4(rv3d->persmat, orig_origin);
 +              mul_v4_fl(orig_origin, 1.0f / orig_origin[3]);
 +              mul_m4_v4(rv3d->persmat, offset);
 +              mul_v4_fl(offset, 1.0f / offset[3]);
 +
 +              sub_v2_v2v2(dir_2d, offset, orig_origin);
 +              dir_2d[0] *= ar->winx;
 +              dir_2d[1] *= ar->winy;
 +              normalize_v2(dir_2d);
 +      }
 +      else {
 +              dir_2d[0] = 0.0f;
 +              dir_2d[1] = 1.0f;
 +              use_vertical = true;
 +      }
 +
 +      /* find mouse difference */
 +      m_diff[0] = event->mval[0] - inter->init_mval[0];
 +      m_diff[1] = event->mval[1] - inter->init_mval[1];
 +
 +      /* project the displacement on the screen space arrow direction */
 +      project_v2_v2v2(dir2d_final, m_diff, dir_2d);
 +
 +      float zfac = ED_view3d_calc_zfac(rv3d, orig_origin, NULL);
 +      ED_view3d_win_to_delta(ar, dir2d_final, offset, zfac);
 +
 +      add_v3_v3v3(orig_origin, offset, inter->init_origin);
 +
 +      /* calculate view vector for the new position */
 +      

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to