IC Python API:RLPy RTime

From Reallusion Wiki!
Revision as of 20:37, 17 January 2019 by Chuck (RL) (Talk | contribs) (Member Functions)

Jump to: navigation, search
Main article: System Module.

Class in RLPy / Inherits from: _object

Description

This class is used to hold and manipulate timing information.

Time is stored internally in system as milliseconds. Most API methods that require or return timing information do so through variables of this type. This class also provide methods to convert between Frame and RTime, such as GetFrameIndex() and IndexedFrameTime(). Use of GetFrameTime() can ensure that RTime is on the correct frame.

Operators

This class supports the mathematical operators.

Example of addition and subtraction:

import RLPy

time = RLPy.RTime(3000)
time += RLPy.RTime(1000)
time -= RLPy.RTime(1000)

# Functionally the same as:
time += 1000
time -= 1000

print(time.GetValue())

# 3000.0

Example of multiplication and division:

import RLPy

time = RLPy.RTime(3000)
time *= 2
time /= 2

# Functionaly the same as:
time = time * 2
time = time / 2

print(time.GetValue())

#3000.0

The following example demonstrates order of operation in action:

import RLPy

time = RLPy.RTime(1)
time = time + 3 * 2
print(time.GetValue())

time = RLPy.RTime(1)
time = time * 2 + 3
print(time.GetValue())

# 7.0
# 5.0

Member Functions

Function Syntax Description Examples
GetValue
def RLPy.RTime.GetValue(self)
Get the time in milliseconds for this RTime object.

The current frame time is indicated by the position of your play-head in the timeline.

The following example fetches the current frame time in milliseconds:

import RLPy

# Put the current frame time into a variable.
time = RLPy.RGlobal.GetTime()

# Return the current frame time in milliseconds.
print(time.GetValue())
SetValue
def RLPy.RTime.SetValue(self, fValue)
Set the value for the time object.

The following example creates a time object of 3 seconds then changes it to 100 ms.

import RLPy

time = RLPy.RTime(3000)
time.SetValue(100)

print(time.GetValue())

#100.0
GetFrameIndex
def RLPy.RTime.GetFrameIndex(kTime, nFps)
Convert the current time to frame index.

Since iClone is 60 frames per second, the return value is usually the time in seconds times 60.

The following example gives the frame index at the 3 second mark:

import RLPy

# Create a time object of 3 seconds.
time = RLPy.RTime(3000)

# Print the frame index at the 3 second mark.
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps()))

# 180
GetFrameTime
def RLPy.RTime.GetFrameTime(kTime, nFps)
Deduce the frame time from a time object.

The RTime object may not give a time that perfectly matches a frame. Call this function to get the closest frame time for a RTime object - not to be confused with frame index.

The following code retrieves the frame accurate time from a given time value:

import RLPy

# Construct time object that does not align perfectly with a frame.
time = RLPy.RTime(3005)

# Derive the nearest frame time from the RTime object.
frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps())

# Print the frame-aligned time in milliseconds.
print(frame_time.GetValue())

# 3000.0
IndexedFrameTime
def RLPy.RTime.IndexedFrameTime(nFrameindex, nFps)
Get the frame time from the frame index.

Since iClone runs 60 frames per second, the resultant time in milliseconds is the usually the frame count divided by 60 times 1000.

The following example returns the time in milliseconds to reach the 180th frame:

import RLPy

# Derive the frame time from the frame index
time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())

# 180th frame divided by 60 fps times 1000 ms should return 3000 ms.
print(time.GetValue())