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

From Reallusion Wiki!
Jump to: navigation, search
m (Member Functions)
m
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
{{Parent|IC_Python_API:RL_Python_Modules#System|System Module}}
+
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
+
== Detailed Description ==
Class in RLPy / Inherits from: _object
+
 
+
== Description ==
+
 
+
 
This class is used to hold and manipulate timing information.
 
This class is used to hold and manipulate timing information.
 
+
Time is stored internally in system as milliseconds. Most API methods
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.
+
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 GetFrameTime() can ensure that RTime is on the correct frame. <syntaxhighlight lang="Python">
== Operators ==
+
time = RLPy.RGlobal.GetTime()
 
+
This class supports the mathematical operators.
+
# compare time
 
+
if time == RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
<div class="toccolours mw-collapsible mw-collapsed">
+
  print("equal")
Example of addition and subtraction:
+
else if time > RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
<div class="mw-collapsible-content">
+
  print("greater")
<syntaxhighlight lang="Python">
+
else if time < RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
import RLPy
+
  print("less")
 
+
time = RLPy.RTime(3000)
+
# operator
 
time += RLPy.RTime(1000)
 
time += RLPy.RTime(1000)
 
time -= RLPy.RTime(1000)
 
time -= RLPy.RTime(1000)
 +
time *= 2
 +
time /= 2
 +
 +
# convert between Frame
 +
time = RLPy.RTime(3000)
 +
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps())) # 180
 +
 +
time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())
 +
print(time.GetValue()) # 3000
 +
 +
time = RLPy.RTime(3005)
 +
frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps())
 +
print(frame_time.GetValue()) # 3000
 +
 +
</syntaxhighlight>
 +
==Constructor & Destructors==
 +
===__init__===
 +
<syntaxhighlight lang="Python">
 +
RLPy.RTime.__init__ ( self, args )
 +
</syntaxhighlight>
 +
Constructor, Initialize a new RTime object with a float value and an unit.
 +
====Parameters====
 +
<div style="margin-left: 2em;">
  
# Functionally the same as:
+
'''fValue''' [IN] a float value representing a time - float
time += 1000
+
time -= 1000
+
  
print(time.GetValue())
+
'''eUnit''' [IN] a time unit - RLPy.Unit
 
+
*'''RLPy.kInvalid'''
# 3000.0
+
*'''RLPy.kHours not support
 +
*'''RLPy.kMinutes not support
 +
*'''RLPy.kSeconds not support
 +
*'''RLPy.kMilliseconds 1/1000 of a second
 +
*'''RLPy.k30FPS not support
 +
*'''RLPy.k60FPS 60 frames per second
 +
*'''RLPy.kUserDef not support
 +
</div>
 +
==Member Functions==
 +
===AsUnits===
 +
<syntaxhighlight lang="Python">
 +
RLPy.RTime.AsUnits ( self, eUnit )
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
Returns the current time value in the given units.
 +
This does not affect the current units for the instance.
 +
====Parameters====
 +
<div style="margin-left: 2em;">
 +
 +
'''eUnit''' [IN] a time unit - RLPy.Unit
 +
*'''RLPy.kInvalid'''
 +
*'''RLPy.kHours not support
 +
*'''RLPy.kMinutes not support
 +
*'''RLPy.kSeconds not support
 +
*'''RLPy.kMilliseconds 1/1000 of a second
 +
*'''RLPy.k30FPS not support
 +
*'''RLPy.k60FPS 60 frames per second
 +
*'''RLPy.kUserDef not support
 
</div>
 
</div>
 +
====Returns====
 +
<div style="margin-left: 2em;">The current time value in the given units - float
 
</div>
 
</div>
 
+
-----
<div class="toccolours mw-collapsible mw-collapsed">
+
===GetFrameIndex===
Example of multiplication and division:
+
<div class="mw-collapsible-content">
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
import RLPy
+
RLPy.RTime.GetFrameIndex ( kTime, nFps )
 +
</syntaxhighlight>
 +
