int rna_object_shapekey_index_set(ID *id, PointerRNA value, int current)
{
	Key *key = rna_ShapeKey_find_key(id);

	if (key) {
		int a = BLI_findindex(&key->block, value.data);
		if (a != -1) return a;
	}
	
	return current;
}
Exemple #2
0
PointerRNA rna_object_shapekey_index_get(ID *id, int value)
{
	Key *key = rna_ShapeKey_find_key(id);
	KeyBlock *kb = NULL;
	PointerRNA ptr;

	if (key && value < key->totkey)
		kb = BLI_findlink(&key->block, value);
	
	RNA_pointer_create(id, &RNA_ShapeKey, kb, &ptr);

	return ptr;
}
Exemple #3
0
static int rna_ShapeKey_data_length(PointerRNA *ptr)
{
	Key *key = rna_ShapeKey_find_key(ptr->id.data);
	KeyBlock *kb = (KeyBlock *)ptr->data;
	Curve *cu;
	Nurb *nu;
	int tot = kb->totelem;
	
	if (GS(key->from->name) == ID_CU) {
		cu = (Curve *)key->from;
		nu = cu->nurb.first;
		
		if (nu->bezt)
			tot /= 3;
	}
	
	return tot;
}
Exemple #4
0
static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Key *key = rna_ShapeKey_find_key(ptr->id.data);
	KeyBlock *kb = (KeyBlock *)ptr->data;
	Curve *cu;
	Nurb *nu;
	int tot = kb->totelem, size = key->elemsize;
	
	if (GS(key->from->name) == ID_CU) {
		cu = (Curve *)key->from;
		nu = cu->nurb.first;
		
		if (nu->bezt) {
			tot /= 3;
			size *= 3;
		}
	}
	
	rna_iterator_array_begin(iter, (void *)kb->data, size, tot, 0, NULL);
}
Exemple #5
0
void rna_ShapeKey_name_set(PointerRNA *ptr, const char *value)
{
	KeyBlock *kb= ptr->data;
	char oldname[sizeof(kb->name)];
	
	/* make a copy of the old name first */
	BLI_strncpy(oldname, kb->name, sizeof(kb->name));
	
	/* copy the new name into the name slot */
	BLI_strncpy_utf8(kb->name, value, sizeof(kb->name));
	
	/* make sure the name is truly unique */
	if (ptr->id.data) {
		Key *key= rna_ShapeKey_find_key(ptr->id.data);
		BLI_uniquename(&key->block, kb, "Key", '.', offsetof(KeyBlock, name), sizeof(kb->name));
	}
	
	/* fix all the animation data which may link to this */
	BKE_all_animdata_fix_paths_rename("key_blocks", oldname, kb->name);
}
Exemple #6
0
static PointerRNA rna_ShapeKey_data_get(CollectionPropertyIterator *iter)
{
	Key *key = rna_ShapeKey_find_key(iter->parent.id.data);
	StructRNA *type;
	Curve *cu;
	Nurb *nu;
	
	if (GS(key->from->name) == ID_CU) {
		cu = (Curve *)key->from;
		nu = cu->nurb.first;
		
		if (nu->bezt)
			type = &RNA_ShapeKeyBezierPoint;
		else
			type = &RNA_ShapeKeyCurvePoint;
	}
	else
		type = &RNA_ShapeKeyPoint;
	
	return rna_pointer_inherit_refine(&iter->parent, type, rna_iterator_array_get(iter));
}
static Mesh *rna_KeyBlock_normals_get_mesh(PointerRNA *ptr, ID *id)
{
	Key *key = rna_ShapeKey_find_key((id == NULL && ptr != NULL) ? ptr->id.data : id);
	id = key ? key->from : NULL;

	if (id != NULL) {
		switch (GS(id->name)) {
			case ID_ME:
				return (Mesh *)id;
			case ID_OB:
			{
				Object *ob = (Object *)id;
				if (ob->type == OB_MESH) {
					return ob->data;
				}
			}
		}
	}

	return NULL;
}
Exemple #8
0
static char *rna_ShapeKeyPoint_path(PointerRNA *ptr)
{
	ID *id = (ID *)ptr->id.data;
	Key *key = rna_ShapeKey_find_key(ptr->id.data);
	KeyBlock *kb;
	float *point = (float *)ptr->data;
	
	/* if we can get a key block, we can construct a path */
	kb = rna_ShapeKeyData_find_keyblock(key, point); 
	
	if (kb) {
		int index = rna_ShapeKeyPoint_get_index(key, kb, point);
		
		if (GS(id->name) == ID_KE)
			return BLI_sprintfN("key_blocks[\"%s\"].data[%d]", kb->name, index);
		else
			return BLI_sprintfN("shape_keys.key_blocks[\"%s\"].data[%d]", kb->name, index);
	}
	else
		return NULL; // XXX: there's really no way to resolve this...
}