Difference between revisions of "IC Python API:Blurry Vision"

From Reallusion Wiki!
Jump to: navigation, search
(Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Samples|RL Python Samples}} This article goes into creating, setting, and keying the DOF settings of the camera with a very simple ex...")
 
m (Keying the Blurry Mid-state)
Line 59: Line 59:
 
RLPy.RGlobal.Play(RLPy.RTime(start_time), RLPy.RTime(end_time))
 
RLPy.RGlobal.Play(RLPy.RTime(start_time), RLPy.RTime(end_time))
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Everything Put Together ==
 +
 +
<syntaxhighlight lang="python">
 +
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))
 +
</syntaxhighlight>
 +
 +
== APIs Used ==
 +
 +
You can research the following references for the APIs deployed in this code.
 +
 +
=== Blurry_Vision.py ===
 +
 +
<div style="column-count:4; -moz-column-count:4; -webkit-column-count:4">
 +
* [[ IC_Python_API:RLPy_RScene#GetCurrentCamera | RLPy.RScene.GetCurrentCamera() ]]
 +
* [[ IC_Python_API:RLPy_RKey | RLPy.RKey() ]]
 +
* [[ IC_Python_API:RLPy_RTime | RLPy.RTime() ]]
 +
* [[ IC_Python_API:RLPy_RGlobal#Play | RLPy.RGlobal.Play() ]]
 +
</div>

Revision as of 19:26, 19 August 2019

Main article: RL Python Samples.

This article goes into creating, setting, and keying the DOF settings of the camera with a very simple example script.

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

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.

Blurry_Vision.py