Difference between revisions of "IC Python API:RLPy RTime"

From Reallusion Wiki!
Jump to: navigation, search
m (GetFrameIndex)
m (GetFrameIndex)
Line 32: Line 32:
 
time = RLPy.RTime(3000)
 
time = RLPy.RTime(3000)
  
# Print the frame index at the 3 second mark which should be the 180the frame.
+
# Print the frame index at the 3 second mark which should be the 180th frame.
 
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps()))
 
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps()))
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 23:13, 14 January 2019

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.

Member Functions

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 which should be the 180th frame.
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps()))

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 time: 3000
print(frame_time.GetValue())

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.

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())

GetValue

def RLPy.RTime.GetValue(self)

Get the time in milliseconds for this RTime object.

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

Code:
import RLPy

#Print the current frame time 
time = RLPy.RGlobal.GetTime()
print(time.GetValue())