Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2004 by Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00034 #include <stdlib.h> 00035 #include <string.h> 00036 #include <math.h> 00037 00038 #include "MEM_guardedalloc.h" 00039 00040 #include "DNA_meshdata_types.h" 00041 #include "DNA_object_types.h" 00042 #include "DNA_scene_types.h" 00043 00044 #include "RNA_define.h" 00045 #include "RNA_access.h" 00046 #include "RNA_enum_types.h" 00047 00048 #include "BLI_blenlib.h" 00049 #include "BLI_math.h" 00050 #include "BLI_editVert.h" 00051 #include "BLI_utildefines.h" 00052 00053 #include "BKE_context.h" 00054 #include "BKE_depsgraph.h" 00055 #include "BKE_library.h" 00056 #include "BKE_mesh.h" 00057 #include "BKE_report.h" 00058 00059 #include "WM_api.h" 00060 #include "WM_types.h" 00061 00062 #include "ED_mesh.h" 00063 #include "ED_screen.h" 00064 #include "ED_transform.h" 00065 #include "ED_view3d.h" 00066 #include "ED_object.h" 00067 00068 #include "mesh_intern.h" 00069 00070 /* bpymenu removed XXX */ 00071 00072 /* XXX */ 00073 #define add_numbut(a, b, c, d, e, f, g) {} 00074 /* XXX */ 00075 00076 static float icovert[12][3] = { 00077 {0.0f,0.0f,-200.0f}, 00078 {144.72f, -105.144f,-89.443f}, 00079 {-55.277f, -170.128,-89.443f}, 00080 {-178.885f,0.0f,-89.443f}, 00081 {-55.277f,170.128f,-89.443f}, 00082 {144.72f,105.144f,-89.443f}, 00083 {55.277f,-170.128f,89.443f}, 00084 {-144.72f,-105.144f,89.443f}, 00085 {-144.72f,105.144f,89.443f}, 00086 {55.277f,170.128f,89.443f}, 00087 {178.885f,0.0f,89.443f}, 00088 {0.0f,0.0f,200.0f} 00089 }; 00090 static short icoface[20][3] = { 00091 {2,0,1}, 00092 {1,0,5}, 00093 {3,0,2}, 00094 {4,0,3}, 00095 {5,0,4}, 00096 {1,5,10}, 00097 {2,1,6}, 00098 {3,2,7}, 00099 {4,3,8}, 00100 {5,4,9}, 00101 {6,1,10}, 00102 {7,2,6}, 00103 {8,3,7}, 00104 {9,4,8}, 00105 {10,5,9}, 00106 {6,10,11}, 00107 {7,6,11}, 00108 {8,7,11}, 00109 {9,8,11}, 00110 {10,9,11} 00111 }; 00112 00113 /* *************** add-click-mesh (extrude) operator ************** */ 00114 00115 static int dupli_extrude_cursor(bContext *C, wmOperator *op, wmEvent *event) 00116 { 00117 ViewContext vc; 00118 EditVert *eve; 00119 float min[3], max[3]; 00120 int done= 0; 00121 short use_proj; 00122 00123 em_setup_viewcontext(C, &vc); 00124 00125 use_proj= (vc.scene->toolsettings->snap_flag & SCE_SNAP) && (vc.scene->toolsettings->snap_mode==SCE_SNAP_MODE_FACE); 00126 00127 invert_m4_m4(vc.obedit->imat, vc.obedit->obmat); 00128 00129 INIT_MINMAX(min, max); 00130 00131 for(eve= vc.em->verts.first; eve; eve= eve->next) { 00132 if(eve->f & SELECT) { 00133 DO_MINMAX(eve->co, min, max); 00134 done= 1; 00135 } 00136 } 00137 00138 /* call extrude? */ 00139 if(done) { 00140 const short rot_src= RNA_boolean_get(op->ptr, "rotate_source"); 00141 EditEdge *eed; 00142 float vec[3], cent[3], mat[3][3]; 00143 float nor[3]= {0.0, 0.0, 0.0}; 00144 00145 /* 2D normal calc */ 00146 float mval_f[2]; 00147 00148 mval_f[0]= (float)event->mval[0]; 00149 mval_f[1]= (float)event->mval[1]; 00150 00151 done= 0; 00152 00153 /* calculate the normal for selected edges */ 00154 for(eed= vc.em->edges.first; eed; eed= eed->next) { 00155 if(eed->f & SELECT) { 00156 float co1[3], co2[3]; 00157 mul_v3_m4v3(co1, vc.obedit->obmat, eed->v1->co); 00158 mul_v3_m4v3(co2, vc.obedit->obmat, eed->v2->co); 00159 project_float_noclip(vc.ar, co1, co1); 00160 project_float_noclip(vc.ar, co2, co2); 00161 00162 /* 2D rotate by 90d while adding. 00163 * (x, y) = (y, -x) 00164 * 00165 * accumulate the screenspace normal in 2D, 00166 * with screenspace edge length weighting the result. */ 00167 if(line_point_side_v2(co1, co2, mval_f) >= 0.0f) { 00168 nor[0] += (co1[1] - co2[1]); 00169 nor[1] += -(co1[0] - co2[0]); 00170 } 00171 else { 00172 nor[0] += (co2[1] - co1[1]); 00173 nor[1] += -(co2[0] - co1[0]); 00174 } 00175 done= 1; 00176 } 00177 } 00178 00179 if(done) { 00180 float view_vec[3], cross[3]; 00181 00182 /* convert the 2D nomal into 3D */ 00183 mul_mat3_m4_v3(vc.rv3d->viewinv, nor); /* worldspace */ 00184 mul_mat3_m4_v3(vc.obedit->imat, nor); /* local space */ 00185 00186 /* correct the normal to be aligned on the view plane */ 00187 copy_v3_v3(view_vec, vc.rv3d->viewinv[2]); 00188 mul_mat3_m4_v3(vc.obedit->imat, view_vec); 00189 cross_v3_v3v3(cross, nor, view_vec); 00190 cross_v3_v3v3(nor, view_vec, cross); 00191 normalize_v3(nor); 00192 } 00193 00194 /* center */ 00195 mid_v3_v3v3(cent, min, max); 00196 copy_v3_v3(min, cent); 00197 00198 mul_m4_v3(vc.obedit->obmat, min); // view space 00199 view3d_get_view_aligned_coordinate(&vc, min, event->mval, TRUE); 00200 mul_m4_v3(vc.obedit->imat, min); // back in object space 00201 00202 sub_v3_v3(min, cent); 00203 00204 /* calculate rotation */ 00205 unit_m3(mat); 00206 if(done) { 00207 float dot; 00208 00209 copy_v3_v3(vec, min); 00210 normalize_v3(vec); 00211 dot= dot_v3v3(vec, nor); 00212 00213 if( fabs(dot)<0.999) { 00214 float cross[3], si, q1[4]; 00215 00216 cross_v3_v3v3(cross, nor, vec); 00217 normalize_v3(cross); 00218 dot= 0.5f*saacos(dot); 00219 00220 /* halve the rotation if its applied twice */ 00221 if(rot_src) dot *= 0.5f; 00222 00223 si= (float)sin(dot); 00224 q1[0]= (float)cos(dot); 00225 q1[1]= cross[0]*si; 00226 q1[2]= cross[1]*si; 00227 q1[3]= cross[2]*si; 00228 quat_to_mat3( mat,q1); 00229 } 00230 } 00231 00232 if(rot_src) { 00233 rotateflag(vc.em, SELECT, cent, mat); 00234 /* also project the source, for retopo workflow */ 00235 if(use_proj) 00236 EM_project_snap_verts(C, vc.ar, vc.obedit, vc.em); 00237 } 00238 00239 extrudeflag(vc.obedit, vc.em, SELECT, nor, 0); 00240 rotateflag(vc.em, SELECT, cent, mat); 00241 translateflag(vc.em, SELECT, min); 00242 00243 recalc_editnormals(vc.em); 00244 } 00245 else if(vc.em->selectmode & SCE_SELECT_VERTEX) { 00246 00247 float imat[4][4]; 00248 const float *curs= give_cursor(vc.scene, vc.v3d); 00249 00250 copy_v3_v3(min, curs); 00251 view3d_get_view_aligned_coordinate(&vc, min, event->mval, TRUE); 00252 00253 eve= addvertlist(vc.em, 0, NULL); 00254 00255 invert_m4_m4(imat, vc.obedit->obmat); 00256 mul_v3_m4v3(eve->co, imat, min); 00257 00258 eve->f= SELECT; 00259 } 00260 00261 if(use_proj) 00262 EM_project_snap_verts(C, vc.ar, vc.obedit, vc.em); 00263 00264 WM_event_add_notifier(C, NC_GEOM|ND_DATA, vc.obedit->data); 00265 DAG_id_tag_update(vc.obedit->data, 0); 00266 00267 return OPERATOR_FINISHED; 00268 } 00269 00270 void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot) 00271 { 00272 /* identifiers */ 00273 ot->name= "Duplicate or Extrude at 3D Cursor"; 00274 ot->description= "Duplicate and extrude selected vertices, edges or faces towards 3D Cursor"; 00275 ot->idname= "MESH_OT_dupli_extrude_cursor"; 00276 00277 /* api callbacks */ 00278 ot->invoke= dupli_extrude_cursor; 00279 ot->poll= ED_operator_editmesh; 00280 00281 /* flags */ 00282 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00283 00284 RNA_def_boolean(ot->srna, "rotate_source", 1, "Rotate Source", "Rotate initial selection giving better shape"); 00285 } 00286 00287 00288 /* ********************** */ 00289 00290 /* selected faces get hidden edges */ 00291 static int make_fgon(EditMesh *em, wmOperator *op, int make) 00292 { 00293 EditFace *efa; 00294 EditEdge *eed; 00295 EditVert *eve; 00296 float *nor=NULL; // reference 00297 int done=0; 00298 00299 if(make==0) { 00300 for(efa= em->faces.first; efa; efa= efa->next) { 00301 if(efa->f & SELECT) { 00302 efa->fgonf= 0; 00303 efa->e1->h &= ~EM_FGON; 00304 efa->e2->h &= ~EM_FGON; 00305 efa->e3->h &= ~EM_FGON; 00306 if(efa->e4) efa->e4->h &= ~EM_FGON; 00307 done= 1; 00308 } 00309 } 00310 EM_fgon_flags(em); // redo flags and indices for fgons 00311 00312 return done; 00313 } 00314 00315 /* tagging edges. rule is: 00316 - edge used by exactly 2 selected faces 00317 - no vertices allowed with only tagged edges (return) 00318 - face normals are allowed to difffer 00319 00320 */ 00321 for(eed= em->edges.first; eed; eed= eed->next) { 00322 eed->f1= 0; // amount of selected 00323 eed->f2= 0; // amount of unselected 00324 } 00325 00326 for(efa= em->faces.first; efa; efa= efa->next) { 00327 if(efa->f & SELECT) { 00328 if(nor==NULL) nor= efa->n; 00329 if(efa->e1->f1 < 3) efa->e1->f1++; 00330 if(efa->e2->f1 < 3) efa->e2->f1++; 00331 if(efa->e3->f1 < 3) efa->e3->f1++; 00332 if(efa->e4 && efa->e4->f1 < 3) efa->e4->f1++; 00333 } 00334 else { 00335 if(efa->e1->f2 < 3) efa->e1->f2++; 00336 if(efa->e2->f2 < 3) efa->e2->f2++; 00337 if(efa->e3->f2 < 3) efa->e3->f2++; 00338 if(efa->e4 && efa->e4->f2 < 3) efa->e4->f2++; 00339 } 00340 } 00341 // now eed->f1 becomes tagged edge 00342 for(eed= em->edges.first; eed; eed= eed->next) { 00343 if(eed->f1==2 && eed->f2==0) eed->f1= 1; 00344 else eed->f1= 0; 00345 } 00346 00347 // no vertices allowed with only tagged edges 00348 for(eve= em->verts.first; eve; eve= eve->next) eve->f1= 0; 00349 for(eed= em->edges.first; eed; eed= eed->next) { 00350 if(eed->f1) { 00351 eed->v1->f1 |= 1; 00352 eed->v2->f1 |= 1; 00353 } 00354 else { 00355 eed->v1->f1 |= 2; 00356 eed->v2->f1 |= 2; 00357 } 00358 } 00359 for(eve= em->verts.first; eve; eve= eve->next) { 00360 if(eve->f1==1) break; 00361 } 00362 if(eve) { 00363 BKE_report(op->reports, RPT_WARNING, "Cannot make a polygon with interior vertices"); 00364 return 0; 00365 } 00366 00367 // check for faces 00368 if(nor==NULL) { 00369 BKE_report(op->reports, RPT_WARNING, "No faces were selected to make FGon"); 00370 return 0; 00371 } 00372 00373 // and there we go 00374 for(eed= em->edges.first; eed; eed= eed->next) { 00375 if(eed->f1) { 00376 eed->h |= EM_FGON; 00377 done= 1; 00378 } 00379 } 00380 00381 if(done) 00382 EM_fgon_flags(em); // redo flags and indices for fgons 00383 return done; 00384 } 00385 00386 static int make_fgon_exec(bContext *C, wmOperator *op) 00387 { 00388 Object *obedit= CTX_data_edit_object(C); 00389 EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data)); 00390 00391 if( make_fgon(em, op, 1) ) { 00392 DAG_id_tag_update(obedit->data, 0); 00393 WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); 00394 00395 BKE_mesh_end_editmesh(obedit->data, em); 00396 return OPERATOR_FINISHED; 00397 } 00398 00399 BKE_mesh_end_editmesh(obedit->data, em); 00400 return OPERATOR_CANCELLED; 00401 } 00402 00403 void MESH_OT_fgon_make(struct wmOperatorType *ot) 00404 { 00405 /* identifiers */ 00406 ot->name= "Make F-gon"; 00407 ot->description= "Make fgon from selected faces"; 00408 ot->idname= "MESH_OT_fgon_make"; 00409 00410 /* api callbacks */ 00411 ot->exec= make_fgon_exec; 00412 ot->poll= ED_operator_editmesh; 00413 00414 /* flags */ 00415 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00416 } 00417 00418 static int clear_fgon_exec(bContext *C, wmOperator *op) 00419 { 00420 Object *obedit= CTX_data_edit_object(C); 00421 EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data)); 00422 00423 if( make_fgon(em, op, 0) ) { 00424 DAG_id_tag_update(obedit->data, 0); 00425 WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); 00426 00427 BKE_mesh_end_editmesh(obedit->data, em); 00428 return OPERATOR_FINISHED; 00429 } 00430 00431 BKE_mesh_end_editmesh(obedit->data, em); 00432 return OPERATOR_CANCELLED; 00433 } 00434 00435 void MESH_OT_fgon_clear(struct wmOperatorType *ot) 00436 { 00437 /* identifiers */ 00438 ot->name= "Clear F-gon"; 00439 ot->description= "Clear fgon from selected face"; 00440 ot->idname= "MESH_OT_fgon_clear"; 00441 00442 /* api callbacks */ 00443 ot->exec= clear_fgon_exec; 00444 ot->poll= ED_operator_editmesh; 00445 00446 /* flags */ 00447 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00448 } 00449 00450 /* precondition; 4 vertices selected, check for 4 edges and create face */ 00451 static EditFace *addface_from_edges(EditMesh *em) 00452 { 00453 EditEdge *eed, *eedar[4]={NULL, NULL, NULL, NULL}; 00454 EditVert *v1=NULL, *v2=NULL, *v3=NULL, *v4=NULL; 00455 int a; 00456 00457 /* find the 4 edges */ 00458 for(eed= em->edges.first; eed; eed= eed->next) { 00459 if( (eed->f & SELECT) || (eed->v1->f & eed->v2->f & SELECT) ) { 00460 if(eedar[0]==NULL) eedar[0]= eed; 00461 else if(eedar[1]==NULL) eedar[1]= eed; 00462 else if(eedar[2]==NULL) eedar[2]= eed; 00463 else eedar[3]= eed; 00464 00465 } 00466 } 00467 00468 00469 if(eedar[3]) { 00470 /* first 2 points */ 00471 v1= eedar[0]->v1; 00472 v2= eedar[0]->v2; 00473 00474 /* find the 2 edges connected to first edge */ 00475 for(a=1; a<4; a++) { 00476 if( eedar[a]->v1 == v2) v3= eedar[a]->v2; 00477 else if(eedar[a]->v2 == v2) v3= eedar[a]->v1; 00478 else if( eedar[a]->v1 == v1) v4= eedar[a]->v2; 00479 else if(eedar[a]->v2 == v1) v4= eedar[a]->v1; 00480 } 00481 00482 /* verify if last edge exists */ 00483 if(v3 && v4) { 00484 for(a=1; a<4; a++) { 00485 if( eedar[a]->v1==v3 && eedar[a]->v2==v4) break; 00486 if( eedar[a]->v2==v3 && eedar[a]->v1==v4) break; 00487 } 00488 if(a!=4) { 00489 return addfacelist(em, v1, v2, v3, v4, NULL, NULL); 00490 } 00491 } 00492 } 00493 return NULL; 00494 } 00495 00496 /* ******************************* */ 00497 00498 /* this also allows to prevent triangles being made in quads */ 00499 static int compareface_overlaps(EditFace *vl1, EditFace *vl2) 00500 { 00501 EditVert *v1, *v2, *v3, *v4; 00502 int equal= 0; 00503 00504 v1= vl2->v1; 00505 v2= vl2->v2; 00506 v3= vl2->v3; 00507 v4= vl2->v4; 00508 00509 if(vl1==vl2) return 0; 00510 00511 if(v4==NULL && vl1->v4==NULL) { 00512 if(vl1->v1==v1 || vl1->v2==v1 || vl1->v3==v1) equal++; 00513 if(vl1->v1==v2 || vl1->v2==v2 || vl1->v3==v2) equal++; 00514 if(vl1->v1==v3 || vl1->v2==v3 || vl1->v3==v3) equal++; 00515 } 00516 else { 00517 if(vl1->v1==v1 || vl1->v2==v1 || vl1->v3==v1 || vl1->v4==v1) equal++; 00518 if(vl1->v1==v2 || vl1->v2==v2 || vl1->v3==v2 || vl1->v4==v2) equal++; 00519 if(vl1->v1==v3 || vl1->v2==v3 || vl1->v3==v3 || vl1->v4==v3) equal++; 00520 if(vl1->v1==v4 || vl1->v2==v4 || vl1->v3==v4 || vl1->v4==v4) equal++; 00521 } 00522 00523 if(v4 && vl1->v4) { 00524 if(equal==4) return 1; 00525 } 00526 else 00527 if(equal>=3) return 1; 00528 00529 return 0; 00530 } 00531 00532 /* checks for existence, and for tria overlapping inside quad */ 00533 static EditFace *exist_face_overlaps(EditMesh *em, EditVert *v1, EditVert *v2, EditVert *v3, EditVert *v4) 00534 { 00535 EditFace *efa, efatest; 00536 00537 efatest.v1= v1; 00538 efatest.v2= v2; 00539 efatest.v3= v3; 00540 efatest.v4= v4; 00541 00542 efa= em->faces.first; 00543 while(efa) { 00544 if(compareface_overlaps(&efatest, efa)) return efa; 00545 efa= efa->next; 00546 } 00547 return NULL; 00548 } 00549 00550 /* will be new face smooth or solid? depends on smoothness of face neighbours 00551 * of new face, if function return 1, then new face will be smooth, when functio 00552 * will return zero, then new face will be solid */ 00553 static void fix_new_face(EditMesh *em, EditFace *eface) 00554 { 00555 struct EditFace *efa; 00556 struct EditEdge *eed=NULL; 00557 struct EditVert *v1 = eface->v1, *v2 = eface->v2, *v3 = eface->v3, *v4 = eface->v4; 00558 struct EditVert *ev1=NULL, *ev2=NULL; 00559 short smooth=0; /* "total smoothnes" of faces in neighbourhood */ 00560 short coef; /* "weight" of smoothness */ 00561 short count=0; /* number of edges with same direction as eface */ 00562 short vi00=0, vi01=0, vi10=0, vi11=0; /* vertex indexes */ 00563 00564 efa = em->faces.first; 00565 00566 while(efa) { 00567 00568 if(efa==eface) { 00569 efa = efa->next; 00570 continue; 00571 } 00572 00573 coef = 0; 00574 ev1 = ev2 = NULL; 00575 eed = NULL; 00576 00577 if(efa->v1==v1 || efa->v2==v1 || efa->v3==v1 || efa->v4==v1) { 00578 ev1 = v1; 00579 coef++; 00580 } 00581 if(efa->v1==v2 || efa->v2==v2 || efa->v3==v2 || efa->v4==v2) { 00582 if(ev1) ev2 = v2; 00583 else ev1 = v2; 00584 coef++; 00585 } 00586 if(efa->v1==v3 || efa->v2==v3 || efa->v3==v3 || efa->v4==v3) { 00587 if(coef<2) { 00588 if(ev1) ev2 = v3; 00589 else ev1 = v3; 00590 } 00591 coef++; 00592 } 00593 if((v4) && (efa->v1==v4 || efa->v2==v4 || efa->v3==v4 || efa->v4==v4)) { 00594 if(ev1 && coef<2) ev2 = v4; 00595 coef++; 00596 } 00597 00598 /* "democracy" of smoothness */ 00599 if(efa->flag & ME_SMOOTH) 00600 smooth += coef; 00601 else 00602 smooth -= coef; 00603 00604 /* try to find edge using vertexes ev1 and ev2 */ 00605 if((ev1) && (ev2) && (ev1!=ev2)) eed = findedgelist(em, ev1, ev2); 00606 00607 /* has bordering edge of efa same direction as edge of eface ? */ 00608 if(eed) { 00609 if(eed->v1==v1) vi00 = 1; 00610 else if(eed->v1==v2) vi00 = 2; 00611 else if(eed->v1==v3) vi00 = 3; 00612 else if(v4 && eed->v1==v4) vi00 = 4; 00613 00614 if(eed->v2==v1) vi01 = 1; 00615 else if(eed->v2==v2) vi01 = 2; 00616 else if(eed->v2==v3) vi01 = 3; 00617 else if(v4 && eed->v2==v4) vi01 = 4; 00618 00619 if(v4) { 00620 if(vi01==1 && vi00==4) vi00 = 0; 00621 if(vi01==4 && vi00==1) vi01 = 0; 00622 } 00623 else { 00624 if(vi01==1 && vi00==3) vi00 = 0; 00625 if(vi01==3 && vi00==1) vi01 = 0; 00626 } 00627 00628 if(eed->v1==efa->v1) vi10 = 1; 00629 else if(eed->v1==efa->v2) vi10 = 2; 00630 else if(eed->v1==efa->v3) vi10 = 3; 00631 else if(efa->v4 && eed->v1==efa->v4) vi10 = 4; 00632 00633 if(eed->v2==efa->v1) vi11 = 1; 00634 else if(eed->v2==efa->v2) vi11 = 2; 00635 else if(eed->v2==efa->v3) vi11 = 3; 00636 else if(efa->v4 && eed->v2==efa->v4) vi11 = 4; 00637 00638 if(efa->v4) { 00639 if(vi11==1 && vi10==4) vi10 = 0; 00640 if(vi11==4 && vi10==1) vi11 = 0; 00641 } 00642 else { 00643 if(vi11==1 && vi10==3) vi10 = 0; 00644 if(vi11==3 && vi10==1) vi11 = 0; 00645 } 00646 00647 if(((vi00>vi01) && (vi10>vi11)) || 00648 ((vi00<vi01) && (vi10<vi11))) 00649 count++; 00650 else 00651 count--; 00652 } 00653 00654 efa = efa->next; 00655 } 00656 00657 /* set up smoothness according voting of face in neighbourhood */ 00658 if(smooth >= 0) 00659 eface->flag |= ME_SMOOTH; 00660 else 00661 eface->flag &= ~ME_SMOOTH; 00662 00663 /* flip face, when too much "face normals" in neighbourhood is different */ 00664 if(count > 0) { 00665 flipface(em, eface); 00666 } 00667 } 00668 00669 /* only adds quads or trias when there's edges already */ 00670 static void addfaces_from_edgenet(EditMesh *em) 00671 { 00672 EditVert *eve1, *eve2, *eve3, *eve4; 00673 00674 for(eve1= em->verts.first; eve1; eve1= eve1->next) { 00675 for(eve2= em->verts.first; (eve1->f & 1) && eve2; eve2= eve2->next) { 00676 if(findedgelist(em, eve1,eve2)) { 00677 for(eve3= em->verts.first; (eve2->f & 1) && eve3; eve3= eve3->next) { 00678 if((eve2!=eve3 && (eve3->f & 1) && findedgelist(em, eve1,eve3))) { 00679 EditEdge *sh_edge= NULL; 00680 EditVert *sh_vert= NULL; 00681 00682 sh_edge= findedgelist(em, eve2,eve3); 00683 00684 if(sh_edge) { /* Add a triangle */ 00685 if(!exist_face_overlaps(em, eve1,eve2,eve3,NULL)) 00686 fix_new_face(em, addfacelist(em, eve1,eve2,eve3,NULL,NULL,NULL)); 00687 } 00688 else { /* Check for a shared vertex */ 00689 for(eve4= em->verts.first; eve4; eve4= eve4->next) { 00690 if(eve4!=eve1 && eve4!=eve2 && eve4!=eve3 && (eve4->f & 1) && 00691 !findedgelist(em, eve1,eve4) && findedgelist(em, eve2,eve4) && 00692 findedgelist(em, eve3,eve4)) { 00693 sh_vert= eve4; 00694 break; 00695 } 00696 } 00697 00698 if(sh_vert) { 00699 if(sh_vert) { 00700 if(!exist_face_overlaps(em, eve1,eve2,eve4,eve3)) 00701 fix_new_face(em, addfacelist(em, eve1,eve2,eve4,eve3,NULL,NULL)); 00702 } 00703 } 00704 } 00705 } 00706 } 00707 } 00708 } 00709 } 00710 00711 EM_select_flush(em); 00712 00713 // XXX DAG_id_tag_update(obedit->data, 0); 00714 } 00715 00716 static void addedgeface_mesh(EditMesh *em, wmOperator *op) 00717 { 00718 EditVert *eve, *neweve[4]; 00719 EditEdge *eed; 00720 EditFace *efa; 00721 short amount=0; 00722 00723 /* how many selected ? */ 00724 if(em->selectmode & SCE_SELECT_EDGE) { 00725 /* in edge mode finding selected vertices means flushing down edge codes... */ 00726 /* can't make face with only edge selection info... */ 00727 EM_selectmode_set(em); 00728 } 00729 00730 for(eve= em->verts.first; eve; eve= eve->next) { 00731 if(eve->f & SELECT) { 00732 amount++; 00733 if(amount>4) break; 00734 neweve[amount-1]= eve; 00735 } 00736 } 00737 00738 if(amount==2) { 00739 eed= addedgelist(em, neweve[0], neweve[1], NULL); 00740 EM_select_edge(eed, 1); 00741 00742 // XXX DAG_id_tag_update(obedit->data, 0); 00743 return; 00744 } 00745 else if(amount > 4) { 00746 addfaces_from_edgenet(em); 00747 return; 00748 } 00749 else if(amount<2) { 00750 BKE_report(op->reports, RPT_WARNING, "More vertices are needed to make an edge/face"); 00751 return; 00752 } 00753 00754 efa= NULL; // check later 00755 00756 if(amount==3) { 00757 00758 if(exist_face_overlaps(em, neweve[0], neweve[1], neweve[2], NULL)==0) { 00759 efa= addfacelist(em, neweve[0], neweve[1], neweve[2], 0, NULL, NULL); 00760 EM_select_face(efa, 1); 00761 } 00762 else BKE_report(op->reports, RPT_WARNING, "The selected vertices already form a face"); 00763 } 00764 else if(amount==4) { 00765 /* this test survives when theres 2 triangles */ 00766 if(exist_face(em, neweve[0], neweve[1], neweve[2], neweve[3])==0) { 00767 int tria= 0; 00768 00769 /* remove trias if they exist, 4 cases.... */ 00770 if(exist_face(em, neweve[0], neweve[1], neweve[2], NULL)) tria++; 00771 if(exist_face(em, neweve[0], neweve[1], neweve[3], NULL)) tria++; 00772 if(exist_face(em, neweve[0], neweve[2], neweve[3], NULL)) tria++; 00773 if(exist_face(em, neweve[1], neweve[2], neweve[3], NULL)) tria++; 00774 00775 if(tria==2) join_triangles(em); 00776 else if(exist_face_overlaps(em, neweve[0], neweve[1], neweve[2], neweve[3])==0) { 00777 /* If there are 4 Verts, But more selected edges, we need to call addfaces_from_edgenet */ 00778 EditEdge *eedcheck; 00779 int count; 00780 count = 0; 00781 for(eedcheck= em->edges.first; eedcheck; eedcheck= eedcheck->next) { 00782 if(eedcheck->f & SELECT) { 00783 count++; 00784 } 00785 } 00786 00787 if(count++ > 4){ 00788 addfaces_from_edgenet(em); 00789 return; 00790 } else { 00791 /* if 4 edges exist, we just create the face, convex or not */ 00792 efa= addface_from_edges(em); 00793 if(efa==NULL) { 00794 00795 /* the order of vertices can be anything, 6 cases to check */ 00796 if( convex(neweve[0]->co, neweve[1]->co, neweve[2]->co, neweve[3]->co) ) { 00797 efa= addfacelist(em, neweve[0], neweve[1], neweve[2], neweve[3], NULL, NULL); 00798 } 00799 else if( convex(neweve[0]->co, neweve[2]->co, neweve[3]->co, neweve[1]->co) ) { 00800 efa= addfacelist(em, neweve[0], neweve[2], neweve[3], neweve[1], NULL, NULL); 00801 } 00802 else if( convex(neweve[0]->co, neweve[2]->co, neweve[1]->co, neweve[3]->co) ) { 00803 efa= addfacelist(em, neweve[0], neweve[2], neweve[1], neweve[3], NULL, NULL); 00804 } 00805 else if( convex(neweve[0]->co, neweve[1]->co, neweve[3]->co, neweve[2]->co) ) { 00806 efa= addfacelist(em, neweve[0], neweve[1], neweve[3], neweve[2], NULL, NULL); 00807 } 00808 else if( convex(neweve[0]->co, neweve[3]->co, neweve[2]->co, neweve[1]->co) ) { 00809 efa= addfacelist(em, neweve[0], neweve[3], neweve[2], neweve[1], NULL, NULL); 00810 } 00811 else if( convex(neweve[0]->co, neweve[3]->co, neweve[1]->co, neweve[2]->co) ) { 00812 efa= addfacelist(em, neweve[0], neweve[3], neweve[1], neweve[2], NULL, NULL); 00813 } 00814 else BKE_report(op->reports, RPT_WARNING, "cannot find nice quad from concave set of vertices"); 00815 00816 } 00817 } 00818 } 00819 else BKE_report(op->reports, RPT_WARNING, "The selected vertices already form a face"); 00820 } 00821 else BKE_report(op->reports, RPT_WARNING, "The selected vertices already form a face"); 00822 } 00823 00824 if(efa) { 00825 EM_select_face(efa, 1); 00826 00827 fix_new_face(em, efa); 00828 00829 recalc_editnormals(em); 00830 } 00831 } 00832 00833 static int addedgeface_mesh_exec(bContext *C, wmOperator *op) 00834 { 00835 Object *obedit= CTX_data_edit_object(C); 00836 EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data)); 00837 00838 addedgeface_mesh(em, op); 00839 00840 DAG_id_tag_update(obedit->data, 0); 00841 WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); 00842 00843 BKE_mesh_end_editmesh(obedit->data, em); 00844 return OPERATOR_FINISHED; 00845 } 00846 00847 void MESH_OT_edge_face_add(wmOperatorType *ot) 00848 { 00849 /* identifiers */ 00850 ot->name= "Make Edge/Face"; 00851 ot->description= "Add an edge or face to selected"; 00852 ot->idname= "MESH_OT_edge_face_add"; 00853 00854 /* api callbacks */ 00855 ot->exec= addedgeface_mesh_exec; 00856 ot->poll= ED_operator_editmesh; 00857 00858 /* flags */ 00859 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 00860 00861 } 00862 00863 00864 00865 /* ************************ primitives ******************* */ 00866 00867 // HACK: these can also be found in cmoview.tga.c, but are here so that they can be found by linker 00868 // this hack is only used so that scons+mingw + split-sources hack works 00869 // ------------------------------- start copied code 00870 /* these are not the monkeys you are looking for */ 00871 static int monkeyo= 4; 00872 static int monkeynv= 271; 00873 static int monkeynf= 250; 00874 static signed char monkeyv[271][3]= { 00875 {-71,21,98},{-63,12,88},{-57,7,74},{-82,-3,79},{-82,4,92}, 00876 {-82,17,100},{-92,21,102},{-101,12,95},{-107,7,83}, 00877 {-117,31,84},{-109,31,95},{-96,31,102},{-92,42,102}, 00878 {-101,50,95},{-107,56,83},{-82,66,79},{-82,58,92}, 00879 {-82,46,100},{-71,42,98},{-63,50,88},{-57,56,74}, 00880 {-47,31,72},{-55,31,86},{-67,31,97},{-66,31,99}, 00881 {-70,43,100},{-82,48,103},{-93,43,105},{-98,31,105}, 00882 {-93,20,105},{-82,31,106},{-82,15,103},{-70,20,100}, 00883 {-127,55,95},{-127,45,105},{-127,-87,94},{-127,-41,100}, 00884 {-127,-24,102},{-127,-99,92},{-127,52,77},{-127,73,73}, 00885 {-127,115,-70},{-127,72,-109},{-127,9,-106},{-127,-49,-45}, 00886 {-101,-24,72},{-87,-56,73},{-82,-89,73},{-80,-114,68}, 00887 {-85,-121,67},{-104,-124,71},{-127,-126,74},{-71,-18,68}, 00888 {-46,-5,69},{-21,19,57},{-17,55,76},{-36,62,80}, 00889 {-64,77,88},{-86,97,94},{-107,92,97},{-119,63,96}, 00890 {-106,53,99},{-111,39,98},{-101,12,95},{-79,2,90}, 00891 {-64,8,86},{-47,24,83},{-45,38,83},{-50,48,85}, 00892 {-72,56,92},{-95,60,97},{-127,-98,94},{-113,-92,94}, 00893 {-112,-107,91},{-119,-113,89},{-127,-114,88},{-127,-25,96}, 00894 {-127,-18,95},{-114,-19,95},{-111,-29,96},{-116,-37,95}, 00895 {-76,-6,86},{-48,7,80},{-34,26,77},{-32,48,84}, 00896 {-39,53,93},{-71,70,102},{-87,82,107},{-101,79,109}, 00897 {-114,55,108},{-111,-13,104},{-100,-57,91},{-95,-90,88}, 00898 {-93,-105,85},{-97,-117,81},{-106,-119,81},{-127,-121,82}, 00899 {-127,6,93},{-127,27,98},{-85,61,95},{-106,18,96}, 00900 {-110,27,97},{-112,-88,94},{-117,-57,96},{-127,-57,96}, 00901 {-127,-42,95},{-115,-35,100},{-110,-29,102},{-113,-17,100}, 00902 {-122,-16,100},{-127,-26,106},{-121,-19,104},{-115,-20,104}, 00903 {-113,-29,106},{-117,-32,103},{-127,-37,103},{-94,-40,71}, 00904 {-106,-31,91},{-104,-40,91},{-97,-32,71},{-127,-112,88}, 00905 {-121,-111,88},{-115,-105,91},{-115,-95,93},{-127,-100,84}, 00906 {-115,-96,85},{-115,-104,82},{-121,-109,81},{-127,-110,81}, 00907 {-105,28,100},{-103,20,99},{-84,55,97},{-92,54,99}, 00908 {-73,51,99},{-55,45,89},{-52,37,88},{-53,25,87}, 00909 {-66,13,92},{-79,8,95},{-98,14,100},{-104,38,100}, 00910 {-100,48,100},{-97,46,97},{-102,38,97},{-96,16,97}, 00911 {-79,11,93},{-68,15,90},{-57,27,86},{-56,36,86}, 00912 {-59,43,87},{-74,50,96},{-91,51,98},{-84,52,96}, 00913 {-101,22,96},{-102,29,96},{-113,59,78},{-102,85,79}, 00914 {-84,88,76},{-65,71,71},{-40,58,63},{-25,52,59}, 00915 {-28,21,48},{-50,0,53},{-71,-12,60},{-127,115,37}, 00916 {-127,126,-10},{-127,-25,-86},{-127,-59,24},{-127,-125,59}, 00917 {-127,-103,44},{-127,-73,41},{-127,-62,36},{-18,30,7}, 00918 {-17,41,-6},{-28,34,-56},{-68,56,-90},{-33,-6,9}, 00919 {-51,-16,-21},{-45,-1,-55},{-84,7,-85},{-97,-45,52}, 00920 {-104,-53,33},{-90,-91,49},{-95,-64,50},{-85,-117,51}, 00921 {-109,-97,47},{-111,-69,46},{-106,-121,56},{-99,-36,55}, 00922 {-100,-29,60},{-101,-22,64},{-100,-50,21},{-89,-40,-34}, 00923 {-83,-19,-69},{-69,111,-49},{-69,119,-9},{-69,109,30}, 00924 {-68,67,55},{-34,52,43},{-46,58,36},{-45,90,7}, 00925 {-25,72,16},{-25,79,-15},{-45,96,-25},{-45,87,-57}, 00926 {-25,69,-46},{-48,42,-75},{-65,3,-70},{-22,42,-26}, 00927 {-75,-22,19},{-72,-25,-27},{-13,52,-30},{-28,-18,-16}, 00928 {6,-13,-42},{37,7,-55},{46,41,-54},{31,65,-54}, 00929 {4,61,-40},{3,53,-37},{25,56,-50},{35,37,-52}, 00930 {28,10,-52},{5,-5,-39},{-21,-9,-17},{-9,46,-28}, 00931 {-6,39,-37},{-14,-3,-27},{6,0,-47},{25,12,-57}, 00932 {31,32,-57},{23,46,-56},{4,44,-46},{-19,37,-27}, 00933 {-20,22,-35},{-30,12,-35},{-22,11,-35},{-19,2,-35}, 00934 {-23,-2,-35},{-34,0,-9},{-35,-3,-22},{-35,5,-24}, 00935 {-25,26,-27},{-13,31,-34},{-13,30,-41},{-23,-2,-41}, 00936 {-18,2,-41},{-21,10,-41},{-29,12,-41},{-19,22,-41}, 00937 {6,42,-53},{25,44,-62},{34,31,-63},{28,11,-62}, 00938 {7,0,-54},{-14,-2,-34},{-5,37,-44},{-13,14,-42}, 00939 {-7,8,-43},{1,16,-47},{-4,22,-45},{3,30,-48}, 00940 {8,24,-49},{15,27,-50},{12,35,-50},{4,56,-62}, 00941 {33,60,-70},{48,38,-64},{41,7,-68},{6,-11,-63}, 00942 {-26,-16,-42},{-17,49,-49}, 00943 }; 00944 00945 static signed char monkeyf[250][4]= { 00946 {27,4,5,26}, {25,4,5,24}, {3,6,5,4}, {1,6,5,2}, {5,6,7,4}, 00947 {3,6,7,2}, {5,8,7,6}, {3,8,7,4}, {7,8,9,6}, 00948 {5,8,9,4}, {7,10,9,8}, {5,10,9,6}, {9,10,11,8}, 00949 {7,10,11,6}, {9,12,11,10}, {7,12,11,8}, {11,6,13,12}, 00950 {5,4,13,12}, {3,-2,13,12}, {-3,-4,13,12}, {-5,-10,13,12}, 00951 {-11,-12,14,12}, {-13,-18,14,13}, {-19,4,5,13}, {10,12,4,4}, 00952 {10,11,9,9}, {8,7,9,9}, {7,5,6,6}, {6,3,4,4}, 00953 {5,1,2,2}, {4,-1,0,0}, {3,-3,-2,-2}, {22,67,68,23}, 00954 {20,65,66,21}, {18,63,64,19}, {16,61,62,17}, {14,59,60,15}, 00955 {12,19,48,57}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, 00956 {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, {18,19,48,47}, 00957 {18,19,48,47}, {18,-9,-8,47}, {18,27,45,46}, {26,55,43,44}, 00958 {24,41,42,54}, {22,39,40,23}, {20,37,38,21}, {18,35,36,19}, 00959 {16,33,34,17}, {14,31,32,15}, {12,39,30,13}, {11,48,45,38}, 00960 {8,36,-19,9}, {8,-20,44,47}, {42,45,46,43}, {18,19,40,39}, 00961 {16,17,38,37}, {14,15,36,35}, {32,44,43,33}, {12,33,32,42}, 00962 {19,44,43,42}, {40,41,42,-27}, {8,9,39,-28}, {15,43,42,16}, 00963 {13,43,42,14}, {11,43,42,12}, {9,-30,42,10}, {37,12,38,-32}, 00964 {-33,37,45,46}, {-33,40,41,39}, {38,40,41,37}, {36,40,41,35}, 00965 {34,40,41,33}, {36,39,38,37}, {35,40,39,38}, {1,2,14,21}, 00966 {1,2,40,13}, {1,2,40,39}, {1,24,12,39}, {-34,36,38,11}, 00967 {35,38,36,37}, {-37,8,35,37}, {-11,-12,-45,40}, {-11,-12,39,38}, 00968 {-11,-12,37,36}, {-11,-12,35,34}, {33,34,40,41}, {33,34,38,39}, 00969 {33,34,36,37}, {33,-52,34,35}, {33,37,36,34}, {33,35,34,34}, 00970 {8,7,37,36}, {-32,7,35,46}, {-34,-33,45,46}, {4,-33,43,34}, 00971 {-34,-33,41,42}, {-34,-33,39,40}, {-34,-33,37,38}, {-34,-33,35,36}, 00972 {-34,-33,33,34}, {-34,-33,31,32}, {-34,-4,28,30}, {-5,-34,28,27}, 00973 {-35,-44,36,27}, {26,35,36,45}, {24,25,44,45}, {25,23,44,42}, 00974 {25,24,41,40}, {25,24,39,38}, {25,24,37,36}, {25,24,35,34}, 00975 {25,24,33,32}, {25,24,31,30}, {15,24,29,38}, {25,24,27,26}, 00976 {23,12,37,26}, {11,12,35,36}, {-86,-59,36,-80}, {-60,-61,36,35}, 00977 {-62,-63,36,35}, {-64,-65,36,35}, {-66,-67,36,35}, {-68,-69,36,35}, 00978 {-70,-71,36,35}, {-72,-73,36,35}, {-74,-75,36,35}, {42,43,53,58}, 00979 {40,41,57,56}, {38,39,55,57}, {-81,-80,37,56}, {-83,-82,55,52}, 00980 {-85,-84,51,49}, {-87,-86,48,49}, {47,50,51,48}, {46,48,51,49}, 00981 {43,46,49,44}, {-92,-91,45,42}, {-23,49,50,-20}, {-94,40,48,-24}, 00982 {-96,-22,48,49}, {-97,48,21,-90}, {-100,36,50,23}, {22,49,48,-100}, 00983 {-101,47,46,22}, {21,45,35,25}, {33,34,44,41}, {13,14,28,24}, 00984 {-107,26,30,-106}, {14,46,45,15}, {14,44,43,-110}, {-111,42,23,-110}, 00985 {6,7,45,46}, {45,44,47,46}, {45,46,47,48}, {47,46,49,48}, 00986 {17,49,47,48}, {17,36,46,48}, {35,36,44,45}, {35,36,40,43}, 00987 {35,36,38,39}, {-4,-3,37,35}, {-123,34,33,1}, {-9,-8,-7,-6}, 00988 {-10,-7,32,-125}, {-127,-11,-126,-126}, {-7,-6,5,31}, {4,5,33,30}, 00989 {4,39,33,32}, {4,35,32,38}, {20,21,39,38}, {4,37,38,5}, 00990 {-11,-10,36,3}, {-11,15,14,35}, {13,16,34,34}, {-13,14,13,13}, 00991 {-3,1,30,29}, {-3,28,29,1}, {-2,31,28,-1}, {12,13,27,30}, 00992 {-2,26,12,12}, {35,29,42,36}, {34,35,36,33}, {32,35,36,31}, 00993 {30,35,36,29}, {28,35,36,27}, {26,35,36,25}, {34,39,38,35}, 00994 {32,39,38,33}, {30,39,38,31}, {28,39,38,29}, {26,39,38,27}, 00995 {25,31,32,38}, {-18,-17,45,44}, {-18,17,28,44}, {-24,-20,42,-23}, 00996 {11,35,27,14}, {25,28,39,41}, {37,41,40,38}, {34,40,36,35}, 00997 {32,40,39,33}, {30,39,31,40}, {21,29,39,22}, {-31,37,28,4}, 00998 {-32,33,35,36}, {32,33,34,34}, {18,35,36,48}, {34,25,40,35}, 00999 {24,25,38,39}, {24,25,36,37}, {24,25,34,35}, {24,25,32,33}, 01000 {24,13,41,31}, {17,11,41,35}, {15,16,34,35}, {13,14,34,35}, 01001 {11,12,34,35}, {9,10,34,35}, {7,8,34,35}, {26,25,37,36}, 01002 {35,36,37,38}, {37,36,39,38}, {37,38,39,40}, {25,31,36,39}, 01003 {18,34,35,30}, {17,22,30,33}, {19,29,21,20}, {16,26,29,17}, 01004 {24,29,28,25}, {22,31,28,23}, {20,31,30,21}, {18,31,30,19}, 01005 {16,30,17,17}, {-21,-22,35,34}, {-21,-22,33,32}, {-21,-22,31,30}, 01006 {-21,-22,29,28}, {-21,-22,27,26}, {-28,-22,25,31}, {24,28,29,30}, 01007 {23,24,26,27}, {23,24,25,25}, {-69,-35,-32,27}, {-70,26,25,-66}, 01008 {-68,-67,24,-33}, 01009 }; 01010 // ------------------------------- end copied code 01011 01012 01013 #define PRIM_PLANE 0 01014 #define PRIM_CUBE 1 01015 #define PRIM_CIRCLE 4 01016 #define PRIM_CYLINDER 5 01017 #define PRIM_CONE 7 01018 #define PRIM_GRID 10 01019 #define PRIM_UVSPHERE 11 01020 #define PRIM_ICOSPHERE 12 01021 #define PRIM_MONKEY 13 01022 01023 static void make_prim(Object *obedit, int type, float mat[4][4], int tot, int seg, 01024 int subdiv, float dia, float depth, int ext, int fill) 01025 { 01026 /* 01027 * type - for the type of shape 01028 * dia - the radius for cone,sphere cylinder etc. 01029 * depth - 01030 * ext - extrude 01031 * fill - end capping, and option to fill in circle 01032 * cent[3] - center of the data. 01033 * */ 01034 EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data)); 01035 EditVert *eve, *v1=NULL, *v2, *v3, *v4=NULL, *vtop, *vdown; 01036 float phi, phid, vec[3]; 01037 float q[4], cmat[3][3], nor[3]= {0.0, 0.0, 0.0}; 01038 short a, b; 01039 01040 EM_clear_flag_all(em, SELECT); 01041 01042 phid= 2.0f*(float)M_PI/tot; 01043 phi= .25f*(float)M_PI; 01044 01045 switch(type) { 01046 case PRIM_GRID: /* grid */ 01047 /* clear flags */ 01048 eve= em->verts.first; 01049 while(eve) { 01050 eve->f= 0; 01051 eve= eve->next; 01052 } 01053 01054 /* one segment first: the X axis */ 01055 phi = (2*dia)/(float)(tot-1); 01056 phid = (2*dia)/(float)(seg-1); 01057 for(a=tot-1;a>=0;a--) { 01058 vec[0] = (phi*a) - dia; 01059 vec[1]= - dia; 01060 vec[2]= 0.0f; 01061 eve= addvertlist(em, vec, NULL); 01062 eve->f= 1+2+4; 01063 if(a < tot -1) addedgelist(em, eve->prev, eve, NULL); 01064 } 01065 /* extrude and translate */ 01066 vec[0]= vec[2]= 0.0; 01067 vec[1]= phid; 01068 01069 for(a=0;a<seg-1;a++) { 01070 extrudeflag_vert(obedit, em, 2, nor, 0); // nor unused 01071 translateflag(em, 2, vec); 01072 } 01073 01074 /* and now do imat */ 01075 eve= em->verts.first; 01076 while(eve) { 01077 if(eve->f & SELECT) { 01078 mul_m4_v3(mat,eve->co); 01079 } 01080 eve= eve->next; 01081 } 01082 recalc_editnormals(em); 01083 break; 01084 01085 case PRIM_UVSPHERE: /* UVsphere */ 01086 01087 /* clear all flags */ 01088 eve= em->verts.first; 01089 while(eve) { 01090 eve->f= 0; 01091 eve= eve->next; 01092 } 01093 01094 /* one segment first */ 01095 phi= 0; 01096 phid/=2; 01097 for(a=0; a<=tot; a++) { 01098 vec[0]= dia*sinf(phi); 01099 vec[1]= 0.0; 01100 vec[2]= dia*cosf(phi); 01101 eve= addvertlist(em, vec, NULL); 01102 eve->f= 1+2+4; 01103 if(a==0) v1= eve; 01104 else addedgelist(em, eve, eve->prev, NULL); 01105 phi+= phid; 01106 } 01107 01108 /* extrude and rotate */ 01109 phi= M_PI/seg; 01110 q[0]= cos(phi); 01111 q[3]= sin(phi); 01112 q[1]=q[2]= 0; 01113 quat_to_mat3( cmat,q); 01114 01115 for(a=0; a<seg; a++) { 01116 extrudeflag_vert(obedit, em, 2, nor, 0); // nor unused 01117 rotateflag(em, 2, v1->co, cmat); 01118 } 01119 01120 removedoublesflag(em, 4, 0, 0.0001); 01121 01122 /* and now do imat */ 01123 eve= em->verts.first; 01124 while(eve) { 01125 if(eve->f & SELECT) { 01126 mul_m4_v3(mat,eve->co); 01127 } 01128 eve= eve->next; 01129 } 01130 recalc_editnormals(em); 01131 break; 01132 case PRIM_ICOSPHERE: /* Icosphere */ 01133 { 01134 EditVert *eva[12]; 01135 EditEdge *eed; 01136 01137 /* clear all flags */ 01138 eve= em->verts.first; 01139 while(eve) { 01140 eve->f= 0; 01141 eve= eve->next; 01142 } 01143 dia/=200; 01144 for(a=0;a<12;a++) { 01145 vec[0]= dia*icovert[a][0]; 01146 vec[1]= dia*icovert[a][1]; 01147 vec[2]= dia*icovert[a][2]; 01148 eva[a]= addvertlist(em, vec, NULL); 01149 eva[a]->f= 1+2; 01150 } 01151 for(a=0;a<20;a++) { 01152 EditFace *evtemp; 01153 v1= eva[ icoface[a][0] ]; 01154 v2= eva[ icoface[a][1] ]; 01155 v3= eva[ icoface[a][2] ]; 01156 evtemp = addfacelist(em, v1, v2, v3, 0, NULL, NULL); 01157 evtemp->e1->f = 1+2; 01158 evtemp->e2->f = 1+2; 01159 evtemp->e3->f = 1+2; 01160 } 01161 01162 dia*=200; 01163 for(a=1; a<subdiv; a++) esubdivideflag(obedit, em, 2, dia, 0, B_SPHERE,1, SUBDIV_CORNER_PATH, 0); 01164 /* and now do imat */ 01165 eve= em->verts.first; 01166 while(eve) { 01167 if(eve->f & 2) { 01168 mul_m4_v3(mat,eve->co); 01169 } 01170 eve= eve->next; 01171 } 01172 01173 // Clear the flag 2 from the edges 01174 for(eed=em->edges.first;eed;eed=eed->next){ 01175 if(eed->f & 2){ 01176 eed->f &= !2; 01177 } 01178 } 01179 } 01180 break; 01181 case PRIM_MONKEY: /* Monkey */ 01182 { 01183 //extern int monkeyo, monkeynv, monkeynf; 01184 //extern signed char monkeyf[][4]; 01185 //extern signed char monkeyv[][3]; 01186 EditVert **tv= MEM_mallocN(sizeof(*tv)*monkeynv*2, "tv"); 01187 int i; 01188 01189 for (i=0; i<monkeynv; i++) { 01190 float v[3]; 01191 v[0]= (monkeyv[i][0]+127)/128.0, v[1]= monkeyv[i][1]/128.0, v[2]= monkeyv[i][2]/128.0; 01192 tv[i]= addvertlist(em, v, NULL); 01193 tv[i]->f |= SELECT; 01194 tv[monkeynv+i]= (fabs(v[0]= -v[0])<0.001)?tv[i]:addvertlist(em, v, NULL); 01195 tv[monkeynv+i]->f |= SELECT; 01196 } 01197 for (i=0; i<monkeynf; i++) { 01198 addfacelist(em, tv[monkeyf[i][0]+i-monkeyo], tv[monkeyf[i][1]+i-monkeyo], tv[monkeyf[i][2]+i-monkeyo], (monkeyf[i][3]!=monkeyf[i][2])?tv[monkeyf[i][3]+i-monkeyo]:NULL, NULL, NULL); 01199 addfacelist(em, tv[monkeynv+monkeyf[i][2]+i-monkeyo], tv[monkeynv+monkeyf[i][1]+i-monkeyo], tv[monkeynv+monkeyf[i][0]+i-monkeyo], (monkeyf[i][3]!=monkeyf[i][2])?tv[monkeynv+monkeyf[i][3]+i-monkeyo]:NULL, NULL, NULL); 01200 } 01201 01202 MEM_freeN(tv); 01203 01204 /* and now do imat */ 01205 for(eve= em->verts.first; eve; eve= eve->next) { 01206 if(eve->f & SELECT) { 01207 mul_m4_v3(mat,eve->co); 01208 } 01209 } 01210 recalc_editnormals(em); 01211 } 01212 break; 01213 default: /* all types except grid, sphere... */ 01214 if(type==PRIM_CONE); 01215 else if(ext==0) 01216 depth= 0.0f; 01217 01218 /* first vertex at 0° for circular objects */ 01219 if( ELEM3(type, PRIM_CIRCLE,PRIM_CYLINDER,PRIM_CONE) ) 01220 phi = 0.0f; 01221 01222 vtop= vdown= v1= v2= 0; 01223 for(b=0; b<=ext; b++) { 01224 for(a=0; a<tot; a++) { 01225 01226 vec[0]= dia*sinf(phi); 01227 vec[1]= dia*cosf(phi); 01228 vec[2]= b?depth:-depth; 01229 01230 mul_m4_v3(mat, vec); 01231 eve= addvertlist(em, vec, NULL); 01232 eve->f= SELECT; 01233 if(a==0) { 01234 if(b==0) v1= eve; 01235 else v2= eve; 01236 } 01237 phi+=phid; 01238 } 01239 } 01240 01241 /* center vertices */ 01242 /* type PRIM_CONE can only have 1 one side filled 01243 * if the cone has no capping, dont add vtop */ 01244 if(type == PRIM_CONE || (fill && !ELEM(type, PRIM_PLANE, PRIM_CUBE))) { 01245 vec[0]= vec[1]= 0.0f; 01246 vec[2]= type==PRIM_CONE ? depth : -depth; 01247 mul_m4_v3(mat, vec); 01248 vdown= addvertlist(em, vec, NULL); 01249 if((ext || type==PRIM_CONE) && fill) { 01250 vec[0]= vec[1]= 0.0f; 01251 vec[2]= type==PRIM_CONE ? -depth : depth; 01252 mul_m4_v3(mat,vec); 01253 vtop= addvertlist(em, vec, NULL); 01254 } 01255 } else { 01256 vdown= v1; 01257 vtop= v2; 01258 } 01259 if(vtop) vtop->f= SELECT; 01260 if(vdown) vdown->f= SELECT; 01261 01262 /* top and bottom face */ 01263 if(fill || type==PRIM_CONE) { 01264 if(tot==4 && ELEM(type, PRIM_PLANE, PRIM_CUBE)) { 01265 v3= v1->next->next; 01266 if(ext) v4= v2->next->next; 01267 01268 addfacelist(em, v3, v1->next, v1, v3->next, NULL, NULL); 01269 if(ext) addfacelist(em, v2, v2->next, v4, v4->next, NULL, NULL); 01270 01271 } 01272 else { 01273 v3= v1; 01274 v4= v2; 01275 for(a=1; a<tot; a++) { 01276 addfacelist(em, vdown, v3, v3->next, 0, NULL, NULL); 01277 v3= v3->next; 01278 if(ext && fill) { 01279 addfacelist(em, vtop, v4, v4->next, 0, NULL, NULL); 01280 v4= v4->next; 01281 } 01282 } 01283 if(!ELEM(type, PRIM_PLANE, PRIM_CUBE)) { 01284 addfacelist(em, vdown, v3, v1, 0, NULL, NULL); 01285 if(ext) addfacelist(em, vtop, v4, v2, 0, NULL, NULL); 01286 } 01287 } 01288 } 01289 else if(type==PRIM_CIRCLE) { /* we need edges for a circle */ 01290 v3= v1; 01291 for(a=1;a<tot;a++) { 01292 addedgelist(em, v3, v3->next, NULL); 01293 v3= v3->next; 01294 } 01295 addedgelist(em, v3, v1, NULL); 01296 } 01297 /* side faces */ 01298 if(ext) { 01299 v3= v1; 01300 v4= v2; 01301 for(a=1; a<tot; a++) { 01302 addfacelist(em, v3, v3->next, v4->next, v4, NULL, NULL); 01303 v3= v3->next; 01304 v4= v4->next; 01305 } 01306 addfacelist(em, v3, v1, v2, v4, NULL, NULL); 01307 } 01308 else if(fill && type==PRIM_CONE) { 01309 /* add the bottom flat area of the cone 01310 * if capping is disabled dont bother */ 01311 v3= v1; 01312 for(a=1; a<tot; a++) { 01313 addfacelist(em, vtop, v3->next, v3, 0, NULL, NULL); 01314 v3= v3->next; 01315 } 01316 addfacelist(em, vtop, v1, v3, 0, NULL, NULL); 01317 } 01318 } 01319 01320 EM_stats_update(em); 01321 /* simple selection flush OK, based on fact it's a single model */ 01322 EM_select_flush(em); /* flushes vertex -> edge -> face selection */ 01323 01324 if(!ELEM5(type, PRIM_GRID, PRIM_PLANE, PRIM_ICOSPHERE, PRIM_UVSPHERE, PRIM_MONKEY)) 01325 EM_recalc_normal_direction(em, FALSE, TRUE); /* otherwise monkey has eyes in wrong direction */ 01326 01327 BKE_mesh_end_editmesh(obedit->data, em); 01328 } 01329 01330 /* ********* add primitive operators ************* */ 01331 01332 static const char *get_mesh_defname(int type) 01333 { 01334 switch (type) { 01335 case PRIM_PLANE: return "Plane"; 01336 case PRIM_CUBE: return "Cube"; 01337 case PRIM_CIRCLE: return "Circle"; 01338 case PRIM_CYLINDER: return "Cylinder"; 01339 case PRIM_CONE: return "Cone"; 01340 case PRIM_GRID: return "Grid"; 01341 case PRIM_UVSPHERE: return "Sphere"; 01342 case PRIM_ICOSPHERE: return "Icosphere"; 01343 case PRIM_MONKEY: return "Monkey"; 01344 default: 01345 return "Mesh"; 01346 } 01347 } 01348 01349 static void make_prim_ext(bContext *C, float *loc, float *rot, int enter_editmode, unsigned int layer, 01350 int type, int tot, int seg, 01351 int subdiv, float dia, float depth, int ext, int fill) 01352 { 01353 Object *obedit= CTX_data_edit_object(C); 01354 int newob = 0; 01355 float mat[4][4]; 01356 float scale; 01357 01358 if(obedit==NULL || obedit->type!=OB_MESH) { 01359 obedit= ED_object_add_type(C, OB_MESH, loc, rot, FALSE, layer); 01360 01361 rename_id((ID *)obedit, get_mesh_defname(type)); 01362 rename_id((ID *)obedit->data, get_mesh_defname(type)); 01363 01364 /* create editmode */ 01365 ED_object_enter_editmode(C, EM_DO_UNDO|EM_IGNORE_LAYER); /* rare cases the active layer is messed up */ 01366 newob = 1; 01367 } 01368 else DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); 01369 01370 scale= ED_object_new_primitive_matrix(C, obedit, loc, rot, mat); 01371 01372 dia *= scale; 01373 depth *= scale * 0.5f; 01374 01375 make_prim(obedit, type, mat, tot, seg, subdiv, dia, depth, ext, fill); 01376 01377 DAG_id_tag_update(obedit->data, 0); 01378 WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); 01379 01380 01381 /* userdef */ 01382 if (newob && !enter_editmode) { 01383 ED_object_exit_editmode(C, EM_FREEDATA); /* adding EM_DO_UNDO messes up operator redo */ 01384 } 01385 WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); 01386 } 01387 01388 static int add_primitive_plane_exec(bContext *C, wmOperator *op) 01389 { 01390 int enter_editmode; 01391 unsigned int layer; 01392 float loc[3], rot[3]; 01393 01394 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01395 return OPERATOR_CANCELLED; 01396 01397 /* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */ 01398 make_prim_ext(C, loc, rot, enter_editmode, layer, 01399 PRIM_PLANE, 4, 0, 0, sqrt(2.0f), 0.0f, 0, 1); 01400 return OPERATOR_FINISHED; 01401 } 01402 01403 void MESH_OT_primitive_plane_add(wmOperatorType *ot) 01404 { 01405 /* identifiers */ 01406 ot->name= "Add Plane"; 01407 ot->description= "Construct a filled planar mesh with 4 vertices"; 01408 ot->idname= "MESH_OT_primitive_plane_add"; 01409 01410 /* api callbacks */ 01411 ot->invoke= ED_object_add_generic_invoke; 01412 ot->exec= add_primitive_plane_exec; 01413 ot->poll= ED_operator_scene_editable; 01414 01415 /* flags */ 01416 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01417 01418 ED_object_add_generic_props(ot, TRUE); 01419 } 01420 01421 static int add_primitive_cube_exec(bContext *C, wmOperator *op) 01422 { 01423 int enter_editmode; 01424 unsigned int layer; 01425 float loc[3], rot[3]; 01426 01427 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01428 return OPERATOR_CANCELLED; 01429 01430 /* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */ 01431 make_prim_ext(C, loc, rot, enter_editmode, layer, 01432 PRIM_CUBE, 4, 0, 0, sqrt(2.0f), 2.0f, 1, 1); 01433 return OPERATOR_FINISHED; 01434 } 01435 01436 void MESH_OT_primitive_cube_add(wmOperatorType *ot) 01437 { 01438 /* identifiers */ 01439 ot->name= "Add Cube"; 01440 ot->description= "Construct a cube mesh"; 01441 ot->idname= "MESH_OT_primitive_cube_add"; 01442 01443 /* api callbacks */ 01444 ot->invoke= ED_object_add_generic_invoke; 01445 ot->exec= add_primitive_cube_exec; 01446 ot->poll= ED_operator_scene_editable; 01447 01448 /* flags */ 01449 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01450 01451 ED_object_add_generic_props(ot, TRUE); 01452 } 01453 01454 static int add_primitive_circle_exec(bContext *C, wmOperator *op) 01455 { 01456 int enter_editmode; 01457 unsigned int layer; 01458 float loc[3], rot[3]; 01459 01460 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01461 return OPERATOR_CANCELLED; 01462 01463 make_prim_ext(C, loc, rot, enter_editmode, layer, 01464 PRIM_CIRCLE, RNA_int_get(op->ptr, "vertices"), 0, 0, 01465 RNA_float_get(op->ptr,"radius"), 0.0f, 0, 01466 RNA_boolean_get(op->ptr, "fill")); 01467 01468 return OPERATOR_FINISHED; 01469 } 01470 01471 void MESH_OT_primitive_circle_add(wmOperatorType *ot) 01472 { 01473 PropertyRNA *prop; 01474 01475 /* identifiers */ 01476 ot->name= "Add Circle"; 01477 ot->description= "Construct a circle mesh"; 01478 ot->idname= "MESH_OT_primitive_circle_add"; 01479 01480 /* api callbacks */ 01481 ot->invoke= ED_object_add_generic_invoke; 01482 ot->exec= add_primitive_circle_exec; 01483 ot->poll= ED_operator_scene_editable; 01484 01485 /* flags */ 01486 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01487 01488 /* props */ 01489 RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); 01490 prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); 01491 RNA_def_property_subtype(prop, PROP_DISTANCE); 01492 RNA_def_boolean(ot->srna, "fill", 0, "Fill", ""); 01493 01494 ED_object_add_generic_props(ot, TRUE); 01495 } 01496 01497 static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) 01498 { 01499 int enter_editmode; 01500 unsigned int layer; 01501 float loc[3], rot[3]; 01502 01503 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01504 return OPERATOR_CANCELLED; 01505 01506 make_prim_ext(C, loc, rot, enter_editmode, layer, 01507 PRIM_CYLINDER, RNA_int_get(op->ptr, "vertices"), 0, 0, 01508 RNA_float_get(op->ptr,"radius"), 01509 RNA_float_get(op->ptr, "depth"), 1, 01510 RNA_boolean_get(op->ptr, "cap_ends")); 01511 01512 return OPERATOR_FINISHED; 01513 } 01514 01515 void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) 01516 { 01517 PropertyRNA *prop; 01518 01519 /* identifiers */ 01520 ot->name= "Add Cylinder"; 01521 ot->description= "Construct a cylinder mesh"; 01522 ot->idname= "MESH_OT_primitive_cylinder_add"; 01523 01524 /* api callbacks */ 01525 ot->invoke= ED_object_add_generic_invoke; 01526 ot->exec= add_primitive_cylinder_exec; 01527 ot->poll= ED_operator_scene_editable; 01528 01529 /* flags */ 01530 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01531 01532 /* props */ 01533 RNA_def_int(ot->srna, "vertices", 32, 2, INT_MAX, "Vertices", "", 2, 500); 01534 prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); 01535 RNA_def_property_subtype(prop, PROP_DISTANCE); 01536 prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); 01537 RNA_def_property_subtype(prop, PROP_DISTANCE); 01538 RNA_def_boolean(ot->srna, "cap_ends", 1, "Cap Ends", ""); 01539 01540 ED_object_add_generic_props(ot, TRUE); 01541 } 01542 01543 static int add_primitive_cone_exec(bContext *C, wmOperator *op) 01544 { 01545 int enter_editmode; 01546 unsigned int layer; 01547 float loc[3], rot[3]; 01548 01549 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01550 return OPERATOR_CANCELLED; 01551 01552 make_prim_ext(C, loc, rot, enter_editmode, layer, 01553 PRIM_CONE, RNA_int_get(op->ptr, "vertices"), 0, 0, 01554 RNA_float_get(op->ptr,"radius"), RNA_float_get(op->ptr, "depth"), 01555 0, RNA_boolean_get(op->ptr, "cap_end")); 01556 01557 return OPERATOR_FINISHED; 01558 } 01559 01560 void MESH_OT_primitive_cone_add(wmOperatorType *ot) 01561 { 01562 PropertyRNA *prop; 01563 01564 /* identifiers */ 01565 ot->name= "Add Cone"; 01566 ot->description= "Construct a conic mesh (ends filled)"; 01567 ot->idname= "MESH_OT_primitive_cone_add"; 01568 01569 /* api callbacks */ 01570 ot->invoke= ED_object_add_generic_invoke; 01571 ot->exec= add_primitive_cone_exec; 01572 ot->poll= ED_operator_scene_editable; 01573 01574 /* flags */ 01575 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01576 01577 /* props */ 01578 RNA_def_int(ot->srna, "vertices", 32, 2, INT_MAX, "Vertices", "", 2, 500); 01579 prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); 01580 RNA_def_property_subtype(prop, PROP_DISTANCE); 01581 prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); 01582 RNA_def_property_subtype(prop, PROP_DISTANCE); 01583 RNA_def_boolean(ot->srna, "cap_end", 1, "Cap End", ""); 01584 01585 ED_object_add_generic_props(ot, TRUE); 01586 } 01587 01588 static int add_primitive_grid_exec(bContext *C, wmOperator *op) 01589 { 01590 int enter_editmode; 01591 unsigned int layer; 01592 float loc[3], rot[3]; 01593 01594 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01595 return OPERATOR_CANCELLED; 01596 01597 make_prim_ext(C, loc, rot, enter_editmode, layer, 01598 PRIM_GRID, RNA_int_get(op->ptr, "x_subdivisions"), 01599 RNA_int_get(op->ptr, "y_subdivisions"), 0, 01600 RNA_float_get(op->ptr,"size"), 0.0f, 0, 1); 01601 01602 return OPERATOR_FINISHED; 01603 } 01604 01605 void MESH_OT_primitive_grid_add(wmOperatorType *ot) 01606 { 01607 PropertyRNA *prop; 01608 01609 /* identifiers */ 01610 ot->name= "Add Grid"; 01611 ot->description= "Construct a grid mesh"; 01612 ot->idname= "MESH_OT_primitive_grid_add"; 01613 01614 /* api callbacks */ 01615 ot->invoke= ED_object_add_generic_invoke; 01616 ot->exec= add_primitive_grid_exec; 01617 ot->poll= ED_operator_scene_editable; 01618 01619 /* flags */ 01620 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01621 01622 /* props */ 01623 RNA_def_int(ot->srna, "x_subdivisions", 10, 3, INT_MAX, "X Subdivisions", "", 3, 1000); 01624 RNA_def_int(ot->srna, "y_subdivisions", 10, 3, INT_MAX, "Y Subdivisions", "", 3, 1000); 01625 prop = RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, FLT_MAX); 01626 RNA_def_property_subtype(prop, PROP_DISTANCE); 01627 01628 ED_object_add_generic_props(ot, TRUE); 01629 } 01630 01631 static int add_primitive_monkey_exec(bContext *C, wmOperator *op) 01632 { 01633 int enter_editmode; 01634 unsigned int layer; 01635 float loc[3], rot[3]; 01636 01637 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01638 return OPERATOR_CANCELLED; 01639 01640 make_prim_ext(C, loc, rot, enter_editmode, layer, 01641 PRIM_MONKEY, 0, 0, 2, 0.0f, 0.0f, 0, 0); 01642 01643 return OPERATOR_FINISHED; 01644 } 01645 01646 void MESH_OT_primitive_monkey_add(wmOperatorType *ot) 01647 { 01648 /* identifiers */ 01649 ot->name= "Add Monkey"; 01650 ot->description= "Construct a Suzanne mesh"; 01651 ot->idname= "MESH_OT_primitive_monkey_add"; 01652 01653 /* api callbacks */ 01654 ot->invoke= ED_object_add_generic_invoke; 01655 ot->exec= add_primitive_monkey_exec; 01656 ot->poll= ED_operator_scene_editable; 01657 01658 /* flags */ 01659 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01660 01661 ED_object_add_generic_props(ot, TRUE); 01662 } 01663 01664 static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op) 01665 { 01666 int enter_editmode; 01667 unsigned int layer; 01668 float loc[3], rot[3]; 01669 01670 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01671 return OPERATOR_CANCELLED; 01672 01673 make_prim_ext(C, loc, rot, enter_editmode, layer, 01674 PRIM_UVSPHERE, RNA_int_get(op->ptr, "ring_count"), 01675 RNA_int_get(op->ptr, "segments"), 0, 01676 RNA_float_get(op->ptr,"size"), 0.0f, 0, 0); 01677 01678 return OPERATOR_FINISHED; 01679 } 01680 01681 void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) 01682 { 01683 PropertyRNA *prop; 01684 01685 /* identifiers */ 01686 ot->name= "Add UV Sphere"; 01687 ot->description= "Construct a UV sphere mesh"; 01688 ot->idname= "MESH_OT_primitive_uv_sphere_add"; 01689 01690 /* api callbacks */ 01691 ot->invoke= ED_object_add_generic_invoke; 01692 ot->exec= add_primitive_uvsphere_exec; 01693 ot->poll= ED_operator_scene_editable; 01694 01695 /* flags */ 01696 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01697 01698 /* props */ 01699 RNA_def_int(ot->srna, "segments", 32, 3, INT_MAX, "Segments", "", 3, 500); 01700 RNA_def_int(ot->srna, "ring_count", 16, 3, INT_MAX, "Rings", "", 3, 500); 01701 prop = RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, 100.00); 01702 RNA_def_property_subtype(prop, PROP_DISTANCE); 01703 01704 ED_object_add_generic_props(ot, TRUE); 01705 } 01706 01707 static int add_primitive_icosphere_exec(bContext *C, wmOperator *op) 01708 { 01709 int enter_editmode; 01710 unsigned int layer; 01711 float loc[3], rot[3]; 01712 01713 if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) 01714 return OPERATOR_CANCELLED; 01715 01716 make_prim_ext(C, loc, rot, enter_editmode, layer, 01717 PRIM_ICOSPHERE, 0, 0, RNA_int_get(op->ptr, "subdivisions"), 01718 RNA_float_get(op->ptr,"size"), 0.0f, 0, 0); 01719 01720 return OPERATOR_FINISHED; 01721 } 01722 01723 void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot) 01724 { 01725 PropertyRNA *prop; 01726 01727 /* identifiers */ 01728 ot->name= "Add Ico Sphere"; 01729 ot->description= "Construct an Icosphere mesh"; 01730 ot->idname= "MESH_OT_primitive_ico_sphere_add"; 01731 01732 /* api callbacks */ 01733 ot->invoke= ED_object_add_generic_invoke; 01734 ot->exec= add_primitive_icosphere_exec; 01735 ot->poll= ED_operator_scene_editable; 01736 01737 /* flags */ 01738 ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; 01739 01740 /* props */ 01741 RNA_def_int(ot->srna, "subdivisions", 2, 1, INT_MAX, "Subdivisions", "", 1, 8); 01742 prop = RNA_def_float(ot->srna, "size", 1.0f, 0.0f, FLT_MAX, "Size", "", 0.001f, 100.00); 01743 RNA_def_property_subtype(prop, PROP_DISTANCE); 01744 01745 ED_object_add_generic_props(ot, TRUE); 01746 } 01747 01748 /****************** add duplicate operator ***************/ 01749 01750 static int mesh_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) 01751 { 01752 Object *ob= CTX_data_edit_object(C); 01753 EditMesh *em= BKE_mesh_get_editmesh(ob->data); 01754 01755 adduplicateflag(em, SELECT); 01756 01757 BKE_mesh_end_editmesh(ob->data, em); 01758 01759 DAG_id_tag_update(ob->data, 0); 01760 WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); 01761 01762 return OPERATOR_FINISHED; 01763 } 01764 01765 static int mesh_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) 01766 { 01767 WM_cursor_wait(1); 01768 mesh_duplicate_exec(C, op); 01769 WM_cursor_wait(0); 01770 01771 return OPERATOR_FINISHED; 01772 } 01773 01774 void MESH_OT_duplicate(wmOperatorType *ot) 01775 { 01776 /* identifiers */ 01777 ot->name= "Duplicate Mesh"; 01778 ot->description= "Duplicate selected vertices, edges or faces"; 01779 ot->idname= "MESH_OT_duplicate"; 01780 01781 /* api callbacks */ 01782 ot->invoke= mesh_duplicate_invoke; 01783 ot->exec= mesh_duplicate_exec; 01784 01785 ot->poll= ED_operator_editmesh; 01786 01787 /* to give to transform */ 01788 RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", ""); 01789 } 01790