-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild Chair.py
More file actions
327 lines (239 loc) · 9.62 KB
/
Build Chair.py
File metadata and controls
327 lines (239 loc) · 9.62 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import os, RLPy, math
from winreg import *
from PySide2 import QtWidgets
from PySide2.shiboken2 import wrapInstance
from PySide2.QtCore import *
def PositionAndScaleProp(prop, scaleX, scaleY, scaleZ, moveX, moveY, moveZ):
# get access to the control
ts_control = prop.GetControl("Transform")
ts_data_block = ts_control.GetDataBlock()
# now scale
ts_data_block.SetData("Scale/ScaleX", RLPy.RTime(0), RLPy.RVariant(scaleX))
ts_data_block.SetData("Scale/ScaleY", RLPy.RTime(0), RLPy.RVariant(scaleY))
ts_data_block.SetData("Scale/ScaleZ", RLPy.RTime(0), RLPy.RVariant(scaleZ))
# now posiiton
ts_data_block.SetData("Position/PositionX", RLPy.RTime(0), RLPy.RVariant(moveX))
ts_data_block.SetData("Position/PositionY", RLPy.RTime(0), RLPy.RVariant(moveY))
ts_data_block.SetData("Position/PositionZ", RLPy.RTime(0), RLPy.RVariant(moveZ))
def RotateProp(prop, rotateX, rotateY, rotateZ):
# get access to the control
ts_control = prop.GetControl("Transform")
ts_data_block = ts_control.GetDataBlock()
#-- Set Rotation Z = by a random amount
ts_data_block.SetData("Rotation/RotationX", RLPy.RTime(0), RLPy.RVariant(rotateX * RLPy.RMath.CONST_DEG_TO_RAD))
ts_data_block.SetData("Rotation/RotationY", RLPy.RTime(0), RLPy.RVariant(rotateY * RLPy.RMath.CONST_DEG_TO_RAD))
ts_data_block.SetData("Rotation/RotationZ", RLPy.RTime(0), RLPy.RVariant(rotateZ * RLPy.RMath.CONST_DEG_TO_RAD))
def ApplyMaterial(prop, materialPath):
material_component = prop.GetMaterialComponent()
mesh_list = prop.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
# apply the material
result = material_component.LoadImageToTexture(mesh_name, material_name, texture_channel, materialPath)
def CreateChair():
text_edit.clear()
#-- Get iClone 7 default template path --#
Registry = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
RawKey = OpenKey(Registry, r"SOFTWARE\Reallusion\iClone\7.0")
ic_template_path = os.path.abspath(QueryValueEx(RawKey, "Template Data" )[0])
# estimate of 10
progress_bar.setRange(1, 10)
fileName = ""
text_edit.insertPlainText("Creating the chair rails. Please Wait." + "\r\n")
fileName = ic_template_path + "//iClone Template//Props//3D Blocks//Beveled//Rounded_Box.iProp"
#-- Load iProp --#
chair = RLPy.RFileIO.LoadObject(fileName)
# now create the rail
leftRail = chair.Clone()
leftRail.SetName("LeftRail")
# constants for the rail size
scaleX = .927
scaleY = .021
scaleZ = .024
# constants for the rail position
moveX = -35.521
moveY = 68.657
moveZ = 35.413
# position and scale the left rail
PositionAndScaleProp(leftRail, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# apply the material
ApplyMaterial(leftRail, ChairRailMaterialPath)
# now clone the rail for leftRail2
leftRail2 = leftRail.Clone()
leftRail2.SetName("LeftRail2")
# just move this prop down
moveZ = 0.522
# position and scale the left rail
PositionAndScaleProp(leftRail2, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now clone the rail for leftRail3
leftRail3 = leftRail.Clone()
leftRail3.SetName("LeftRail3")
# just move this prop down
moveZ = -14.028
# position and scale the left rail
PositionAndScaleProp(leftRail3, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now clone the rail for leftRail4
leftRail4 = leftRail.Clone()
leftRail4.SetName("LeftRail4")
# this prop has to be rotated, moved and scaled
rotateY = 90
scaleX = .52
moveX = -84.556
moveY = 68.657
moveZ = 11.845
# Rotate leftRail 4
RotateProp(leftRail4, 0, rotateY, 0)
# position and scale the leftRail4
PositionAndScaleProp(leftRail4, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now the final rail for the left rail
leftRail5 = leftRail4.Clone()
leftRail5.SetName("LeftRail5")
# The only thing that has to be changed here is the moveX
moveX = 9.429
# position and scale the leftRail4
PositionAndScaleProp(leftRail5, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now set the parents
leftRail2.SetParent(leftRail)
leftRail3.SetParent(leftRail)
leftRail4.SetParent(leftRail)
leftRail5.SetParent(leftRail)
# now we are going to clone the leftRail and its sub props to form RightRail
rightRail = leftRail.Clone()
rightRail.SetName("RightRail")
# now position and scale the rightRail
scaleX = .927
scaleY = .021
scaleZ = .024
moveX = -35.521
moveY = -65.007
moveZ = 35.413
# position and scale the rightRail
PositionAndScaleProp(rightRail, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now the back rail
backRail = leftRail.Clone()
backRail.SetName("BackRail")
# Now Position and Scale
scaleX = 1.307
moveX = 11.049
moveY = 0.722
moveZ = 35.413
rotateZ = 90.000
# Rotate the backRail
RotateProp(backRail, 0, 0, rotateZ)
# position and scale the backRail
PositionAndScaleProp(backRail, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now setup the Chair
chair.SetName("Chair")
# apply the material
ApplyMaterial(chair, ChairMaterialPath)
# now scale and position the chair back
moveX = -2.152
moveY = 1.6
moveZ = 0
scaleX = .244
scaleY = .94
scaleZ = .753
# position and scale the backRail
PositionAndScaleProp(chair, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now create the chairLeftArm
chairLeftArm = chair.Clone()
chairLeftArm.SetName("ChairLeftArm")
# now rotate chairLeftArm
rotateX = 0
rotateY = 0
rotateZ = 90
# perform the rotate
RotateProp(chairLeftArm, rotateX, rotateY, rotateZ)
# now scale and position chairLeftArm
moveX = -36
moveY = 59.023
moveZ = 0
scaleX = .172
scaleY = .9
scaleZ = .541
# position and scale the chairLeftArm
PositionAndScaleProp(chairLeftArm, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now create the chairRightArm
chairRightArm = chairLeftArm.Clone()
# set the name
chairRightArm.SetName("ChairRightArm")
# the only attribute that changes between chairLeftArm and chairRightArm is moveY
moveY = -55.864
# position and scale the backRail
PositionAndScaleProp(chairRightArm, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now create the chair seat
chairSeat = chair.Clone()
chairSeat.SetName("ChairSeat")
# now rotate the chairSeat
rotateX = 0
rotateY = 90
rotateZ = 0
# perform the rotate
RotateProp(chairSeat, rotateX, rotateY, rotateZ)
# now position and scale the chairSeat
moveX = -83.582
moveY = 1.600
moveZ = 13.832
scaleX = .244
scaleY = .92
scaleZ = .716
# position and scale the backRail
PositionAndScaleProp(chairSeat, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# now attach all the pieces to the chair prop
leftRail.SetParent(chair)
rightRail.SetParent(chair)
backRail.SetParent(chair)
chairLeftArm.SetParent(chair)
chairRightArm.SetParent(chair)
chairSeat.SetParent(chair)
# now move the chair
moveX = -2.152
moveY = 1.6
moveZ = 14.2
scaleX = .244
scaleY = .92
scaleZ = .753
# position and scale the backRail
PositionAndScaleProp(chair, scaleX, scaleY, scaleZ, moveX, moveY, moveZ)
# show a message chair created
text_edit.insertPlainText("Chair created." + "\r\n")
# Create an iClone Dock Widget
dockable_window = RLPy.RUi.CreateRDockWidget()
dockable_window.SetWindowTitle("Chair creator")
# 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)
textToSpellLabel = QtWidgets.QLabel("Enter Text To Spell")
text_edit2 = QtWidgets.QTextEdit(readOnly=False)
ChairMaterialPath = ""
ChairRailMaterialPath = ""
filedialog = QtWidgets.QFileDialog()
filedialog.setWindowTitle('Select Chair Texture')
filedialog.setNameFilters(["Images (*.png *.jpg)"])
filedialog.setFileMode(QtWidgets.QFileDialog.ExistingFile)
if filedialog.exec_() == QtWidgets.QDialog.Accepted:
ChairMaterialPath = str(filedialog.selectedFiles()[0])
filedialog2 = QtWidgets.QFileDialog()
filedialog2.setWindowTitle('Select Chair Rail Texture')
filedialog2.setNameFilters(["Images (*.png *.jpg)"])
filedialog2.setFileMode(QtWidgets.QFileDialog.ExistingFile)
if filedialog2.exec_() == QtWidgets.QDialog.Accepted:
ChairRailMaterialPath = str(filedialog2.selectedFiles()[0])
# Buttons #
CreateChairButton = QtWidgets.QPushButton("Create Chair")
CreateChairButton.clicked.connect(CreateChair)
# Margin Label
marginLabel = QtWidgets.QLabel("")
for widget in [progress_bar, text_edit2, text_edit, marginLabel, CreateChairButton]:
main_widget_layout.addWidget(widget)
dockable_window.Show()