-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateSpheres.py
More file actions
169 lines (115 loc) · 5.2 KB
/
RotateSpheres.py
File metadata and controls
169 lines (115 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import os, RLPy, math
from winreg import *
from PySide2 import QtWidgets
from PySide2.shiboken2 import wrapInstance
from PySide2.QtCore import *
def ChangeTransitionType(control, currentTime):
key = RLPy.RTransformKey()
key.SetTime(RLPy.RTime(currentTime))
key.SetTransitionType(RLPy.ETransitionType_Linear)
# add this key
control.AddKey(key, 0)
def RotateSphere(control, dataBlock, lastEndTime, startRotation, endRotation):
# Setup the frame after the last end time
startTime = lastEndTime
##-- Set Rotation Z
dataBlock.SetData("Rotation/RotationY", RLPy.RTime(startTime), RLPy.RVariant(startRotation * RLPy.RMath.CONST_DEG_TO_RAD))
# change the TransitionType
# ChangeTransitionType(control, startTime)
# now set the endTime
endTime = startTime + 1000
##-- Set Rotation Z
dataBlock.SetData("Rotation/RotationY", RLPy.RTime(endTime), RLPy.RVariant(endRotation * RLPy.RMath.CONST_DEG_TO_RAD))
# change the TransitionType
# ChangeTransitionType(control, endTime)
# now set the endTime
endTime = endTime + 1000
##-- Set Rotation Z
dataBlock.SetData("Rotation/RotationY", RLPy.RTime(endTime), RLPy.RVariant(startRotation * RLPy.RMath.CONST_DEG_TO_RAD))
# change the TransitionType
# ChangeTransitionType(control, endTime)
# return value
return endTime
def RotateSpheres():
# Update 3.31.2021: Now the lights are applied at a certain time
frameTime = RLPy.RGlobal.GetTime()
currentTime = frameTime.GetValue()
# currentFrame seems to need the Add 1 to get the current frame value from IClone
currentFrame = round(currentTime * .001 * 60, 0) + 1
framesLength = RLPy.RGlobal.GetProjectLength()
endTime = framesLength.GetValue()
frames = endTime * .001 * 60
# setup the progress bar
loops = round((endTime - currentTime) / 360, 0)
loop = 0
progress_bar.setRange(1, loops * 2)
progress_bar.setValue(0)
text_edit.insertPlainText("Current Frame: " + str(currentFrame) + "\r\n");
text_edit.insertPlainText("Total Frames: " + str(frames) + "\r\n");
# show the user another message
text_edit.insertPlainText("Creating Sphere Animation. Please wait..." + "\r\n");
# Get Cylinder1
sourcePropName = "Cylinder1"
cylinder1 = RLPy.RScene.FindObject(RLPy.EObjectType_Prop, sourcePropName)
# Get Cylinder5
sourcePropName = "Cylinder5"
cylinder5 = RLPy.RScene.FindObject(RLPy.EObjectType_Prop, sourcePropName)
# get access to the control
# Cylinder1
cylinder1Control = cylinder1.GetControl("Transform")
cylinder1DataBlock = cylinder1Control.GetDataBlock()
# Cylinder5
cylinder5Control = cylinder5.GetControl("Transform")
cylinder5DataBlock = cylinder5Control.GetDataBlock()
# values for the rotate
cylinderDefault = 0
cylinder1Open = 45
cylinder5Open = -45
while (currentTime < endTime):
# Rotate Cylinder 5 to open and back to close
currentTime = RotateSphere(cylinder5Control, cylinder5DataBlock, currentTime, cylinderDefault, cylinder5Open)
# increment the value for loop
loop += 1
# set the value for loop
progress_bar.setValue(loop)
if (currentTime > endTime):
# exit loop
break
# Rotate Cylinder 5 to open and back to close
currentTime = RotateSphere(cylinder1Control, cylinder1DataBlock, currentTime, cylinderDefault, cylinder1Open)
# increment the value for loop
loop += 1
# ensure the graph is in range
if (loop <= loops):
# set the value for loop
progress_bar.setValue(loop)
# message
message = "Your Newtown's Cradle is ready." + "\r\n"
text_edit.insertPlainText(message);
# Create an iClone Dock Widget
dockable_window = RLPy.RUi.CreateRDockWidget()
dockable_window.SetWindowTitle("Newton's Cradle Python Widget")
# Use wrapInstance to convert the dockable window to something that Python can understand, in this case a Dock Widget
dock = wrapInstance(int(dockable_window.GetWindow()), QtWidgets.QDockWidget)
dock.setFixedSize(800, 640)
main_widget = QtWidgets.QWidget()
dock.setWidget(main_widget)
main_widget_layout = QtWidgets.QVBoxLayout()
main_widget.setLayout(main_widget_layout)
progress_bar = QtWidgets.QProgressBar()
text_edit = QtWidgets.QTextEdit(readOnly=True)
NumberRowsToCreateLabel = QtWidgets.QLabel("Add the Newton's Creadle prop to your scene before clicking the 'Rotate Spheres' button.")
# Buttons #
RotateSpheresButton = QtWidgets.QPushButton("Rotate Spheres")
RotateSpheresButton.clicked.connect(RotateSpheres)
# Margin Label
marginLabel = QtWidgets.QLabel("")
for widget in [progress_bar, NumberRowsToCreateLabel, text_edit, marginLabel, RotateSpheresButton]:
main_widget_layout.addWidget(widget)
dockable_window.Show()
# File Info
# Version 1.0.0
# New Features / Fixes:
# This is the 1st version
# Copyright 2021 Corby Nichols / aka Data Juggler
# This is a free prop and Python script. You are welcome to share this file if you like.