Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
| #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_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| #include "BKE_localview.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" | ||||
| #include "BKE_nla.h" | #include "BKE_nla.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_particle.h" | #include "BKE_particle.h" | ||||
| ▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | if (RNA_property_is_set(op->ptr, prop)) { | ||||
| *layer = 0; | *layer = 0; | ||||
| for (a = 0; a < 20; a++) { | for (a = 0; a < 20; a++) { | ||||
| if (layer_values[a]) | if (layer_values[a]) | ||||
| *layer |= (1 << a); | *layer |= (1 << a); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| *layer = BKE_screen_view3d_layer_active_ex(v3d, scene, false); | *layer = BKE_screen_view3d_layer_active(v3d, scene); | ||||
| for (a = 0; a < 20; a++) { | for (a = 0; a < 20; a++) { | ||||
| layer_values[a] = (*layer & (1 << a)) != 0; | layer_values[a] = (*layer & (1 << a)) != 0; | ||||
| } | } | ||||
| RNA_property_boolean_set_array(op->ptr, prop, layer_values); | RNA_property_boolean_set_array(op->ptr, prop, layer_values); | ||||
| } | } | ||||
| /* in local view we additionally add local view layers, | |||||
| * not part of operator properties */ | |||||
| if (v3d && v3d->localvd) | |||||
| *layer |= v3d->lay; | |||||
| } | } | ||||
| /* Location! */ | /* Location! */ | ||||
| { | { | ||||
| float _loc[3]; | float _loc[3]; | ||||
| if (!loc) | if (!loc) | ||||
| loc = _loc; | loc = _loc; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| 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 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); | ||||
| View3D *v3d = CTX_wm_view3d(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, type, name); | ||||
| BASACT->lay = ob->lay = layer; | BASACT->lay = ob->lay = layer; | ||||
| /* editor level activate, notifiers */ | /* editor level activate, notifiers */ | ||||
| ED_base_object_activate(C, BASACT); | ED_base_object_activate(C, BASACT); | ||||
| /* Add to local view if needed */ | |||||
| if (v3d) { | |||||
| BKE_localview_object_assign(v3d, ob); | |||||
| } | |||||
| /* more editor stuff */ | /* more editor stuff */ | ||||
| ED_object_base_init_transform(C, BASACT, loc, rot); | ED_object_base_init_transform(C, 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 */ | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,836 Lines • ▼ Show 20 Lines | static int add_named_exec(bContext *C, wmOperator *op) | ||||
| if (basen == NULL) { | if (basen == NULL) { | ||||
| MEM_freeN(base); | MEM_freeN(base); | ||||
| BKE_report(op->reports, RPT_ERROR, "Object could not be duplicated"); | BKE_report(op->reports, RPT_ERROR, "Object could not be duplicated"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| basen->lay = basen->object->lay = BKE_screen_view3d_layer_active(v3d, scene); | basen->lay = basen->object->lay = BKE_screen_view3d_layer_active(v3d, scene); | ||||
| basen->object->restrictflag &= ~OB_RESTRICT_VIEW; | basen->object->restrictflag &= ~OB_RESTRICT_VIEW; | ||||
| if (v3d) { | |||||
| /* Add to localview (function checks if v3d is in local view) */ | |||||
| BKE_localview_object_assign(v3d, basen->object); | |||||
| } | |||||
| if (event) { | if (event) { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| const int mval[2] = {event->x - ar->winrct.xmin, | const int mval[2] = {event->x - ar->winrct.xmin, | ||||
| event->y - ar->winrct.ymin}; | event->y - ar->winrct.ymin}; | ||||
| ED_object_location_from_view(C, basen->object->loc); | ED_object_location_from_view(C, basen->object->loc); | ||||
| ED_view3d_cursor3d_position(C, basen->object->loc, mval); | ED_view3d_cursor3d_position(C, basen->object->loc, mval); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines | |||||