Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_DerivedMesh.h" | #include "BKE_DerivedMesh.h" | ||||
| #include "BKE_displist.h" | #include "BKE_displist.h" | ||||
| #include "BKE_effect.h" | #include "BKE_effect.h" | ||||
| #include "BKE_font.h" | #include "BKE_font.h" | ||||
| #include "BKE_group.h" | #include "BKE_group.h" | ||||
| #include "BKE_gpencil.h" | |||||
| #include "BKE_lamp.h" | #include "BKE_lamp.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| #include "BKE_library_remap.h" | #include "BKE_library_remap.h" | ||||
| #include "BKE_key.h" | #include "BKE_key.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| Show All 17 Lines | |||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "RNA_enum_types.h" | #include "RNA_enum_types.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "ED_curve.h" | #include "ED_curve.h" | ||||
| #include "ED_gpencil.h" | |||||
| #include "ED_mball.h" | #include "ED_mball.h" | ||||
| #include "ED_mesh.h" | #include "ED_mesh.h" | ||||
| #include "ED_node.h" | #include "ED_node.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| #include "ED_physics.h" | #include "ED_physics.h" | ||||
| #include "ED_render.h" | #include "ED_render.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_transform.h" | #include "ED_transform.h" | ||||
| ▲ Show 20 Lines • Show All 871 Lines • ▼ Show 20 Lines | void OBJECT_OT_drop_named_image(wmOperatorType *ot) | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | ||||
| RNA_def_boolean(ot->srna, "relative_path", true, "Relative Path", "Select the file relative to the blend file"); | RNA_def_boolean(ot->srna, "relative_path", true, "Relative Path", "Select the file relative to the blend file"); | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | ||||
| prop = RNA_def_string(ot->srna, "name", NULL, MAX_ID_NAME - 2, "Name", "Image name to assign"); | prop = RNA_def_string(ot->srna, "name", NULL, MAX_ID_NAME - 2, "Name", "Image name to assign"); | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | ||||
| ED_object_add_generic_props(ot, false); | ED_object_add_generic_props(ot, false); | ||||
| } | } | ||||
| /********************* Add Gpencil Operator ********************/ | |||||
| static int object_gpencil_add_exec(bContext *C, wmOperator *op) | |||||
| { | |||||
| Object *ob; | |||||
| int type = RNA_enum_get(op->ptr, "type"); | |||||
| unsigned int layer; | |||||
| float loc[3], rot[3]; | |||||
| WM_operator_view3d_unit_defaults(C, op); | |||||
| if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, &layer, NULL)) | |||||
| return OPERATOR_CANCELLED; | |||||
| ob = ED_object_add_type(C, OB_GPENCIL, NULL, loc, rot, false, layer); | |||||
| BKE_object_obdata_size_init(ob, GP_OBGPENCIL_DEFAULT_SIZE); | |||||
| /* set grease pencil mode to object */ | |||||
| ToolSettings *ts = CTX_data_tool_settings(C); | |||||
| ts->gpencil_src = GP_TOOL_SOURCE_OBJECT; | |||||
| /* add a grease pencil datablock */ | |||||
| ob->gpd = BKE_gpencil_data_addnew("GPencil"); | |||||
| /* if type is monkey, create a 2D Suzanne */ | |||||
| // TODO: create with offset to cursor? | |||||
| switch (type) { | |||||
| case GP_MONKEY: | |||||
| { | |||||
| ED_gpencil_create_monkey(C, ob->gpd); | |||||
| ED_object_rotation_from_view(C, rot, 'Y'); | |||||
| copy_v3_v3(ob->rot, rot); | |||||
| ED_gpencil_add_defaults(C); | |||||
| break; | |||||
| } | |||||
| case GP_EMPTY: | |||||
| /* do nothing */ | |||||
| ED_gpencil_add_defaults(C); | |||||
| break; | |||||
| default: | |||||
| BKE_report(op->reports, RPT_WARNING, "Not implemented"); | |||||
| break; | |||||
| } | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| void OBJECT_OT_gpencil_add(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Add Gpencil"; | |||||
| ot->description = "Add a grease pencil object to the scene"; | |||||
| ot->idname = "OBJECT_OT_gpencil_add"; | |||||
| /* api callbacks */ | |||||
| ot->exec = object_gpencil_add_exec; | |||||
| ot->poll = ED_operator_objectmode; | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| /* properties */ | |||||
| ED_object_add_unit_props(ot); | |||||
| ED_object_add_generic_props(ot, false); | |||||
| ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_gpencil_type_items, 0, "Type", ""); | |||||
| } | |||||
| /********************* Add Lamp Operator ********************/ | /********************* Add Lamp Operator ********************/ | ||||
| static const char *get_lamp_defname(int type) | static const char *get_lamp_defname(int type) | ||||
| { | { | ||||
| switch (type) { | switch (type) { | ||||
| case LA_LOCAL: return CTX_DATA_(BLT_I18NCONTEXT_ID_LAMP, "Point"); | case LA_LOCAL: return CTX_DATA_(BLT_I18NCONTEXT_ID_LAMP, "Point"); | ||||
| case LA_SUN: return CTX_DATA_(BLT_I18NCONTEXT_ID_LAMP, "Sun"); | case LA_SUN: return CTX_DATA_(BLT_I18NCONTEXT_ID_LAMP, "Sun"); | ||||
| case LA_SPOT: return CTX_DATA_(BLT_I18NCONTEXT_ID_LAMP, "Spot"); | case LA_SPOT: return CTX_DATA_(BLT_I18NCONTEXT_ID_LAMP, "Spot"); | ||||
| ▲ Show 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) { | ||||
| if (gpl->parent != NULL) { | if (gpl->parent != NULL) { | ||||
| if (gpl->parent == ob) { | if (gpl->parent == ob) { | ||||
| gpl->parent = NULL; | gpl->parent = NULL; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* remove as scene default annotation object */ | |||||
| if (ob->type == OB_GPENCIL) { | |||||
| Scene *scene_iter; | |||||
| for (scene_iter = bmain->scene.first; scene_iter; scene_iter = scene_iter->id.next) { | |||||
| if (scene->gp_object == ob) { | |||||
| scene->gp_object = NULL; | |||||
| } | |||||
| } | |||||
| } | |||||
| /* remove from current scene only */ | /* remove from current scene only */ | ||||
| ED_base_object_free_and_unlink(bmain, scene, ob); | ED_base_object_free_and_unlink(bmain, scene, ob); | ||||
| changed = true; | changed = true; | ||||
| if (use_global) { | if (use_global) { | ||||
| Scene *scene_iter; | Scene *scene_iter; | ||||
| for (scene_iter = bmain->scene.first; scene_iter; scene_iter = scene_iter->id.next) { | for (scene_iter = bmain->scene.first; scene_iter; scene_iter = scene_iter->id.next) { | ||||
| if (scene_iter != scene && !ID_IS_LINKED_DATABLOCK(scene_iter)) { | if (scene_iter != scene && !ID_IS_LINKED_DATABLOCK(scene_iter)) { | ||||
| ▲ Show 20 Lines • Show All 861 Lines • ▼ Show 20 Lines | if (dupflag & USER_DUP_PSYS) { | ||||
| if (dupflag & USER_DUP_ACT) { | if (dupflag & USER_DUP_ACT) { | ||||
| BKE_animdata_copy_id_action(&psys->part->id, true); | BKE_animdata_copy_id_action(&psys->part->id, true); | ||||
| } | } | ||||
| id_us_min(id); | id_us_min(id); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* duplicate grease pencil data for OB_GPENCIL */ | |||||
| if ((dupflag != 0) && (obn->type == OB_GPENCIL)) { | |||||
| obn->gpd = BKE_gpencil_data_duplicate(bmain, obn->gpd, false); | |||||
| } | |||||
| id = obn->data; | id = obn->data; | ||||
| didit = 0; | didit = 0; | ||||
| switch (obn->type) { | switch (obn->type) { | ||||
| case OB_MESH: | case OB_MESH: | ||||
| if (dupflag & USER_DUP_MESH) { | if (dupflag & USER_DUP_MESH) { | ||||
| ID_NEW_REMAP_US2(obn->data) | ID_NEW_REMAP_US2(obn->data) | ||||
| ▲ Show 20 Lines • Show All 439 Lines • Show Last 20 Lines | |||||