Ejemplo n.º 1
0
/* Get unit conversion factor for given ID + F-Curve */
float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag)
{
	if (flag & ANIM_UNITCONV_NORMALIZE) {
		return normalzation_factor_get(fcu, flag);
	}

	/* sanity checks */
	if (id && fcu && fcu->rna_path) {
		PointerRNA ptr, id_ptr;
		PropertyRNA *prop;
		
		/* get RNA property that F-Curve affects */
		RNA_id_pointer_create(id, &id_ptr);
		if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) {
			/* rotations: radians <-> degrees? */
			if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) {
				/* if the radians flag is not set, default to using degrees which need conversions */
				if ((scene) && (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS) == 0) {
					if (flag & ANIM_UNITCONV_RESTORE)
						return DEG2RADF(1.0f);  /* degrees to radians */
					else
						return RAD2DEGF(1.0f);  /* radians to degrees */
				}
			}
			
			/* TODO: other rotation types here as necessary */
		}
	}

	/* no mapping needs to occur... */
	return 1.0f;
}
Ejemplo n.º 2
0
/* Get unit conversion factor for given ID + F-Curve */
float ANIM_unit_mapping_get_factor (Scene *scene, ID *id, FCurve *fcu, short restore)
{
	/* sanity checks */
	if (id && fcu && fcu->rna_path) 
	{
		PointerRNA ptr, id_ptr;
		PropertyRNA *prop;
		
		/* get RNA property that F-Curve affects */
		RNA_id_pointer_create(id, &id_ptr);
		if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) 
		{
			/* rotations: radians <-> degrees? */
			if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION)
			{
				/* if the radians flag is not set, default to using degrees which need conversions */
				if ((scene) && (scene->unit.system_rotation == USER_UNIT_ROT_RADIANS) == 0) {
					if (restore)
						return M_PI / 180.0f;	/* degrees to radians */
					else
						return 180.0f / M_PI;	/* radians to degrees */
				}
			}
			
			// TODO: other rotation types here as necessary
		}
	}
	
	/* no mapping needs to occur... */
	return 1.0f;
}
Ejemplo n.º 3
0
static void graph_panel_key_properties(const bContext *C, Panel *pa)
{
	bAnimListElem *ale;
	FCurve *fcu;
	BezTriple *bezt, *prevbezt;
	
	uiLayout *layout = pa->layout;
	uiLayout *col;
	uiBlock *block;

	if (!graph_panel_context(C, &ale, &fcu))
		return;
	
	block = uiLayoutGetBlock(layout);
	uiBlockSetHandleFunc(block, do_graph_region_buttons, NULL);
	
	/* only show this info if there are keyframes to edit */
	if (get_active_fcurve_keyframe_edit(fcu, &bezt, &prevbezt)) {
		PointerRNA bezt_ptr, id_ptr, fcu_prop_ptr;
		PropertyRNA *fcu_prop = NULL;
		uiBut *but;
		int unit = B_UNIT_NONE;
		
		/* RNA pointer to keyframe, to allow editing */
		RNA_pointer_create(ale->id, &RNA_Keyframe, bezt, &bezt_ptr);
		
		/* get property that F-Curve affects, for some unit-conversion magic */
		RNA_id_pointer_create(ale->id, &id_ptr);
		if (RNA_path_resolve(&id_ptr, fcu->rna_path, &fcu_prop_ptr, &fcu_prop) && fcu_prop) {
			/* determine the unit for this property */
			unit = RNA_SUBTYPE_UNIT(RNA_property_subtype(fcu_prop));
		}		
		
		/* interpolation */
		col = uiLayoutColumn(layout, FALSE);
		uiItemR(col, &bezt_ptr, "interpolation", 0, NULL, ICON_NONE);
			
		/* numerical coordinate editing 
		 *  - we use the button-versions of the calls so that we can attach special update handlers
		 *    and unit conversion magic that cannot be achieved using a purely RNA-approach
		 */
		// XXX: 
		col = uiLayoutColumn(layout, TRUE);
		/* keyframe itself */
		{
			uiItemL(col, IFACE_("Key:"), ICON_NONE);

			but = uiDefButR(block, NUM, B_REDR, IFACE_("Frame"), 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "co", 0, 0, 0, -1, -1, NULL);
			uiButSetFunc(but, graphedit_activekey_update_cb, fcu, bezt);

			but = uiDefButR(block, NUM, B_REDR, IFACE_("Value"), 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "co", 1, 0, 0, -1, -1, NULL);
			uiButSetFunc(but, graphedit_activekey_update_cb, fcu, bezt);
			uiButSetUnitType(but, unit);
		}

		/* previous handle - only if previous was Bezier interpolation */
		if ((prevbezt) && (prevbezt->ipo == BEZT_IPO_BEZ)) {
			uiItemL(col, IFACE_("Left Handle:"), ICON_NONE);

			but = uiDefButR(block, NUM, B_REDR, "X", 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_left", 0, 0, 0, -1, -1, NULL);
			uiButSetFunc(but, graphedit_activekey_handles_cb, fcu, bezt);

			but = uiDefButR(block, NUM, B_REDR, "Y", 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_left", 1, 0, 0, -1, -1, NULL);
			uiButSetFunc(but, graphedit_activekey_handles_cb, fcu, bezt);
			uiButSetUnitType(but, unit);
		}

		/* next handle - only if current is Bezier interpolation */
		if (bezt->ipo == BEZT_IPO_BEZ) {
			uiItemL(col, IFACE_("Right Handle:"), ICON_NONE);

			but = uiDefButR(block, NUM, B_REDR, "X", 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_right", 0, 0, 0, -1, -1, NULL);
			uiButSetFunc(but, graphedit_activekey_handles_cb, fcu, bezt);

			but = uiDefButR(block, NUM, B_REDR, "Y", 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_right", 1, 0, 0, -1, -1, NULL);
			uiButSetFunc(but, graphedit_activekey_handles_cb, fcu, bezt);
			uiButSetUnitType(but, unit);
		}
	}
	else {
		if ((fcu->bezt == NULL) && (fcu->modifiers.first)) {
			/* modifiers only - so no keyframes to be active */
			uiItemL(layout, IFACE_("F-Curve only has F-Modifiers"), ICON_NONE);
			uiItemL(layout, IFACE_("See Modifiers panel below"), ICON_INFO);
		}
		else if (fcu->fpt) {
			/* samples only */
			uiItemL(layout, IFACE_("F-Curve doesn't have any keyframes as it only contains sampled points"),
			        ICON_NONE);
		}
		else
			uiItemL(layout, IFACE_("No active keyframe on F-Curve"), ICON_NONE);
	}
	
	MEM_freeN(ale);
}
Ejemplo n.º 4
0
static int rna_Property_unit_get(PointerRNA *ptr)
{
	PropertyRNA *prop= (PropertyRNA*)ptr->data;
	rna_idproperty_check(&prop, ptr);
	return RNA_SUBTYPE_UNIT(prop->subtype);
}
Ejemplo n.º 5
0
static void graph_panel_key_properties(const bContext *C, Panel *pa)
{
	bAnimListElem *ale;
	FCurve *fcu;
	BezTriple *bezt, *prevbezt;
	
	uiLayout *layout = pa->layout;
	uiLayout *col;
	uiBlock *block;

	if (!graph_panel_context(C, &ale, &fcu))
		return;
	
	block = uiLayoutGetBlock(layout);
	/* UI_block_func_handle_set(block, do_graph_region_buttons, NULL); */
	
	/* only show this info if there are keyframes to edit */
	if (get_active_fcurve_keyframe_edit(fcu, &bezt, &prevbezt)) {
		PointerRNA bezt_ptr, id_ptr, fcu_prop_ptr;
		PropertyRNA *fcu_prop = NULL;
		uiBut *but;
		int unit = B_UNIT_NONE;
		
		/* RNA pointer to keyframe, to allow editing */
		RNA_pointer_create(ale->id, &RNA_Keyframe, bezt, &bezt_ptr);
		
		/* get property that F-Curve affects, for some unit-conversion magic */
		RNA_id_pointer_create(ale->id, &id_ptr);
		if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &fcu_prop_ptr, &fcu_prop)) {
			/* determine the unit for this property */
			unit = RNA_SUBTYPE_UNIT(RNA_property_subtype(fcu_prop));
		}
		
		/* interpolation */
		col = uiLayoutColumn(layout, false);
		if (fcu->flag & FCURVE_DISCRETE_VALUES) {
			uiLayout *split = uiLayoutSplit(col, 0.33f, true);
			uiItemL(split, IFACE_("Interpolation:"), ICON_NONE);
			uiItemL(split, IFACE_("None for Enum/Boolean"), ICON_IPO_CONSTANT);
		}
		else {
			uiItemR(col, &bezt_ptr, "interpolation", 0, NULL, ICON_NONE);
		}
		
		/* easing type */
		if (bezt->ipo > BEZT_IPO_BEZ)
			uiItemR(col, &bezt_ptr, "easing", 0, NULL, 0);

		/* easing extra */
		switch (bezt->ipo) {
			case BEZT_IPO_BACK:
				col = uiLayoutColumn(layout, 1);
				uiItemR(col, &bezt_ptr, "back", 0, NULL, 0);
				break;
			case BEZT_IPO_ELASTIC:
				col = uiLayoutColumn(layout, 1);
				uiItemR(col, &bezt_ptr, "amplitude", 0, NULL, 0);
				uiItemR(col, &bezt_ptr, "period", 0, NULL, 0);
				break;
			default:
				break;
		}
		
		/* numerical coordinate editing 
		 *  - we use the button-versions of the calls so that we can attach special update handlers
		 *    and unit conversion magic that cannot be achieved using a purely RNA-approach
		 */
		col = uiLayoutColumn(layout, true);
		/* keyframe itself */
		{
			uiItemL(col, IFACE_("Key:"), ICON_NONE);
			
			but = uiDefButR(block, UI_BTYPE_NUM, B_REDR, IFACE_("Frame:"), 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "co", 0, 0, 0, -1, -1, NULL);
			UI_but_func_set(but, graphedit_activekey_update_cb, fcu, bezt);
			
			but = uiDefButR(block, UI_BTYPE_NUM, B_REDR, IFACE_("Value:"), 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "co", 1, 0, 0, -1, -1, NULL);
			UI_but_func_set(but, graphedit_activekey_update_cb, fcu, bezt);
			UI_but_unit_type_set(but, unit);
		}
		
		/* previous handle - only if previous was Bezier interpolation */
		if ((prevbezt) && (prevbezt->ipo == BEZT_IPO_BEZ)) {
			uiItemL(col, IFACE_("Left Handle:"), ICON_NONE);
			
			but = uiDefButR(block, UI_BTYPE_NUM, B_REDR, "X:", 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_left", 0, 0, 0, -1, -1, NULL);
			UI_but_func_set(but, graphedit_activekey_left_handle_coord_cb, fcu, bezt);
			
			but = uiDefButR(block, UI_BTYPE_NUM, B_REDR, "Y:", 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_left", 1, 0, 0, -1, -1, NULL);
			UI_but_func_set(but, graphedit_activekey_left_handle_coord_cb, fcu, bezt);
			UI_but_unit_type_set(but, unit);
			
			/* XXX: with label? */
			but = uiDefButR(block, UI_BTYPE_MENU, B_REDR, NULL, 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_left_type", 0, 0, 0, -1, -1, "Type of left handle");
			UI_but_func_set(but, graphedit_activekey_handles_cb, fcu, bezt);
		}
		
		/* next handle - only if current is Bezier interpolation */
		if (bezt->ipo == BEZT_IPO_BEZ) {
			/* NOTE: special update callbacks are needed on the coords here due to T39911 */
			uiItemL(col, IFACE_("Right Handle:"), ICON_NONE);
			
			but = uiDefButR(block, UI_BTYPE_NUM, B_REDR, "X:", 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_right", 0, 0, 0, -1, -1, NULL);
			UI_but_func_set(but, graphedit_activekey_right_handle_coord_cb, fcu, bezt);
			
			but = uiDefButR(block, UI_BTYPE_NUM, B_REDR, "Y:", 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_right", 1, 0, 0, -1, -1, NULL);
			UI_but_func_set(but, graphedit_activekey_right_handle_coord_cb, fcu, bezt);
			UI_but_unit_type_set(but, unit);
			
			/* XXX: with label? */
			but = uiDefButR(block, UI_BTYPE_MENU, B_REDR, NULL, 0, 0, UI_UNIT_X, UI_UNIT_Y,
			                &bezt_ptr, "handle_right_type", 0, 0, 0, -1, -1, "Type of right handle");
			UI_but_func_set(but, graphedit_activekey_handles_cb, fcu, bezt);
		}
	}
	else {
		if ((fcu->bezt == NULL) && (fcu->modifiers.first)) {
			/* modifiers only - so no keyframes to be active */
			uiItemL(layout, IFACE_("F-Curve only has F-Modifiers"), ICON_NONE);
			uiItemL(layout, IFACE_("See Modifiers panel below"), ICON_INFO);
		}
		else if (fcu->fpt) {
			/* samples only */
			uiItemL(layout, IFACE_("F-Curve doesn't have any keyframes as it only contains sampled points"),
			        ICON_NONE);
		}
		else
			uiItemL(layout, IFACE_("No active keyframe on F-Curve"), ICON_NONE);
	}
	
	MEM_freeN(ale);
}