Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_depsgraph.h" | #include "BKE_depsgraph.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_lamp.h" | #include "BKE_lamp.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.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" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_mball.h" | #include "BKE_mball.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | if (rv3d) { | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| zero_v3(rot); | zero_v3(rot); | ||||
| } | } | ||||
| } | } | ||||
| void ED_object_base_init_transform(bContext *C, Base *base, const float loc[3], const float rot[3]) | void ED_object_base_init_transform(bContext *C, ObjectBase *base, const float loc[3], const float rot[3]) | ||||
| { | { | ||||
| Object *ob = base->object; | Object *ob = base->object; | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| if (!scene) return; | if (!scene) return; | ||||
| if (loc) | if (loc) | ||||
| copy_v3_v3(ob->loc, loc); | copy_v3_v3(ob->loc, loc); | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* For object add primitive operators. | /* For object add primitive operators. | ||||
| * Do not call undo push in this function (users of this function have to). */ | * Do not call undo push in this function (users of this function have to). */ | ||||
| Object *ED_object_add_type( | Object *ED_object_add_type( | ||||
| bContext *C, | bContext *C, | ||||
| int type, const char *name, | int type, const char *name, | ||||
| const float loc[3], const float rot[3], | const float loc[3], const float rot[3], | ||||
| bool enter_editmode, unsigned int layer) | bool enter_editmode, unsigned int UNUSED(layer)) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | |||||
| Object *ob; | Object *ob; | ||||
| /* for as long scene has editmode... */ | /* for as long scene has editmode... */ | ||||
| if (CTX_data_edit_object(C)) | if (CTX_data_edit_object(C)) | ||||
| ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO); /* freedata, and undo */ | ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO); /* freedata, and undo */ | ||||
| /* deselects all, sets scene->basact */ | /* deselects all, sets scene->basact */ | ||||
| ob = BKE_object_add(bmain, scene, type, name); | ob = BKE_object_add(bmain, scene, sl, type, name); | ||||
| BASACT->lay = ob->lay = layer; | |||||
| /* editor level activate, notifiers */ | /* editor level activate, notifiers */ | ||||
| ED_base_object_activate(C, BASACT); | ED_object_base_activate(C, sl->basact); | ||||
| /* more editor stuff */ | /* more editor stuff */ | ||||
| ED_object_base_init_transform(C, BASACT, loc, rot); | ED_object_base_init_transform(C, sl->basact, loc, rot); | ||||
| /* Ignore collisions by default for non-mesh objects */ | /* Ignore collisions by default for non-mesh objects */ | ||||
| if (type != OB_MESH) { | if (type != OB_MESH) { | ||||
| ob->body_type = OB_BODY_TYPE_NO_COLLISION; | ob->body_type = OB_BODY_TYPE_NO_COLLISION; | ||||
| ob->gameflag &= ~(OB_SENSOR | OB_RIGID_BODY | OB_SOFT_BODY | OB_COLLISION | OB_CHARACTER | OB_OCCLUDER | OB_DYNAMIC | OB_NAVMESH); /* copied from rna_object.c */ | ob->gameflag &= ~(OB_SENSOR | OB_RIGID_BODY | OB_SOFT_BODY | OB_COLLISION | OB_CHARACTER | OB_OCCLUDER | OB_DYNAMIC | OB_NAVMESH); /* copied from rna_object.c */ | ||||
| } | } | ||||
| DAG_id_type_tag(bmain, ID_OB); | DAG_id_type_tag(bmain, ID_OB); | ||||
| ▲ Show 20 Lines • Show All 1,769 Lines • ▼ Show 20 Lines | |||||
| /* 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. | /* leaves selection of base/object unaltered. | ||||
| * note: don't call this within a loop since clear_* funcs loop over the entire database. | * 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); | * note: caller must do DAG_relations_tag_update(bmain); | ||||
| * this is not done automatic since we may duplicate many objects in a batch */ | * this is not done automatic since we may duplicate many objects in a batch */ | ||||
| Base *ED_object_add_duplicate(Main *bmain, Scene *scene, Base *base, int dupflag) | Base *ED_object_add_duplicate(Main *bmain, Scene *scene, Base *base, int dupflag) | ||||
| { | { | ||||
| Base *basen; | #if 0 | ||||
| ObjectBase *basen; | |||||
| Object *ob; | Object *ob; | ||||
| clear_sca_new_poins(); /* BGE logic */ | clear_sca_new_poins(); /* BGE logic */ | ||||
| basen = object_add_duplicate_internal(bmain, scene, base, dupflag); | basen = object_add_duplicate_internal(bmain, scene, base, dupflag); | ||||
| if (basen == NULL) { | if (basen == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ob = basen->object; | ob = basen->object; | ||||
| /* link own references to the newly duplicated data [#26816] */ | /* link own references to the newly duplicated data [#26816] */ | ||||
| BKE_libblock_relink_to_newid(&ob->id); | BKE_libblock_relink_to_newid(&ob->id); | ||||
| set_sca_new_poins_ob(ob); | set_sca_new_poins_ob(ob); | ||||
| /* DAG_relations_tag_update(bmain); */ /* caller must do */ | /* DAG_relations_tag_update(bmain); */ /* caller must do */ | ||||
| if (ob->data) { | if (ob->data) { | ||||
| ED_render_id_flush_update(bmain, ob->data); | ED_render_id_flush_update(bmain, ob->data); | ||||
| } | } | ||||
| BKE_main_id_clear_newpoins(bmain); | BKE_main_id_clear_newpoins(bmain); | ||||
| return basen; | return basen; | ||||
| #else | |||||
| /* handle duplicate */ | |||||
| TODO_LAYER_BASE | |||||
| (void)bmain; | |||||
| (void)scene; | |||||
| (void)base; | |||||
| (void)dupflag; | |||||
| return NULL; | |||||
| #endif | |||||
| } | } | ||||
| /* contextual operator dupli */ | /* contextual operator dupli */ | ||||
| static int duplicate_exec(bContext *C, wmOperator *op) | static int duplicate_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const bool linked = RNA_boolean_get(op->ptr, "linked"); | const bool linked = RNA_boolean_get(op->ptr, "linked"); | ||||
| ▲ Show 20 Lines • Show All 245 Lines • Show Last 20 Lines | |||||