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

From Reallusion Wiki!
Jump to: navigation, search
m
m
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
== Detailed Description ==
+
{{last_modified}}
This class is used to hold and manipulate timing information.
+
 
Time is stored internally in system as milliseconds. Most API methods
+
== Description ==
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">
+
This class represents the midst unit (a.k.a unit of time) in animation.  Currently, it provides two states: milliseconds and 60FPS (frames per second). When you create an animation key, you'll need to set the value according to the incoming time. This class also provides different unit conversions such as '''GetFrameIndex()''', '''IndexedFrameTime()''', and '''GetFrameTime()''' to ensure that the time retrieved is alined with animation frames.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Get current time
 
time = RLPy.RGlobal.GetTime()
 
time = RLPy.RGlobal.GetTime()
+
# compare time
+
# Compare time
 
if time == RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
 
if time == RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
print("equal")
+
  print("equal")
else if time > RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
+
elif time > RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
print("greater")
+
  print("greater")
else if time < RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
+
elif time < RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
print("less")
+
  print("less")
+
# operator
+
# Operator 
 
time += RLPy.RTime(1000)
 
time += RLPy.RTime(1000)
 
time -= RLPy.RTime(1000)
 
time -= RLPy.RTime(1000)
 
time *= 2
 
time *= 2
 
time /= 2
 
time /= 2
+
# convert between Frame
+
# Convert between frame
 
time = RLPy.RTime(3000)
 
time = RLPy.RTime(3000)
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps())) # 180
+
frame_index = RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps())
+
print(frame_index)           # 180
 +
 
time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())
 
time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())
print(time.GetValue()) # 3000
+
print(time.GetValue())       # 3000
+
 
time = RLPy.RTime(3005)
 
time = RLPy.RTime(3005)
 
frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps())
 
frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps())
print(frame_time.GetValue()) # 3000
+
print(frame_time.GetValue()) # 3000
+
 
</syntaxhighlight>
 
</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;">
 
  
'''fValue''' [IN] a float value representing a time - float
+
== Member Functions ==
 +
 
 +
=== __init__ ( self, args ) ===
 +
 
 +
This operation creates an instance of an RTime object.
 +
 
 +
Currently provided units of time (RLPy.Unit):
  
'''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>
 
==Operators==
 
This class supports the following operators:
 
 
{| class="wikitable"
 
{| class="wikitable"
!Member
+
!Unit
!Operation
+
!Syntax
+
 
!Description
 
!Description
!Example
 
 
|-
 
|-
! scope="row"|__add__
+
|RLPy.kInvalid
|Addition
+
|Invalid value
|a + b
+
|Adds values on either side of the operator.
+
|a + b = 30
+
 
|-
 
|-
! scope="row"|__sub__
+
|RLPy.kHours
|Subtraction
+
|Not supported
|a - b
+
|Subtracts right hand operand from left hand operand.
+
|a – b = -10
+
 
|-
 
|-
! scope="row"|__mul__
+
|RLPy.kMinutes
|Multiplication
+
|Not supported
|a * b
+
|Multiplies values on either side of the operator.
+
|a * b = 200
+
 
|-
 
|-
! scope="row"|__truediv__
+
|RLPy.kSeconds
|Division
+
|Not supported
|a / b
+
|Divides left hand operand by right hand operand.
+
|b / a = 2
+
 
|-
 
|-
! scope="row"|__eq__
+
|RLPy.kMilliseconds
|Equality
+
|1000 units per second
|a == b
+
|If the values of two operands are equal, then the condition becomes true.
+
|(a == b) is not true.
+
 
|-
 
|-
! scope="row"|__ne__
+
|RLPy.k30FPS
|Difference
+
|Not supported
|a != b
+
|If values of two operands are not equal, then condition becomes true.
+
|(a != b) is true.
+
 
|-
 
|-
! scope="row"|__gt__
+
|RLPy.k60FPS
|Greater Than
+
|1 second equals 60 frames
|a > b
+
|If the value of left operand is greater than the value of right operand, then condition becomes true.
+
|(a > b) is not true.
+
 
|-
 
|-
! scope="row"|__lt__
+
|RLPy.kUserDef
|Less Than
+
|Not supported
|a < b
+
|If the value of left operand is less than the value of right operand, then condition becomes true.
+
|(a < b) is true.
+
|-
+
! scope="row"|__ge__
+
|Greater Than or Equal
+
|a >= b
+
|If the value of left operand is greater than or equal to the value of right operand, then condition becomes true.
+
|(a >= b) is not true.
+
|-
+
! scope="row"|__le__
+
|Less or Equal
+
|a <= b
+
|If the value of left operand is less than or equal to the value of right operand, then condition becomes true.
+
|(a <= b) is true.
+
|-
+
! scope="row"|__iadd__
+
|Addition (Inplace)
+
|a += b
+
|It adds right operand to the left operand and assign the result to left operand.
+
|c += a is equivalent to c = c + a
+
|-
+
! scope="row"|__isub__
+
|Subtraction (Inplace)
+
|a -= b
+
|It subtracts right operand from the left operand and assign the result to left operand.
+
|c -= a is equivalent to c = c - a
+
|-
+
! scope="row"|__imul__
+
|Multiply (Inplace)
+
|a *= b
+
|It multiplies right operand with the left operand and assign the result to left operand.
+
|c *= a is equivalent to c = c * a
+
|-
+
! scope="row"|__itruediv__
+
|Divide (Inplace)
+
|a /= b
+
|It divides left operand with the right operand and assign the result to left operand.
+
|c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a
+
 
|}
 
|}
==Member Functions==
+
 
