Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Show First 20 Lines • Show All 326 Lines • ▼ Show 20 Lines | if (rot) { | ||||
| copy_v3_v3(object->rot, rot); | copy_v3_v3(object->rot, rot); | ||||
| } | } | ||||
| BKE_object_to_mat4(object, object->obmat); | BKE_object_to_mat4(object, object->obmat); | ||||
| } | } | ||||
| /* Uses context to figure out transform for primitive. | /* Uses context to figure out transform for primitive. | ||||
| * Returns standard diameter. */ | * Returns standard diameter. */ | ||||
| float ED_object_new_primitive_matrix( | float ED_object_new_primitive_matrix(bContext *C, | ||||
| bContext *C, Object *obedit, const float loc[3], const float rot[3], float r_primmat[4][4]) | Object *obedit, | ||||
| const float loc[3], | |||||
| const float rot[3], | |||||
| const float scale[3], | |||||
| float r_primmat[4][4]) | |||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3]; | float mat[3][3], rmat[3][3], cmat[3][3], imat[3][3]; | ||||
| unit_m4(r_primmat); | unit_m4(r_primmat); | ||||
| eul_to_mat3(rmat, rot); | eul_to_mat3(rmat, rot); | ||||
| invert_m3(rmat); | invert_m3(rmat); | ||||
| /* inverse transform for initial rotation and object */ | /* inverse transform for initial rotation and object */ | ||||
| copy_m3_m4(mat, obedit->obmat); | copy_m3_m4(mat, obedit->obmat); | ||||
| mul_m3_m3m3(cmat, rmat, mat); | mul_m3_m3m3(cmat, rmat, mat); | ||||
| invert_m3_m3(imat, cmat); | invert_m3_m3(imat, cmat); | ||||
| copy_m4_m3(r_primmat, imat); | copy_m4_m3(r_primmat, imat); | ||||
| /* center */ | /* center */ | ||||
| copy_v3_v3(r_primmat[3], loc); | copy_v3_v3(r_primmat[3], loc); | ||||
| sub_v3_v3v3(r_primmat[3], r_primmat[3], obedit->obmat[3]); | sub_v3_v3v3(r_primmat[3], r_primmat[3], obedit->obmat[3]); | ||||
| invert_m3_m3(imat, mat); | invert_m3_m3(imat, mat); | ||||
| mul_m3_v3(imat, r_primmat[3]); | mul_m3_v3(imat, r_primmat[3]); | ||||
| if (scale != NULL) { | |||||
| rescale_m4(r_primmat, scale); | |||||
| } | |||||
| { | { | ||||
| const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) : | const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, NULL) : | ||||
| ED_scene_grid_scale(scene, NULL); | ED_scene_grid_scale(scene, NULL); | ||||
| return dia; | return dia; | ||||
| } | } | ||||
| /* return 1.0f; */ | /* return 1.0f; */ | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | prop = RNA_def_float_rotation(ot->srna, | ||||
| -OBJECT_ADD_SIZE_MAXF, | -OBJECT_ADD_SIZE_MAXF, | ||||
| OBJECT_ADD_SIZE_MAXF, | OBJECT_ADD_SIZE_MAXF, | ||||
| "Rotation", | "Rotation", | ||||
| "Rotation for the newly added object", | "Rotation for the newly added object", | ||||
| DEG2RADF(-360.0f), | DEG2RADF(-360.0f), | ||||
| DEG2RADF(360.0f)); | DEG2RADF(360.0f)); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| prop = RNA_def_float_vector_xyz(ot->srna, | prop = RNA_def_float_vector_xyz( | ||||
| ot->srna, | |||||
| "scale", | "scale", | ||||
| 3, | 3, | ||||
| NULL, | NULL, | ||||
| -OBJECT_ADD_SIZE_MAXF, | -OBJECT_ADD_SIZE_MAXF, | ||||
| OBJECT_ADD_SIZE_MAXF, | OBJECT_ADD_SIZE_MAXF, | ||||
| "Scale", | "Scale", | ||||
| "Scale for the newly added object", | "Scale for the newly added object. Hint: If the object has a radius and the scale should be " | ||||
| "different from (1,1,1), the scale needs to be doubled to get the expected behavior. " | |||||
| "Example: a sphere with a radius of 2 scaled along the z-axis by 2 can be created with the " | |||||
| "parameters radius=2,scale=(2,2,4)", | |||||
| -1000.0f, | -1000.0f, | ||||
| 1000.0f); | 1000.0f); | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | ||||
| } | } | ||||
| void ED_object_add_mesh_props(wmOperatorType *ot) | void ED_object_add_mesh_props(wmOperatorType *ot) | ||||
| { | { | ||||
| RNA_def_boolean(ot->srna, "calc_uvs", true, "Generate UVs", "Generate a default UV map"); | RNA_def_boolean(ot->srna, "calc_uvs", true, "Generate UVs", "Generate a default UV map"); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | if (type == PFIELD_GUIDE) { | ||||
| ob = ED_object_add_type( | ob = ED_object_add_type( | ||||
| C, OB_CURVE, get_effector_defname(type), loc, rot, false, local_view_bits); | C, OB_CURVE, get_effector_defname(type), loc, rot, false, local_view_bits); | ||||
| cu = ob->data; | cu = ob->data; | ||||
| cu->flag |= CU_PATH | CU_3D; | cu->flag |= CU_PATH | CU_3D; | ||||
| ED_object_editmode_enter_ex(bmain, scene, ob, 0); | ED_object_editmode_enter_ex(bmain, scene, ob, 0); | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| ED_object_new_primitive_matrix(C, ob, loc, rot, mat); | ED_object_new_primitive_matrix(C, ob, loc, rot, NULL, mat); | ||||
| mul_mat3_m4_fl(mat, dia); | mul_mat3_m4_fl(mat, dia); | ||||
| BLI_addtail(&cu->editnurb->nurbs, | BLI_addtail(&cu->editnurb->nurbs, | ||||
| ED_curve_add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, 1)); | ED_curve_add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, 1)); | ||||
| if (!enter_editmode) { | if (!enter_editmode) { | ||||
| ED_object_editmode_exit_ex(bmain, scene, ob, EM_FREEDATA); | ED_object_editmode_exit_ex(bmain, scene, ob, EM_FREEDATA); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | if (obedit == NULL || obedit->type != OB_MBALL) { | ||||
| obedit = ED_object_add_type(C, OB_MBALL, NULL, loc, rot, true, local_view_bits); | obedit = ED_object_add_type(C, OB_MBALL, NULL, loc, rot, true, local_view_bits); | ||||
| newob = true; | newob = true; | ||||
| } | } | ||||
| else { | else { | ||||
| DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY); | ||||
| } | } | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| ED_object_new_primitive_matrix(C, obedit, loc, rot, mat); | ED_object_new_primitive_matrix(C, obedit, loc, rot, NULL, mat); | ||||
| /* Halving here is done to account for constant values from #BKE_mball_element_add. | /* Halving here is done to account for constant values from #BKE_mball_element_add. | ||||
| * While the default radius of the resulting meta element is 2, | * While the default radius of the resulting meta element is 2, | ||||
| * we want to pass in 1 so other values such as resolution are scaled by 1.0. */ | * we want to pass in 1 so other values such as resolution are scaled by 1.0. */ | ||||
| float dia = RNA_float_get(op->ptr, "radius") / 2; | float dia = RNA_float_get(op->ptr, "radius") / 2; | ||||
| ED_mball_add_primitive(C, obedit, newob, mat, dia, RNA_enum_get(op->ptr, "type")); | ED_mball_add_primitive(C, obedit, newob, mat, dia, RNA_enum_get(op->ptr, "type")); | ||||
| /* userdef */ | /* userdef */ | ||||
| ▲ Show 20 Lines • Show All 349 Lines • ▼ Show 20 Lines | else { | ||||
| WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_ADDED, NULL); | WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_ADDED, NULL); | ||||
| } | } | ||||
| /* create relevant geometry */ | /* create relevant geometry */ | ||||
| switch (type) { | switch (type) { | ||||
| case GP_EMPTY: { | case GP_EMPTY: { | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| ED_object_new_primitive_matrix(C, ob, loc, rot, mat); | ED_object_new_primitive_matrix(C, ob, loc, rot, NULL, mat); | ||||
| ED_gpencil_create_blank(C, ob, mat); | ED_gpencil_create_blank(C, ob, mat); | ||||
| break; | break; | ||||
| } | } | ||||
| case GP_STROKE: { | case GP_STROKE: { | ||||
| float radius = RNA_float_get(op->ptr, "radius"); | float radius = RNA_float_get(op->ptr, "radius"); | ||||
| float scale[3]; | |||||
| copy_v3_fl(scale, radius); | |||||
| float mat[4][4]; | float mat[4][4]; | ||||
| ED_object_new_primitive_matrix(C, ob, loc, rot, mat); | ED_object_new_primitive_matrix(C, ob, loc, rot, scale, mat); | ||||
| mul_v3_fl(mat[0], radius); | |||||
| mul_v3_fl(mat[1], radius); | |||||
| mul_v3_fl(mat[2], radius); | |||||
| ED_gpencil_create_stroke(C, ob, mat); | ED_gpencil_create_stroke(C, ob, mat); | ||||
| break; | break; | ||||
| } | } | ||||
| case GP_MONKEY: { | case GP_MONKEY: { | ||||
| float radius = RNA_float_get(op->ptr, "radius"); | float radius = RNA_float_get(op->ptr, "radius"); | ||||
| float scale[3]; | |||||
| copy_v3_fl(scale, radius); | |||||
| float mat[4][4]; | float mat[4][4]; | ||||
| ED_object_new_primitive_matrix(C, ob, loc, rot, mat); | ED_object_new_primitive_matrix(C, ob, loc, rot, scale, mat); | ||||
| mul_v3_fl(mat[0], radius); | |||||
| mul_v3_fl(mat[1], radius); | |||||
| mul_v3_fl(mat[2], radius); | |||||
| ED_gpencil_create_monkey(C, ob, mat); | ED_gpencil_create_monkey(C, ob, mat); | ||||
| break; | break; | ||||
| } | } | ||||
| case GP_LRT_SCENE: | case GP_LRT_SCENE: | ||||
| case GP_LRT_COLLECTION: | case GP_LRT_COLLECTION: | ||||
| case GP_LRT_OBJECT: { | case GP_LRT_OBJECT: { | ||||
| float radius = RNA_float_get(op->ptr, "radius"); | float radius = RNA_float_get(op->ptr, "radius"); | ||||
| float scale[3]; | |||||
| copy_v3_fl(scale, radius); | |||||
| float mat[4][4]; | float mat[4][4]; | ||||
| ED_object_new_primitive_matrix(C, ob, loc, rot, mat); | ED_object_new_primitive_matrix(C, ob, loc, rot, scale, mat); | ||||
| mul_v3_fl(mat[0], radius); | |||||
| mul_v3_fl(mat[1], radius); | |||||
| mul_v3_fl(mat[2], radius); | |||||
| ED_gpencil_create_lineart(C, ob); | ED_gpencil_create_lineart(C, ob); | ||||
| gpd = ob->data; | gpd = ob->data; | ||||
| /* Add Line Art modifier */ | /* Add Line Art modifier */ | ||||
| LineartGpencilModifierData *md = (LineartGpencilModifierData *)BKE_gpencil_modifier_new( | LineartGpencilModifierData *md = (LineartGpencilModifierData *)BKE_gpencil_modifier_new( | ||||
| eGpencilModifierType_Lineart); | eGpencilModifierType_Lineart); | ||||
| ▲ Show 20 Lines • Show All 2,324 Lines • Show Last 20 Lines | |||||