FCurveEditor

Object Hierarchy

導入

v3.0

詳細

FCurveEditor オブジェクトは、Softimage の F カーブエディタのコンテキスト情報を提供します。FCurveEditor オブジェクトが公開している情報を使用することにより、F カーブエディタでのユーザ操作に応答するカスタムF カーブ編集スクリプトやプラグインを記述できます。

このオブジェクトのインスタンスにアクセスするために、siFCurveCategory に設定されている siCommandCategory を使用して、カスタムコマンドを作成する必要があります。このコマンドは f カーブエディタの[編集]メニューに表示され、必要に応じて実行できます。また、FCurveEditor オブジェクトのインスタンスを参照する引数を 1 つ持ちます。

カスタムコマンドは、オブジェクト FCurve および FCurveKey オブジェクトのメソッドとプロパティを使用して F カーブを変更します。基本F カーブオブジェクトが変更されると、ユーザインターフェイスは自動的に更新されます。

以下に 2 つのカスタムF カーブエディタスクリプトを例示し、XSI Local: Tools: Animate 以下の NetView についてさらに詳しい例を挙げます。

メソッド

GetEditorAttribute2 GetSelectedKeys2    
       

プロパティ

EditorAttribute SelectedFCurves SelectedKeys  
       

VBScript の例

'

' Custom FCurve Command Demo

'

'This script demontrates the Softimage support for plugging in a 

'custom command.

'

'Instructions:

'

'1) In order to try this code the commands needs to be saved onto disk in a .vbs 

'file so that it can be registered.

'

'2) install the commands using the following, (changing the path according to your config):

'  xsi -script "C:/temp/FCurveDemo.vbs" -main InstallFCurveCmdExamples -args -Location "c:/temp/FCurveDemo.vbs"

'

'3) Launch Softimage, 

'4) Create some animated parameters, 

'5) Open the fcurve editor, select curves and keys from your animated parameters

'6) Try the FCurveEditorInfo and AvgSelectedPoints commands which will appear in the Edit menu

sub InstallFCurveCmdExamples( Location )

	dim cmd

	'Location argument is expected to be the full path name of the script file 

	'where the commands we are installing are implemented

	logmessage "Installing fcurve editor commands found in " & Location

	'Remove any existing earlier registrations of this command

	Application.RemoveCommand "FCurveEditorInfo"		

	Application.RemoveCommand "AvgSelectedPoints" 

	set cmd = Application.CreateCommand("FCurveEditorInfo", siFCurveCategory)

	cmd.Description = "FCurveEditorInfo shows information about FCurve Context"

	cmd.ScriptingName = "FCurveEditorInfo"

	cmd.Handler = "OnFCurveEditorInfo"

	cmd.FileName = Location

	cmd.Language = "VBScript"

	'FCurve callbacks are a sub not a function

	cmd.ReturnValue = false											

	'FCurve commands get a pointer to an FCurveEditor OM object

	cmd.Arguments.Add "FCurveEditor", siArgumentInput, 0, siDispatch

	Application.AddCommand cmd

	logmessage "FCurveEditorInfo is now added to fcurve editor Edit menu"

	set cmd = Application.CreateCommand("AvgSelectedPoints", siFCurveCategory)

	cmd.Description = "AvgSelectedPoints change value of selected keys"

	cmd.ScriptingName = "AvgSelectedPoints"

	cmd.Handler = "OnAvgSelectedPoints"

	cmd.FileName = Location

	cmd.Language = "VBScript"

	cmd.ReturnValue = false											

	cmd.Arguments.Add "FCurveEditor", siArgumentInput, 0, siDispatch

	Application.AddCommand cmd

	logmessage "AvgSelectedPoints is now added to fcurve editor Edit menu"

end sub

'This first demo is informative - it logs a bunch of information about the 

'state of the FCurve editor, in effect demonstrating what you can find out

