IC Python API:RLPy RTime
Contents
- 1 Description
- 2 Member Functions
- 2.1 __init__ ( self, args )
- 2.2 GetUnit ( self )
- 2.3 GetValue ( self )
- 2.4 SetUnit ( self, eUnit )
- 2.5 SetValue ( self, fValue )
- 2.6 AsUnits ( self, eUnit )
- 2.7 __eq__ ( self, rhs )
- 2.8 __ne__ ( self, rhs )
- 2.9 __le__ ( self, rhs )
- 2.10 __ge__ ( self, rhs )
- 2.11 __lt__ ( self, rhs )
- 2.12 __gt__ ( self, rhs )
- 2.13 __add__ ( self, args )
- 2.14 __iadd__ ( self, args )
- 2.15 __sub__ ( self, args )
- 2.16 __isub__ ( self, args )
- 2.17 __mul__ ( self, args )
- 2.18 __imul__ ( self, args )
- 2.19 __truediv__ ( self, args )
- 2.20 __itruediv__ ( self, args )
- 2.21 GetFrameIndex ( self, kTime, nFps )
- 2.22 IndexedFrameTime ( self, nFrameIndex, nFps )
- 2.23 GetFrameTime ( self, kTime, nFps )
- 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: 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: 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: 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: 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)