Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_object.c
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
| #include "rna_internal.h" | #include "rna_internal.h" | ||||
| #include "BLI_sys_types.h" /* needed for intptr_t used in ED_mesh.h */ | #include "BLI_sys_types.h" /* needed for intptr_t used in ED_mesh.h */ | ||||
| #include "ED_mesh.h" | #include "ED_mesh.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "DEG_depsgraph_query.h" | |||||
| const EnumPropertyItem rna_enum_object_mode_items[] = { | const EnumPropertyItem rna_enum_object_mode_items[] = { | ||||
| {OB_MODE_OBJECT, "OBJECT", ICON_OBJECT_DATAMODE, "Object Mode", ""}, | {OB_MODE_OBJECT, "OBJECT", ICON_OBJECT_DATAMODE, "Object Mode", ""}, | ||||
| {OB_MODE_EDIT, "EDIT", ICON_EDITMODE_HLT, "Edit Mode", ""}, | {OB_MODE_EDIT, "EDIT", ICON_EDITMODE_HLT, "Edit Mode", ""}, | ||||
| {OB_MODE_POSE, "POSE", ICON_POSE_HLT, "Pose Mode", ""}, | {OB_MODE_POSE, "POSE", ICON_POSE_HLT, "Pose Mode", ""}, | ||||
| {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt Mode", ""}, | {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt Mode", ""}, | ||||
| {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""}, | {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""}, | ||||
| {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""}, | {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""}, | ||||
| {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""}, | {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""}, | ||||
| ▲ Show 20 Lines • Show All 1,175 Lines • ▼ Show 20 Lines | if (ob->protectflag & OB_LOCK_ROT4D) { | ||||
| else if ((index == 3) && (ob->protectflag & OB_LOCK_ROTZ)) { | else if ((index == 3) && (ob->protectflag & OB_LOCK_ROTZ)) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
| return PROP_EDITABLE; | return PROP_EDITABLE; | ||||
| } | } | ||||
| static int rna_MaterialSlot_index(PointerRNA *ptr) | |||||
| { | |||||
| return POINTER_AS_INT(ptr->data); | |||||
| } | |||||
| static int rna_MaterialSlot_material_editable(PointerRNA *ptr, const char **UNUSED(r_info)) | static int rna_MaterialSlot_material_editable(PointerRNA *ptr, const char **UNUSED(r_info)) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| const int index = (Material **)ptr->data - ob->mat; | const int index = rna_MaterialSlot_index(ptr); | ||||
| bool is_editable; | bool is_editable; | ||||
| if ((ob->matbits == NULL) || ob->matbits[index]) { | if ((ob->matbits == NULL) || ob->matbits[index]) { | ||||
| is_editable = !ID_IS_LINKED(ob); | is_editable = !ID_IS_LINKED(ob); | ||||
| } | } | ||||
| else { | else { | ||||
| is_editable = ob->data ? !ID_IS_LINKED(ob->data) : false; | is_editable = ob->data ? !ID_IS_LINKED(ob->data) : false; | ||||
| } | } | ||||
| return is_editable ? PROP_EDITABLE : 0; | return is_editable ? PROP_EDITABLE : 0; | ||||
| } | } | ||||
| static PointerRNA rna_MaterialSlot_material_get(PointerRNA *ptr) | static PointerRNA rna_MaterialSlot_material_get(PointerRNA *ptr) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| Material *ma; | Material *ma; | ||||
| const int index = (Material **)ptr->data - ob->mat; | const int index = rna_MaterialSlot_index(ptr); | ||||
| if (DEG_is_evaluated_object(ob)) { | |||||
| ma = BKE_object_material_get_eval(ob, index + 1); | |||||
| } | |||||
| else { | |||||
| ma = BKE_object_material_get(ob, index + 1); | ma = BKE_object_material_get(ob, index + 1); | ||||
| } | |||||
| return rna_pointer_inherit_refine(ptr, &RNA_Material, ma); | return rna_pointer_inherit_refine(ptr, &RNA_Material, ma); | ||||
| } | } | ||||
| static void rna_MaterialSlot_material_set(PointerRNA *ptr, | static void rna_MaterialSlot_material_set(PointerRNA *ptr, | ||||
| PointerRNA value, | PointerRNA value, | ||||
| struct ReportList *UNUSED(reports)) | struct ReportList *UNUSED(reports)) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| int index = (Material **)ptr->data - ob->mat; | int index = rna_MaterialSlot_index(ptr); | ||||
| BLI_assert(BKE_id_is_in_global_main(&ob->id)); | BLI_assert(BKE_id_is_in_global_main(&ob->id)); | ||||
| BLI_assert(BKE_id_is_in_global_main(value.data)); | BLI_assert(BKE_id_is_in_global_main(value.data)); | ||||
| BKE_object_material_assign(G_MAIN, ob, value.data, index + 1, BKE_MAT_ASSIGN_EXISTING); | BKE_object_material_assign(G_MAIN, ob, value.data, index + 1, BKE_MAT_ASSIGN_EXISTING); | ||||
| } | } | ||||
| static bool rna_MaterialSlot_material_poll(PointerRNA *ptr, PointerRNA value) | static bool rna_MaterialSlot_material_poll(PointerRNA *ptr, PointerRNA value) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| Material *ma = (Material *)value.data; | Material *ma = (Material *)value.data; | ||||
| if (ob->type == OB_GPENCIL) { | if (ob->type == OB_GPENCIL) { | ||||
| /* GP Materials only */ | /* GP Materials only */ | ||||
| return (ma->gp_style != NULL); | return (ma->gp_style != NULL); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Everything except GP materials */ | /* Everything except GP materials */ | ||||
| return (ma->gp_style == NULL); | return (ma->gp_style == NULL); | ||||
| } | } | ||||
| } | } | ||||
| static int rna_MaterialSlot_link_get(PointerRNA *ptr) | static int rna_MaterialSlot_link_get(PointerRNA *ptr) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| int index = (Material **)ptr->data - ob->mat; | int index = rna_MaterialSlot_index(ptr); | ||||
| if (index < ob->totcol) { | |||||
| return ob->matbits[index] != 0; | return ob->matbits[index] != 0; | ||||
| } | } | ||||
| return false; | |||||
| } | |||||
| static void rna_MaterialSlot_link_set(PointerRNA *ptr, int value) | static void rna_MaterialSlot_link_set(PointerRNA *ptr, int value) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| int index = (Material **)ptr->data - ob->mat; | int index = rna_MaterialSlot_index(ptr); | ||||
| if (value) { | if (value) { | ||||
| ob->matbits[index] = 1; | ob->matbits[index] = 1; | ||||
| /* DEPRECATED */ | /* DEPRECATED */ | ||||
| // ob->colbits |= (1 << index); | // ob->colbits |= (1 << index); | ||||
| } | } | ||||
| else { | else { | ||||
| ob->matbits[index] = 0; | ob->matbits[index] = 0; | ||||
| /* DEPRECATED */ | /* DEPRECATED */ | ||||
| // ob->colbits &= ~(1 << index); | // ob->colbits &= ~(1 << index); | ||||
| } | } | ||||
| } | } | ||||
| static int rna_MaterialSlot_name_length(PointerRNA *ptr) | static int rna_MaterialSlot_name_length(PointerRNA *ptr) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| Material *ma; | Material *ma; | ||||
| int index = (Material **)ptr->data - ob->mat; | int index = rna_MaterialSlot_index(ptr); | ||||
| ma = BKE_object_material_get(ob, index + 1); | ma = BKE_object_material_get(ob, index + 1); | ||||
| if (ma) { | if (ma) { | ||||
| return strlen(ma->id.name + 2); | return strlen(ma->id.name + 2); | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static void rna_MaterialSlot_name_get(PointerRNA *ptr, char *str) | static void rna_MaterialSlot_name_get(PointerRNA *ptr, char *str) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| Material *ma; | Material *ma; | ||||
| int index = (Material **)ptr->data - ob->mat; | int index = rna_MaterialSlot_index(ptr); | ||||
| ma = BKE_object_material_get(ob, index + 1); | ma = BKE_object_material_get(ob, index + 1); | ||||
| if (ma) { | if (ma) { | ||||
| strcpy(str, ma->id.name + 2); | strcpy(str, ma->id.name + 2); | ||||
| } | } | ||||
| else { | else { | ||||
| str[0] = '\0'; | str[0] = '\0'; | ||||
| } | } | ||||
| } | } | ||||
| static void rna_MaterialSlot_update(Main *bmain, Scene *scene, PointerRNA *ptr) | static void rna_MaterialSlot_update(Main *bmain, Scene *scene, PointerRNA *ptr) | ||||
| { | { | ||||
| rna_Object_internal_update(bmain, scene, ptr); | rna_Object_internal_update(bmain, scene, ptr); | ||||
| WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, ptr->owner_id); | WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, ptr->owner_id); | ||||
| WM_main_add_notifier(NC_MATERIAL | ND_SHADING_LINKS, NULL); | WM_main_add_notifier(NC_MATERIAL | ND_SHADING_LINKS, NULL); | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| } | } | ||||
| static char *rna_MaterialSlot_path(PointerRNA *ptr) | static char *rna_MaterialSlot_path(PointerRNA *ptr) | ||||
| { | { | ||||
| int index = rna_MaterialSlot_index(ptr); | |||||
| return BLI_sprintfN("material_slots[%d]", index); | |||||
| } | |||||
| static int rna_Object_material_slots_length(PointerRNA *ptr) | |||||
| { | |||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| int index = (Material **)ptr->data - ob->mat; | if (DEG_is_evaluated_object(ob)) { | ||||
| return BKE_object_material_count_eval(ob); | |||||
| } | |||||
| else { | |||||
| return ob->totcol; | |||||
| } | |||||
| } | |||||
| return BLI_sprintfN("material_slots[%d]", index); | static void rna_Object_material_slots_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) | ||||
| { | |||||
| const int length = rna_Object_material_slots_length(ptr); | |||||
| iter->internal.count.item = 0; | |||||
| iter->internal.count.ptr = ptr->owner_id; | |||||
| iter->valid = length > 0; | |||||
| } | |||||
| static void rna_Object_material_slots_next(CollectionPropertyIterator *iter) | |||||
| { | |||||
| const int length = rna_Object_material_slots_length(&iter->ptr); | |||||
| iter->internal.count.item++; | |||||
| iter->valid = iter->internal.count.item < length; | |||||
| } | |||||
| static PointerRNA rna_Object_material_slots_get(CollectionPropertyIterator *iter) | |||||
| { | |||||
| PointerRNA ptr; | |||||
| RNA_pointer_create((ID *)iter->internal.count.ptr, | |||||
| &RNA_MaterialSlot, | |||||
| POINTER_FROM_INT(iter->internal.count.item), | |||||
| &ptr); | |||||
| return ptr; | |||||
| } | |||||
| static void rna_Object_material_slots_end(CollectionPropertyIterator *UNUSED(iter)) | |||||
| { | |||||
| } | } | ||||
| static PointerRNA rna_Object_display_get(PointerRNA *ptr) | static PointerRNA rna_Object_display_get(PointerRNA *ptr) | ||||
| { | { | ||||
| return rna_pointer_inherit_refine(ptr, &RNA_ObjectDisplay, ptr->data); | return rna_pointer_inherit_refine(ptr, &RNA_ObjectDisplay, ptr->data); | ||||
| } | } | ||||
| static char *rna_ObjectDisplay_path(PointerRNA *UNUSED(ptr)) | static char *rna_ObjectDisplay_path(PointerRNA *UNUSED(ptr)) | ||||
| ▲ Show 20 Lines • Show All 1,565 Lines • ▼ Show 20 Lines | static void rna_def_object(BlenderRNA *brna) | ||||
| RNA_def_property_pointer_sdna(prop, NULL, "proxy_group"); | RNA_def_property_pointer_sdna(prop, NULL, "proxy_group"); | ||||
| RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON); | RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON); | ||||
| RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); | RNA_def_property_override_clear_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); | ||||
| RNA_def_property_ui_text( | RNA_def_property_ui_text( | ||||
| prop, "Proxy Collection", "Library collection duplicator object this proxy object controls"); | prop, "Proxy Collection", "Library collection duplicator object this proxy object controls"); | ||||
| /* materials */ | /* materials */ | ||||
| prop = RNA_def_property(srna, "material_slots", PROP_COLLECTION, PROP_NONE); | prop = RNA_def_property(srna, "material_slots", PROP_COLLECTION, PROP_NONE); | ||||
| RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol"); | |||||
| RNA_def_property_struct_type(prop, "MaterialSlot"); | RNA_def_property_struct_type(prop, "MaterialSlot"); | ||||
| RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_PROP_NAME); | RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_PROP_NAME); | ||||
| /* don't dereference pointer! */ | /* Don't dereference the material slot pointer, it is the slot index encoded in a pointer. */ | ||||
| RNA_def_property_collection_funcs( | RNA_def_property_collection_funcs(prop, | ||||
| prop, NULL, NULL, NULL, "rna_iterator_array_get", NULL, NULL, NULL, NULL); | "rna_Object_material_slots_begin", | ||||
| "rna_Object_material_slots_next", | |||||
| "rna_Object_material_slots_end", | |||||
| "rna_Object_material_slots_get", | |||||
| "rna_Object_material_slots_length", | |||||
| NULL, | |||||
| NULL, | |||||
| NULL); | |||||
| RNA_def_property_ui_text(prop, "Material Slots", "Material slots in the object"); | RNA_def_property_ui_text(prop, "Material Slots", "Material slots in the object"); | ||||
| prop = RNA_def_property(srna, "active_material", PROP_POINTER, PROP_NONE); | prop = RNA_def_property(srna, "active_material", PROP_POINTER, PROP_NONE); | ||||
| RNA_def_property_struct_type(prop, "Material"); | RNA_def_property_struct_type(prop, "Material"); | ||||
| RNA_def_property_pointer_funcs(prop, | RNA_def_property_pointer_funcs(prop, | ||||
| "rna_Object_active_material_get", | "rna_Object_active_material_get", | ||||
| "rna_Object_active_material_set", | "rna_Object_active_material_set", | ||||
| NULL, | NULL, | ||||
| ▲ Show 20 Lines • Show All 649 Lines • Show Last 20 Lines | |||||