===AsUnits===
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RTime.AsUnits ( self, eUnit )
+
# Constructor RTime object
 +
time1 = RLPy.RTime()
 +
 
 +
# Constructor RTime object with RTime object
 +
time2 = RLPy.RTime(time1)
 +
 
 +
# Constructor RTime object with float value and unit
 +
time3 = RLPy.RTime(0, RLPy.kMilliseconds)
 
</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
+
=== GetUnit ( self ) ===
*'''RLPy.kInvalid'''
+
 
*'''RLPy.kHours not support
+
Get the midst unit for the RTime object.
*'''RLPy.kMinutes not support
+
 
*'''RLPy.kSeconds not support
+
See Also: [[SetUnit|RLPy.RTime.SetUnit( self, eUnit )]]
*'''RLPy.kMilliseconds 1/1000 of a second
+
 
*'''RLPy.k30FPS not support
+
==== Returns ====
*'''RLPy.k60FPS 60 frames per second
+
:Midst unit of a given RTime object - RLPy.Unit
*'''RLPy.kUserDef not support
+
 
</div>
+
====Returns====
+
<div style="margin-left: 2em;">The current time value in the given units - float
+
</div>
+
-----
+
===GetFrameIndex===
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RTime.GetFrameIndex ( kTime, nFps )
+
# Get time unit
 +
time = RLPy.RTime(0, RLPy.kMilliseconds)
 +
time_unit = time.GetUnit()
 +
print(time_unit)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get frame index from frame time.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''kTime''' [IN] the time for this frame - RLPy.RTime
+
=== GetValue ( self ) ===
 +
 
 +
Get the time value of the RTime object.
 +
 
 +
See Also: [[SetValue|RLPy.RTime.SetValue( self, fValue )]]
 +
 
 +
==== Returns ====
 +
:Time value of the RTime object - float
  
'''nFps''' [IN] frames per second - int
 
</div>
 
====Returns====
 
<div style="margin-left: 2em;">The frame index - int
 
</div>
 
-----
 
===GetFrameTime===
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RTime.GetFrameTime ( kTime, nFps )
+
# Get time value
 +
time = RLPy.RTime(3000)
 +
time_value = time.GetValue()
 +
print(time_value)
 
</syntaxhighlight>
 
</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;">
 
  
'''kTime''' [IN] the time in an animation - RLPy.RTime
+
=== SetUnit ( self, eUnit ) ===
 +
 
 +
Set the midst unit for the RTime object.
 +
 
 +
See Also: [[GetUnit|RLPy.RTime.GetUnit( self )]]
 +
 
 +
