Difference between revisions of "IC Python API:Blurry Vision"
Chuck (RL) (Talk | contribs) (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...") |
Chuck (RL) (Talk | contribs) m (→Required Modules and Starting Variables) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
{{Parent|IC_Python_API:RL_Python_Samples|RL Python Samples}} | {{Parent|IC_Python_API:RL_Python_Samples|RL Python Samples}} | ||
− | This article goes into creating, setting, and keying the DOF settings | + | 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. |
− | == | + | == Necessary Modules and Starting Variables == |
Let's load the standard Reallusion python module and establish variables for the duration of the DOF animation. | Let's load the standard Reallusion python module and establish variables for the duration of the DOF animation. | ||
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 == | ||
+ | |||
+ | [[File:Ic_python_api_blurry_vision_01.gif|frame]] | ||
+ | |||
+ | 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. | ||
+ | |||
+ | <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. | ||
+ | |||
+ | <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> |
Latest revision as of 19:27, 30 September 2019
- 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.
Necessary 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
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.