| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  |  * 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, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup edobj | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | #include "BLI_listbase.h"
 | 
					
						
							|  |  |  | #include "BLI_string.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-13 08:54:33 +00:00
										 |  |  | #include "DNA_armature_types.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | #include "DNA_curve_types.h"
 | 
					
						
							|  |  |  | #include "DNA_lattice_types.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | #include "DNA_meshdata_types.h"
 | 
					
						
							|  |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | #include "BKE_action.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | #include "BKE_context.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-30 11:41:33 +02:00
										 |  |  | #include "BKE_layer.h"
 | 
					
						
							| 
									
										
										
										
											2010-08-01 12:47:49 +00:00
										 |  |  | #include "BKE_main.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | #include "BKE_modifier.h"
 | 
					
						
							|  |  |  | #include "BKE_object.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | #include "BKE_report.h"
 | 
					
						
							|  |  |  | #include "BKE_scene.h"
 | 
					
						
							| 
									
										
										
										
											2011-06-30 03:04:39 +00:00
										 |  |  | #include "BKE_deform.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-13 20:31:52 +00:00
										 |  |  | #include "BKE_editmesh.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-08 10:14:53 +02:00
										 |  |  | #include "DEG_depsgraph.h"
 | 
					
						
							|  |  |  | #include "DEG_depsgraph_build.h"
 | 
					
						
							| 
									
										
										
										
											2019-07-30 00:35:49 +10:00
										 |  |  | #include "DEG_depsgraph_query.h"
 | 
					
						
							| 
									
										
										
										
											2017-06-08 10:14:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							| 
									
										
										
											
												* Multiply for panorama cameras
* Some cases of struct name being set where it shouldnt have been.
* Spelling: wich --> which
* Copy and initialize uv modifier scale, remove unneeded enum.
* Ability to pin any object into the context.
* Update uv window while transforming (useful when used with UVProject modifier)
* Patch by Wahooney, so new template's are internal text and dont get saved over
  by mistake.
* Fix for https://bugzilla.redhat.com/show_bug.cgi?id=572186
  Bug 572186 - [abrt] crash in blender-2.49b-5.fc12: Process
  /usr/bin/blender.bin was killed by signal 6 (SIGABRT). Original fix submitted
  by Jochen Schmitt.
