Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}