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

From Reallusion Wiki!
Jump to: navigation, search
m (GetFrameIndex)
m
(48 intermediate revisions by the same user not shown)
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">
== Member Functions ==
+
time = RLPy.RGlobal.GetTime()
 
+
{{Collapse|
+
# compare time
=== GetFrameIndex ===
+
if time == RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
|
+
  print("equal")
{{Input|def RLPy.RTime.GetFrameIndex(kTime, nFps)}}
+
else if time > RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
 
+
  print("greater")
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.
+
else if time < RLPy.RGlobal.SetTime(RLPy.RTime(1000)):
 
+
  print("less")
The following example gives the frame index at the 3 second mark.
+
 
+
# operator
{{Code|<nowiki>
+
time += RLPy.RTime(1000)
import RLPy
+
time -= RLPy.RTime(1000)
 
+
time *= 2
#create a time object of 3 seconds
+
time /= 2
 +
 +
# convert between Frame
 
time = RLPy.RTime(3000)
 
time = RLPy.RTime(3000)
 
+
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps())) # 180
#print the frame index at the 3 second mark: 180
+
print(RLPy.RTime.GetFrameIndex(time, RLPy.RGlobal.GetFps()))
+
time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())
</nowiki>}}
+
print(time.GetValue()) # 3000
}}
+
 
+
=== GetFrameTime ===
+
 