Get frame index from frame time.
 +
====Parameters====
 +
<div style="margin-left: 2em;">
  
time = RLPy.RTime(3000)
+
'''kTime''' [IN] the time for this frame - RLPy.RTime
time *= 2
+
time /= 2
+
  
# Functionaly the same as:
+
'''nFps''' [IN] frames per second - int
time = time * 2
+
time = time / 2
+
 
+
print(time.GetValue())
+
 
+
#3000.0
+
</syntaxhighlight>
+
 
</div>
 
</div>
 +
====Returns====
 +
<div style="margin-left: 2em;">The frame index - int
 
</div>
 
</div>
 
+
-----
<div class="toccolours mw-collapsible mw-collapsed">
+
===GetFrameTime===
The following example demonstrates order of operation in action:
+
<div class="mw-collapsible-content">
+
 
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
import RLPy
+
RLPy.RTime.GetFrameTime ( kTime, nFps )
 +
</syntaxhighlight>
 +
Get frame time from a time.
 +
The time of a RTime object may not located exactly on a frame. Call this function to get the closest frame time for this RTime object.
 +
====Parameters====
 +
<div style="margin-left: 2em;">
  
time = RLPy.RTime(1)
+
'''kTime''' [IN] the time in an animation - RLPy.RTime
time = time + 3 * 2
+
print(time.GetValue())
+
  
time = RLPy.RTime(1)
+
'''nFps''' [IN] frames per second - int
time = time * 2 + 3
+
print(time.GetValue())
+
 
+
# 7.0
+
# 5.0
+
</syntaxhighlight>
+
 
</div>
 
</div>
 +
====Returns====
 +
<div style="margin-left: 2em;">The frame time - RLPy.RTime
 
</div>
 
</div>
 
+
-----
== Member Functions ==
+
===GetUnit===
 
