/* ***************** add primitives *************** */ static int object_metaball_add_exec(bContext *C, wmOperator *op) { Object *obedit= CTX_data_edit_object(C); /*MetaElem *elem;*/ /*UNUSED*/ int newob= 0; int enter_editmode; unsigned int layer; float loc[3], rot[3]; float mat[4][4]; object_add_generic_invoke_options(C, op); // XXX these props don't get set right when only exec() is called if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) return OPERATOR_CANCELLED; if(obedit==NULL || obedit->type!=OB_MBALL) { obedit= ED_object_add_type(C, OB_MBALL, loc, rot, TRUE, layer); newob = 1; } else DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); ED_object_new_primitive_matrix(C, obedit, loc, rot, mat); /* elem= (MetaElem *) */ add_metaball_primitive(C, mat, RNA_enum_get(op->ptr, "type"), newob); /* userdef */ if (newob && !enter_editmode) { ED_object_exit_editmode(C, EM_FREEDATA); } WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); return OPERATOR_FINISHED; }
/* for effector add primitive operators */ static Object *effector_add_type(bContext *C, wmOperator *op, int type) { Object *ob; int enter_editmode; unsigned int layer; float loc[3], rot[3]; float mat[4][4]; object_add_generic_invoke_options(C, op); if(!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer)) return NULL; if(type==PFIELD_GUIDE) { ob= ED_object_add_type(C, OB_CURVE, loc, rot, FALSE, layer); rename_id(&ob->id, "CurveGuide"); ((Curve*)ob->data)->flag |= CU_PATH|CU_3D; ED_object_enter_editmode(C, 0); ED_object_new_primitive_matrix(C, ob, loc, rot, mat); BLI_addtail(curve_get_editcurve(ob), add_nurbs_primitive(C, mat, CU_NURBS|CU_PRIM_PATH, 1)); if(!enter_editmode) ED_object_exit_editmode(C, EM_FREEDATA); } else { ob= ED_object_add_type(C, OB_EMPTY, loc, rot, FALSE, layer); rename_id(&ob->id, "Field"); switch(type) { case PFIELD_WIND: case PFIELD_VORTEX: ob->empty_drawtype = OB_SINGLE_ARROW; break; } } ob->pd= object_add_collision_fields(type); DAG_scene_sort(CTX_data_main(C), CTX_data_scene(C)); return ob; }
static Object *make_prim_init(bContext *C, const char *idname, float *dia, float mat[4][4], bool *was_editmode, const float loc[3], const float rot[3], const unsigned int layer) { Object *obedit = CTX_data_edit_object(C); *was_editmode = false; if (obedit == NULL || obedit->type != OB_MESH) { obedit = ED_object_add_type(C, OB_MESH, loc, rot, false, layer); rename_id((ID *)obedit, idname); rename_id((ID *)obedit->data, idname); /* create editmode */ ED_object_editmode_enter(C, EM_DO_UNDO | EM_IGNORE_LAYER); /* rare cases the active layer is messed up */ *was_editmode = true; } *dia = ED_object_new_primitive_matrix(C, obedit, loc, rot, mat, false); return obedit; }
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) { 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_tag_update(&obedit->id, OB_RECALC_DATA); scale= ED_object_new_primitive_matrix(C, obedit, loc, rot, mat); dia *= scale; depth *= scale * 0.5f; make_prim(obedit, type, mat, tot, seg, subdiv, dia, depth, ext, fill); DAG_id_tag_update(obedit->data, 0); WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); /* userdef */ if (newob && !enter_editmode) { ED_object_exit_editmode(C, EM_FREEDATA); /* adding EM_DO_UNDO messes up operator redo */ } WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit); }
static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf) { Object *obedit = CTX_data_edit_object(C); ListBase *editnurb; Nurb *nu; bool newob = false; bool enter_editmode; unsigned int layer; float dia; float loc[3], rot[3]; float mat[4][4]; WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL)) return OPERATOR_CANCELLED; if (!isSurf) { /* adding curve */ if (obedit == NULL || obedit->type != OB_CURVE) { const char *name = get_curve_defname(type); Curve *cu; obedit = ED_object_add_type(C, OB_CURVE, name, loc, rot, true, layer); newob = true; cu = (Curve *)obedit->data; cu->flag |= CU_DEFORM_FILL; if (type & CU_PRIM_PATH) cu->flag |= CU_PATH | CU_3D; } else { DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); } } else { /* adding surface */ if (obedit == NULL || obedit->type != OB_SURF) { const char *name = get_surf_defname(type); obedit = ED_object_add_type(C, OB_SURF, name, loc, rot, true, layer); newob = true; } else { DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); } } ED_object_new_primitive_matrix(C, obedit, loc, rot, mat); dia = RNA_float_get(op->ptr, "radius"); mul_mat3_m4_fl(mat, dia); nu = ED_curve_add_nurbs_primitive(C, obedit, mat, type, newob); editnurb = object_editcurve_get(obedit); BLI_addtail(editnurb, nu); /* userdef */ if (newob && !enter_editmode) { ED_object_editmode_exit(C, EM_FREEDATA); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); return OPERATOR_FINISHED; }
static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf) { Object *obedit = CTX_data_edit_object(C); ListBase *editnurb; Nurb *nu; bool newob = false; bool enter_editmode, is_view_aligned; unsigned int layer; float dia; float loc[3], rot[3]; float mat[4][4]; WM_operator_view3d_unit_defaults(C, op); if (!ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, &is_view_aligned)) return OPERATOR_CANCELLED; if (!isSurf) { /* adding curve */ if (obedit == NULL || obedit->type != OB_CURVE) { Curve *cu; obedit = ED_object_add_type(C, OB_CURVE, loc, rot, true, layer); newob = true; cu = (Curve *)obedit->data; cu->flag |= CU_DEFORM_FILL; if (type & CU_PRIM_PATH) cu->flag |= CU_PATH | CU_3D; } else { DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); } } else { /* adding surface */ if (obedit == NULL || obedit->type != OB_SURF) { obedit = ED_object_add_type(C, OB_SURF, loc, rot, true, layer); newob = true; } else { DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); } } /* rename here, the undo stack checks name for valid undo pushes */ if (newob) { if (obedit->type == OB_CURVE) { rename_id((ID *)obedit, get_curve_defname(type)); rename_id((ID *)obedit->data, get_curve_defname(type)); } else { rename_id((ID *)obedit, get_surf_defname(type)); rename_id((ID *)obedit->data, get_surf_defname(type)); } } /* ED_object_add_type doesnt do an undo, is needed for redo operator on primitive */ if (newob && enter_editmode) ED_undo_push(C, "Enter Editmode"); ED_object_new_primitive_matrix(C, obedit, loc, rot, mat, false); dia = RNA_float_get(op->ptr, "radius"); mat[0][0] *= dia; mat[1][1] *= dia; mat[2][2] *= dia; nu = add_nurbs_primitive(C, obedit, mat, type, newob); editnurb = object_editcurve_get(obedit); BLI_addtail(editnurb, nu); /* userdef */ if (newob && !enter_editmode) { ED_object_editmode_exit(C, EM_FREEDATA); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); return OPERATOR_FINISHED; }