How to create Random Fcurves or Camera Shake

Post Reply
User avatar
Draise
Captain
Posts: 3198
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

How to create Random Fcurves or Camera Shake

Post by Draise »

Loading the following script and running it will create random X Y Z translation fcurves.

This is handy for camera shake or for other shaking objects!

Code: Select all

'##########################################################
'NAME:    RandomFCurve.vbs
'Version: v1.0.1
'XSI:     3.x
'AUTHOR: Ken Obayashi
'LAST MODIFIED: 07.23.2003
'Note: This script creates FCurve from a rnd function.
'USAGE:1.Select object and marked parameters.
'	 2.Run the script.
'
'		Start : Aniamrion start frame
'		End : Animation end frame
'		Step : Skip frame
'		Value : Random value
'		Seed : Random seed
'
'##########################################################

Option Explicit

Dim oRoot,oSelList,aParams

	set oRoot = application.activeproject.activescene.root
	set oSelList = GetValue("SelectionList")
	
	if oSelList.count = 0 then
		msgbox "There is no selected object.",,"Error"
	else
		aParams = GetMarking()
		if typename(aParams) = "Empty" then
			msgbox "There is no marked parameter.",,"Error"
		else
			CreateRandomFCurve
		end if
	end if

'----------------------------------------------------------

sub CreateRandomFCurve

Dim oCParam
Dim oParams,iStep,iStart,iEnd,dValue,iSeed
Dim i,j,k,oObj,oParam,sDefaultValue

'Create CustomParameterSet.
	oParams = GetMarking()
		
	set oCParam = oRoot.AddProperty("Custom_parameter_list",,"RandomFCurve")
	set iStart = oCParam.AddParameter2("Int2CustomParam",siInt2,GetValue("Project.Data.PlayControl.In"),0,1000,,,,,,"Start")
	set iEnd = oCParam.AddParameter2("Int2CustomParam",siInt2,GetValue("Project.Data.PlayControl.Out"),1,1000,,,,,,"End")
	set iStep = oCParam.AddParameter2("Int2CustomParam",siInt2,1,1,100,,,,,,"Step")
	set dValue = oCParam.AddParameter2("Double2CustomParam",siDouble,1,0,10000,,,,,,"Value")
	set iSeed = oCParam.AddParameter2("Int2CustomParam",siInt2,1,0,100,,,,,,"Seed")
	
	On Error Resume Next
	InspectObj oCParam,,oCParam,4
	if Err.Number <> 0 then
		DeleteObj oCParam
		exit sub
	end if

'Create FCurve.
	For each oObj in oSelList
		For k = 0 to UBound(oParams)
			oParam = oObj &"."& oParams(k)
			sDefaultValue = GetValue(oParam)
			Randomize iSeed.Value
			For i = iStart.Value to iEnd.Value
				SetKey oParam,i,sDefaultValue - dValue.Value + rnd * dValue.Value * 2
				i = i + iStep.Value - 1
			Next
		Next
	Next
	
	DeleteObj oCParam
	
end sub

'----------------------------------------------------------
Post Reply