Fix objects added via py being on the wrong layer when viewport is decoupled from scene

This commit is contained in:
Sergey Sharybin 2016-10-11 15:35:14 +02:00
parent 5322ff3b48
commit 17603b9f01
2 changed files with 18 additions and 2 deletions

View File

@ -145,8 +145,12 @@ def object_data_add(context, obdata, operator=None, use_active_layer=True, name=
base.layers_from_view(context.space_data)
base.layers[scene.active_layer] = True
else:
base.layers = [True if i == scene.active_layer
else False for i in range(len(scene.layers))]
if v3d and not v3d.lock_camera_and_layers:
base.layers = [True if i == v3d.active_layer
else False for i in range(len(v3d.layers))]
else:
base.layers = [True if i == scene.active_layer
else False for i in range(len(scene.layers))]
else:
if v3d:
base.layers_from_view(context.space_data)

View File

@ -522,6 +522,13 @@ static void rna_SpaceView3D_layer_set(PointerRNA *ptr, const int *values)
v3d->lay = ED_view3d_scene_layer_set(v3d->lay, values, &v3d->layact);
}
static int rna_SpaceView3D_active_layer_get(PointerRNA *ptr)
{
View3D *v3d = (View3D *)(ptr->data);
return (int)(log(v3d->layact) / M_LN2);
}
static void rna_SpaceView3D_layer_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
DAG_on_visible_update(bmain, false);
@ -2647,6 +2654,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Visible Layers", "Layers visible in this 3D View");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_layer_update");
prop = RNA_def_property(srna, "active_layer", PROP_INT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
RNA_def_property_int_funcs(prop, "rna_SpaceView3D_active_layer_get", NULL, NULL);
RNA_def_property_ui_text(prop, "Active Layer", "Active 3D view layer index");
prop = RNA_def_property(srna, "layers_local_view", PROP_BOOLEAN, PROP_LAYER_MEMBER);
RNA_def_property_boolean_sdna(prop, NULL, "lay", 0x01000000);
RNA_def_property_array(prop, 8);