IC Python API:Blurry Vision

From Reallusion Wiki!
Revision as of 23:58, 21 August 2019 by Chuck (RL) (Talk | contribs)

Jump to: navigation, search
Main article: RL Python Samples.

This article goes into creating, setting, and keying the DOF settings for the camera. As an example, we'll simulate blurry vision by going in and out of blurring the current scene by changing and keying the near and far blur scale for the DOF settings.

Required Modules and Starting Variables

Let's load the standard Reallusion python module and establish variables for the duration of the DOF animation.

import RLPy

start_time = 1
end_time = 3000

DOF Settings

We can start off by retrieving the current DOF settings of the current camera and adjusting some of its settings to simulate a blurry vision effect:SetNearBlurScale and SetFarBlurScale in particular.

current_camera = RLPy.RScene.GetCurrentCamera()
dof = current_camera.GetDOFData()

dof.SetEnable(True)  # Activate
dof.SetNearBlurScale(0)
dof.SetFarBlurScale(0)

Keying the Start and End Frames

First, we'll set a key for the start and end time of the animation where the vision starts off and end up clear.

key = RLPy.RKey()
key.SetTime(RLPy.RTime(start_time))
current_camera.AddDofKey(key, dof)

key.SetTime(RLPy.RTime(end_time))
current_camera.AddDofKey(key, dof)

Notice that the same key object is reused with just slight adjustments to time.

Keying the Blurry Mid-state

Now, we can reuse the DOF and key objects with slight adjustments to key the blurry mid-state for the camera.

dof.SetNearBlurScale(2)
dof.SetFarBlurScale(2)
key.SetTime(RLPy.RTime((end_time-start_time) * 0.5))
current_camera.AddDofKey(key, dof)

Now we can play the animation back:

RLPy.RGlobal.Play(RLPy.RTime(start_time), RLPy.RTime(end_time))

Everything Put Together

Ic python api blurry vision 01.gif

You can copy and paste the following code into a PY file and load it into iClone via Script > Load Python. You'll need to create and look through a new camera for this script to work.

import RLPy

start_time = 1
end_time = 3000

current_camera = RLPy.RScene.GetCurrentCamera()
dof = current_camera.GetDOFData()

dof.SetEnable(True)  # Activate
dof.SetNearBlurScale(0)
dof.SetFarBlurScale(0)

key = RLPy.RKey()
key.SetTime(RLPy.RTime(start_time))
current_camera.AddDofKey(key, dof)

key.SetTime(RLPy.RTime(end_time))
current_camera.AddDofKey(key, dof)

dof.SetNearBlurScale(2)
dof.SetFarBlurScale(2)
key.SetTime(RLPy.RTime((end_time-start_time) * 0.5))
current_camera.AddDofKey(key, dof)

RLPy.RGlobal.Play(RLPy.RTime(start_time), RLPy.RTime(end_time))

APIs Used

You can research the following references for the APIs deployed in this code.