-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageRotator.py
More file actions
266 lines (178 loc) · 8.02 KB
/
ImageRotator.py
File metadata and controls
266 lines (178 loc) · 8.02 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import os, RLPy, math, glob
from winreg import *
from PySide2 import QtWidgets
from PySide2.shiboken2 import wrapInstance
from PySide2.QtCore import *
def AddTextToGlowChannelChanged():
isChecked = addTextToGlowChannelCheckBox.isChecked()
glowStrengthLabel.setVisible(isChecked)
glowStrengthSlider.setVisible(isChecked)
def FindProp(all_props, propName):
for i in range(len(all_props)):
name = all_props[i].GetName()
if (name == propName):
return all_props[i]
def ApplyImages():
applyMaterial = False
text_edit.clear()
# I couldn't do what I wanted, which is apply a texture at keyframes, or I haven't figured that out yet.
# so what I am doing is making x duplicates of the prop selected, where x = number of files in the directory
# minus one.
# get the range value
interval = (IntervalSlider.value() * 20) + 100
print ("interval" + str(interval))
text_edit.insertPlainText("Interval: " + str(interval) + "\r\n");
propName = str(combo_box.currentText())
# 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
print ("End Time: " + str(endTime))
text_edit.insertPlainText("Current Frame: " + str(currentFrame) + "\r\n");
text_edit.insertPlainText("Total Frames: " + str(frames) + "\r\n");
# find the prop
prop = FindProp(all_props, propName)
progress_bar.setRange(1, 100)
text_edit.insertPlainText("Adding images to prop: " + propName + "\r\n")
# test
directory = "";
path = directoryChooser.getExistingDirectory()
directory = path + "\\*.png";
print (directory)
files = []
props = []
for file in glob.glob(directory):
files.append(file)
text_edit.insertPlainText("Found Files in Directory: " + directory + "\r\n")
text_edit.insertPlainText(str(len(files)) + "\r\n")
#text_edit.insertPlainText(propName + "\r\n")
loops = 0
index = -1
props.append(prop)
# store something for now
lastProp = prop
# duplicate props
for i in range(len(files)):
if (i > 0):
copy = prop.Clone()
copy.SetName(prop.GetName() + str(i + 1))
copy.SetVisible(RLPy.RTime(currentTime), False)
props.append(copy)
firstPass = True
while (currentTime < endTime):
if (firstPass == False):
loops = loops +1
index = index + 1
if (index >= len(files)):
# reset
index = 0
# no longer first pass
firstPass = False
fileName = files[index]
print (fileName)
thisProp = props[index]
# we only need to apply the images on the first pass
if (firstPass):
# apply material
material_component = thisProp.GetMaterialComponent()
mesh_list = thisProp.GetMeshNames()
mesh_name = mesh_list[0]
material_list = material_component.GetMaterialNames(mesh_name)
material_name = material_list[0]
#Load image to material channel
texture_channel = RLPy.EMaterialTextureChannel_Diffuse
diffuse_weight = 1;
key = RLPy.RKey()
key.SetTime(RLPy.RTime(0))
result = material_component.LoadImageToTexture(mesh_name, material_name, texture_channel, fileName)
material_component.AddTextureWeightKey(key, mesh_name, material_name, texture_channel, diffuse_weight)
if (addTextToGlowChannelCheckBox.isChecked()):
texture_channel = RLPy.EMaterialTextureChannel_Glow
diffuse_weight = glowStrengthSlider.value() * .01
result = material_component.LoadImageToTexture(mesh_name, material_name, texture_channel, fileName)
material_component.AddTextureWeightKey(key, mesh_name, material_name, texture_channel, diffuse_weight)
else:
# Set the last prop to invisible
lastProp.SetVisible(RLPy.RTime(currentTime), False)
# Show this prop
thisProp.SetVisible(RLPy.RTime(currentTime), True)
# Now set the new lastProp
lastProp = thisProp
if (firstPass == False):
# add the current time
currentTime += interval
# if we are done
if (currentTime >= endTime):
# exit while loop
break
else:
# testing how far it gets
print ("Current Time: " + str(currentTime))
# increment
loops = loops + 1
if (loops < 100):
progress_bar.setValue(loops)
elif(loops == 100):
text_edit.insertPlainText("Finishing up...\r\n")
# The parent has to be set after all the keyframes are set
text_edit.insertPlainText("Setting child props. Almost done...\r\n")
for i in range(len(props)):
if (i > 0):
prop = props[i]
prop.SetParent(props[0])
text_edit.insertPlainText("Result: " + str(loops) + " key frames set \r\n")
# Create an iClone Dock Widget
dockable_window = RLPy.RUi.CreateRDockWidget()
dockable_window.SetWindowTitle("Image Rotator")
# 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(640, 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)
directoryChooser = QtWidgets.QFileDialog();
directoryChooser.FileMode = QtWidgets.QFileDialog.Directory
directoryChooser.Options = QtWidgets.QFileDialog.ShowDirsOnly
directoryChooser.setWindowTitle('Select folder containing your images')
# Interval
IntervalSliderLabel = QtWidgets.QLabel("Interval Seconds (.1 - 30)")
IntervalSlider = QtWidgets.QSlider(orientation=Qt.Horizontal)
# .1 To 30 Seconds
IntervalSlider.setRange(1, 300)
IntervalSlider.setSingleStep(1)
# Default to 5 Seconds
IntervalSlider.setValue(50)
# checkbox and slider for Glow Channel Strength
addTextToGlowChannelCheckBox = QtWidgets.QCheckBox("Add Texture To Glow Channel")
addTextToGlowChannelCheckBox.stateChanged.connect(AddTextToGlowChannelChanged)
glowStrengthLabel = QtWidgets.QLabel("Glow Strength")
glowStrengthSlider = QtWidgets.QSlider(orientation=Qt.Horizontal)
glowStrengthSlider.setRange(1, 100)
glowStrengthSlider.setSingleStep(10)
glowStrengthSlider.setValue(50)
# hide both by default
glowStrengthLabel.setVisible(False)
glowStrengthSlider.setVisible(False)
# Grab all props in the scene
all_props = RLPy.RScene.FindObjects(RLPy.EObjectType_Prop)
combo_box = QtWidgets.QComboBox()
main_widget_layout.addWidget(combo_box)
# Add an entry into the combo-box for every prop found
for i in range(len(all_props)):
combo_box.addItem(all_props[i].GetName())
# Buttons #
ApplyImagesButton = QtWidgets.QPushButton("Apply Images")
ApplyImagesButton.clicked.connect(ApplyImages)
# Margin Label
marginLabel = QtWidgets.QLabel("")
for widget in [progress_bar, text_edit, IntervalSliderLabel, IntervalSlider, addTextToGlowChannelCheckBox, glowStrengthLabel, glowStrengthSlider, marginLabel, ApplyImagesButton]:
main_widget_layout.addWidget(widget)
dockable_window.Show()