Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | |||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "object_intern.h" | #include "object_intern.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Local Enum Declarations | /** \name Local Enum Declarations | ||||
| * \{ */ | * \{ */ | ||||
| /* this is an exact copy of the define in rna_light.c | /* This is an exact copy of the define in `rna_light.c` | ||||
| * kept here because of linking order. | * kept here because of linking order. | ||||
| * Icons are only defined here */ | * Icons are only defined here */ | ||||
| const EnumPropertyItem rna_enum_light_type_items[] = { | const EnumPropertyItem rna_enum_light_type_items[] = { | ||||
| {LA_LOCAL, "POINT", ICON_LIGHT_POINT, "Point", "Omnidirectional point light source"}, | {LA_LOCAL, "POINT", ICON_LIGHT_POINT, "Point", "Omnidirectional point light source"}, | ||||
| {LA_SUN, "SUN", ICON_LIGHT_SUN, "Sun", "Constant direction parallel ray light source"}, | {LA_SUN, "SUN", ICON_LIGHT_SUN, "Sun", "Constant direction parallel ray light source"}, | ||||
| {LA_SPOT, "SPOT", ICON_LIGHT_SPOT, "Spot", "Directional cone light source"}, | {LA_SPOT, "SPOT", ICON_LIGHT_SPOT, "Spot", "Directional cone light source"}, | ||||
| {LA_AREA, "AREA", ICON_LIGHT_AREA, "Area", "Directional area light source"}, | {LA_AREA, "AREA", ICON_LIGHT_AREA, "Area", "Directional area light source"}, | ||||
| {0, NULL, 0, NULL, NULL}, | {0, NULL, 0, NULL, NULL}, | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | void ED_object_base_init_transform_on_add(Object *object, const float loc[3], const float rot[3]) | ||||
| if (rot) { | 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. | |||||
| * Returns standard diameter. */ | |||||
| float ED_object_new_primitive_matrix(bContext *C, | float ED_object_new_primitive_matrix(bContext *C, | ||||
| Object *obedit, | Object *obedit, | ||||
| const float loc[3], | const float loc[3], | ||||
| const float rot[3], | const float rot[3], | ||||
| const float scale[3], | const float scale[3], | ||||
| float r_primmat[4][4]) | float r_primmat[4][4]) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | if (prop != NULL) { | ||||
| RNA_property_float_set_array(op->ptr, prop, r_scale); | RNA_property_float_set_array(op->ptr, prop, r_scale); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | |||||
| * For object add primitive operators, or for object creation when `obdata != NULL`. | |||||
| * \param obdata: Assigned to #Object.data, with increased user count. | |||||
| * | |||||
| * \note Do not call undo push in this function (users of this function have to). | |||||
| */ | |||||
| Object *ED_object_add_type_with_obdata(bContext *C, | Object *ED_object_add_type_with_obdata(bContext *C, | ||||
| const int type, | const int type, | ||||
| const char *name, | const char *name, | ||||
| const float loc[3], | const float loc[3], | ||||
| const float rot[3], | const float rot[3], | ||||
| const bool enter_editmode, | const bool enter_editmode, | ||||
| const ushort local_view_bits, | const ushort local_view_bits, | ||||
| ID *obdata) | ID *obdata) | ||||
| ▲ Show 20 Lines • Show All 1,099 Lines • ▼ Show 20 Lines | static int object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| if (!RNA_struct_property_is_set(op->ptr, "name") && | if (!RNA_struct_property_is_set(op->ptr, "name") && | ||||
| !RNA_struct_property_is_set(op->ptr, "session_uuid")) { | !RNA_struct_property_is_set(op->ptr, "session_uuid")) { | ||||
| return WM_enum_search_invoke(C, op, event); | return WM_enum_search_invoke(C, op, event); | ||||
| } | } | ||||
| return op->type->exec(C, op); | return op->type->exec(C, op); | ||||
| } | } | ||||
| /* only used as menu */ | |||||
| void OBJECT_OT_collection_instance_add(wmOperatorType *ot) | void OBJECT_OT_collection_instance_add(wmOperatorType *ot) | ||||
| { | { | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Add Collection Instance"; | ot->name = "Add Collection Instance"; | ||||
| ot->description = "Add a collection instance"; | ot->description = "Add a collection instance"; | ||||
| ot->idname = "OBJECT_OT_collection_instance_add"; | ot->idname = "OBJECT_OT_collection_instance_add"; | ||||
| ▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | void OBJECT_OT_pointcloud_add(wmOperatorType *ot) | ||||
| ED_object_add_generic_props(ot, false); | ED_object_add_generic_props(ot, false); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Delete Object Operator | /** \name Delete Object Operator | ||||
| * \{ */ | * \{ */ | ||||
| /* remove base from a specific scene */ | |||||
| /* NOTE: now unlinks constraints as well. */ | |||||
| void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob) | void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob) | ||||
| { | { | ||||
| if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 && | if (ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0 && | ||||
| BKE_library_ID_is_indirectly_used(bmain, ob)) { | BKE_library_ID_is_indirectly_used(bmain, ob)) { | ||||
| /* We cannot delete indirectly used object... */ | /* We cannot delete indirectly used object... */ | ||||
| printf( | printf( | ||||
| "WARNING, undeletable object '%s', should have been caught before reaching this " | "WARNING, undeletable object '%s', should have been caught before reaching this " | ||||
| "function!", | "function!", | ||||
| ob->id.name + 2); | ob->id.name + 2); | ||||
| return; | return; | ||||
| } | } | ||||
| DEG_id_tag_update_ex(bmain, &ob->id, ID_RECALC_BASE_FLAGS); | DEG_id_tag_update_ex(bmain, &ob->id, ID_RECALC_BASE_FLAGS); | ||||
| BKE_scene_collections_object_remove(bmain, scene, ob, true); | BKE_scene_collections_object_remove(bmain, scene, ob, true); | ||||
| } | } | ||||
| /** | |||||
| * Remove base from a specific scene. | |||||
| * `ob` must not be indirectly used. | |||||
| */ | |||||
| void ED_object_base_free_and_unlink_no_indirect_check(Main *bmain, Scene *scene, Object *ob) | void ED_object_base_free_and_unlink_no_indirect_check(Main *bmain, Scene *scene, Object *ob) | ||||
| { | { | ||||
| BLI_assert(!BKE_library_ID_is_indirectly_used(bmain, ob)); | BLI_assert(!BKE_library_ID_is_indirectly_used(bmain, ob)); | ||||
| DEG_id_tag_update_ex(bmain, &ob->id, ID_RECALC_BASE_FLAGS); | DEG_id_tag_update_ex(bmain, &ob->id, ID_RECALC_BASE_FLAGS); | ||||
| BKE_scene_collections_object_remove(bmain, scene, ob, true); | BKE_scene_collections_object_remove(bmain, scene, ob, true); | ||||
| } | } | ||||
| static int object_delete_exec(bContext *C, wmOperator *op) | static int object_delete_exec(bContext *C, wmOperator *op) | ||||
| ▲ Show 20 Lines • Show All 1,339 Lines • ▼ Show 20 Lines | if (ob->rigidbody_object || ob->rigidbody_constraint) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return basen; | return basen; | ||||
| } | } | ||||
| /* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */ | /* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */ | ||||
| /* leaves selection of base/object unaltered. | |||||
| * NOTE: don't call this within a loop since clear_* funcs loop over the entire database. | |||||
| * NOTE: caller must do DAG_relations_tag_update(bmain); | |||||
| * this is not done automatic since we may duplicate many objects in a batch */ | |||||
| Base *ED_object_add_duplicate( | Base *ED_object_add_duplicate( | ||||
| Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, const eDupli_ID_Flags dupflag) | Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, const eDupli_ID_Flags dupflag) | ||||
| { | { | ||||
| Base *basen; | Base *basen; | ||||
| Object *ob; | Object *ob; | ||||
| basen = object_add_duplicate_internal(bmain, | basen = object_add_duplicate_internal(bmain, | ||||
| scene, | scene, | ||||
| ▲ Show 20 Lines • Show All 495 Lines • Show Last 20 Lines | |||||