+
{|class = "wikitable" style="width:100%"
+
!Function
+
!Syntax
+
!Description
+
!Examples
+
|-
+
!GetValue
+
|<syntaxhighlight lang="Python">
+
def RLPy.RTime.GetValue(self)
+
</syntaxhighlight>
+
|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.
+
|<div class="toccolours mw-collapsible mw-collapsed">
+
The following example fetches the current frame time in milliseconds:
+
<div class="mw-collapsible-content">
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
import RLPy
+
RLPy.RTime.GetUnit ( self )
 
+
# Put the current frame time into a variable.
+
time = RLPy.RGlobal.GetTime()
+
 
+
# Return the current frame time in milliseconds.
+
print(time.GetValue())
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
Get the unit of this RTime object.
 +
====Returns====
 +
<div style="margin-left: 2em;">The unit of this RTime object - RLPy.Unit
 +
*'''RLPy.kInvalid'''
 +
*'''RLPy.kHours not support
 +
*'''RLPy.kMinutes not support
 +
*'''RLPy.kSeconds not support
 +
*'''RLPy.kMilliseconds 1/1000 of a second
 +
*'''RLPy.k30FPS not support
 +
*'''RLPy.k60FPS 60 frames per second
 +
*'''RLPy.kUserDef not support
 
</div>
 
</div>
</div>
+
-----
|-
+
===GetValue===
!SetValue
+
|<syntaxhighlight lang="Python">
+
def RLPy.RTime.SetValue(self, fValue)
+
</syntaxhighlight>
+
|Set the value for the time object.
+
|<div class="toccolours mw-collapsible mw-collapsed">
+
The following example creates a time object of 3 seconds then changes it to 100 ms.
+
<div class="mw-collapsible-content">
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
import RLPy
+
RLPy.RTime.GetValue ( self )
 
+
time = RLPy.RTime(3000)
+
time.SetValue(100)
+
 
+
print(time.GetValue())
+
 
+
#100.0
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
Get the float value of this RTime object.
 +
====Returns====
 +
<div style="margin-left: 2em;">The float value of this RTime object - float
 
</div>
 
</div>
</div>
+
-----
|-
+
===IndexedFrameTime===
!GetFrameIndex
+
<syntaxhighlight lang="Python">
|<syntaxhighlight lang="Python">
+
RLPy.RTime.IndexedFrameTime ( nFrameIndex, nFps )
def RLPy.RTime.GetFrameIndex(kTime, nFps)
+
 
</syntaxhighlight>
 
</syntaxhighlight>
|Convert the current time to frame index.
+
Get frame time from frame index.
Since iClone is 60 frames per second, the return value is usually the time in seconds times 60.
+
====Parameters====
|<div class="toccolours mw-collapsible mw-collapsed">
+
<div style="margin-left: 2em;">
The following example gives the frame index at the 3 second mark:
+
<div class="mw-collapsible-content">
+
<syntaxhighlight lang="Python">
+
import RLPy
+
  
# Create a time object of 3 seconds.
+
'''nFrameIndex''' [IN] the frame index for this frame time - int
time = RLPy.RTime(3000)
+
  
# Print the frame index at the 3 second mark.
+
'''nFps''' [IN] frames per second - int
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps()))
+
 
+
# 180
+
</syntaxhighlight>
+
 
</div>
 
</div>
 +
====Returns====
 +
<div style="margin-left: 2em;">The frame time - RLPy.RTime
 
</div>
 
</div>
|-
+
-----
!GetFrameTime
+
===SetUnit===
|<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="Python">
def RLPy.RTime.GetFrameTime(kTime, nFps)
+
RLPy.RTime.SetUnit ( self, eUnit )
 
</syntaxhighlight>
 
</syntaxhighlight>
|Deduce the frame time from a time object.
+
Set time unit.
The RTime object may not give a time that perfectly matches a frame.
+
====Parameters====
Call this function to get the closest frame time for a RTime object - not to be confused with frame index.
+
<div style="margin-left: 2em;">
|<div class="toccolours mw-collapsible mw-collapsed">
+
The following code retrieves the frame accurate time from a given time value:
+
<div class="mw-collapsible-content">
+
<syntaxhighlight lang="Python">
+
import RLPy
+
  
# Construct time object that does not align perfectly with a frame.
+
'''eUnit''' [IN] a time unit - RLPy.Unit
time = RLPy.RTime(3005)
+
*'''RLPy.kInvalid'''
 
+
*'''RLPy.kHours not support
# Derive the nearest frame time from the RTime object.
+
*'''RLPy.kMinutes not support
frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps())
+
*'''RLPy.kSeconds not support
 
+
*'''RLPy.kMilliseconds 1/1000 of a second
# Print the frame-aligned time in milliseconds.
+
*'''RLPy.k30FPS not support
print(frame_time.GetValue())
+
*'''RLPy.k60FPS 60 frames per second
 
+
*'''RLPy.kUserDef not support
# 3000.0
+
</syntaxhighlight>
+
 
</div>
 
</div>
</div>
+
-----
|-
+
===SetValue===
!IndexedFrameTime
+
<syntaxhighlight lang="Python">
|<syntaxhighlight lang="Python">
+
RLPy.RTime.SetValue ( self, fValue )
def RLPy.RTime.IndexedFrameTime(nFrameindex, nFps)
+
 
</syntaxhighlight>
 
</syntaxhighlight>
|Get the frame time from the frame index.  
+
Set the float value of a time.
Since iClone runs 60 frames per second, the resultant time in milliseconds is the usually the frame count divided by 60 times 1000.
+
====Parameters====
|<div class="toccolours mw-collapsible mw-collapsed">
+
<div style="margin-left: 2em;">
The following example returns the time in milliseconds to reach the 180th frame:
+
<div class="mw-collapsible-content">
+
<syntaxhighlight lang="Python">
+
import RLPy
+
  
# Derive the frame time from the frame index
+
'''fValue''' [IN] a float value of a time - float
time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())
+
 
+
# 180th frame divided by 60 fps times 1000 ms should return 3000 ms.
+
print(time.GetValue())
+
</syntaxhighlight>
+
</div>
+
 
</div>
 