sub OnFCurveEditorInfo( in_objFCurveEditor )

	LogMessage "FCurveEditorInfo called - showing information about current context of FCurve Editor"

	if ( typename( in_objFCurveEditor ) = "Nothing" ) then

		Logmessage "FCurve Argument is NULL"

	elseif ( typename( in_objFCurveEditor ) <> "FCurveEditor" ) then

		LogMessage "FCurve Argument is not an FCurve, it is a " & typename( in_objFCurveEditor ) 

	else		

		'Now access the FCurve Context listing the contents.

		dim oCurves, oCurve

		set oCurves = in_objFCurveEditor.SelectedFCurves

		if ( oCurves.Count = 0 ) then

			logmessage "There are no selected fcurves in the editor"

		end if

		dim i, strInfo

		for each oCurve in oCurves

			logmessage "-------------------------------------"

			'build a string description of the frame/keyvalues 

			'(for a real motion capture fcurve this would be too long to display like this)

			strInfo = ""

			for i = 0 to ( oCurve.Keys.Count - 1 )

				strInfo = strInfo & "(" & Round( oCurve.Keys.Item( i ).Time, 3 ) _

							& ", " & Round( oCurve.Keys.Item( i ).Value, 3 ) & ") "

			next		

			LogMessage "Selected FCurve has the following keys: " & strInfo

			'List the selected keys

			dim oKeys, oKey

			set oKeys = in_objFCurveEditor.SelectedKeys( oCurve )

			if ( oKeys.Count = 0 ) then

				logmessage "There are no keys selected on this fcurve"

			else

				strInfo = ""

				for each oKey in oKeys

					strInfo = strInfo & "(" & Round( oKey.Time, 3 ) & ", " & Round( oKey.Value, 3 ) & ") "

				next

				LogMessage "The following keys are selected on this FCurve: " & strInfo

			end if			

		next

		'The user may have selected a region in the fcurve editor.  This information is available like this:

		logmessage "-------------------------------------"

		dim Start, endFrame, Min, Max

		Start = in_objFCurveEditor.EditorAttribute( siRegionStartFrame )

		endFrame = in_objFCurveEditor.EditorAttribute( siRegionEndFrame )

		Min = in_objFCurveEditor.EditorAttribute( siRegionMin )

		Max = in_objFCurveEditor.EditorAttribute( siRegionMax )

		if ( Start <> endFrame ) then

			logmessage "User has selected time region from frame " &_ 

						round( Start, 2 ) & " to " & round( endFrame, 2 )

		else

			logmessage "No time region is selected"

		end if 

		if ( Min <> Max ) then

			logmessage "User has selected key value range from " &_ 

						round( Min, 2 ) & " to " & round( Max, 2 )

		else

			logmessage "No Value region is selected"

		end if 

	end if

end sub

'This second demo is action oriented - it changes the state of the FCurves that are selected.

'

'In this case we take the selected keys and set their values to the average.

sub OnAvgSelectedPoints( in_objFCurveEditor )

	LogMessage "AvgSelectedPoints called"

	'Example of some simple error handling

	if ( typename( in_objFCurveEditor ) <> "FCurveEditor" ) then

		LogMessage "Invalid argument to command - Should be FCurveEditor object instead we got a " _ 

					& typename( in_objFCurveEditor ), siError

		exit sub

	end if

	dim bDidSomething

	bDidSomething = false

	dim oCurves, oCurve

	set oCurves = in_objFCurveEditor.SelectedFCurves

	for each oCurve in oCurves

		dim oKeys, oKey, cntKeys

		set oKeys = in_objFCurveEditor.SelectedKeys( oCurve )

		cntKeys = oKeys.Count

		if ( cntKeys > 1 ) then

			dim sumValues, avgValue

			sumValues = 0

			for each oKey in oKeys

				sumValues = sumValues + oKey.Value

			next

			avgValue = sumValues / cntKeys

			for each oKey in oKeys

				oKey.Value = avgValue

			next

			bDidSomething = true

		end if 

	next

	if ( not bDidSomething ) then

		LogMessage "Please select two or more keys on an fcurve to average"

	end if

end sub

関連項目

Command FCurve