+
{{Input|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.
+
 
+
{{Code|<nowiki>
+
import RLPy
+
 
+
#Construct time object that does not align perfectly with a frame.
+
 
time = RLPy.RTime(3005)
 
time = RLPy.RTime(3005)
 
#Derive the nearest frame time from the RTime object.
 
 
frame_time = RLPy.RTime.GetFrameTime(time, RLPy.RGlobal.GetFps())
 
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;">
  
#Print the frame time: 3000
+
'''fValue''' [IN] a float value representing a time - float
print(frame_time.GetValue())     
+
</nowiki>
+
}}
+
  
===IndexedFrameTime===
+
'''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"
 +
!Member
 +
!Operation
 +
!Syntax
 +
!Description
 +
!Example
 +
|-
 +
! scope="row"|__add__
 +
|Addition
 +
|a + b
 +
|Adds values on either side of the operator.
 +
|a + b = 30
 +
|-
 +
! scope="row"|__sub__
 +
|Subtraction
 +
|a - b
 +
|Subtracts right hand operand from left hand operand.
 +
|a – b = -10
 +
|-
 +
! scope="row"|__mul__
 +
|Multiplication
 +
|a * b
 +
|Multiplies values on either side of the operator.
 +
|a * b = 200
 +
|-
 +
! scope="row"|__truediv__
 +
|Division
 +
|a / b
 +
|Divides left hand operand by right hand operand.
 +
|b / a = 2
 +
|-
 +
! scope="row"|__eq__
 +
|Equality
 +
|a == b
 +
|If the values of two operands are equal, then the condition becomes true.
 +
|(a == b) is not true.
 +
|-
 +
! scope="row"|__ne__
 +
|Difference
 +
|a != b
 +
|If values of two operands are not equal, then condition becomes true.
 +
|(a != b) is true.
 +
|-
 +
! scope="row"|__gt__
 +
|Greater Than
 +
|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__
 +
|Less Than
 +
|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">
 +
RLPy.RTime.AsUnits ( self, eUnit )
 +
</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;">
  
{{Input|
+
'''eUnit''' [IN] a time unit - RLPy.Unit
def RLPy.RTime.IndexedFrameTime(nFrameindex,nFps)
+
*'''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>
 +
====Returns====
 +
<div style="margin-left: 2em;">The current time value in the given units - float
 +
</div>
 +
-----
 +
===GetFrameIndex===
 +
<syntaxhighlight lang="Python">
 +
RLPy.RTime.GetFrameIndex ( kTime, nFps )
 +
</syntaxhighlight>
 +
Get frame index from frame time.
 +
====Parameters====
 +
<div style="margin-left: 2em;">
  
Get the frame time from the frame index.  
+
'''kTime''' [IN] the time for this frame - RLPy.RTime
  
Since iClone runs 60 frames per second, the resultant time in milliseconds is the usually the frame count divided by 60 times 1000.
+
'''nFps''' [IN] frames per second - int
 +
</div>
 +
====Returns====
 +
<div style="margin-left: 2em;">The frame index - int
 +
</div>
 +
-----
 +
===GetFrameTime===
 +
<syntaxhighlight lang="Python">
 +
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;">
  
{{Code|<nowiki>
+
'''kTime''' [IN] the time in an animation - RLPy.RTime
import RLPy
+
 
+
#Derive the frame time from the frame index: 3000 (ms)
+
time = RLPy.RTime.IndexedFrameTime(180, RLPy.RGlobal.GetFps())
+
print(time.GetValue())
+
</nowiki>}}
+
  
 +
'''nFps''' [IN] frames per second - int
 +
</div>
 +
====Returns====
 +
<div style="margin-left: 2em;">The frame time - RLPy.RTime
 +
</div>
 +
-----
 +
===GetUnit===
 +
<syntaxhighlight lang="Python">
 +
RLPy.RTime.GetUnit ( self )
 +
</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>
 +
-----
 
===GetValue===
 
===GetValue===
 +
<syntaxhighlight lang="Python">
 +
RLPy.RTime.GetValue ( self )
 +
</syntaxhighlight>
 +
Get the float value of this RTime object.
 +
====Returns====
 +
<div style="margin-left: 2em;">The float value of this RTime object - float
 +
</div>
 +
-----
 +
===IndexedFrameTime===
 +
<syntaxhighlight lang="Python">
 +
RLPy.RTime.IndexedFrameTime ( nFrameIndex, nFps )
 +
</syntaxhighlight>
 +
Get frame time from frame index.
 +
====Parameters====
 +
<div style="margin-left: 2em;">
  
{{Input|
+
'''nFrameIndex''' [IN] the frame index for this frame time - int
def RLPy.RTime.GetValue(self)
+
}}
+
  
Get the time in milliseconds for this RTime object.
+
'''nFps''' [IN] frames per second - int
 +
</div>
 +
====Returns====
 +
<div style="margin-left: 2em;">The frame time - RLPy.RTime
 +
</div>
 +
-----
 +
===SetUnit===
 +
<syntaxhighlight lang="Python">
 +
RLPy.RTime.SetUnit ( self, eUnit )
 +
</syntaxhighlight>
 +
Set time unit.
 +
====Parameters====
 +
<div style="margin-left: 2em;">
  
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.
+
'''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>
 +
-----
 +
===SetValue===
 +
<syntaxhighlight lang="Python">
 +
RLPy.RTime.SetValue ( self, fValue )
 +
</syntaxhighlight>
 +
Set the float value of a time.
 +
====Parameters====
 +
<div style="margin-left: 2em;">
  
{{Code|<nowiki>
+
'''fValue''' [IN] a float value of a time - float
import RLPy
+
</div>
 
+
#Print the current frame time
+
time = RLPy.RGlobal.GetTime()
+
print(time.GetValue())
+
</nowiki>}}
+

Revision as of 00:36, 27 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

Operators

This class supports the following operators:

Member Operation Syntax Description Example
__add__ Addition a + b Adds values on either side of the operator. a + b = 30
__sub__ Subtraction a - b Subtracts right hand operand from left hand operand. a – b = -10
__mul__ Multiplication a * b Multiplies values on either side of the operator. a * b = 200
__truediv__ Division a / b Divides left hand operand by right hand operand. b / a = 2
__eq__ Equality a == b If the values of two operands are equal, then the condition becomes true. (a == b) is not true.
__ne__ Difference a != b If values of two operands are not equal, then condition becomes true. (a != b) is true.
__gt__ Greater Than 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.
__lt__ Less Than a < b If the value of left operand is less than the value of right operand, then condition becomes true. (a < b) is true.
__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.
__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.
__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
__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
__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
__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

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