* [#21816] bpy.data.add_image has stopped working on Windows. moved to
  bpy.data.images.load(), missed this call.
(commits 27726,27825,27828,27831,27832,27833,27834,27836,27837,27838,27839,27858 by Campbell from render25 branch)
											
										 
											2010-03-30 12:15:16 +00:00
										 |  |  | #include "RNA_enum_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | #include "ED_curve.h"
 | 
					
						
							|  |  |  | #include "ED_mesh.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | #include "ED_screen.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | #include "UI_resources.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | #include "object_intern.h"
 | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static int return_editmesh_indexar(BMEditMesh *em, int *r_tot, int **r_indexar, float r_cent[3]) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   BMVert *eve; | 
					
						
							|  |  |  |   BMIter iter; | 
					
						
							|  |  |  |   int *index, nr, totvert = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       totvert++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (totvert == 0) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   *r_indexar = index = MEM_mallocN(4 * totvert, "hook indexar"); | 
					
						
							|  |  |  |   *r_tot = totvert; | 
					
						
							|  |  |  |   nr = 0; | 
					
						
							|  |  |  |   zero_v3(r_cent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  |     if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  |       *index = nr; | 
					
						
							|  |  |  |       index++; | 
					
						
							|  |  |  |       add_v3_v3(r_cent, eve->co); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     nr++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mul_v3_fl(r_cent, 1.0f / (float)totvert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return totvert; | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 03:24:05 +11:00
										 |  |  | static bool return_editmesh_vgroup(Object *obedit, BMEditMesh *em, char *r_name, float r_cent[3]) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const int cd_dvert_offset = obedit->actdef ? | 
					
						
							|  |  |  |                                   CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT) : | 
					
						
							|  |  |  |                                   -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   zero_v3(r_cent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (cd_dvert_offset != -1) { | 
					
						
							|  |  |  |     const int defgrp_index = obedit->actdef - 1; | 
					
						
							|  |  |  |     int totvert = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MDeformVert *dvert; | 
					
						
							|  |  |  |     BMVert *eve; | 
					
						
							|  |  |  |     BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* find the vertices */ | 
					
						
							|  |  |  |     BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  |       dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (defvert_find_weight(dvert, defgrp_index) > 0.0f) { | 
					
						
							|  |  |  |         add_v3_v3(r_cent, eve->co); | 
					
						
							|  |  |  |         totvert++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (totvert) { | 
					
						
							|  |  |  |       bDeformGroup *dg = BLI_findlink(&obedit->defbase, defgrp_index); | 
					
						
							|  |  |  |       BLI_strncpy(r_name, dg->name, sizeof(dg->name)); | 
					
						
							|  |  |  |       mul_v3_fl(r_cent, 1.0f / (float)totvert); | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | static void select_editbmesh_hook(Object *ob, HookModifierData *hmd) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Mesh *me = ob->data; | 
					
						
							|  |  |  |   BMEditMesh *em = me->edit_mesh; | 
					
						
							|  |  |  |   BMVert *eve; | 
					
						
							|  |  |  |   BMIter iter; | 
					
						
							|  |  |  |   int index = 0, nr = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (hmd->indexar == NULL) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  |     if (nr == hmd->indexar[index]) { | 
					
						
							|  |  |  |       BM_vert_select_set(em->bm, eve, true); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       if (index < hmd->totindex - 1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         index++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     nr++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   EDBM_select_flush(em); | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static int return_editlattice_indexar(Lattice *editlatt, | 
					
						
							|  |  |  |                                       int *r_tot, | 
					
						
							|  |  |  |                                       int **r_indexar, | 
					
						
							|  |  |  |                                       float r_cent[3]) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   BPoint *bp; | 
					
						
							|  |  |  |   int *index, nr, totvert = 0, a; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* count */ | 
					
						
							|  |  |  |   a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw; | 
					
						
							|  |  |  |   bp = editlatt->def; | 
					
						
							|  |  |  |   while (a--) { | 
					
						
							|  |  |  |     if (bp->f1 & SELECT) { | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       if (bp->hide == 0) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         totvert++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     bp++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (totvert == 0) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   *r_indexar = index = MEM_mallocN(4 * totvert, "hook indexar"); | 
					
						
							|  |  |  |   *r_tot = totvert; | 
					
						
							|  |  |  |   nr = 0; | 
					
						
							|  |  |  |   zero_v3(r_cent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   a = editlatt->pntsu * editlatt->pntsv * editlatt->pntsw; | 
					
						
							|  |  |  |   bp = editlatt->def; | 
					
						
							|  |  |  |   while (a--) { | 
					
						
							|  |  |  |     if (bp->f1 & SELECT) { | 
					
						
							|  |  |  |       if (bp->hide == 0) { | 
					
						
							|  |  |  |         *index = nr; | 
					
						
							|  |  |  |         index++; | 
					
						
							|  |  |  |         add_v3_v3(r_cent, bp->vec); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     bp++; | 
					
						
							|  |  |  |     nr++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mul_v3_fl(r_cent, 1.0f / (float)totvert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return totvert; | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void select_editlattice_hook(Object *obedit, HookModifierData *hmd) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Lattice *lt = obedit->data, *editlt; | 
					
						
							|  |  |  |   BPoint *bp; | 
					
						
							|  |  |  |   int index = 0, nr = 0, a; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   editlt = lt->editlatt->latt; | 
					
						
							|  |  |  |   /* count */ | 
					
						
							|  |  |  |   a = editlt->pntsu * editlt->pntsv * editlt->pntsw; | 
					
						
							|  |  |  |   bp = editlt->def; | 
					
						
							|  |  |  |   while (a--) { | 
					
						
							|  |  |  |     if (hmd->indexar[index] == nr) { | 
					
						
							|  |  |  |       bp->f1 |= SELECT; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       if (index < hmd->totindex - 1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         index++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     nr++; | 
					
						
							|  |  |  |     bp++; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static int return_editcurve_indexar(Object *obedit, int *r_tot, int **r_indexar, float r_cent[3]) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ListBase *editnurb = object_editcurve_get(obedit); | 
					
						
							|  |  |  |   Nurb *nu; | 
					
						
							|  |  |  |   BPoint *bp; | 
					
						
							|  |  |  |   BezTriple *bezt; | 
					
						
							|  |  |  |   int *index, a, nr, totvert = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (nu = editnurb->first; nu; nu = nu->next) { | 
					
						
							|  |  |  |     if (nu->type == CU_BEZIER) { | 
					
						
							|  |  |  |       bezt = nu->bezt; | 
					
						
							|  |  |  |       a = nu->pntsu; | 
					
						
							|  |  |  |       while (a--) { | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         if (bezt->f1 & SELECT) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           totvert++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (bezt->f2 & SELECT) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           totvert++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (bezt->f3 & SELECT) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           totvert++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         bezt++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       bp = nu->bp; | 
					
						
							|  |  |  |       a = nu->pntsu * nu->pntsv; | 
					
						
							|  |  |  |       while (a--) { | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         if (bp->f1 & SELECT) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           totvert++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         bp++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (totvert == 0) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   *r_indexar = index = MEM_mallocN(sizeof(*index) * totvert, "hook indexar"); | 
					
						
							|  |  |  |   *r_tot = totvert; | 
					
						
							|  |  |  |   nr = 0; | 
					
						
							|  |  |  |   zero_v3(r_cent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (nu = editnurb->first; nu; nu = nu->next) { | 
					
						
							|  |  |  |     if (nu->type == CU_BEZIER) { | 
					
						
							|  |  |  |       bezt = nu->bezt; | 
					
						
							|  |  |  |       a = nu->pntsu; | 
					
						
							|  |  |  |       while (a--) { | 
					
						
							|  |  |  |         if (bezt->f1 & SELECT) { | 
					
						
							|  |  |  |           *index = nr; | 
					
						
							|  |  |  |           index++; | 
					
						
							|  |  |  |           add_v3_v3(r_cent, bezt->vec[0]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         nr++; | 
					
						
							|  |  |  |         if (bezt->f2 & SELECT) { | 
					
						
							|  |  |  |           *index = nr; | 
					
						
							|  |  |  |           index++; | 
					
						
							|  |  |  |           add_v3_v3(r_cent, bezt->vec[1]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         nr++; | 
					
						
							|  |  |  |         if (bezt->f3 & SELECT) { | 
					
						
							|  |  |  |           *index = nr; | 
					
						
							|  |  |  |           index++; | 
					
						
							|  |  |  |           add_v3_v3(r_cent, bezt->vec[2]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         nr++; | 
					
						
							|  |  |  |         bezt++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       bp = nu->bp; | 
					
						
							|  |  |  |       a = nu->pntsu * nu->pntsv; | 
					
						
							|  |  |  |       while (a--) { | 
					
						
							|  |  |  |         if (bp->f1 & SELECT) { | 
					
						
							|  |  |  |           *index = nr; | 
					
						
							|  |  |  |           index++; | 
					
						
							|  |  |  |           add_v3_v3(r_cent, bp->vec); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         nr++; | 
					
						
							|  |  |  |         bp++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   mul_v3_fl(r_cent, 1.0f / (float)totvert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return totvert; | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static bool object_hook_index_array(Main *bmain, | 
					
						
							|  |  |  |                                     Scene *scene, | 
					
						
							|  |  |  |                                     Object *obedit, | 
					
						
							|  |  |  |                                     int *r_tot, | 
					
						
							|  |  |  |                                     int **r_indexar, | 
					
						
							|  |  |  |                                     char *r_name, | 
					
						
							|  |  |  |                                     float r_cent[3]) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   *r_indexar = NULL; | 
					
						
							|  |  |  |   *r_tot = 0; | 
					
						
							|  |  |  |   r_name[0] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (obedit->type) { | 
					
						
							|  |  |  |     case OB_MESH: { | 
					
						
							|  |  |  |       Mesh *me = obedit->data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       BMEditMesh *em; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       EDBM_mesh_load(bmain, obedit); | 
					
						
							|  |  |  |       EDBM_mesh_make(obedit, scene->toolsettings->selectmode, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       DEG_id_tag_update(obedit->data, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       em = me->edit_mesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       EDBM_mesh_normals_update(em); | 
					
						
							| 
									
										
										
										
											2019-08-25 14:32:47 +10:00
										 |  |  |       BKE_editmesh_looptri_calc(em); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       /* check selected vertices first */ | 
					
						
							|  |  |  |       if (return_editmesh_indexar(em, r_tot, r_indexar, r_cent) == 0) { | 
					
						
							|  |  |  |         return return_editmesh_vgroup(obedit, em, r_name, r_cent); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     case OB_CURVE: | 
					
						
							|  |  |  |     case OB_SURF: | 
					
						
							|  |  |  |       ED_curve_editnurb_load(bmain, obedit); | 
					
						
							|  |  |  |       ED_curve_editnurb_make(obedit); | 
					
						
							|  |  |  |       return return_editcurve_indexar(obedit, r_tot, r_indexar, r_cent); | 
					
						
							|  |  |  |     case OB_LATTICE: { | 
					
						
							|  |  |  |       Lattice *lt = obedit->data; | 
					
						
							|  |  |  |       return return_editlattice_indexar(lt->editlatt->latt, r_tot, r_indexar, r_cent); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void select_editcurve_hook(Object *obedit, HookModifierData *hmd) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ListBase *editnurb = object_editcurve_get(obedit); | 
					
						
							|  |  |  |   Nurb *nu; | 
					
						
							|  |  |  |   BPoint *bp; | 
					
						
							|  |  |  |   BezTriple *bezt; | 
					
						
							|  |  |  |   int index = 0, a, nr = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (nu = editnurb->first; nu; nu = nu->next) { | 
					
						
							|  |  |  |     if (nu->type == CU_BEZIER) { | 
					
						
							|  |  |  |       bezt = nu->bezt; | 
					
						
							|  |  |  |       a = nu->pntsu; | 
					
						
							|  |  |  |       while (a--) { | 
					
						
							|  |  |  |         if (nr == hmd->indexar[index]) { | 
					
						
							|  |  |  |           bezt->f1 |= SELECT; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |           if (index < hmd->totindex - 1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             index++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         nr++; | 
					
						
							|  |  |  |         if (nr == hmd->indexar[index]) { | 
					
						
							|  |  |  |           bezt->f2 |= SELECT; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |           if (index < hmd->totindex - 1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             index++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         nr++; | 
					
						
							|  |  |  |         if (nr == hmd->indexar[index]) { | 
					
						
							|  |  |  |           bezt->f3 |= SELECT; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |           if (index < hmd->totindex - 1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             index++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         nr++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bezt++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       bp = nu->bp; | 
					
						
							|  |  |  |       a = nu->pntsu * nu->pntsv; | 
					
						
							|  |  |  |       while (a--) { | 
					
						
							|  |  |  |         if (nr == hmd->indexar[index]) { | 
					
						
							|  |  |  |           bp->f1 |= SELECT; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |           if (index < hmd->totindex - 1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             index++; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         nr++; | 
					
						
							|  |  |  |         bp++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static void object_hook_from_context( | 
					
						
							|  |  |  |     bContext *C, PointerRNA *ptr, const int num, Object **r_ob, HookModifierData **r_hmd) | 
					
						
							| 
									
										
										
										
											2013-02-13 15:14:29 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Object *ob; | 
					
						
							|  |  |  |   HookModifierData *hmd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (ptr->data) { /* if modifier context is available, use that */ | 
					
						
							| 
									
										
										
										
											2019-08-23 09:52:12 +02:00
										 |  |  |     ob = (Object *)ptr->owner_id; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     hmd = ptr->data; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { /* use the provided property */ | 
					
						
							|  |  |  |     ob = CTX_data_edit_object(C); | 
					
						
							|  |  |  |     hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (ob && hmd && (hmd->modifier.type == eModifierType_Hook)) { | 
					
						
							|  |  |  |     *r_ob = ob; | 
					
						
							|  |  |  |     *r_hmd = hmd; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     *r_ob = NULL; | 
					
						
							|  |  |  |     *r_hmd = NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-02-13 15:14:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | static void object_hook_select(Object *ob, HookModifierData *hmd) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (hmd->indexar == NULL) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (ob->type == OB_MESH) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     select_editbmesh_hook(ob, hmd); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (ob->type == OB_LATTICE) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     select_editlattice_hook(ob, hmd); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (ob->type == OB_CURVE) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     select_editcurve_hook(ob, hmd); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (ob->type == OB_SURF) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     select_editcurve_hook(ob, hmd); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-23 02:27:52 +00:00
										 |  |  | /* special poll operators for hook operators */ | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | /* TODO: check for properties window modifier context too as alternative? */ | 
					
						
							| 
									
										
										
										
											2018-07-02 11:47:00 +02:00
										 |  |  | static bool hook_op_edit_poll(bContext *C) | 
					
						
							| 
									
										
										
										
											2009-11-23 02:27:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (obedit) { | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     if (ED_operator_editmesh(C)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       return 1; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (ED_operator_editsurfcurve(C)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       return 1; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (ED_operator_editlattice(C)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       return 1; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-01 11:09:22 +10:00
										 |  |  |     // if (ED_operator_editmball(C)) return 1;
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2009-11-23 02:27:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static Object *add_hook_object_new( | 
					
						
							|  |  |  |     Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, Object *obedit) | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Base *basedit; | 
					
						
							|  |  |  |   Object *ob; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ob = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, NULL); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   basedit = BKE_view_layer_base_find(view_layer, obedit); | 
					
						
							|  |  |  |   BLI_assert(view_layer->basact->object == ob); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (v3d && v3d->localvd) { | 
					
						
							|  |  |  |     view_layer->basact->local_view_bits |= v3d->local_view_uuid; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-03-12 17:42:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* icky, BKE_object_add sets new base as active.
 | 
					
						
							|  |  |  |    * so set it back to the original edit object */ | 
					
						
							|  |  |  |   view_layer->basact = basedit; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return ob; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static int add_hook_object(const bContext *C, | 
					
						
							|  |  |  |                            Main *bmain, | 
					
						
							|  |  |  |                            Scene *scene, | 
					
						
							|  |  |  |                            ViewLayer *view_layer, | 
					
						
							|  |  |  |                            View3D *v3d, | 
					
						
							|  |  |  |                            Object *obedit, | 
					
						
							|  |  |  |                            Object *ob, | 
					
						
							|  |  |  |                            int mode, | 
					
						
							|  |  |  |                            ReportList *reports) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-25 16:36:22 +02:00
										 |  |  |   Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ModifierData *md = NULL; | 
					
						
							|  |  |  |   HookModifierData *hmd = NULL; | 
					
						
							|  |  |  |   float cent[3]; | 
					
						
							|  |  |  |   float pose_mat[4][4]; | 
					
						
							|  |  |  |   int tot, ok, *indexar; | 
					
						
							|  |  |  |   char name[MAX_NAME]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ok = object_hook_index_array(bmain, scene, obedit, &tot, &indexar, name, cent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!ok) { | 
					
						
							|  |  |  |     BKE_report(reports, RPT_ERROR, "Requires selected vertices or active vertex group"); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (mode == OBJECT_ADDHOOK_NEWOB && !ob) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ob = add_hook_object_new(bmain, scene, view_layer, v3d, obedit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* transform cent to global coords for loc */ | 
					
						
							|  |  |  |     mul_v3_m4v3(ob->loc, obedit->obmat, cent); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   md = obedit->modifiers.first; | 
					
						
							|  |  |  |   while (md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform) { | 
					
						
							|  |  |  |     md = md->next; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   hmd = (HookModifierData *)modifier_new(eModifierType_Hook); | 
					
						
							|  |  |  |   BLI_insertlinkbefore(&obedit->modifiers, md, hmd); | 
					
						
							|  |  |  |   BLI_snprintf(hmd->modifier.name, sizeof(hmd->modifier.name), "Hook-%s", ob->id.name + 2); | 
					
						
							|  |  |  |   modifier_unique_name(&obedit->modifiers, (ModifierData *)hmd); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   hmd->object = ob; | 
					
						
							|  |  |  |   hmd->indexar = indexar; | 
					
						
							|  |  |  |   copy_v3_v3(hmd->cent, cent); | 
					
						
							|  |  |  |   hmd->totindex = tot; | 
					
						
							|  |  |  |   BLI_strncpy(hmd->name, name, sizeof(hmd->name)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unit_m4(pose_mat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   invert_m4_m4(obedit->imat, obedit->obmat); | 
					
						
							|  |  |  |   if (mode == OBJECT_ADDHOOK_NEWOB) { | 
					
						
							|  |  |  |     /* pass */ | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     /* may overwrite with pose-bone location, below */ | 
					
						
							|  |  |  |     mul_v3_m4v3(cent, obedit->imat, ob->obmat[3]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (mode == OBJECT_ADDHOOK_SELOB_BONE) { | 
					
						
							|  |  |  |     bArmature *arm = ob->data; | 
					
						
							|  |  |  |     BLI_assert(ob->type == OB_ARMATURE); | 
					
						
							|  |  |  |     if (arm->act_bone) { | 
					
						
							|  |  |  |       bPoseChannel *pchan_act; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       BLI_strncpy(hmd->subtarget, arm->act_bone->name, sizeof(hmd->subtarget)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       pchan_act = BKE_pose_channel_active(ob); | 
					
						
							|  |  |  |       if (LIKELY(pchan_act)) { | 
					
						
							|  |  |  |         invert_m4_m4(pose_mat, pchan_act->pose_mat); | 
					
						
							|  |  |  |         mul_v3_m4v3(cent, ob->obmat, pchan_act->pose_mat[3]); | 
					
						
							|  |  |  |         mul_v3_m4v3(cent, obedit->imat, cent); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       BKE_report(reports, RPT_WARNING, "Armature has no active object bone"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   copy_v3_v3(hmd->cent, cent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* matrix calculus */ | 
					
						
							|  |  |  |   /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */ | 
					
						
							|  |  |  |   /*        (parentinv         )                          */ | 
					
						
							| 
									
										
										
										
											2019-07-25 16:36:22 +02:00
										 |  |  |   Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); | 
					
						
							|  |  |  |   Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); | 
					
						
							|  |  |  |   BKE_object_transform_copy(object_eval, ob); | 
					
						
							|  |  |  |   BKE_object_where_is_calc(depsgraph, scene_eval, object_eval); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 16:36:22 +02:00
										 |  |  |   invert_m4_m4(object_eval->imat, object_eval->obmat); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* apparently this call goes from right to left... */ | 
					
						
							| 
									
										
										
										
											2019-07-25 16:36:22 +02:00
										 |  |  |   mul_m4_series(hmd->parentinv, pose_mat, object_eval->imat, obedit->obmat); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   DEG_relations_tag_update(bmain); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | static int object_add_hook_selob_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Main *bmain = CTX_data_main(C); | 
					
						
							|  |  |  |   Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  |   ViewLayer *view_layer = CTX_data_view_layer(C); | 
					
						
							|  |  |  |   Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  |   Object *obsel = NULL; | 
					
						
							|  |  |  |   const bool use_bone = RNA_boolean_get(op->ptr, "use_bone"); | 
					
						
							|  |  |  |   const int mode = use_bone ? OBJECT_ADDHOOK_SELOB_BONE : OBJECT_ADDHOOK_SELOB; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { | 
					
						
							|  |  |  |     if (ob != obedit) { | 
					
						
							|  |  |  |       obsel = ob; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   CTX_DATA_END; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!obsel) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_ERROR, "Cannot add hook with no other selected objects"); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (use_bone && obsel->type != OB_ARMATURE) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_ERROR, "Cannot add hook bone for a non armature object"); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (add_hook_object(C, bmain, scene, view_layer, NULL, obedit, obsel, mode, op->reports)) { | 
					
						
							|  |  |  |     WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit); | 
					
						
							|  |  |  |     return OPERATOR_FINISHED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-17 07:17:04 +00:00
										 |  |  | void OBJECT_OT_hook_add_selob(wmOperatorType *ot) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Hook to Selected Object"; | 
					
						
							|  |  |  |   ot->description = "Hook selected vertices to the first selected object"; | 
					
						
							|  |  |  |   ot->idname = "OBJECT_OT_hook_add_selob"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = object_add_hook_selob_exec; | 
					
						
							|  |  |  |   ot->poll = hook_op_edit_poll; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RNA_def_boolean(ot->srna, | 
					
						
							|  |  |  |                   "use_bone", | 
					
						
							|  |  |  |                   false, | 
					
						
							|  |  |  |                   "Active Bone", | 
					
						
							|  |  |  |                   "Assign the hook to the hook objects active bone"); | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-13 08:54:33 +00:00
										 |  |  | static int object_add_hook_newob_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Main *bmain = CTX_data_main(C); | 
					
						
							|  |  |  |   Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  |   ViewLayer *view_layer = CTX_data_view_layer(C); | 
					
						
							|  |  |  |   View3D *v3d = CTX_wm_view3d(C); | 
					
						
							|  |  |  |   Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (add_hook_object( | 
					
						
							|  |  |  |           C, bmain, scene, view_layer, v3d, obedit, NULL, OBJECT_ADDHOOK_NEWOB, op->reports)) { | 
					
						
							|  |  |  |     DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); | 
					
						
							|  |  |  |     WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); | 
					
						
							|  |  |  |     WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit); | 
					
						
							|  |  |  |     return OPERATOR_FINISHED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-17 07:17:04 +00:00
										 |  |  | void OBJECT_OT_hook_add_newob(wmOperatorType *ot) | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Hook to New Object"; | 
					
						
							|  |  |  |   ot->description = "Hook selected vertices to a newly created object"; | 
					
						
							|  |  |  |   ot->idname = "OBJECT_OT_hook_add_newob"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = object_add_hook_newob_exec; | 
					
						
							|  |  |  |   ot->poll = hook_op_edit_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int object_hook_remove_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   int num = RNA_enum_get(op->ptr, "modifier"); | 
					
						
							|  |  |  |   Object *ob = CTX_data_edit_object(C); | 
					
						
							|  |  |  |   HookModifierData *hmd = NULL; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num); | 
					
						
							|  |  |  |   if (!hmd) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* remove functionality */ | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   BLI_remlink(&ob->modifiers, (ModifierData *)hmd); | 
					
						
							|  |  |  |   modifier_free((ModifierData *)hmd); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static const EnumPropertyItem *hook_mod_itemf(bContext *C, | 
					
						
							|  |  |  |                                               PointerRNA *UNUSED(ptr), | 
					
						
							|  |  |  |                                               PropertyRNA *UNUSED(prop), | 
					
						
							|  |  |  |                                               bool *r_free) | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Object *ob = CTX_data_edit_object(C); | 
					
						
							|  |  |  |   EnumPropertyItem tmp = {0, "", 0, "", ""}; | 
					
						
							|  |  |  |   EnumPropertyItem *item = NULL; | 
					
						
							|  |  |  |   ModifierData *md = NULL; | 
					
						
							|  |  |  |   int a, totitem = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (!ob) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return DummyRNA_NULL_items; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for (a = 0, md = ob->modifiers.first; md; md = md->next, a++) { | 
					
						
							|  |  |  |     if (md->type == eModifierType_Hook) { | 
					
						
							|  |  |  |       tmp.value = a; | 
					
						
							|  |  |  |       tmp.icon = ICON_HOOK; | 
					
						
							|  |  |  |       tmp.identifier = md->name; | 
					
						
							|  |  |  |       tmp.name = md->name; | 
					
						
							|  |  |  |       RNA_enum_item_add(&item, &totitem, &tmp); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RNA_enum_item_end(&item, &totitem); | 
					
						
							|  |  |  |   *r_free = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return item; | 
					
						
							| 
									
										
										
											
												2.5: Object module
* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
											
										 
											2009-09-09 11:52:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | void OBJECT_OT_hook_remove(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Remove Hook"; | 
					
						
							|  |  |  |   ot->idname = "OBJECT_OT_hook_remove"; | 
					
						
							|  |  |  |   ot->description = "Remove a hook from the active object"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = object_hook_remove_exec; | 
					
						
							|  |  |  |   ot->invoke = WM_menu_invoke; | 
					
						
							|  |  |  |   ot->poll = hook_op_edit_poll; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* flags */ | 
					
						
							|  |  |  |   /* this operator removes modifier which isn't stored in local undo stack,
 | 
					
						
							|  |  |  |    * so redoing it from redo panel gives totally weird results  */ | 
					
						
							|  |  |  |   ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* properties */ | 
					
						
							|  |  |  |   prop = RNA_def_enum( | 
					
						
							|  |  |  |       ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to remove"); | 
					
						
							|  |  |  |   RNA_def_enum_funcs(prop, hook_mod_itemf); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | 
					
						
							|  |  |  |   ot->prop = prop; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 14:54:12 +00:00
										 |  |  | static int object_hook_reset_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); | 
					
						
							|  |  |  |   int num = RNA_enum_get(op->ptr, "modifier"); | 
					
						
							|  |  |  |   Object *ob = NULL; | 
					
						
							|  |  |  |   HookModifierData *hmd = NULL; | 
					
						
							| 
									
										
										
										
											2013-10-15 14:54:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   object_hook_from_context(C, &ptr, num, &ob, &hmd); | 
					
						
							|  |  |  |   if (hmd == NULL) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-10-15 14:54:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   BKE_object_modifier_hook_reset(ob, hmd); | 
					
						
							| 
									
										
										
										
											2013-10-15 14:54:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | void OBJECT_OT_hook_reset(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PropertyRNA *prop; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Reset Hook"; | 
					
						
							|  |  |  |   ot->description = "Recalculate and clear offset transformation"; | 
					
						
							|  |  |  |   ot->idname = "OBJECT_OT_hook_reset"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* callbacks */ | 
					
						
							|  |  |  |   ot->exec = object_hook_reset_exec; | 
					
						
							|  |  |  |   ot->poll = hook_op_edit_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* properties */ | 
					
						
							|  |  |  |   prop = RNA_def_enum( | 
					
						
							|  |  |  |       ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to assign to"); | 
					
						
							|  |  |  |   RNA_def_enum_funcs(prop, hook_mod_itemf); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | static int object_hook_recenter_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); | 
					
						
							|  |  |  |   int num = RNA_enum_get(op->ptr, "modifier"); | 
					
						
							|  |  |  |   Object *ob = NULL; | 
					
						
							|  |  |  |   HookModifierData *hmd = NULL; | 
					
						
							|  |  |  |   Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  |   float bmat[3][3], imat[3][3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   object_hook_from_context(C, &ptr, num, &ob, &hmd); | 
					
						
							|  |  |  |   if (hmd == NULL) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* recenter functionality */ | 
					
						
							|  |  |  |   copy_m3_m4(bmat, ob->obmat); | 
					
						
							|  |  |  |   invert_m3_m3(imat, bmat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sub_v3_v3v3(hmd->cent, scene->cursor.location, ob->obmat[3]); | 
					
						
							|  |  |  |   mul_m3_v3(imat, hmd->cent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | void OBJECT_OT_hook_recenter(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PropertyRNA *prop; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Recenter Hook"; | 
					
						
							|  |  |  |   ot->description = "Set hook center to cursor position"; | 
					
						
							|  |  |  |   ot->idname = "OBJECT_OT_hook_recenter"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* callbacks */ | 
					
						
							|  |  |  |   ot->exec = object_hook_recenter_exec; | 
					
						
							|  |  |  |   ot->poll = hook_op_edit_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* properties */ | 
					
						
							|  |  |  |   prop = RNA_def_enum( | 
					
						
							|  |  |  |       ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to assign to"); | 
					
						
							|  |  |  |   RNA_def_enum_funcs(prop, hook_mod_itemf); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | static int object_hook_assign_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   Main *bmain = CTX_data_main(C); | 
					
						
							|  |  |  |   Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  |   PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); | 
					
						
							|  |  |  |   int num = RNA_enum_get(op->ptr, "modifier"); | 
					
						
							|  |  |  |   Object *ob = NULL; | 
					
						
							|  |  |  |   HookModifierData *hmd = NULL; | 
					
						
							|  |  |  |   float cent[3]; | 
					
						
							|  |  |  |   char name[MAX_NAME]; | 
					
						
							|  |  |  |   int *indexar, tot; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   object_hook_from_context(C, &ptr, num, &ob, &hmd); | 
					
						
							|  |  |  |   if (hmd == NULL) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* assign functionality */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!object_hook_index_array(bmain, scene, ob, &tot, &indexar, name, cent)) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_WARNING, "Requires selected vertices or active vertex group"); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   if (hmd->indexar) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     MEM_freeN(hmd->indexar); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:19:45 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   copy_v3_v3(hmd->cent, cent); | 
					
						
							|  |  |  |   hmd->indexar = indexar; | 
					
						
							|  |  |  |   hmd->totindex = tot; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | void OBJECT_OT_hook_assign(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Assign to Hook"; | 
					
						
							|  |  |  |   ot->description = "Assign the selected vertices to a hook"; | 
					
						
							|  |  |  |   ot->idname = "OBJECT_OT_hook_assign"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* callbacks */ | 
					
						
							|  |  |  |   ot->exec = object_hook_assign_exec; | 
					
						
							|  |  |  |   ot->poll = hook_op_edit_poll; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* flags */ | 
					
						
							|  |  |  |   /* this operator changes data stored in modifier which doesn't get pushed to undo stack,
 | 
					
						
							|  |  |  |    * so redoing it from redo panel gives totally weird results  */ | 
					
						
							|  |  |  |   ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* properties */ | 
					
						
							|  |  |  |   prop = RNA_def_enum( | 
					
						
							|  |  |  |       ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to assign to"); | 
					
						
							|  |  |  |   RNA_def_enum_funcs(prop, hook_mod_itemf); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int object_hook_select_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); | 
					
						
							|  |  |  |   int num = RNA_enum_get(op->ptr, "modifier"); | 
					
						
							|  |  |  |   Object *ob = NULL; | 
					
						
							|  |  |  |   HookModifierData *hmd = NULL; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   object_hook_from_context(C, &ptr, num, &ob, &hmd); | 
					
						
							|  |  |  |   if (hmd == NULL) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier"); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* select functionality */ | 
					
						
							|  |  |  |   object_hook_select(ob, hmd); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   DEG_id_tag_update(ob->data, ID_RECALC_SELECT); | 
					
						
							|  |  |  |   WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data); | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 06:20:56 +00:00
										 |  |  | void OBJECT_OT_hook_select(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   PropertyRNA *prop; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Select Hook"; | 
					
						
							|  |  |  |   ot->description = "Select affected vertices on mesh"; | 
					
						
							|  |  |  |   ot->idname = "OBJECT_OT_hook_select"; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* callbacks */ | 
					
						
							|  |  |  |   ot->exec = object_hook_select_exec; | 
					
						
							|  |  |  |   ot->poll = hook_op_edit_poll; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2018-06-04 09:31:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* properties */ | 
					
						
							|  |  |  |   prop = RNA_def_enum( | 
					
						
							|  |  |  |       ot->srna, "modifier", DummyRNA_NULL_items, 0, "Modifier", "Modifier number to remove"); | 
					
						
							|  |  |  |   RNA_def_enum_funcs(prop, hook_mod_itemf); | 
					
						
							|  |  |  |   RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | 
					
						
							| 
									
										
										
										
											2009-11-16 13:59:27 +00:00
										 |  |  | } |