[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18509] branches/blender2.5/blender/source /blender/editors: 2.5
Ton Roosendaal
ton at blender.org
Wed Jan 14 20:26:11 CET 2009
Revision: 18509
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18509
Author: ton
Date: 2009-01-14 20:26:11 +0100 (Wed, 14 Jan 2009)
Log Message:
-----------
2.5
Editmesh: add primitive basics back. Had to clean up a load of
crap there... but it's sorta in control, so I think Shul can
pick it up again.
Test: ctrl+0 adds plane, or ctrl+9 adds grid.
Notes for Shul:
- i've added a transform function, which gets correctly passed
on to the add_prim function, should work for all object
transforms. Only the code inside add_prim might be needed
to check (it uses 4x4 mat now, not a 3x3)
- The old code with buttons has been ifdeffed out, check for
user input and make it rna properties, which get read
in the exec(), and handed over to the add_prim. Set them
default now to the values from old buttons.
- Operator naming is preferred lower case, I gave this
a new name.
- check a bit on formatting code, but don't use the old code
as example! Look also at ED_keymap_mesh() for example.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/mesh/editmesh.c
branches/blender2.5/blender/source/blender/editors/mesh/editmesh_add.c
branches/blender2.5/blender/source/blender/editors/mesh/editmesh_lib.c
branches/blender2.5/blender/source/blender/editors/mesh/mesh_intern.h
branches/blender2.5/blender/source/blender/editors/mesh/mesh_ops.c
branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_header.c
Modified: branches/blender2.5/blender/source/blender/editors/mesh/editmesh.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/mesh/editmesh.c 2009-01-14 18:48:16 UTC (rev 18508)
+++ branches/blender2.5/blender/source/blender/editors/mesh/editmesh.c 2009-01-14 19:26:11 UTC (rev 18509)
@@ -1022,7 +1022,7 @@
ClothModifierData *clmd;
PTCacheID pid;
float *fp, *newkey, *oldkey, nor[3], cacheco[3], cachemat[4][4];
- int i, a, ototvert, totedge=0, cacheedit= 0;
+ int i, a, ototvert, cacheedit= 0;
/* this one also tests of edges are not in faces: */
/* eed->f2==0: not in face, f2==1: draw it */
@@ -1031,19 +1031,17 @@
/* eve->f2 : being used in vertexnormals */
edge_drawflags(em);
- eed= em->edges.first;
- while(eed) {
- totedge++;
- eed= eed->next;
- }
+ G.totvert= BLI_countlist(&em->verts);
+ G.totedge= BLI_countlist(&em->edges);
+ G.totface= BLI_countlist(&em->faces);
/* new Vertex block */
if(G.totvert==0) mvert= NULL;
else mvert= MEM_callocN(G.totvert*sizeof(MVert), "loadeditMesh vert");
/* new Edge block */
- if(totedge==0) medge= NULL;
- else medge= MEM_callocN(totedge*sizeof(MEdge), "loadeditMesh edge");
+ if(G.totedge==0) medge= NULL;
+ else medge= MEM_callocN(G.totedge*sizeof(MEdge), "loadeditMesh edge");
/* new Face block */
if(G.totface==0) mface= NULL;
@@ -1064,7 +1062,7 @@
/* add new custom data */
me->totvert= G.totvert;
- me->totedge= totedge;
+ me->totedge= G.totedge;
me->totface= G.totface;
CustomData_copy(&em->vdata, &me->vdata, CD_MASK_MESH, CD_CALLOC, me->totvert);
@@ -2096,21 +2094,24 @@
int i;
if (forVert) {
- g_em_vert_array = MEM_mallocN(sizeof(*g_em_vert_array)*G.totvert, "em_v_arr");
+ int tot= BLI_countlist(&em->verts);
+ g_em_vert_array = MEM_mallocN(sizeof(*g_em_vert_array)*tot, "em_v_arr");
for (i=0,eve=em->verts.first; eve; i++,eve=eve->next)
g_em_vert_array[i] = eve;
}
if (forEdge) {
- g_em_edge_array = MEM_mallocN(sizeof(*g_em_edge_array)*G.totedge, "em_e_arr");
+ int tot= BLI_countlist(&em->edges);
+ g_em_edge_array = MEM_mallocN(sizeof(*g_em_edge_array)*tot, "em_e_arr");
for (i=0,eed=em->edges.first; eed; i++,eed=eed->next)
g_em_edge_array[i] = eed;
}
if (forFace) {
- g_em_face_array = MEM_mallocN(sizeof(*g_em_face_array)*G.totface, "em_f_arr");
+ int tot= BLI_countlist(&em->faces);
+ g_em_face_array = MEM_mallocN(sizeof(*g_em_face_array)*tot, "em_f_arr");
for (i=0,efa=em->faces.first; efa; i++,efa=efa->next)
g_em_face_array[i] = efa;
Modified: branches/blender2.5/blender/source/blender/editors/mesh/editmesh_add.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/mesh/editmesh_add.c 2009-01-14 18:48:16 UTC (rev 18508)
+++ branches/blender2.5/blender/source/blender/editors/mesh/editmesh_add.c 2009-01-14 19:26:11 UTC (rev 18509)
@@ -34,7 +34,6 @@
#include "MEM_guardedalloc.h"
-
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
@@ -43,11 +42,13 @@
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BLI_editVert.h"
+#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_library.h"
@@ -57,8 +58,13 @@
#include "BIF_retopo.h"
+#include "WM_api.h"
+#include "WM_types.h"
+
#include "ED_mesh.h"
+#include "ED_util.h"
#include "ED_view3d.h"
+#include "ED_screen.h"
#include "mesh_intern.h"
@@ -70,9 +76,6 @@
static void error() {}
static int pupmenu() {return 0;}
#define add_numbut(a, b, c, d, e, f, g) {}
-static int do_clever_numbuts() {return 0;}
-static void check_editmode() {}
-static void exit_editmode() {}
/* XXX */
static float icovert[12][3] = {
@@ -225,7 +228,7 @@
eve->f= SELECT;
}
- retopo_do_all();
+ //retopo_do_all();
BIF_undo_push("Add vertex/edge/face");
// XXX DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
@@ -756,38 +759,7 @@
// Transform();
}
-/* check whether an object to add mesh to exists, if not, create one
-* returns 1 if new object created, else 0 */
-static int confirm_objectExists(Scene *scene, Object *obedit, Mesh **me, float mat[][3] )
-{
- int newob = 0;
-
- /* if no obedit: new object and enter editmode */
- if(obedit==NULL) {
- /* add_object actually returns an object ! :-)
- But it also stores the added object struct in
- scene->basact->object (BASACT->object) */
-// XXX add_object_draw(OB_MESH);
-
- obedit= BASACT->object;
-
- where_is_object(scene, obedit);
-
- make_editMesh(scene, obedit);
- newob= 1;
- }
- *me = obedit->data;
-
- /* deselectall */
- EM_clear_flag_all((*me)->edit_mesh, SELECT);
-
- /* imat and center and size */
- Mat3CpyMat4(mat, obedit->obmat);
-
- return newob;
-}
-
// HACK: these can also be found in cmoview.tga.c, but are here so that they can be found by linker
// this hack is only used so that scons+mingw + split-sources hack works
// ------------------------------- start copied code
@@ -934,29 +906,35 @@
// ------------------------------- end copied code
-void make_prim(Object *obedit, EditMesh *em, int type, float imat[3][3], int tot, int seg,
- int subdiv, float dia, float d, int ext, int fill,
- float cent[3])
+#define PRIM_PLANE 0
+#define PRIM_CUBE 1
+#define PRIM_CIRCLE 4
+#define PRIM_GRID 10
+
+static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int seg,
+ int subdiv, float dia, float depth, int ext, int fill)
{
/*
* type - for the type of shape
* dia - the radius for cone,sphere cylinder etc.
- * d - depth for the cone
- * ext - ?
+ * depth -
+ * ext - extrude
* fill - end capping, and option to fill in circle
* cent[3] - center of the data.
* */
-
+ EditMesh *em= ((Mesh *)obedit->data)->edit_mesh;
EditVert *eve, *v1=NULL, *v2, *v3, *v4=NULL, *vtop, *vdown;
float phi, phid, vec[3];
float q[4], cmat[3][3], nor[3]= {0.0, 0.0, 0.0};
short a, b;
+
+ EM_clear_flag_all(em, SELECT);
phid= 2*M_PI/tot;
phi= .25*M_PI;
switch(type) {
- case 10: /* grid */
+ case PRIM_GRID: /* grid */
/* clear flags */
eve= em->verts.first;
while(eve) {
@@ -967,10 +945,10 @@
phi= 1.0;
phid= 2.0/((float)tot-1);
for(a=0;a<tot;a++) {
- vec[0]= cent[0]+dia*phi;
- vec[1]= cent[1]- dia;
- vec[2]= cent[2];
- Mat3MulVecfl(imat,vec);
+ vec[0]= dia*phi;
+ vec[1]= - dia;
+ vec[2]= 0.0f;
+ Mat4MulVecfl(mat,vec);
eve= addvertlist(em, vec, NULL);
eve->f= 1+2+4;
if (a) {
@@ -981,7 +959,8 @@
/* extrude and translate */
vec[0]= vec[2]= 0.0;
vec[1]= dia*phid;
- Mat3MulVecfl(imat, vec);
+ Mat4Mul3Vecfl(mat, vec);
+
for(a=0;a<seg-1;a++) {
extrudeflag_vert(obedit, em, 2, nor); // nor unused
translateflag(em, 2, vec);
@@ -1028,8 +1007,7 @@
eve= em->verts.first;
while(eve) {
if(eve->f & SELECT) {
- VecAddf(eve->co,eve->co,cent);
- Mat3MulVecfl(imat,eve->co);
+ Mat4MulVecfl(mat,eve->co);
}
eve= eve->next;
}
@@ -1070,8 +1048,7 @@
eve= em->verts.first;
while(eve) {
if(eve->f & 2) {
- VecAddf(eve->co,eve->co,cent);
- Mat3MulVecfl(imat,eve->co);
+ Mat4MulVecfl(mat,eve->co);
}
eve= eve->next;
}
@@ -1110,26 +1087,25 @@
/* and now do imat */
for(eve= em->verts.first; eve; eve= eve->next) {
if(eve->f & SELECT) {
- VecAddf(eve->co,eve->co,cent);
- Mat3MulVecfl(imat,eve->co);
+ Mat4MulVecfl(mat,eve->co);
}
}
recalc_editnormals(em);
}
break;
default: /* all types except grid, sphere... */
- if(ext==0 && type!=7) d= 0;
+ if(ext==0 && type!=7) depth= 0.0f;
/* vertices */
vtop= vdown= v1= v2= 0;
for(b=0; b<=ext; b++) {
for(a=0; a<tot; a++) {
- vec[0]= cent[0]+dia*sin(phi);
- vec[1]= cent[1]+dia*cos(phi);
- vec[2]= cent[2]+d;
+ vec[0]= dia*sin(phi);
+ vec[1]= dia*cos(phi);
+ vec[2]= depth;
- Mat3MulVecfl(imat, vec);
+ Mat4MulVecfl(mat, vec);
eve= addvertlist(em, vec, NULL);
eve->f= SELECT;
if(a==0) {
@@ -1138,20 +1114,20 @@
}
phi+=phid;
}
- d= -d;
+ depth= -depth;
}
/* center vertices */
/* type 7, a cone can only have 1 one side filled
* if the cone has no capping, dont add vtop */
if((fill && type>1) || type == 7) {
- VECCOPY(vec,cent);
- vec[2]-= -d;
- Mat3MulVecfl(imat,vec);
+ vec[0]= vec[1]= 0.0f;
+ vec[2]-= -depth;
+ Mat4MulVecfl(mat, vec);
vdown= addvertlist(em, vec, NULL);
if((ext || type==7) && fill) {
- VECCOPY(vec,cent);
- vec[2]-= d;
- Mat3MulVecfl(imat,vec);
+ vec[0]= vec[1]= 0.0f;
+ vec[2]-= depth;
+ Mat4MulVecfl(mat,vec);
vtop= addvertlist(em, vec, NULL);
}
} else {
@@ -1225,6 +1201,7 @@
righthandfaces(em, 1); /* otherwise monkey has eyes in wrong direction */
}
+#if 0
void add_primitiveMesh(Scene *scene, View3D *v3d, Object *obedit, EditMesh *em, int type)
{
Mesh *me;
@@ -1378,7 +1355,7 @@
phid= 2*M_PI/tot;
phi= .25*M_PI;
- make_prim(obedit, em, type, imat, tot, seg, subdiv, dia, d, ext, fill, cent);
+ make_prim(obedit, type, imat, tot, seg, subdiv, dia, d, ext, fill, cent);
if(type<2) tot = totoud;
@@ -1398,4 +1375,101 @@
BIF_undo_push(undostr);
}
+#endif
+/* uses context to figure out transform for primitive */
+/* returns standard diameter */
+static float new_primitive_matrix(bContext *C, float primmat[][4])
+{
+ Object *obedit= CTX_data_edit_object(C);
+ Scene *scene = CTX_data_scene(C);
+ ScrArea *sa = CTX_wm_area(C);
+ View3D *v3d = NULL;
+ float *curs, mat[3][3], vmat[3][3], cmat[3][3], imat[3][3];
+
+ Mat4One(primmat);
+
+ if(sa->spacetype==SPACE_VIEW3D)
+ v3d= sa->spacedata.first;
+
+ if(v3d)
+ Mat3CpyMat4(vmat, v3d->viewmat);
+ else
+ Mat3One(vmat);
+
+ /* inverse transform for view and object */
+ Mat3CpyMat4(mat, obedit->obmat);
+ Mat3MulMat3(cmat, vmat, mat);
+ Mat3Inv(imat, cmat);
+ Mat4CpyMat3(primmat, imat);
+
+ /* center */
+ curs= give_cursor(scene, v3d);
+ VECCOPY(primmat[3], curs);
+ Mat3Inv(imat, mat);
+ Mat3MulVecfl(imat, primmat[3]);
+ VECSUB(primmat[3], primmat[3], obedit->obmat[3]);
+
+ if(v3d) return v3d->grid;
+ return 1.0f;
+}
+
+/* ********* add primitive operators ************* */
+
+static int add_primitive_plane_exec(bContext *C, wmOperator *op)
+{
+ Object *obedit= CTX_data_edit_object(C);
+ float dia, mat[4][4];
+
+ dia= new_primitive_matrix(C, mat);
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list