Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r--source/blender/editors/mesh/CMakeLists.txt40
-rw-r--r--source/blender/editors/mesh/Makefile2
-rw-r--r--source/blender/editors/mesh/editface.c11
-rw-r--r--source/blender/editors/mesh/editmesh.c62
-rw-r--r--source/blender/editors/mesh/editmesh_add.c65
-rw-r--r--source/blender/editors/mesh/editmesh_lib.c24
-rw-r--r--source/blender/editors/mesh/editmesh_loop.c14
-rw-r--r--source/blender/editors/mesh/editmesh_mods.c66
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c262
-rw-r--r--source/blender/editors/mesh/loopcut.c14
-rw-r--r--source/blender/editors/mesh/mesh_data.c112
-rw-r--r--source/blender/editors/mesh/mesh_intern.h1
-rw-r--r--source/blender/editors/mesh/mesh_ops.c11
-rw-r--r--source/blender/editors/mesh/meshtools.c177
14 files changed, 504 insertions, 357 deletions
diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt
new file mode 100644
index 00000000000..5f75ceb34ef
--- /dev/null
+++ b/source/blender/editors/mesh/CMakeLists.txt
@@ -0,0 +1,40 @@
+# $Id: CMakeLists.txt 12931 2007-12-17 18:20:48Z theeth $
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Contributor(s): Jacques Beaurain.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+FILE(GLOB SRC *.c)
+
+SET(INC
+ ../include
+ ../../blenkernel
+ ../../blenlib
+ ../../imbuf
+ ../../makesdna
+ ../../makesrna
+ ../../windowmanager
+ ../../render/extern/include
+ ../../../../intern/guardedalloc
+)
+
+IF(WIN32)
+ SET(INC ${INC} ${PTHREADS_INC})
+ENDIF(WIN32)
+
+BLENDERLIB(bf_editor_mesh "${SRC}" "${INC}")
diff --git a/source/blender/editors/mesh/Makefile b/source/blender/editors/mesh/Makefile
index 8ae40e1b957..be57f72329a 100644
--- a/source/blender/editors/mesh/Makefile
+++ b/source/blender/editors/mesh/Makefile
@@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2007 Blender Foundation
# All rights reserved.
diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c
index 7d47473e739..fc92598591a 100644
--- a/source/blender/editors/mesh/editface.c
+++ b/source/blender/editors/mesh/editface.c
@@ -44,21 +44,12 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "BKE_brush.h"
-#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
-#include "BKE_displist.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
-#include "BKE_object.h"
-#include "BKE_texture.h"
-#include "BKE_utildefines.h"
-#include "BKE_customdata.h"
#include "BKE_context.h"
#include "BIF_gl.h"
-#include "BIF_glutil.h"
#ifndef DISABLE_PYTHON
@@ -77,7 +68,7 @@
#include "mesh_intern.h"
/* ***************** XXX **************** */
-static int pupmenu() {return 0;}
+static int pupmenu(const char *dummy) {return 0;}
/* ***************** XXX **************** */
diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c
index e3f0d96ccfc..e6ba228c260 100644
--- a/source/blender/editors/mesh/editmesh.c
+++ b/source/blender/editors/mesh/editmesh.c
@@ -32,8 +32,11 @@
#include "MEM_guardedalloc.h"
-
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
#include "DNA_key_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
@@ -41,27 +44,15 @@
#include "BLI_dynstr.h"
#include "BLI_rand.h"
-#include "BKE_cloth.h"
+#include "BKE_DerivedMesh.h"
#include "BKE_context.h"
-#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
-#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_key.h"
-#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
-#include "BKE_modifier.h"
-#include "BKE_object.h"
#include "BKE_paint.h"
-#include "BKE_pointcache.h"
-#include "BKE_softbody.h"
-#include "BKE_texture.h"
-#include "BKE_utildefines.h"
-
-#include "LBM_fluidsim.h"
-
#include "ED_mesh.h"
#include "ED_object.h"
@@ -87,8 +78,8 @@ editmesh.c:
*/
/* XXX */
-static void BIF_undo_push() {}
-static void error() {}
+static void BIF_undo_push(const char *dummy) {}
+static void error(const char *dummy) {}
/* ***************** HASH ********************* */
@@ -1333,7 +1324,7 @@ static EnumPropertyItem prop_separate_types[] = {
};
/* return 1: success */
-static int mesh_separate_selected(Scene *scene, Base *editbase)
+static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase)
{
EditMesh *em, *emnew;
EditVert *eve, *v1;
@@ -1375,7 +1366,7 @@ static int mesh_separate_selected(Scene *scene, Base *editbase)
*/
/* 1 */
- basenew= ED_object_add_duplicate(scene, editbase, 0); /* 0 = fully linked */
+ basenew= ED_object_add_duplicate(bmain, scene, editbase, 0); /* 0 = fully linked */
ED_base_object_select(basenew, BA_DESELECT);
/* 2 */
@@ -1444,7 +1435,7 @@ static int mesh_separate_selected(Scene *scene, Base *editbase)
}
/* return 1: success */
-static int mesh_separate_material(Scene *scene, Base *editbase)
+static int mesh_separate_material(Main *bmain, Scene *scene, Base *editbase)
{
Mesh *me= editbase->object->data;
EditMesh *em= BKE_mesh_get_editmesh(me);
@@ -1456,7 +1447,7 @@ static int mesh_separate_material(Scene *scene, Base *editbase)
/* select the material */
EM_select_by_material(em, curr_mat);
/* and now separate */
- if(0==mesh_separate_selected(scene, editbase)) {
+ if(0==mesh_separate_selected(bmain, scene, editbase)) {
BKE_mesh_end_editmesh(me, em);
return 0;
}
@@ -1467,7 +1458,7 @@ static int mesh_separate_material(Scene *scene, Base *editbase)
}
/* return 1: success */
-static int mesh_separate_loose(Scene *scene, Base *editbase)
+static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase)
{
Mesh *me;
EditMesh *em;
@@ -1483,10 +1474,18 @@ static int mesh_separate_loose(Scene *scene, Base *editbase)
}
EM_clear_flag_all(em, SELECT);
-
- while(doit && em->verts.first) {
+
+ while(doit) {
/* Select a random vert to start with */
- EditVert *eve= em->verts.first;
+ EditVert *eve;
+ int tot;
+
+ /* check if all verts that are visible have been done */
+ for(eve=em->verts.first; eve; eve= eve->next)
+ if(!eve->h) break;
+ if(eve==NULL) break; /* only hidden verts left, quit early */
+
+ /* first non hidden vert */
eve->f |= SELECT;
selectconnected_mesh_all(em);
@@ -1496,8 +1495,14 @@ static int mesh_separate_loose(Scene *scene, Base *editbase)
if((eve->f & SELECT)==0) break;
if(eve==NULL) break;
+ tot= BLI_countlist(&em->verts);
+
/* and now separate */
- doit= mesh_separate_selected(scene, editbase);
+ doit= mesh_separate_selected(bmain, scene, editbase);
+
+ /* with hidden verts this can happen */
+ if(tot == BLI_countlist(&em->verts))
+ break;
}
BKE_mesh_end_editmesh(me, em);
@@ -1507,16 +1512,17 @@ static int mesh_separate_loose(Scene *scene, Base *editbase)
static int mesh_separate_exec(bContext *C, wmOperator *op)
{
+ Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Base *base= CTX_data_active_base(C);
int retval= 0, type= RNA_enum_get(op->ptr, "type");
if(type == 0)
- retval= mesh_separate_selected(scene, base);
+ retval= mesh_separate_selected(bmain, scene, base);
else if(type == 1)
- retval= mesh_separate_material (scene, base);
+ retval= mesh_separate_material(bmain, scene, base);
else if(type == 2)
- retval= mesh_separate_loose(scene, base);
+ retval= mesh_separate_loose(bmain, scene, base);
if(retval) {
WM_event_add_notifier(C, NC_GEOM|ND_DATA, base->object->data);
diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c
index 47ff6ad7c8c..ca1a80110f3 100644
--- a/source/blender/editors/mesh/editmesh_add.c
+++ b/source/blender/editors/mesh/editmesh_add.c
@@ -47,11 +47,8 @@
#include "BKE_context.h"
#include "BKE_depsgraph.h"
-#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_mesh.h"
-#include "BKE_object.h"
-#include "BKE_utildefines.h"
#include "BKE_report.h"
#include "WM_api.h"
@@ -140,7 +137,7 @@ static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event)
if( (eed->v1->f & SELECT)+(eed->v2->f & SELECT) == SELECT ) {
if(eed->v1->f & SELECT) sub_v3_v3v3(vec, eed->v1->co, eed->v2->co);
else sub_v3_v3v3(vec, eed->v2->co, eed->v1->co);
- add_v3_v3v3(nor, nor, vec);
+ add_v3_v3(nor, vec);
done= 1;
}
}
@@ -1262,6 +1259,23 @@ static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int se
/* ********* add primitive operators ************* */
+static char *get_mesh_defname(int type)
+{
+ switch (type) {
+ case PRIM_PLANE: return "Plane";
+ case PRIM_CUBE: return "Cube";
+ case PRIM_CIRCLE: return "Circle";
+ case PRIM_CYLINDER: return "Tube";
+ case PRIM_CONE: return "Cone";
+ case PRIM_GRID: return "Grid";
+ case PRIM_UVSPHERE: return "Sphere";
+ case PRIM_ICOSPHERE: return "Icosphere";
+ case PRIM_MONKEY: return "Monkey";
+ default:
+ return "Mesh";
+ }
+}
+
static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmode, unsigned int layer,
int type, int tot, int seg,
int subdiv, float dia, float depth, int ext, int fill)
@@ -1269,18 +1283,24 @@ static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmod
Object *obedit= CTX_data_edit_object(C);
int newob = 0;
float mat[4][4];
+ float scale;
if(obedit==NULL || obedit->type!=OB_MESH) {
obedit= ED_object_add_type(C, OB_MESH, loc, rot, FALSE, layer);
+ rename_id((ID *)obedit, get_mesh_defname(type));
+ rename_id((ID *)obedit->data, get_mesh_defname(type));
+
/* create editmode */
ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
newob = 1;
}
else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
- dia *= ED_object_new_primitive_matrix(C, loc, rot, mat);
- depth *= ED_object_new_primitive_matrix(C, loc, rot, mat);
+ scale= ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
+
+ dia *= scale;
+ depth *= scale;
make_prim(obedit, type, mat, tot, seg, subdiv, dia, depth, ext, fill);
@@ -1301,7 +1321,8 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
/* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */
make_prim_ext(C, loc, rot, enter_editmode, layer,
@@ -1333,7 +1354,8 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
/* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */
make_prim_ext(C, loc, rot, enter_editmode, layer,
@@ -1365,7 +1387,8 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
make_prim_ext(C, loc, rot, enter_editmode, layer,
PRIM_CIRCLE, RNA_int_get(op->ptr, "vertices"), 0, 0,
@@ -1404,7 +1427,8 @@ static int add_primitive_tube_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
make_prim_ext(C, loc, rot, enter_editmode, layer,
PRIM_CYLINDER, RNA_int_get(op->ptr, "vertices"), 0, 0,
@@ -1445,7 +1469,8 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
make_prim_ext(C, loc, rot, enter_editmode, layer,
PRIM_CONE, RNA_int_get(op->ptr, "vertices"), 0, 0,
@@ -1485,7 +1510,8 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
make_prim_ext(C, loc, rot, enter_editmode, layer,
PRIM_GRID, RNA_int_get(op->ptr, "x_subdivisions"),
@@ -1524,7 +1550,8 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
make_prim_ext(C, loc, rot, enter_editmode, layer,
PRIM_MONKEY, 0, 0, 2, 0.0f, 0.0f, 0, 0);
@@ -1556,10 +1583,11 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
make_prim_ext(C, loc, rot, enter_editmode, layer,
- PRIM_UVSPHERE, RNA_int_get(op->ptr, "rings"),
+ PRIM_UVSPHERE, RNA_int_get(op->ptr, "ring_count"),
RNA_int_get(op->ptr, "segments"), 0,
RNA_float_get(op->ptr,"size"), 0.0f, 0, 0);
@@ -1583,7 +1611,7 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
/* props */
RNA_def_int(ot->srna, "segments", 32, INT_MIN, INT_MAX, "Segments", "", 3, 500);
- RNA_def_int(ot->srna, "rings", 16, INT_MIN, INT_MAX, "Rings", "", 3, 500);
+ RNA_def_int(ot->srna, "ring_count", 16, INT_MIN, INT_MAX, "Rings", "", 3, 500);
RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, 100.00);
ED_object_add_generic_props(ot, TRUE);
@@ -1595,7 +1623,8 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
unsigned int layer;
float loc[3], rot[3];
- ED_object_add_generic_get_opts(op, loc, rot, &enter_editmode, &layer);
+ if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer))
+ return OPERATOR_CANCELLED;
make_prim_ext(C, loc, rot, enter_editmode, layer,
PRIM_ICOSPHERE, 0, 0, RNA_int_get(op->ptr, "subdivisions"),
@@ -1620,7 +1649,7 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
- RNA_def_int(ot->srna, "subdivisions", 2, 0, 6, "Subdivisions", "", 0, 8);
+ RNA_def_int(ot->srna, "subdivisions", 2, 0, INT_MAX, "Subdivisions", "", 0, 8);
RNA_def_float(ot->srna, "size", 1.0f, 0.0f, FLT_MAX, "Size", "", 0.001f, 100.00);
ED_object_add_generic_props(ot, TRUE);
diff --git a/source/blender/editors/mesh/editmesh_lib.c b/source/blender/editors/mesh/editmesh_lib.c
index 90d720e9c18..d34cca0d358 100644
--- a/source/blender/editors/mesh/editmesh_lib.c
+++ b/source/blender/editors/mesh/editmesh_lib.c
@@ -967,13 +967,13 @@ static void update_data_blocks(EditMesh *em, CustomData *olddata, CustomData *da
}
}
-void EM_add_data_layer(EditMesh *em, CustomData *data, int type)
+void EM_add_data_layer(EditMesh *em, CustomData *data, int type, const char *name)
{
CustomData olddata;
olddata= *data;
olddata.layers= (olddata.layers)? MEM_dupallocN(olddata.layers): NULL;
- CustomData_add_layer(data, type, CD_CALLOC, NULL, 0);
+ CustomData_add_layer_named(data, type, CD_CALLOC, NULL, 0, name);
update_data_blocks(em, &olddata, data);
if (olddata.layers) MEM_freeN(olddata.layers);
@@ -996,9 +996,9 @@ void EM_free_data_layer(EditMesh *em, CustomData *data, int type)
static void add_normal_aligned(float *nor, float *add)
{
if( INPR(nor, add) < -0.9999f)
- sub_v3_v3v3(nor, nor, add);
+ sub_v3_v3(nor, add);
else
- add_v3_v3v3(nor, nor, add);
+ add_v3_v3(nor, add);
}
static void set_edge_directions_f2(EditMesh *em, int val)
@@ -1316,8 +1316,8 @@ static short extrudeflag_edge(Object *obedit, EditMesh *em, short flag, float *n
copy_v3_v3(co2, eed->v2->co);
if (mmd->mirror_ob) {
- mul_v3_m4v3(co1, mtx, co1);
- mul_v3_m4v3(co2, mtx, co2);
+ mul_m4_v3(mtx, co1);
+ mul_m4_v3(mtx, co2);
}
if (mmd->flag & MOD_MIR_AXIS_X)
@@ -1605,8 +1605,8 @@ short extrudeflag_vert(Object *obedit, EditMesh *em, short flag, float *nor, int
copy_v3_v3(co2, eed->v2->co);
if (mmd->mirror_ob) {
- mul_v3_m4v3(co1, mtx, co1);
- mul_v3_m4v3(co2, mtx, co2);
+ mul_m4_v3(mtx, co1);
+ mul_m4_v3(mtx, co2);
}
if (mmd->flag & MOD_MIR_AXIS_X)
@@ -2006,15 +2006,15 @@ void recalc_editnormals(EditMesh *em)
if(efa->v4) {
normal_quad_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
cent_quad_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
- add_v3_v3v3(efa->v4->no, efa->v4->no, efa->n);
+ add_v3_v3(efa->v4->no, efa->n);
}
else {
normal_tri_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co);
cent_tri_v3(efa->cent, efa->v1->co, efa->v2->co, efa->v3->co);
}
- add_v3_v3v3(efa->v1->no, efa->v1->no, efa->n);
- add_v3_v3v3(efa->v2->no, efa->v2->no, efa->n);
- add_v3_v3v3(efa->v3->no, efa->v3->no, efa->n);
+ add_v3_v3(efa->v1->no, efa->n);
+ add_v3_v3(efa->v2->no, efa->n);
+ add_v3_v3(efa->v3->no, efa->n);
}
/* following Mesh convention; we use vertex coordinate itself for normal in this case */
diff --git a/source/blender/editors/mesh/editmesh_loop.c b/source/blender/editors/mesh/editmesh_loop.c
index 90de0a01eea..682fbca5072 100644
--- a/source/blender/editors/mesh/editmesh_loop.c
+++ b/source/blender/editors/mesh/editmesh_loop.c
@@ -51,13 +51,7 @@ editmesh_loop: tools with own drawing subloops, select, knife, subdiv
#include "BKE_context.h"
#include "BKE_depsgraph.h"
-#include "BKE_displist.h"
-#include "BKE_global.h"
-#include "BKE_library.h"
#include "BKE_mesh.h"
-#include "BKE_object.h"
-#include "BKE_report.h"
-#include "BKE_utildefines.h"
#include "PIL_time.h"
@@ -75,9 +69,9 @@ editmesh_loop: tools with own drawing subloops, select, knife, subdiv
#include "mesh_intern.h"
/* **** XXX ******** */
-static void BIF_undo_push() {}
+static void BIF_undo_push(const char *dummy) {}
static void BIF_undo() {}
-static void error() {}
+static void error(const char *dummy) {}
static int qtest() {return 0;}
/* **** XXX ******** */
@@ -629,7 +623,7 @@ static int knife_cut_exec(bContext *C, wmOperator *op)
int len=0;
short numcuts= RNA_int_get(op->ptr, "num_cuts");
short mode= RNA_int_get(op->ptr, "type");
- int corner_cut_pattern= RNA_enum_get(op->ptr,"corner_cut_pattern");
+// int corner_cut_pattern= RNA_enum_get(op->ptr,"corner_cut_pattern");
/* edit-object needed for matrix, and ar->regiondata for projections to work */
if (ELEM3(NULL, obedit, ar, ar->regiondata))
@@ -660,7 +654,7 @@ static int knife_cut_exec(bContext *C, wmOperator *op)
eed->tmp.fp = 0.0;
/*the floating point coordinates of verts in screen space will be stored in a hash table according to the vertices pointer*/
- gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+ gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife_cut_exec gh");
for(eve=em->verts.first; eve; eve=eve->next){
scr = MEM_mallocN(sizeof(float)*2, "Vertex Screen Coordinates");
VECCOPY(co, eve->co);
diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c
index 7a5fd2d13cd..0274bf1004d 100644
--- a/source/blender/editors/mesh/editmesh_mods.c
+++ b/source/blender/editors/mesh/editmesh_mods.c
@@ -55,14 +55,9 @@ editmesh_mods.c, UI level access, no geometry changes
#include "BKE_context.h"
#include "BKE_displist.h"
#include "BKE_depsgraph.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_customdata.h"
-#include "BKE_global.h"
#include "BKE_mesh.h"
#include "BKE_material.h"
#include "BKE_paint.h"
-#include "BKE_texture.h"
-#include "BKE_utildefines.h"
#include "BKE_report.h"
#include "IMB_imbuf_types.h"
@@ -82,7 +77,6 @@ editmesh_mods.c, UI level access, no geometry changes
#include "ED_view3d.h"
#include "BIF_gl.h"
-#include "BIF_glutil.h"
#include "mesh_intern.h"
@@ -90,7 +84,7 @@ editmesh_mods.c, UI level access, no geometry changes
/* XXX */
static void waitcursor(int val) {}
-static int pupmenu() {return 0;}
+static int pupmenu(const char *dummy) {return 0;}
/* ****************************** MIRROR **************** */
@@ -186,7 +180,7 @@ static void draw_triangulated(short mcords[][2], short tot)
}
/* do the fill */
- filldisplist(&lb, &lb);
+ filldisplist(&lb, &lb, 0);
/* do the draw */
dl= lb.first; /* filldisplist adds in head of list */
@@ -931,7 +925,7 @@ static int similar_edge_select__internal(ToolSettings *ts, EditMesh *em, int mod
/* cound how many faces each edge uses use tmp.l */
for(efa= em->faces.first; efa; efa= efa->next) {
/* here we use the edges temp data to assign a face
- if a face has alredy been assigned (eed->f2==1)
+ if a face has already been assigned (eed->f2==1)
we calculate the angle between the current face and
the edges previously found face.
store the angle in eed->tmp.fp (loosing the face eed->tmp.f)
@@ -1207,7 +1201,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
if (dvert && !(eve->f & SELECT) && !eve->h && dvert->totweight) {
/* do the extra check for selection in the following if, so were not
- checking verts that may be alredy selected */
+ checking verts that may be already selected */
for (i=0; base_dvert->totweight >i && !(eve->f & SELECT); i++) {
for (j=0; dvert->totweight >j; j++) {
if (base_dvert->dw[i].def_nr==dvert->dw[j].def_nr) {
@@ -2150,7 +2144,7 @@ static void mouse_mesh_shortest_path(bContext *C, short mval[2])
if(ese && ese->type == EDITEDGE) {
eed_act = (EditEdge*)ese->data;
if (eed_act != eed) {
- if (edgetag_shortest_path(vc.scene, em, eed_act, eed)) {
+ if (edgetag_shortest_path(vc.scene, em, eed_act, eed)) { /* <- this is where the magic happens */
EM_remove_selection(em, eed_act, EDITEDGE);
path = 1;
}
@@ -2163,13 +2157,19 @@ static void mouse_mesh_shortest_path(bContext *C, short mval[2])
}
/* even if this is selected it may not be in the selection list */
- if(edgetag_context_check(vc.scene, eed)==EDGE_MODE_SELECT)
+ if(edgetag_context_check(vc.scene, eed)==0) {
EM_remove_selection(em, eed, EDITEDGE);
+ }
else {
/* other modes need to keep the last edge tagged */
- if(eed_act)
- EM_select_edge(eed_act, 0);
+ if(eed_act) {
+ if(vc.scene->toolsettings->edge_mode!=EDGE_MODE_SELECT) {
+ /* for non-select modes, always de-select the previous active edge */
+ EM_select_edge(eed_act, 0);
+ }
+ }
+ /* set the new edge active */
EM_select_edge(eed, 1);
EM_store_selection(em, eed, EDITEDGE);
}
@@ -2208,6 +2208,16 @@ static int mesh_shortest_path_select_invoke(bContext *C, wmOperator *op, wmEvent
return OPERATOR_FINISHED;
}
+
+static int mesh_shortest_path_select_poll(bContext *C)
+{
+ if(ED_operator_editmesh_view3d(C)) {
+ Object *obedit= CTX_data_edit_object(C);
+ EditMesh *em= BKE_mesh_get_editmesh(obedit->data);
+ return (em->selectmode & SCE_SELECT_EDGE);
+ }
+ return 0;
+}
void MESH_OT_select_shortest_path(wmOperatorType *ot)
{
@@ -2218,7 +2228,7 @@ void MESH_OT_select_shortest_path(wmOperatorType *ot)
/* api callbacks */
ot->invoke= mesh_shortest_path_select_invoke;
- ot->poll= ED_operator_editmesh_view3d;
+ ot->poll= mesh_shortest_path_select_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -3420,7 +3430,7 @@ static int select_all_exec(bContext *C, wmOperator *op)
void MESH_OT_select_all(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "Select/Deselect All";
+ ot->name= "Select or Deselect All";
ot->description= "Change selection of all vertices, edges or faces";
ot->idname= "MESH_OT_select_all";
@@ -4058,7 +4068,7 @@ static void editmesh_calc_selvert_center(EditMesh *em, float cent_r[3])
EditVert *eve;
int nsel= 0;
- cent_r[0]= cent_r[1]= cent_r[0]= 0.0;
+ zero_v3(cent_r);
for (eve= em->verts.first; eve; eve= eve->next) {
if (eve->f & SELECT) {
@@ -4301,11 +4311,11 @@ static int smooth_vertex(bContext *C, wmOperator *op)
if((eed->v1->f & SELECT) && eed->v1->f1<255) {
eed->v1->f1++;
- add_v3_v3v3(eed->v1->tmp.p, eed->v1->tmp.p, fvec);
+ add_v3_v3(eed->v1->tmp.p, fvec);
}
if((eed->v2->f & SELECT) && eed->v2->f1<255) {
eed->v2->f1++;
- add_v3_v3v3(eed->v2->tmp.p, eed->v2->tmp.p, fvec);
+ add_v3_v3(eed->v2->tmp.p, fvec);
}
}
eed= eed->next;
@@ -4317,6 +4327,10 @@ static int smooth_vertex(bContext *C, wmOperator *op)
if(eve->f & SELECT) {
if(eve->f1) {
+ int xaxis= RNA_boolean_get(op->ptr, "xaxis");
+ int yaxis= RNA_boolean_get(op->ptr, "yaxis");
+ int zaxis= RNA_boolean_get(op->ptr, "zaxis");
+
if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) {
eve_mir= editmesh_get_x_mirror_vert(obedit, em, eve, eve->co, index);
}
@@ -4324,9 +4338,12 @@ static int smooth_vertex(bContext *C, wmOperator *op)
adr = eve->tmp.p;
fac= 0.5/(float)eve->f1;
- eve->co[0]= 0.5*eve->co[0]+fac*adr[0];
- eve->co[1]= 0.5*eve->co[1]+fac*adr[1];
- eve->co[2]= 0.5*eve->co[2]+fac*adr[2];
+ if(xaxis)
+ eve->co[0]= 0.5*eve->co[0]+fac*adr[0];
+ if(yaxis)
+ eve->co[1]= 0.5*eve->co[1]+fac*adr[1];
+ if(zaxis)
+ eve->co[2]= 0.5*eve->co[2]+fac*adr[2];
/* clip if needed by mirror modifier */
@@ -4395,6 +4412,9 @@ void MESH_OT_vertices_smooth(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Smooth Iterations", "", 1, INT_MAX);
+ RNA_def_boolean(ot->srna, "xaxis", 1, "X-Axis", "Smooth along the X axis.");
+ RNA_def_boolean(ot->srna, "yaxis", 1, "Y-Axis", "Smooth along the Y axis.");
+ RNA_def_boolean(ot->srna, "zaxis", 1, "Z-Axis", "Smooth along the Z axis.");
}
void vertexnoise(Object *obedit, EditMesh *em)
@@ -4426,7 +4446,7 @@ void vertexnoise(Object *obedit, EditMesh *em)
vec[1]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1]+ofs, eve->co[2]));
vec[2]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]+ofs));
- add_v3_v3v3(eve->co, eve->co, vec);
+ add_v3_v3(eve->co, vec);
}
else {
float tin, dum;
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 35fc5c1e3bc..5d6d9e314f2 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -37,8 +37,6 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
#include <math.h>
#include <float.h>
-#include "MEM_guardedalloc.h"
-
#include "BLO_sys_types.h" // for intptr_t support
#include "DNA_meshdata_types.h"
@@ -47,6 +45,8 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
#include "DNA_scene_types.h"
#include "DNA_key_types.h"
+#include "MEM_guardedalloc.h"
+
#include "RNA_define.h"
#include "RNA_access.h"
@@ -59,19 +59,13 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
#include "BLI_heap.h"
#include "BKE_context.h"
-#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_key.h"
-#include "BKE_library.h"
#include "BKE_mesh.h"
-#include "BKE_object.h"
-#include "BKE_utildefines.h"
#include "BKE_bmesh.h"
#include "BKE_report.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -80,6 +74,7 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
#include "ED_screen.h"
#include "ED_transform.h"
#include "ED_view3d.h"
+#include "ED_object.h"
#include "mesh_intern.h"
@@ -481,20 +476,19 @@ static int removedoublesflag_exec(bContext *C, wmOperator *op)
{
Object *obedit= CTX_data_edit_object(C);
EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
- /*char msg[100];*/
- /*int cnt =*/ removedoublesflag(em,1,0,RNA_float_get(op->ptr, "limit"));
- /*XXX this messes up last operator panel
- if(cnt)
- {
- sprintf(msg, "Removed %d vertices", cnt);
- BKE_report(op->reports, RPT_INFO, msg);
- }*/
+ int count = removedoublesflag(em,1,0,RNA_float_get(op->ptr, "limit"));
+
+ if(count) {
+ recalc_editnormals(em);
- DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+ DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
+ }
+ BKE_reportf(op->reports, RPT_INFO, "Removed %d vertices", count);
BKE_mesh_end_editmesh(obedit->data, em);
+
return OPERATOR_FINISHED;
}
@@ -648,8 +642,7 @@ void extrude_mesh(Scene *scene, Object *obedit, EditMesh *em, wmOperator *op, sh
* This shouldn't be necessary, derived queries should be
* automatically building this data if invalid. Or something.
*/
-// DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
- object_handle_update(scene, obedit);
+ DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
/* individual faces? */
// BIF_TransformSetUndo("Extrude");
@@ -661,7 +654,7 @@ void extrude_mesh(Scene *scene, Object *obedit, EditMesh *em, wmOperator *op, sh
// initTransform(TFM_TRANSLATION, CTX_NO_PET|CTX_NO_MIRROR);
if(transmode=='n') {
mul_m4_v3(obedit->obmat, nor);
- sub_v3_v3v3(nor, nor, obedit->obmat[3]);
+ sub_v3_v3(nor, obedit->obmat[3]);
// BIF_setSingleAxisConstraint(nor, "along normal");
}
// Transform();
@@ -798,6 +791,7 @@ void MESH_OT_extrude(wmOperatorType *ot)
/* properties */
prop= RNA_def_enum(ot->srna, "type", extrude_items, 0, "Type", "");
+ RNA_def_property_flag(prop, PROP_HIDDEN);
RNA_def_enum_funcs(prop, extrude_itemf);
ot->prop= prop;
}
@@ -1034,11 +1028,11 @@ void MESH_OT_spin(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
- RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX);
+ RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 128);
RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates");
RNA_def_float(ot->srna, "degrees", 90.0f, -FLT_MAX, FLT_MAX, "Degrees", "Degrees", -360.0f, 360.0f);
- RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
+ RNA_def_float_vector_xyz(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
}
@@ -1145,7 +1139,7 @@ void MESH_OT_screw(wmOperatorType *ot)
RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256);
RNA_def_int(ot->srna, "turns", 1, 0, INT_MAX, "Turns", "Turns", 0, 256);
- RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
+ RNA_def_float_vector_xyz(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX);
RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX);
}
@@ -1447,7 +1441,7 @@ static void alter_co(float *co, EditEdge *edge, float smooth, float fractal, int
vec1[0]= fac*(float)(0.5-BLI_drand());
vec1[1]= fac*(float)(0.5-BLI_drand());
vec1[2]= fac*(float)(0.5-BLI_drand());
- add_v3_v3v3(co, co, vec1);
+ add_v3_v3(co, vec1);
}
}
@@ -2729,7 +2723,7 @@ void esubdivideflag(Object *obedit, EditMesh *em, int flag, float smooth, float
}
}
- gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+ gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "subdivideedgenum gh");
// If we are knifing, We only need the selected edges that were cut, so deselect if it was not cut
if(beauty & B_KNIFE) {
@@ -3094,21 +3088,21 @@ static void givequadverts(EditFace *efa, EditFace *efa1, EditVert **v1, EditVert
if VTEST(efa1, 1, efa) {
*v3= efa1->v1;
- *v4= efa1->v2;
+ *v4= (efa1->v2 == *v2)? efa1->v3: efa1->v2;
vindex[2]= 0;
- vindex[3]= 1;
+ vindex[3]= (efa1->v2 == *v2)? 2: 1;
}
else if VTEST(efa1, 2, efa) {
*v3= efa1->v2;
- *v4= efa1->v3;
+ *v4= (efa1->v3 == *v2)? efa1->v1: efa1->v3;
vindex[2]= 1;
- vindex[3]= 2;
+ vindex[3]= (efa1->v3 == *v2)? 0: 2;
}
else if VTEST(efa1, 3, efa) {
*v3= efa1->v3;
- *v4= efa1->v1;
+ *v4= (efa1->v1 == *v2)? efa1->v2: efa1->v1;
vindex[2]= 2;
- vindex[3]= 0;
+ vindex[3]= (efa1->v1 == *v2)? 1: 0;
}
else
*v3= *v4= NULL;
@@ -3417,7 +3411,7 @@ void join_triangles(EditMesh *em)
efaa= (EVPtr *)eed->tmp.p;
v1 = v2 = v3 = v4 = NULL;
givequadverts(efaa[0], efaa[1], &v1, &v2, &v3, &v4, vindex);
- if((v1 && v2 && v3 && v4) && (exist_face(em, v1, v2, v3, v4)==0)){ /*exist_face is very slow! Needs to be adressed.*/
+ if((v1 && v2 && v3 && v4) && (exist_face(em, v1, v2, v3, v4)==0)){ /*exist_face is very slow! Needs to be addressed.*/
/*flag for delete*/
eed->f1 |= T2QDELETE;
/*create new quad and select*/
@@ -3657,10 +3651,10 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
newFace[1]= EM_face_from_faces(em, face[1], face[0], p[1][1], p[1][2], 4+p[0][1], -1);
}
else if(fac1 == 4 && fac2 == 3) {
- if(dir == DIRECTION_CW) {
+ if(dir == DIRECTION_CCW) {
newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][1], p[0][2], p[0][3], 4+p[1][1]);
newFace[1]= EM_face_from_faces(em, face[1], face[0], p[1][1], p[1][2], 4+p[0][1], -1);
- } else if (dir == DIRECTION_CCW) {
+ } else if (dir == DIRECTION_CW) {
newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][2], 4+p[1][1], p[0][0], p[0][1]);
newFace[1]= EM_face_from_faces(em, face[1], face[0], 4+p[0][2], p[1][0], p[1][1], -1);
@@ -3669,10 +3663,10 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
}
}
else if(fac1 == 3 && fac2 == 4) {
- if(dir == DIRECTION_CW) {
+ if(dir == DIRECTION_CCW) {
newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][1], p[0][2], 4+p[1][1], -1);
newFace[1]= EM_face_from_faces(em, face[1], face[0], p[1][1], p[1][2], p[1][3], 4+p[0][1]);
- } else if (dir == DIRECTION_CCW) {
+ } else if (dir == DIRECTION_CW) {
newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][0], p[0][1], 4+p[1][2], -1);
newFace[1]= EM_face_from_faces(em, face[1], face[0], p[1][1], p[1][2], 4+p[0][1], 4+p[0][2]);
@@ -3682,10 +3676,10 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
}
else if(fac1 == 4 && fac2 == 4) {
- if(dir == DIRECTION_CW) {
+ if(dir == DIRECTION_CCW) {
newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][1], p[0][2], p[0][3], 4+p[1][1]);
newFace[1]= EM_face_from_faces(em, face[1], face[0], p[1][1], p[1][2], p[1][3], 4+p[0][1]);
- } else if (dir == DIRECTION_CCW) {
+ } else if (dir == DIRECTION_CW) {
newFace[0]= EM_face_from_faces(em, face[0], face[1], p[0][2], p[0][3], 4+p[1][1], 4+p[1][2]);
newFace[1]= EM_face_from_faces(em, face[1], face[0], p[1][2], p[1][3], 4+p[0][1], 4+p[0][2]);
@@ -3696,7 +3690,7 @@ static void edge_rotate(EditMesh *em, wmOperator *op, EditEdge *eed, int dir)
else
return; /* This should never happen */
- if(dir == DIRECTION_CW || (fac1 == 3 && fac2 == 3)) {
+ if(dir == DIRECTION_CCW || (fac1 == 3 && fac2 == 3)) {
verts[0][p[0][1]]->f |= SELECT;
verts[1][p[1][1]]->f |= SELECT;
}
@@ -4091,7 +4085,7 @@ useless:
// populate the SlideVerts
- vertgh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+ vertgh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "EdgeSlide gh");
look = vertlist;
while(look) {
i=0;
@@ -4259,7 +4253,7 @@ useless:
for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) {
- uvarray[uvlay_idx] = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+ uvarray[uvlay_idx] = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "EdgeSlideUV gh");
for(ev=em->verts.first;ev;ev=ev->next) {
ev->tmp.l = 0;
@@ -5162,7 +5156,7 @@ static int blend_from_shape_exec(bContext *C, wmOperator *op)
if(add) {
mul_v3_fl(co, blend);
- add_v3_v3v3(eve->co, eve->co, co);
+ add_v3_v3(eve->co, co);
}
else
interp_v3_v3v3(eve->co, eve->co, co, blend);
@@ -5778,7 +5772,7 @@ static void em_snap_to_center(EditMesh *em)
for (eve=em->verts.first; eve; eve=eve->next) {
if (eve->f & SELECT) {
- add_v3_v3v3(cent, cent, eve->co);
+ add_v3_v3(cent, eve->co);
i++;
}
}
@@ -5863,6 +5857,7 @@ static int merge_exec(bContext *C, wmOperator *op)
if(!count)
return OPERATOR_CANCELLED;
+ recalc_editnormals(em);
BKE_reportf(op->reports, RPT_INFO, "Removed %d vert%s.", count, (count==1)?"ex":"ices");
@@ -6174,6 +6169,7 @@ static int region_to_loop(bContext *C, wmOperator *op)
}
em->selectmode = SCE_SELECT_EDGE;
+ CTX_data_tool_settings(C)->selectmode= em->selectmode;
EM_selectmode_set(em);
BKE_mesh_end_editmesh(obedit->data, em);
@@ -7080,6 +7076,184 @@ void MESH_OT_beautify_fill(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
+/* ********************** SORT FACES ******************* */
+
+static void permutate(void *list, int num, int size, int *index)
+{
+ void *buf;
+ int len;
+ int i;
+
+ len = num * size;
+
+ buf = MEM_mallocN(len, "permutate");
+ memcpy(buf, list, len);
+
+ for (i = 0; i < num; i++) {
+ memcpy((char *)list + (i * size), (char *)buf + (index[i] * size), size);
+ }
+ MEM_freeN(buf);
+}
+
+/* sort faces on view axis */
+static float *face_sort_floats;
+static int float_sort(const void *v1, const void *v2)
+{
+ float x1, x2;
+
+ x1 = face_sort_floats[((int *) v1)[0]];
+ x2 = face_sort_floats[((int *) v2)[0]];
+
+ if( x1 > x2 ) return 1;
+ else if( x1 < x2 ) return -1;
+ return 0;
+}
+
+
+static int sort_faces_exec(bContext *C, wmOperator *op)
+{
+ RegionView3D *rv3d= ED_view3d_context_rv3d(C);
+ View3D *v3d= CTX_wm_view3d(C);
+ Object *ob= CTX_data_edit_object(C);
+ Scene *scene= CTX_data_scene(C);
+ Mesh *me;
+ CustomDataLayer *layer;
+ int i, *index;
+ int event;
+ float reverse = 1;
+ // XXX int ctrl= 0;
+
+ if (!v3d) return OPERATOR_CANCELLED;
+
+ /* This operator work in Object Mode, not in edit mode.
+ * After talk with Cambell we agree that there is no point to port this to EditMesh right now.
+ * so for now, we just exit_editmode and enter_editmode at the end of this function.
+ */
+ ED_object_exit_editmode(C, EM_FREEDATA);
+
+ me= ob->data;
+ if(me->totface==0) {
+ ED_object_enter_editmode(C, 0);
+ return OPERATOR_FINISHED;
+ }
+
+ event= RNA_enum_get(op->ptr, "type");
+
+ // XXX
+ //if(ctrl)
+ // reverse = -1;
+
+ /* create index list */
+ index= (int *)MEM_mallocN(sizeof(int) * me->totface, "sort faces");
+ for (i = 0; i < me->totface; i++) {
+ index[i] = i;
+ }
+
+ face_sort_floats = (float *) MEM_mallocN(sizeof(float) * me->totface, "sort faces float");
+
+ /* sort index list instead of faces itself
+ * and apply this permutation to all face layers
+ */
+ if (event == 5) {
+ /* Random */
+ for(i=0; i<me->totface; i++) {
+ face_sort_floats[i] = BLI_frand();
+ }
+ qsort(index, me->totface, sizeof(int), float_sort);
+ } else {
+ MFace *mf;
+ float vec[3];
+ float mat[4][4];
+ float cur[3];
+
+ if (event == 1)
+ mul_m4_m4m4(mat, OBACT->obmat, rv3d->viewmat); /* apply the view matrix to the object matrix */
+ else if (event == 2) { /* sort from cursor */
+ if( v3d && v3d->localvd ) {
+ VECCOPY(cur, v3d->cursor);
+ } else {
+ VECCOPY(cur, scene->cursor);
+ }
+ invert_m4_m4(mat, OBACT->obmat);
+ mul_m4_v3(mat, cur);
+ }
+
+ mf= me->mface;
+
+ for(i=0; i<me->totface; i++, mf++) {
+ if (event==3) {
+ face_sort_floats[i] = ((float)mf->mat_nr)*reverse;
+ } else if (event==4) {
+ /*selected first*/
+ if (mf->flag & ME_FACE_SEL)
+ face_sort_floats[i] = 0.0;
+ else
+ face_sort_floats[i] = reverse;
+ } else {
+ /* find the faces center */
+ add_v3_v3v3(vec, (me->mvert+mf->v1)->co, (me->mvert+mf->v2)->co);
+ if (mf->v4) {
+ add_v3_v3(vec, (me->mvert+mf->v3)->co);
+ add_v3_v3(vec, (me->mvert+mf->v4)->co);
+ mul_v3_fl(vec, 0.25f);
+ } else {
+ add_v3_v3(vec, (me->mvert+mf->v3)->co);
+ mul_v3_fl(vec, 1.0f/3.0f);
+ } /* done */
+
+ if (event == 1) { /* sort on view axis */
+ mul_m4_v3(mat, vec);
+ face_sort_floats[i] = vec[2] * reverse;
+ } else if(event == 2) { /* distance from cursor*/
+ face_sort_floats[i] = len_v3v3(cur, vec) * reverse; /* back to front */
+ }
+ }
+ }
+ qsort(index, me->totface, sizeof(int), float_sort);
+ }
+
+ MEM_freeN(face_sort_floats);
+ for(i = 0; i < me->fdata.totlayer; i++) {
+ layer = &me->fdata.layers[i];
+ permutate(layer->data, me->totface, CustomData_sizeof(layer->type), index);
+ }
+
+ MEM_freeN(index);
+ DAG_id_flush_update(ob->data, OB_RECALC_DATA);
+
+ /* Return to editmode. */
+ ED_object_enter_editmode(C, 0);
+
+ return OPERATOR_FINISHED;
+}
+
+void MESH_OT_sort_faces(wmOperatorType *ot)
+{
+ static EnumPropertyItem type_items[]= {
+ { 1, "VIEW_AXIS", 0, "View Axis", "" },
+ { 2, "CURSOR_DISTANCE", 0, "Cursor Distance", "" },
+ { 3, "MATERIAL", 0, "Material", "" },
+ { 4, "SELECTION", 0, "Selection", "" },
+ { 5, "RANDOMIZE", 0, "Randomize", "" },
+ { 0, NULL, 0, NULL, NULL }};
+
+ /* identifiers */
+ ot->name= "Sort Faces"; // XXX (Ctrl to reverse)%t|
+ ot->description= "The faces of the active Mesh Object are sorted, based on the current view.";
+ ot->idname= "MESH_OT_sort_faces";
+
+ /* api callbacks */
+ ot->invoke= WM_menu_invoke;
+ ot->exec= sort_faces_exec;
+ ot->poll= ED_operator_editmesh;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ ot->prop= RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
+}
+
/********************** Quad/Tri Operators *************************/
static int quads_convert_to_tris_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/mesh/loopcut.c b/source/blender/editors/mesh/loopcut.c
index 314aa2c345f..488b59fa29e 100644
--- a/source/blender/editors/mesh/loopcut.c
+++ b/source/blender/editors/mesh/loopcut.c
@@ -51,7 +51,6 @@
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_scene.h"
-#include "BKE_utildefines.h"
#include "BKE_mesh.h"
#include "BIF_gl.h"
@@ -60,7 +59,6 @@
#include "IMB_imbuf_types.h"
#include "ED_screen.h"
-#include "ED_util.h"
#include "ED_space_api.h"
#include "ED_view3d.h"
#include "ED_mesh.h"
@@ -271,6 +269,16 @@ static void ringsel_finish(bContext *C, wmOperator *op)
if (lcd->do_cut) {
EditMesh *em = BKE_mesh_get_editmesh(lcd->ob->data);
esubdivideflag(lcd->ob, em, SELECT, 0.0f, 0.0f, 0, cuts, 0, SUBDIV_SELECT_LOOPCUT);
+
+ /* force edge slide to edge select mode in in face select mode */
+ if (em->selectmode & SCE_SELECT_FACE) {
+ if (em->selectmode == SCE_SELECT_FACE)
+ em->selectmode = SCE_SELECT_EDGE;
+ else
+ em->selectmode &= ~SCE_SELECT_FACE;
+ CTX_data_tool_settings(C)->selectmode= em->selectmode;
+ EM_selectmode_set(em);
+ }
DAG_id_flush_update(lcd->ob->data, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, lcd->ob->data);
@@ -403,7 +411,7 @@ static int ringcut_modal (bContext *C, wmOperator *op, wmEvent *event)
switch (event->type) {
case LEFTMOUSE: /* confirm */ // XXX hardcoded
- if (event->val == KM_RELEASE) {
+ if (event->val == KM_PRESS) {
/* finish */
ED_region_tag_redraw(lcd->ar);
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index 70352e9399f..35cb9f02b64 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -39,10 +39,9 @@
#include "DNA_view3d_types.h"
#include "BKE_context.h"
-#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_displist.h"
-#include "BKE_global.h"
+#include "BKE_image.h"
#include "BKE_library.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
@@ -158,7 +157,7 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
}
}
-int ED_mesh_uv_texture_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
+int ED_mesh_uv_texture_add(bContext *C, Scene *scene, Object *ob, Mesh *me, const char *name, int active_set)
{
EditMesh *em;
int layernum;
@@ -168,22 +167,25 @@ int ED_mesh_uv_texture_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
layernum= CustomData_number_of_layers(&em->fdata, CD_MTFACE);
if(layernum >= MAX_MTFACE)
- return OPERATOR_CANCELLED;
+ return 0;
- EM_add_data_layer(em, &em->fdata, CD_MTFACE);
- CustomData_set_layer_active(&em->fdata, CD_MTFACE, layernum);
+ EM_add_data_layer(em, &em->fdata, CD_MTFACE, name);
+ if(active_set || layernum==0)
+ CustomData_set_layer_active(&em->fdata, CD_MTFACE, layernum);
}
else {
layernum= CustomData_number_of_layers(&me->fdata, CD_MTFACE);
if(layernum >= MAX_MTFACE)
- return OPERATOR_CANCELLED;
+ return 0;
if(me->mtface)
- CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface);
+ CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface, name);
else
- CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface);
+ CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface, name);
+
+ if(active_set || layernum==0)
+ CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum);
- CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum);
mesh_update_customdata_pointers(me);
}
@@ -199,7 +201,7 @@ int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me)
CustomDataLayer *cdl;
int index;
- index= CustomData_get_active_layer_index(data, CD_MTFACE);
+ index= CustomData_get_active_layer_index(data, CD_MTFACE);
cdl= (index == -1) ? NULL: &data->layers[index];
if(!cdl)
@@ -212,7 +214,7 @@ int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me)
return 1;
}
-int ED_mesh_color_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
+int ED_mesh_color_add(bContext *C, Scene *scene, Object *ob, Mesh *me, const char *name, int active_set)
{
EditMesh *em;
MCol *mcol;
@@ -225,8 +227,9 @@ int ED_mesh_color_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
if(layernum >= MAX_MCOL)
return 0;
- EM_add_data_layer(em, &em->fdata, CD_MCOL);
- CustomData_set_layer_active(&em->fdata, CD_MCOL, layernum);
+ EM_add_data_layer(em, &em->fdata, CD_MCOL, name);
+ if(active_set || layernum==0)
+ CustomData_set_layer_active(&em->fdata, CD_MCOL, layernum);
}
else {
layernum= CustomData_number_of_layers(&me->fdata, CD_MCOL);
@@ -236,11 +239,13 @@ int ED_mesh_color_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
mcol= me->mcol;
if(me->mcol)
- CustomData_add_layer(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface);
+ CustomData_add_layer_named(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface, name);
else
- CustomData_add_layer(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface);
+ CustomData_add_layer_named(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface, name);
+
+ if(active_set || layernum==0)
+ CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum);
- CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum);
mesh_update_customdata_pointers(me);
if(!mcol)
@@ -287,7 +292,7 @@ static int uv_texture_add_exec(bContext *C, wmOperator *op)
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Mesh *me= ob->data;
- if(!ED_mesh_uv_texture_add(C, scene, ob, me))
+ if(!ED_mesh_uv_texture_add(C, scene, ob, me, NULL, TRUE))
return OPERATOR_CANCELLED;
return OPERATOR_FINISHED;
@@ -312,17 +317,33 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
Scene *scene= CTX_data_scene(C);
Base *base= ED_view3d_give_base_under_cursor(C, event->mval);
- Image *ima;
+ Image *ima= NULL;
Mesh *me;
Object *obedit;
int exitmode= 0;
char name[32];
+ /* Check context */
+ if(base==NULL || base->object->type!=OB_MESH) {
+ BKE_report(op->reports, RPT_ERROR, "Not an Object or Mesh");
+ return OPERATOR_CANCELLED;
+ }
+
/* check input variables */
- RNA_string_get(op->ptr, "name", name);
- ima= (Image *)find_id("IM", name);
- if(base==NULL || base->object->type!=OB_MESH || ima==NULL) {
- BKE_report(op->reports, RPT_ERROR, "Not a Mesh or no Image.");
+ if(RNA_property_is_set(op->ptr, "filepath")) {
+ char path[FILE_MAX];
+
+ RNA_string_get(op->ptr, "filepath", path);
+ ima= BKE_add_image_file(path,
+ scene ? scene->r.cfra : 1);
+ }
+ else {
+ RNA_string_get(op->ptr, "name", name);
+ ima= (Image *)find_id("IM", name);
+ }
+
+ if(!ima) {
+ BKE_report(op->reports, RPT_ERROR, "Not an Image.");
return OPERATOR_CANCELLED;
}
@@ -368,6 +389,7 @@ void MESH_OT_drop_named_image(wmOperatorType *ot)
/* properties */
RNA_def_string(ot->srna, "name", "Image", 24, "Name", "Image name to assign.");
+ RNA_def_string(ot->srna, "filepath", "Path", FILE_MAX, "Filepath", "Path to image file");
}
static int uv_texture_remove_exec(bContext *C, wmOperator *op)
@@ -404,7 +426,7 @@ static int vertex_color_add_exec(bContext *C, wmOperator *op)
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Mesh *me= ob->data;
- if(!ED_mesh_color_add(C, scene, ob, me))
+ if(!ED_mesh_color_add(C, scene, ob, me, NULL, TRUE))
return OPERATOR_CANCELLED;
return OPERATOR_FINISHED;
@@ -699,6 +721,7 @@ static void mesh_add_faces(Mesh *mesh, int len)
mesh->totface= totface;
}
+/*
void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, int faces)
{
if(mesh->edit_mesh) {
@@ -713,23 +736,50 @@ void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges,
if(faces)
mesh_add_faces(mesh, faces);
}
+*/
+
+void ED_mesh_faces_add(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't add faces in edit mode.");
+ return;
+ }
+
+ mesh_add_faces(mesh, count);
+}
+
+void ED_mesh_edges_add(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't add edges in edit mode.");
+ return;
+ }
+
+ mesh_add_edges(mesh, count);
+}
+
+void ED_mesh_vertices_add(Mesh *mesh, ReportList *reports, int count)
+{
+ if(mesh->edit_mesh) {
+ BKE_report(reports, RPT_ERROR, "Can't add vertices in edit mode.");
+ return;
+ }
+
+ mesh_add_verts(mesh, count);
+}
void ED_mesh_calc_normals(Mesh *me)
{
mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
}
-void ED_mesh_material_add(Mesh *me, Material *ma)
+/* always adds the material even if its linked alredy
+ * for pradictable material indicies */
+void ED_mesh_material_link(Mesh *me, Material *ma)
{
- int i;
int totcol = me->totcol + 1;
Material **mat;
- /* don't add if mesh already has it */
- for(i = 0; i < me->totcol; i++)
- if(me->mat[i] == ma)
- return;
-
mat= MEM_callocN(sizeof(void*)*totcol, "newmatar");
if(me->totcol) memcpy(mat, me->mat, sizeof(void*) * me->totcol);
diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h
index 3e175c657f6..6db2a3f211d 100644
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@ -241,6 +241,7 @@ void MESH_OT_rip(struct wmOperatorType *ot);
void MESH_OT_shape_propagate_to_all(struct wmOperatorType *ot);
void MESH_OT_blend_from_shape(struct wmOperatorType *ot);
+void MESH_OT_sort_faces(struct wmOperatorType *ot);
/* ******************* mesh_data.c */
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index 205ff99ee04..6562a4b30ae 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -29,7 +29,6 @@
#include <stdlib.h>
#include <math.h>
-#include "MEM_guardedalloc.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -39,9 +38,6 @@
#include "BLI_editVert.h"
#include "BKE_context.h"
-#include "BKE_global.h"
-#include "BKE_mesh.h"
-#include "BKE_utildefines.h"
#include "RNA_access.h"
@@ -113,6 +109,7 @@ void ED_operatortypes_mesh(void)
WM_operatortype_append(MESH_OT_edge_flip);
WM_operatortype_append(MESH_OT_faces_shade_smooth);
WM_operatortype_append(MESH_OT_faces_shade_flat);
+ WM_operatortype_append(MESH_OT_sort_faces);
WM_operatortype_append(MESH_OT_delete);
@@ -273,6 +270,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "MESH_OT_fill", FKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "MESH_OT_beautify_fill", FKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
+ WM_keymap_add_item(keymap, "MESH_OT_sort_faces", FKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
WM_keymap_add_item(keymap, "MESH_OT_quads_convert_to_tris", TKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "MESH_OT_tris_convert_to_quads", JKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "MESH_OT_edge_flip", FKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
@@ -298,9 +296,6 @@ void ED_keymap_mesh(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "MESH_OT_delete", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "MESH_OT_delete", DELKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "MESH_OT_fgon_make", FKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "MESH_OT_fgon_clear", FKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
-
WM_keymap_add_item(keymap, "MESH_OT_knife_cut", LEFTMOUSE, KM_PRESS, 0, KKEY);
RNA_enum_set(WM_keymap_add_item(keymap, "MESH_OT_knife_cut", LEFTMOUSE, KM_PRESS, KM_SHIFT, KKEY)->ptr, "type", 2/*KNIFE_MIDPOINT*/);
@@ -315,6 +310,6 @@ void ED_keymap_mesh(wmKeyConfig *keyconf)
WM_keymap_add_menu(keymap, "VIEW3D_MT_uv_map", UKEY, KM_PRESS, 0, 0);
WM_keymap_add_menu(keymap, "VIEW3D_MT_vertex_group", GKEY, KM_PRESS, KM_CTRL, 0);
- ED_object_generic_keymap(keyconf, keymap, 2);
+ ED_object_generic_keymap(keyconf, keymap, 3);
}
diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c
index 0d2d39f938f..7cef819a795 100644
--- a/source/blender/editors/mesh/meshtools.c
+++ b/source/blender/editors/mesh/meshtools.c
@@ -44,7 +44,6 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "DNA_view3d_types.h"
#include "BLI_math.h"
#include "BLI_blenlib.h"
@@ -54,20 +53,15 @@
#include "BLI_threads.h"
-#include "BKE_blender.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
+#include "BKE_deform.h"
#include "BKE_DerivedMesh.h"
-#include "BKE_customdata.h"
-#include "BKE_global.h"
-#include "BKE_image.h"
#include "BKE_key.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_material.h"
-#include "BKE_object.h"
-#include "BKE_utildefines.h"
#include "BKE_report.h"
#include "BLO_sys_types.h" // for intptr_t support
@@ -82,10 +76,6 @@
/* own include */
#include "mesh_intern.h"
-/* XXX */
-static int pupmenu() {return 0;}
-/* XXX */
-
/* * ********************** no editmode!!! *********** */
@@ -96,6 +86,7 @@ return 0 if no join is made (error) and 1 of the join is done */
int join_mesh_exec(bContext *C, wmOperator *op)
{
+ Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Object *ob= CTX_data_active_object(C);
Material **matar, *ma;
@@ -194,12 +185,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
/* Join this object's vertex groups to the base one's */
for(dg=base->object->defbase.first; dg; dg=dg->next) {
/* See if this group exists in the object (if it doesn't, add it to the end) */
- for(odg=ob->defbase.first; odg; odg=odg->next) {
- if(!strcmp(odg->name, dg->name)) {
- break;
- }
- }
- if(!odg) {
+ if(!defgroup_find_name(ob, dg->name)) {
odg = MEM_callocN(sizeof(bDeformGroup), "join deformGroup");
memcpy(odg, dg, sizeof(bDeformGroup));
BLI_addtail(&ob->defbase, odg);
@@ -447,7 +433,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
/* free base, now that data is merged */
if(base->object != ob)
- ED_base_object_free_and_unlink(scene, base);
+ ED_base_object_free_and_unlink(bmain, scene, base);
}
}
CTX_DATA_END;
@@ -507,17 +493,17 @@ int join_mesh_exec(bContext *C, wmOperator *op)
/* free it's ipo too - both are not actually freed from memory yet as ID-blocks */
if(nkey->ipo) {
free_ipo(nkey->ipo);
- BLI_remlink(&G.main->ipo, nkey->ipo);
+ BLI_remlink(&bmain->ipo, nkey->ipo);
MEM_freeN(nkey->ipo);
}
#endif
free_key(nkey);
- BLI_remlink(&G.main->key, nkey);
+ BLI_remlink(&bmain->key, nkey);
MEM_freeN(nkey);
}
- DAG_scene_sort(scene); // removed objects, need to rebuild dag before editmode call
+ DAG_scene_sort(bmain, scene); // removed objects, need to rebuild dag before editmode call
ED_object_enter_editmode(C, EM_WAITCURSOR);
ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR|EM_DO_UNDO);
@@ -601,153 +587,6 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
-/* ********************** SORT FACES ******************* */
-
-static void permutate(void *list, int num, int size, int *index)
-{
- void *buf;
- int len;
- int i;
-
- len = num * size;
-
- buf = MEM_mallocN(len, "permutate");
- memcpy(buf, list, len);
-
- for (i = 0; i < num; i++) {
- memcpy((char *)list + (i * size), (char *)buf + (index[i] * size), size);
- }
- MEM_freeN(buf);
-}
-
-/* sort faces on view axis */
-static float *face_sort_floats;
-static int float_sort(const void *v1, const void *v2)
-{
- float x1, x2;
-
- x1 = face_sort_floats[((int *) v1)[0]];
- x2 = face_sort_floats[((int *) v2)[0]];
-
- if( x1 > x2 ) return 1;
- else if( x1 < x2 ) return -1;
- return 0;
-}
-
-
-void sort_faces(Scene *scene, View3D *v3d)
-{
- RegionView3D *rv3d= NULL; // get from context
- Object *ob= OBACT;
- Mesh *me;
- CustomDataLayer *layer;
- int i, *index;
- short event;
- float reverse = 1;
- int ctrl= 0; // XXX
-
- if(!ob) return;
- if(scene->obedit) return;
- if(ob->type!=OB_MESH) return;
- if (!v3d) return;
-
- me= ob->data;
- if(me->totface==0) return;
-
- event = pupmenu(
- "Sort Faces (Ctrl to reverse)%t|"
- "View Axis%x1|"
- "Cursor Distance%x2|"
- "Material%x3|"
- "Selection%x4|"
- "Randomize%x5");
-
- if (event==-1) return;
-
- if(ctrl)
- reverse = -1;
-
-/* create index list */
- index = (int *) MEM_mallocN(sizeof(int) * me->totface, "sort faces");
- for (i = 0; i < me->totface; i++) {
- index[i] = i;
- }
-
- face_sort_floats = (float *) MEM_mallocN(sizeof(float) * me->totface, "sort faces float");
-
-/* sort index list instead of faces itself
- and apply this permutation to all face layers */
-
- if (event == 5) {
- /* Random */
- for(i=0; i<me->totface; i++) {
- face_sort_floats[i] = BLI_frand();
- }
- qsort(index, me->totface, sizeof(int), float_sort);
- } else {
- MFace *mf;
- float vec[3];
- float mat[4][4];
- float cur[3];
-
- if (event == 1)
- mul_m4_m4m4(mat, OBACT->obmat, rv3d->viewmat); /* apply the view matrix to the object matrix */
- else if (event == 2) { /* sort from cursor */
- if( v3d && v3d->localvd ) {
- VECCOPY(cur, v3d->cursor);
- } else {
- VECCOPY(cur, scene->cursor);
- }
- invert_m4_m4(mat, OBACT->obmat);
- mul_m4_v3(mat, cur);
- }
-
- mf= me->mface;
- for(i=0; i<me->totface; i++, mf++) {
-
- if (event==3) {
- face_sort_floats[i] = ((float)mf->mat_nr)*reverse;
- } else if (event==4) {
- /*selected first*/
- if (mf->flag & ME_FACE_SEL) face_sort_floats[i] = 0.0;
- else face_sort_floats[i] = reverse;
- } else {
- /* find the faces center */
- add_v3_v3v3(vec, (me->mvert+mf->v1)->co, (me->mvert+mf->v2)->co);
- if (mf->v4) {
- add_v3_v3v3(vec, vec, (me->mvert+mf->v3)->co);
- add_v3_v3v3(vec, vec, (me->mvert+mf->v4)->co);
- mul_v3_fl(vec, 0.25f);
- } else {
- add_v3_v3v3(vec, vec, (me->mvert+mf->v3)->co);
- mul_v3_fl(vec, 1.0f/3.0f);
- } /* done */
-
- if (event == 1) { /* sort on view axis */
- mul_m4_v3(mat, vec);
- face_sort_floats[i] = vec[2] * reverse;
- } else if(event == 2) { /* distance from cursor*/
- face_sort_floats[i] = len_v3v3(cur, vec) * reverse; /* back to front */
- }
- }
- }
- qsort(index, me->totface, sizeof(int), float_sort);
- }
-
- MEM_freeN(face_sort_floats);
-
- for(i = 0; i < me->fdata.totlayer; i++) {
- layer = &me->fdata.layers[i];
- permutate(layer->data, me->totface, CustomData_sizeof(layer->type), index);
- }
-
- MEM_freeN(index);
-
- DAG_id_flush_update(ob->data, OB_RECALC_DATA);
-}
-
-
-
/* ********************* MESH VERTEX OCTREE LOOKUP ************* */
/* important note; this is unfinished, needs better API for editmode, and custom threshold */
@@ -1374,7 +1213,7 @@ int *mesh_get_x_mirror_faces(Object *ob, EditMesh *em)
mesh_octree_table(ob, em, NULL, 'e');
- fhash= BLI_ghash_new(mirror_facehash, mirror_facecmp);
+ fhash= BLI_ghash_new(mirror_facehash, mirror_facecmp, "mirror_facehash gh");
for(a=0, mf=mface; a<me->totface; a++, mf++)
BLI_ghash_insert(fhash, mf, mf);