==== Parameters ====
 +
:eUnit [IN] Midst unit - RLPy.Unit
  
'''nFps''' [IN] frames per second - int
 
</div>
 
====Returns====
 
<div style="margin-left: 2em;">The frame time - RLPy.RTime
 
</div>
 
-----
 
===GetUnit===
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RTime.GetUnit ( self )
+
# Set time unit
 +
time = RLPy.RTime(0)
 +
time.SetUnit(RLPy.k60FPS)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the unit of this RTime object.
+
 
====Returns====
+
=== SetValue ( self, fValue ) ===
<div style="margin-left: 2em;">The unit of this RTime object - RLPy.Unit
+
 
*'''RLPy.kInvalid'''
+
Set the time value for the RTime object.
*'''RLPy.kHours not support
+
 
*'''RLPy.kMinutes not support
+
See Also: [[GetValue|RLPy.RTime.GetValue( self )]]
*'''RLPy.kSeconds not support
+
 
*'''RLPy.kMilliseconds 1/1000 of a second
+
==== Parameters ====
*'''RLPy.k30FPS not support
+
:fValue [IN] Time value - float
*'''RLPy.k60FPS 60 frames per second
+
 
*'''RLPy.kUserDef not support
+
</div>
+
-----
+
===GetValue===
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RTime.GetValue ( self )
+
# Set time value
 +
time = RLPy.RTime(0)
 +
time.SetValue(3000)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the float value of this RTime object.
+
 
====Returns====
+
=== AsUnits ( self, eUnit ) ===
<div style="margin-left: 2em;">The float value of this RTime object - float
+
 
</div>
+
Convert the time value to a specified midst unit without changing it for the RTime object.
-----
+
 
===IndexedFrameTime===
+
==== Returns ====
 +
:The converted time value of the RTime object in the specified midst unit - float
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RTime.IndexedFrameTime ( nFrameIndex, nFps )
+
# As units milliseconds
 +
time = RLPy.RTime(2000)
 +
time_value = time.AsUnits(RLPy.kMilliseconds)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get frame time from frame index.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''nFrameIndex''' [IN] the frame index for this frame time - int
+
=== __eq__ ( self, rhs ) ===
 +
 
 +
RTime quivalence operator.
 +
 
 +
==== Parameters ====
 +
:rhs [IN] a reference to the RTime object for comparison.
 +
 
 +
==== Returns ====
 +
:If the values of the two RTime objects are equal return '''true''', otherwise return '''false'''.
  
'''nFps''' [IN] frames per second - int
 
</div>
 
====Returns====
 
<div style="margin-left: 2em;">The frame time - RLPy.RTime
 
</div>
 
-----
 
===SetUnit===
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RTime.SetUnit ( self, eUnit )
+
# Equivalence operator
 +
time1 = RLPy.RTime(3000)
 +
time2 = RLPy.RTime(3000)
 +
print(time1 == time2)
 
</syntaxhighlight>
 
</syntaxhighlight>
Set time unit.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''eUnit''' [IN] a time unit - RLPy.Unit
+
=== __ne__ ( self, rhs ) ===
*'''RLPy.kInvalid'''
+
 
*'''RLPy.kHours not support
+
RTime not equal operator.
*'''RLPy.kMinutes not support
+
 
*'''RLPy.kSeconds not support
+
==== Parameters ====
*'''RLPy.kMilliseconds 1/1000 of a second
+
:rhs [IN] a reference to the RTime object for comparison.
*'''RLPy.k30FPS not support
+
 
*'''RLPy.k60FPS 60 frames per second
+
==== Returns ====
*'''RLPy.kUserDef not support
+
:If the values of the two RTime objects are not equal return '''true''', otherwise return '''false'''.
</div>
+
 
-----
+
===SetValue===
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RTime.SetValue ( self, fValue )
+
# Not equal operator
 +
time1 = RLPy.RTime(3000)
 +
time2 = RLPy.RTime(3000, RLPy.k60FPS)
 +
print(time1 != time2)
 
</syntaxhighlight>
 
