Difference between revisions of "IC Python API:Linear Interpolation"

From Reallusion Wiki!
Jump to: navigation, search
(Created page with "This article will introduce the concept of linear interpolation and it's usefulness. This lesson will use linear interpolation to build a staircase and customize it with simp...")
 
m (Required Modules)
Line 9: Line 9:
 
import os
 
import os
 
import winreg
 
import winreg
</syntaxhighllight>
+
</syntaxhighlight>
  
 
== Linear Interpoloation (Lerp) Formula ==
 
== Linear Interpoloation (Lerp) Formula ==
Line 22: Line 22:
  
 
The '''interpolation''' value is always normalized for the size of the line i.e. it is always a value clamped between 0 and 1.
 
The '''interpolation''' value is always normalized for the size of the line i.e. it is always a value clamped between 0 and 1.
 +
 +
== Creating a Box Prop ==
 +
 +
We'll need to create a box prop for constructing the staircase.  This box prop will be used to construct the steps and the skirts (side panels) of the staircase.
 +
 +
<syntaxhighlight lang="Python">
 +
# Get the iClone 7 default template path
 +
registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
 +
rawKey = winreg.OpenKey(registry, r"SOFTWARE\Reallusion\iClone\7.0")
 +
ic_template_path = os.path.abspath(winreg.QueryValueEx(rawKey, "Template Data")[0])
 +
 +
# Load beveled Box.iProp and retrieve its control data block
 +
RLPy.RFileIO.LoadFile(ic_template_path + "//iClone Template//Props//3D Blocks//Beveled//Box.iProp")
 +
box = RLPy.RScene.FindObject(RLPy.EObjectType_Prop, "Box")
 +
box_control = box.GetControl("Transform")
 +
box_db = box_control.GetDataBlock()
 +
</syntaxhighlight>

Revision as of 23:02, 13 May 2019

This article will introduce the concept of linear interpolation and it's usefulness. This lesson will use linear interpolation to build a staircase and customize it with simple to understand attributes.

Required Modules

Besides the rudimentary iClone Python module, we'll also be using os and winreg as a means to import a box prop to build the staircase.

import RLPy
import os
import winreg

Linear Interpoloation (Lerp) Formula

In mathematics, linear interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points. Simply put, linear interpolation can be used to retrieve the location of point along a line. Programmatically, we can reduce the complexity of this formula to simply give us a value between two given values based on far along the line we proceed.

def lerp(value_a, value_b, interpolation):
    # Precise method, which guarantees v = v1 when t = 1
    return (1 - interpolation) * value_a + value_b * interpolation

The interpolation value is always normalized for the size of the line i.e. it is always a value clamped between 0 and 1.

Creating a Box Prop

We'll need to create a box prop for constructing the staircase. This box prop will be used to construct the steps and the skirts (side panels) of the staircase.

# Get the iClone 7 default template path
registry = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
rawKey = winreg.OpenKey(registry, r"SOFTWARE\Reallusion\iClone\7.0")
ic_template_path = os.path.abspath(winreg.QueryValueEx(rawKey, "Template Data")[0])

# Load beveled Box.iProp and retrieve its control data block
RLPy.RFileIO.LoadFile(ic_template_path + "//iClone Template//Props//3D Blocks//Beveled//Box.iProp")
box = RLPy.RScene.FindObject(RLPy.EObjectType_Prop, "Box")
box_control = box.GetControl("Transform")
box_db = box_control.GetDataBlock()