/** * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Contributor(s): Blender Foundation (2008). * * ***** END GPL LICENSE BLOCK ***** */ #include #include "RNA_define.h" #include "RNA_types.h" #include "rna_internal.h" #include "DNA_customdata_types.h" #include "DNA_mesh_types.h" #include "DNA_object_types.h" #include "DNA_property_types.h" #include "DNA_scene_types.h" #include "WM_types.h" #ifdef RNA_RUNTIME #include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_material.h" static void rna_Object_update(bContext *C, PointerRNA *ptr) { DAG_object_flush_update(CTX_data_scene(C), ptr->id.data, OB_RECALC_OB); } static int rna_VertexGroup_index_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; return BLI_findindex(&ob->defbase, ptr->data); } static PointerRNA rna_Object_active_vertex_group_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; return rna_pointer_inherit_refine(ptr, &RNA_VertexGroup, BLI_findlink(&ob->defbase, ob->actdef)); } void rna_object_vgroup_name_index_get(PointerRNA *ptr, char *value, int index) { Object *ob= (Object*)ptr->id.data; bDeformGroup *dg; dg= BLI_findlink(&ob->defbase, index-1); if(dg) BLI_strncpy(value, dg->name, sizeof(dg->name)); else BLI_strncpy(value, "", sizeof(dg->name)); } int rna_object_vgroup_name_index_length(PointerRNA *ptr, int index) { Object *ob= (Object*)ptr->id.data; bDeformGroup *dg; dg= BLI_findlink(&ob->defbase, index-1); return (dg)? strlen(dg->name): 0; } void rna_object_vgroup_name_index_set(PointerRNA *ptr, const char *value, short *index) { Object *ob= (Object*)ptr->id.data; bDeformGroup *dg; int a; for(a=1, dg=ob->defbase.first; dg; dg=dg->next, a++) { if(strcmp(dg->name, value) == 0) { *index= a; return; } } *index= 0; } void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) { Object *ob= (Object*)ptr->id.data; bDeformGroup *dg; for(dg=ob->defbase.first; dg; dg=dg->next) { if(strcmp(dg->name, value) == 0) { BLI_strncpy(result, value, maxlen); return; } } BLI_strncpy(result, "", maxlen); } void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) { Object *ob= (Object*)ptr->id.data; Mesh *me; CustomDataLayer *layer; int a; if(ob->type == OB_MESH && ob->data) { me= (Mesh*)ob->data; for(a=0; afdata.totlayer; a++) { layer= &me->fdata.layers[a]; if(layer->type == CD_MTFACE && strcmp(layer->name, value) == 0) { BLI_strncpy(result, value, maxlen); return; } } } BLI_strncpy(result, "", maxlen); } void rna_object_vcollayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen) { Object *ob= (Object*)ptr->id.data; Mesh *me; CustomDataLayer *layer; int a; if(ob->type == OB_MESH && ob->data) { me= (Mesh*)ob->data; for(a=0; afdata.totlayer; a++) { layer= &me->fdata.layers[a]; if(layer->type == CD_MCOL && strcmp(layer->name, value) == 0) { BLI_strncpy(result, value, maxlen); return; } } } BLI_strncpy(result, "", maxlen); } static void rna_Object_active_material_index_range(PointerRNA *ptr, int *min, int *max) { Object *ob= (Object*)ptr->id.data; *min= 0; *max= ob->totcol-1; } static PointerRNA rna_Object_active_material_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; return rna_pointer_inherit_refine(ptr, &RNA_Material, give_current_material(ob, ob->actcol)); } #if 0 static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value) { Object *ob= (Object*)ptr->id.data; assign_material(ob, value.data, ob->actcol); } #endif static int rna_Object_active_material_link_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; return (ob->colbits & 1<<(ob->actcol)) != 0; } static void rna_Object_active_material_link_set(PointerRNA *ptr, int value) { Object *ob= (Object*)ptr->id.data; if(value) ob->colbits |= (1<<(ob->actcol)); else ob->colbits &= ~(1<<(ob->actcol)); } static PointerRNA rna_Object_game_settings_get(PointerRNA *ptr) { return rna_pointer_inherit_refine(ptr, &RNA_GameObjectSettings, ptr->id.data); } static void rna_Object_layer_set(PointerRNA *ptr, const int *values) { Object *ob= (Object*)ptr->data; int i, tot= 0; /* ensure we always have some layer selected */ for(i=0; i<20; i++) if(values[i]) tot++; if(tot==0) return; for(i=0; i<20; i++) { if(values[i]) ob->lay |= (1<lay &= ~(1<data; int i, tot= 0; /* ensure we always have some stateer selected */ for(i=0; i<20; i++) if(values[i]) tot++; if(tot==0) return; for(i=0; i<20; i++) { if(values[i]) ob->state |= (1<state &= ~(1<