</div>
|}
 

Revision as of 03:00, 26 March 2019

Main article: Modules.

Detailed 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 GetFrameTime() can ensure that RTime is on the correct frame.
time = RLPy.RGlobal.GetTime()

# compare time
if time == RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
 print("equal")
else if time > RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
 print("greater")
else if time < RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
 print("less")

# operator
time += RLPy.RTime(1000)
time -= RLPy.RTime(1000)
time *= 2
time /= 2

# convert between Frame
time = RLPy.RTime(3000)
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps())) # 180

time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())
print(time.GetValue()) # 3000

time = RLPy.RTime(3005)
frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps())
print(frame_time.GetValue()) # 3000

Constructor & Destructors

__init__

RLPy.RTime.__init__ ( self, args )

Constructor, Initialize a new RTime object with a float value and an unit.

Parameters

fValue [IN] a float value representing a time - float

eUnit [IN] a time unit - RLPy.Unit

  • RLPy.kInvalid
  • RLPy.kHours not support
  • RLPy.kMinutes not support
  • RLPy.kSeconds not support
  • RLPy.kMilliseconds 1/1000 of a second
  • RLPy.k30FPS not support
  • RLPy.k60FPS 60 frames per second
  • RLPy.kUserDef not support

Member Functions

AsUnits

RLPy.RTime.AsUnits ( self, eUnit )

Returns the current time value in the given units. This does not affect the current units for the instance.

Parameters

eUnit [IN] a time unit - RLPy.Unit

  • RLPy.kInvalid
  • RLPy.kHours not support
  • RLPy.kMinutes not support
  • RLPy.kSeconds not support
  • RLPy.kMilliseconds 1/1000 of a second
  • RLPy.k30FPS not support
  • RLPy.k60FPS 60 frames per second
  • RLPy.kUserDef not support

Returns

The current time value in the given units - float

GetFrameIndex

RLPy.RTime.GetFrameIndex ( kTime, nFps )

Get frame index from frame time.

Parameters

kTime [IN] the time for this frame - RLPy.RTime

nFps [IN] frames per second - int

Returns

The frame index - int

GetFrameTime

RLPy.RTime.GetFrameTime ( kTime, nFps )

Get frame time from a time. The time of a RTime object may not located exactly on a frame. Call this function to get the closest frame time for this RTime object.

Parameters

kTime [IN] the time in an animation - RLPy.RTime

nFps [IN] frames per second - int

Returns

The frame time - RLPy.RTime

GetUnit

RLPy.RTime.GetUnit ( self )

Get the unit of this RTime object.

Returns

The unit of this RTime object - RLPy.Unit
  • RLPy.kInvalid
  • RLPy.kHours not support
  • RLPy.kMinutes not support
  • RLPy.kSeconds not support
  • RLPy.kMilliseconds 1/1000 of a second
  • RLPy.k30FPS not support
  • RLPy.k60FPS 60 frames per second
  • RLPy.kUserDef not support

GetValue

RLPy.RTime.GetValue ( self )

Get the float value of this RTime object.

Returns

The float value of this RTime object - float

IndexedFrameTime

RLPy.RTime.IndexedFrameTime ( nFrameIndex, nFps )

Get frame time from frame index.

Parameters

nFrameIndex [IN] the frame index for this frame time - int

nFps [IN] frames per second - int

Returns

The frame time - RLPy.RTime

SetUnit

RLPy.RTime.SetUnit ( self, eUnit )

Set time unit.

Parameters

eUnit [IN] a time unit - RLPy.Unit

  • RLPy.kInvalid
  • RLPy.kHours not support
  • RLPy.kMinutes not support
  • RLPy.kSeconds not support
  • RLPy.kMilliseconds 1/1000 of a second
  • RLPy.k30FPS not support
  • RLPy.k60FPS 60 frames per second
  • RLPy.kUserDef not support

SetValue

RLPy.RTime.SetValue ( self, fValue )

Set the float value of a time.

Parameters

fValue [IN] a float value of a time - float