</syntaxhighlight>
Set the float value of a time.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''fValue''' [IN] a float value of a time - float
+
=== __le__ ( self, rhs ) ===
</div>
+
 
 +
RTime less than operator.
 +
 
 +
==== Parameters ====
 +
:rhs [IN] a reference to the RTime object for comparison.
 +
 
 +
==== Returns ====
 +
:If the value is less than or equal to the target RTime object (rhs) return '''true''', otherwise return '''false'''.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Less equal operator
 +
time1 = RLPy.RTime(1000)
 +
time2 = RLPy.RTime(2000)
 +
print(time1 <= time2)
 +
</syntaxhighlight>
 +
 
 +
=== __ge__ ( self, rhs ) ===
 +
 
 +
RTime greater or equal to operator.
 +
 
 +
==== Parameters ====
 +
:rhs [IN] a reference to the RTime object for comparison.
 +
 
 +
==== Returns ====
 +
:If the value is greater than or equal to the target RTime object (rhs) return '''true''', otherwise return '''false'''.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Less equal operator
 +
time1 = RLPy.RTime(2000)
 +
time2 = RLPy.RTime(1000)
 +
print(time1 >= time2)
 +
</syntaxhighlight>
 +
 
 +
=== __lt__ ( self, rhs ) ===
 +
 
 +
RTime less than operator.
 +
 
 +
==== Parameters ====
 +
:rhs [IN] a reference to the RTime object for comparison.
 +
 
 +
==== Returns ====
 +
:If the value is less than the target RTime object (rhs) return '''true''', otherwise return '''false'''.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Less than operator
 +
time1 = RLPy.RTime(1000)
 +
time2 = RLPy.RTime(3000)
 +
print(time1 < time2)
 +
</syntaxhighlight>
 +
 
 +
=== __gt__ ( self, rhs ) ===
 +
 
 +
RTime greater than operator.
 +
 
 +
==== Parameters ====
 +
:rhs [IN] a reference to the RTime object for comparison.
 +
 
 +
==== Returns ====
 +
:The value is greater than the target RTime object (rhs) return '''true''', otherwise return '''false'''.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Greater than operator
 +
time1 = RLPy.RTime(3000)
 +
time2 = RLPy.RTime(1000)
 +
print(time1 > time2)
 +
</syntaxhighlight>
 +
 
 +
=== __add__ ( self, args ) ===
 +
 
 +
RTime addition operator.
 +
 
 +
==== Parameters ====
 +
:args [IN] a reference to the added RTime object.
 +
 
 +
==== Returns ====
 +
:Sum of the two RTime objects.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Addition operator
 +
time1 = RLPy.RTime(1000)
 +
time2 = RLPy.RTime(2000)
 +
time3 = time1 + time2
 +
print(time3)
 +
</syntaxhighlight>
 +
 
 +
=== __iadd__ ( self, args ) ===
 +
 
 +
RTime addition assignment operator.
 +
 
 +
==== Parameters ====
 +
:args [IN] a reference to the addend RTime object.
 +
 
 +
==== Returns ====
 +
:Sum of the two RTime objects.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Addition assignment operator
 +
time1 = RLPy.RTime(1000)
 +
time2 = RLPy.RTime(3000)
 +
time1 += time2
 +
print(time1)
 +
</syntaxhighlight>
 +
 
 +
=== __sub__ ( self, args ) ===
 +
 
 +
RTime subtraction operator.
 +
 
 +
==== Parameters ====
 +
:args [IN] a reference to the minuend RTime object.
 +
 
 +
==== Returns ====
 +
:Difference of the two RTime objects.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Subtraction operator
 +
time1 = RLPy.RTime(1000)
 +
time2 = RLPy.RTime(2000)
 +
time3 = time2 - time1
 +
print(time3)
 +
</syntaxhighlight>
 +
 
 +
=== __isub__ ( self, args ) ===
 +
 
 +
RTime subtraction assignment operator.
 +
 
 +
==== Parameters ====
 +
:args [IN] a reference to the minuend RTime object.
 +
 
 +
==== Returns ====
 +
:Difference of the two RTime objects.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Subtraction assignment operator
 +
time1 = RLPy.RTime(1000)
 +
time2 = RLPy.RTime(3000)
 +
time2 -= time1
 +
print(time2)
 +
</syntaxhighlight>
 +
 
 +
=== __mul__ ( self, args ) ===
 +
 
 +
RTime multiplication operator.
 +
 
 +
==== Parameters ====
 +
:args [IN] a float value of multiplier.
 +
 
 +
==== Returns ====
 +
:RTime object with the multiplied value.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Multiplication operator
 +
time1 = RLPy.RTime(100.0)
 +
time2 = time1 * 0.5
 +
print(time2)
 +
</syntaxhighlight>
 +
 
 +
=== __imul__ ( self, args ) ===
 +
 
 +
RTime multiplication assignment operator.
 +
 
 +
==== Parameters ====
 +
:args [IN] a float value as the multiplier.
 +
 
 +
==== Returns ====
 +
:RTime object with the product value.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Multiplication assignment operator
 +
time1 = RLPy.RTime(200.0)
 +
time1 *= 1.5
 +
print(time1)
 +
</syntaxhighlight>
 +
 
 +
=== __truediv__ ( self, args ) ===
 +
 
 +
RTime division operator.
 +
 
 +
==== Parameters ====
 +
:args [IN] a float value as the divisor.
 +
 
 +
==== Returns ====
 +
:RTime object with the quotient value.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Division operator
 +
time1 = RLPy.RTime(3000)
 +
time2 = time1 / 150
 +
print(time2)
 +
</syntaxhighlight>
 +
 
 +
=== __itruediv__ ( self, args ) ===
 +
 
 +
RTime division assignment operator.
 +
 
 +
==== Parameters ====
 +
:args [IN] a float value as the divisor.
 +
 
 +
==== Returns ====
 +
:RTime object with the quotient value.
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Division assignment operator
 +
time1 = RLPy.RTime(3000.0)
 +
time1 /= 15
 +
print(time1)
 +
</syntaxhighlight>
 +
 
 +
=== GetFrameIndex ( self, kTime, nFps ) ===
 +
 
 +
Get the frame index of a given time based on a specified FPS.
 +
 
 +
==== Parameters ====
 +
:nFps [IN] frames per second - int
 +
 
 +
==== Returns ====
 +
:The corresponding frame index - int
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Get frame index
 +
frame_index = RLPy.RTime.GetFrameIndex(RLPy.RTime(3000.0), 60)
 +
print(frame_index)
 +
</syntaxhighlight>
 +
 
 +
=== IndexedFrameTime ( self, nFrameIndex, nFps ) ===
 +
 
 +
Get the RTime of a given frame index based on a specified FPS.
 +
 
 +
==== Parameters ====
 +
:nFrameIndex [IN] input frame index - int
 +
:nFps [IN] frames per second - int
 +
 
 +
==== Returns ====
 +
:The corresponding RTime - RLPy.RTime
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Get indexed frame time
 +
frame_time = RLPy.RTime.IndexedFrameTime(180, 60)
 +
print(frame_time)
 +
</syntaxhighlight>
 +
 
 +
=== GetFrameTime ( self, kTime, nFps ) ===
 +
 
 +
Checks if the input time falls on a specific frame based on the input FPS.  If the time does not match up correctly with any frame, then return the time of the nearest frame.  This ensures that the return value will always align to a specific animation frame.
 +
 
 +
==== Parameters ====
 +
:kTime [IN] animation time - RLPy.RTime
 +
:nFps [IN] frames per second - int
 +
 
 +
==== Returns ====
 +
:The corresponding RTime - RLPy.RTime
 +
 
 +
<syntaxhighlight lang="Python">
 +
# Get frame time
 +
frame_time = RLPy.RTime.GetFrameTime(RLPy.RTime(3002), 60)
 +
print(time2)
 +
</syntaxhighlight>

Revision as of 02:39, 19 March 2020

Main article: Modules.
Last modified: 03/19/2020

Description

This class represents the midst unit (a.k.a unit of time) in animation. Currently, it provides two states: milliseconds and 60FPS (frames per second). When you create an animation key, you'll need to set the value according to the incoming time. This class also provides different unit conversions such as GetFrameIndex(), IndexedFrameTime(), and GetFrameTime() to ensure that the time retrieved is alined with animation frames.

# Get current time
time = RLPy.RGlobal.GetTime()
 
# Compare time
if time == RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
   print("equal")
elif time > RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
   print("greater")
elif 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)
frame_index = RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps())
print(frame_index)            # 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

Member Functions

__init__ ( self, args )

This operation creates an instance of an RTime object.

Currently provided units of time (RLPy.Unit):

Unit Description
RLPy.kInvalid Invalid value
RLPy.kHours Not supported
RLPy.kMinutes Not supported
RLPy.kSeconds Not supported
RLPy.kMilliseconds 1000 units per second
RLPy.k30FPS Not supported
RLPy.k60FPS 1 second equals 60 frames
RLPy.kUserDef Not supported
# Constructor RTime object
time1 = RLPy.RTime()

# Constructor RTime object with RTime object
time2 = RLPy.RTime(time1)

# Constructor RTime object with float value and unit
time3 = RLPy.RTime(0, RLPy.kMilliseconds)

GetUnit ( self )

Get the midst unit for the RTime object.

See Also: RLPy.RTime.SetUnit( self, eUnit )

Returns

Midst unit of a given RTime object - RLPy.Unit
# Get time unit
time = RLPy.RTime(0, RLPy.kMilliseconds)
time_unit = time.GetUnit()
print(time_unit)

GetValue ( self )

Get the time value of the RTime object.

See Also: RLPy.RTime.SetValue( self, fValue )

Returns

Time value of the RTime object - float
# Get time value
time = RLPy.RTime(3000)
time_value = time.GetValue()
print(time_value)

SetUnit ( self, eUnit )

Set the midst unit for the RTime object.

See Also: RLPy.RTime.GetUnit( self )

Parameters

eUnit [IN] Midst unit - RLPy.Unit
# Set time unit
time = RLPy.RTime(0)
time.SetUnit(RLPy.k60FPS)

SetValue ( self, fValue )

Set the time value for the RTime object.

See Also: RLPy.RTime.GetValue( self )

Parameters

fValue [IN] Time value - float
# Set time value
time = RLPy.RTime(0)
time.SetValue(3000)

AsUnits ( self, eUnit )

Convert the time value to a specified midst unit without changing it for the RTime object.

Returns

The converted time value of the RTime object in the specified midst unit - float
# As units milliseconds
time = RLPy.RTime(2000)
time_value = time.AsUnits(RLPy.kMilliseconds)

__eq__ ( self, rhs )

RTime quivalence operator.

Parameters

rhs [IN] a reference to the RTime object for comparison.

Returns

If the values of the two RTime objects are equal return true, otherwise return false.
# Equivalence operator
time1 = RLPy.RTime(3000)
time2 = RLPy.RTime(3000)
print(time1 == time2)

__ne__ ( self, rhs )

RTime not equal operator.

Parameters

rhs [IN] a reference to the RTime object for comparison.

Returns

If the values of the two RTime objects are not equal return true, otherwise return false.
# Not equal operator
time1 = RLPy.RTime(3000)
time2 = RLPy.RTime(3000, RLPy.k60FPS)
print(time1 != time2)

__le__ ( self, rhs )

RTime less than operator.

Parameters

rhs [IN] a reference to the RTime object for comparison.

Returns

If the value is less than or equal to the target RTime object (rhs) return true, otherwise return false.
# Less equal operator
time1 = RLPy.RTime(1000)
time2 = RLPy.RTime(2000)
print(time1 <= time2)

__ge__ ( self, rhs )

RTime greater or equal to operator.

Parameters

rhs [IN] a reference to the RTime object for comparison.

Returns

If the value is greater than or equal to the target RTime object (rhs) return true, otherwise return false.
# Less equal operator
time1 = RLPy.RTime(2000)
time2 = RLPy.RTime(1000)
print(time1 >= time2)

__lt__ ( self, rhs )

RTime less than operator.

Parameters

rhs [IN] a reference to the RTime object for comparison.

Returns

If the value is less than the target RTime object (rhs) return true, otherwise return false.
# Less than operator
time1 = RLPy.RTime(1000)
time2 = RLPy.RTime(3000)
print(time1 < time2)

__gt__ ( self, rhs )

RTime greater than operator.

Parameters

rhs [IN] a reference to the RTime object for comparison.

Returns

The value is greater than the target RTime object (rhs) return true, otherwise return false.
# Greater than operator
time1 = RLPy.RTime(3000)
time2 = RLPy.RTime(1000)
print(time1 > time2)

__add__ ( self, args )

RTime addition operator.

Parameters

args [IN] a reference to the added RTime object.

Returns

Sum of the two RTime objects.
# Addition operator
time1 = RLPy.RTime(1000)
time2 = RLPy.RTime(2000)
time3 = time1 + time2
print(time3)

__iadd__ ( self, args )

RTime addition assignment operator.

Parameters

args [IN] a reference to the addend RTime object.

Returns

Sum of the two RTime objects.
# Addition assignment operator
time1 = RLPy.RTime(1000)
time2 = RLPy.RTime(3000)
time1 += time2
print(time1)

__sub__ ( self, args )

RTime subtraction operator.

Parameters

args [IN] a reference to the minuend RTime object.

Returns

Difference of the two RTime objects.
# Subtraction operator
time1 = RLPy.RTime(1000)
time2 = RLPy.RTime(2000)
time3 = time2 - time1
print(time3)

__isub__ ( self, args )

RTime subtraction assignment operator.

Parameters

args [IN] a reference to the minuend RTime object.

Returns

Difference of the two RTime objects.
# Subtraction assignment operator
time1 = RLPy.RTime(1000)
time2 = RLPy.RTime(3000)
time2 -= time1
print(time2)

__mul__ ( self, args )

RTime multiplication operator.

Parameters

args [IN] a float value of multiplier.

Returns

RTime object with the multiplied value.
# Multiplication operator
time1 = RLPy.RTime(100.0)
time2 = time1 * 0.5
print(time2)

__imul__ ( self, args )

RTime multiplication assignment operator.

Parameters

args [IN] a float value as the multiplier.

Returns

RTime object with the product value.
# Multiplication assignment operator
time1 = RLPy.RTime(200.0)
time1 *= 1.5
print(time1)

__truediv__ ( self, args )

RTime division operator.

Parameters

args [IN] a float value as the divisor.

Returns

RTime object with the quotient value.
# Division operator
time1 = RLPy.RTime(3000)
time2 = time1 / 150
print(time2)

__itruediv__ ( self, args )

RTime division assignment operator.

Parameters

args [IN] a float value as the divisor.

Returns

RTime object with the quotient value.
# Division assignment operator
time1 = RLPy.RTime(3000.0)
time1 /= 15
print(time1)

GetFrameIndex ( self, kTime, nFps )

Get the frame index of a given time based on a specified FPS.

Parameters

nFps [IN] frames per second - int

Returns

The corresponding frame index - int
# Get frame index
frame_index = RLPy.RTime.GetFrameIndex(RLPy.RTime(3000.0), 60)
print(frame_index)

IndexedFrameTime ( self, nFrameIndex, nFps )

Get the RTime of a given frame index based on a specified FPS.

Parameters

nFrameIndex [IN] input frame index - int
nFps [IN] frames per second - int

Returns

The corresponding RTime - RLPy.RTime
# Get indexed frame time
frame_time = RLPy.RTime.IndexedFrameTime(180, 60)
print(frame_time)

GetFrameTime ( self, kTime, nFps )

Checks if the input time falls on a specific frame based on the input FPS. If the time does not match up correctly with any frame, then return the time of the nearest frame. This ensures that the return value will always align to a specific animation frame.

Parameters

kTime [IN] animation time - RLPy.RTime
nFps [IN] frames per second - int

Returns

The corresponding RTime - RLPy.RTime
# Get frame time
frame_time = RLPy.RTime.GetFrameTime(RLPy.RTime(3002), 60)
print(time2)