Difference between revisions of "IC Python API:Camera Auto-Focus"

From Reallusion Wiki!
Jump to: navigation, search
m (Description)
m
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{TOC}}
 +
{{Parent|IC_Python_API#Python_of_the_Month|Python of the Month}}
 +
 
== Demo Video ==
 
== Demo Video ==
 +
 +
{{#evt:
 +
service=youtube
 +
|id=https://www.youtube.com/watch?v=GGiZxjI42TQ
 +
}}
  
 
== Description ==
 
== Description ==
  
Auto-Focus can be used to automatically calculate the Focus Distance and Focus Range for the current camera according to the viewing distance of a selected object.  This script operates and updates in near real-time.
+
Auto-Focus can be used to automatically calculate the DOF (Depth of Field) distance and range for the current camera according to the viewing distance of a selected object.  This script operates and updates in near real-time.
  
 
[[File:Ic_python_api_auto_focus_02.png|frame|left|DOF distance and range is calculated based on the selected object's distance and bounding size.  The DOF is recalculated when the selection is changed.]]
 
[[File:Ic_python_api_auto_focus_02.png|frame|left|DOF distance and range is calculated based on the selected object's distance and bounding size.  The DOF is recalculated when the selection is changed.]]
Line 11: Line 19:
 
== Course Prerequisites ==
 
== Course Prerequisites ==
  
You should be familiarize yourself with the following fundamental articles before you proceed:
+
You should familiarize yourself with the following fundamental articles before you proceed:
  
 
*[[ iC_Python_API:Stopwatch | Stopwatch ]]
 
*[[ iC_Python_API:Stopwatch | Stopwatch ]]
*[[ iC_Python_API:Object_Bounds | Object Bounds ]]
+
*[[ iC_Python_API:Bounding_Info | Bounding Info ]]
*[[ iC_Python_API:iClone_Linked_Controls | iClone Linked Controls ]]
+
*[[ iC_Python_API:Linked_Controls | Linked Controls ]]
*[[ iC_Python_API:Depth_of_Field | Depth of Field ]]
+
*[[ iC_Python_API:Blurry_Vision | Blurry Vision ]]
*[[ iC_Python_API:Transform_Space | Transform Space ]]
+
*[[ iC_Python_API:Align_to_Camera | Align to Camera ]]
  
 
== Takeaway Lessons ==
 
== Takeaway Lessons ==
  
 
*Calculate single axis distance between two object (useful for finding Z-depth).
 
*Calculate single axis distance between two object (useful for finding Z-depth).
*Create and setting DOF keys on cameras.
+
*Creating and setting camera DOF keys.
*Create timer and handling timer callbacks.
+
*Deploy timer and handling timer callbacks.
  
 
== Required Files ==
 
== Required Files ==
Line 29: Line 37:
 
*Auto-focus Python script
 
*Auto-focus Python script
 
*iClone scene with select-able props or characters.
 
*iClone scene with select-able props or characters.
 +
 +
You can download this plugin from the [https://marketplace.reallusion.com/camera-auto-focus Reallusion Marketplace]. 
 +
To acquire and view the source code, please visit [https://github.com/reallusion/iClone/tree/master/Camera_Auto_Focus Reallusion GitHub].
  
 
== Usage Instructions ==
 
== Usage Instructions ==
  
 
# Clone or download the Reallusion/iClone GitHub.
 
# Clone or download the Reallusion/iClone GitHub.
# Copy '''Auto-Focus''' folder into the iClone install directory > '''...\Bin64\OpenPlugin'''.   
+
# Copy '''Camera_Auto_Focus''' folder into the iClone install directory > '''...\Bin64\OpenPlugin'''.   
# Load the script into the project from the menu: '''Plugins > Python Samples > Auto-Focus'''.
+
# Load the script into the project from the menu: '''Plugins > Python Samples > Camera Auto-Focus'''.
 
# Follow the instructions in the subsequent dialog window.
 
# Follow the instructions in the subsequent dialog window.
  
Line 47: Line 58:
  
 
[[File:Ic_python_api_auto_focus_01.png]]
 
[[File:Ic_python_api_auto_focus_01.png]]
 +
 +
== APIs Used ==
 +
You can research the following references for the APIs deployed in this code.
 +
=== main.py ===
 +
<div style="column-count:4; -moz-column-count:4; -webkit-column-count:4">
 +
* [[ IC_Python_API:RLPy_RMatrix4 | RLPy.RMatrix4() ]]
 +
* [[ IC_Python_API:RLPy_REventCallback#__init__ | RLPy.REventCallback.__init__() ]]
 +
* [[ IC_Python_API:RLPy_RPyTimerCallback#__init__ | RLPy.RPyTimerCallback.__init__() ]]
 +
* [[ IC_Python_API:RLPy_RDialogCallback#__init__ | RLPy.RDialogCallback.__init__() ]]
 +
* [[ IC_Python_API:RLPy_REventHandler#UnregisterCallback | RLPy.REventHandler.UnregisterCallback() ]]
 +
* [[ IC_Python_API:RLPy_RScene#GetCurrentCamera | RLPy.RScene.GetCurrentCamera() ]]
 +
* [[ IC_Python_API:RLPy_RScene#GetSelectedObjects | RLPy.RScene.GetSelectedObjects() ]]
 +
* [[ IC_Python_API:RLPy_RVector3 | RLPy.RVector3() ]]
 +
* [[ IC_Python_API:RLPy_RKey | RLPy.RKey() ]]
 +
* [[ IC_Python_API:RLPy_RGlobal#GetTime | RLPy.RGlobal.GetTime() ]]
 +
* [[ IC_Python_API:RLPy_RPyTimer | RLPy.RPyTimer() ]]
 +
* [[ IC_Python_API:RLPy_REventHandler#RegisterCallback | RLPy.REventHandler.RegisterCallback() ]]
 +
* [[ IC_Python_API:RLPy_RUi#CreateRDockWidget | RLPy.RUi.CreateRDockWidget() ]]
 +
* [[ IC_Python_API:RLPy_RUi#GetMainWindow | RLPy.RUi.GetMainWindow() ]]
 +
* [[ IC_Python_API:RLPy_RUi#AddMenu | RLPy.RUi.AddMenu() ]]
 +
</div>

Latest revision as of 00:12, 19 October 2020

Main article: Python of the Month.

Demo Video

Description

Auto-Focus can be used to automatically calculate the DOF (Depth of Field) distance and range for the current camera according to the viewing distance of a selected object. This script operates and updates in near real-time.

DOF distance and range is calculated based on the selected object's distance and bounding size. The DOF is recalculated when the selection is changed.

Course Prerequisites

You should familiarize yourself with the following fundamental articles before you proceed:

Takeaway Lessons

  • Calculate single axis distance between two object (useful for finding Z-depth).
  • Creating and setting camera DOF keys.
  • Deploy timer and handling timer callbacks.

Required Files

  • Auto-focus Python script
  • iClone scene with select-able props or characters.

You can download this plugin from the Reallusion Marketplace. To acquire and view the source code, please visit Reallusion GitHub.

Usage Instructions

  1. Clone or download the Reallusion/iClone GitHub.
  2. Copy Camera_Auto_Focus folder into the iClone install directory > ...\Bin64\OpenPlugin.
  3. Load the script into the project from the menu: Plugins > Python Samples > Camera Auto-Focus.
  4. Follow the instructions in the subsequent dialog window.

Code Flow

  1. The current viewing camera is the currently driven camera.
  2. The current selection is the DOF target, the first item in multiple selection is designated as the target.
  3. Adjust the parameters such as Auto-Distance and Auto-Range toggle and multiplier.
  4. The z-distance between the target prop from the current viewing camera is calculated.
  5. DOF key is created taking into account the depth distance value and the parameter settings.
  6. The created DOF key is set on the current viewing camera in near real-time.

Ic python api auto focus 01.png

APIs Used

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

main.py