-
Notifications
You must be signed in to change notification settings - Fork 1
/
previewShoes.py
378 lines (323 loc) · 12.8 KB
/
previewShoes.py
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
from direct.showbase.ShowBase import ShowBase
from pathlib import Path
from direct.actor.Actor import Actor
from tkinter.filedialog import askopenfilename
from panda3d.core import Filename, OrthographicLens, GraphicsOutput, WindowProperties, Texture, GraphicsPipe, FrameBufferProperties
from direct.gui.DirectGui import *
import sys, os
# We need to import the tkinter library to
# disable the tk window that pops up.
# We use tk for the file path selector.
import tkinter as tk
root = tk.Tk()
root.withdraw()
# Force high quality for our render
from panda3d.core import loadPrcFileData
loadPrcFileData('', 'default-antialias-enable 1')
loadPrcFileData('', 'framebuffer-multisample 1')
loadPrcFileData('', 'win-size 1600 900')
"""
Controls:
s = Take screenshot
o = toggle oobe/free camera
r = reload loaded textures
e = reset rotation
1 = toggle shirt
2 = toggle bottoms
3 = load dogs body
4 = load dogm body
5 = load dogl body
mouse wheel up = zoom in
mouse wheel down = zoom out
mouse3(middle mouse click) = reset zoom
left arrow = rotate negative heading
right arrow = rotate positive heading
up arrow = rotate positive pitch
down arrow = rotate negative pitch
"""
"""
Todo:
Add onscreen text that displays the offset (camers zoom, clothing rotation, etc.) <-- will be hidden in screenshots
"""
class previewShoes(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.fileName = "output" # Output file name
self.fileFormat = ".png"
self.midPointX = 0
self.leftMargin = self.midPointX - 5
self.rightMargin = self.midPointX + 5
self.shoeTex = None
self.sBootTex = None
self.lBootTex = None
self.loadedTextures = [None, None, None]
self.SshoesVisible = True
self.MshoesVisible = True
self.LshoesVisible = True # Boots
self.shoeModels = None
self.shoeModelsModel = None
self.hiddenLeftShoe = False
self.hiddenRightShoe = False
self.type = 'm' # Body type | s, m, l
self.defaultCamPos = base.cam.getPos()
base.camera.hide()
self.i = 1
self.defaultH = 180 # todo: hotkey to reset all transformations
self.currentH = self.defaultH
self.defaultP = 0
self.currentP = self.defaultP
# Camera
# 16 : 9 aspect ratio default
scaleMultiplier = 0.25
self.filmSizeX_BASE = 16 * scaleMultiplier
self.filmSizeY_BASE = 9 * scaleMultiplier
self.filmSizeX = 16
self.filmSizeY = 9
self.orthoLens = OrthographicLens()
self.orthoLens.setFilmSize(self.filmSizeX, self.filmSizeY)
self.isOrthoView = False
self.defaultLens = base.cam.node().getLens()
# Just in case we have these enabled in the config...
base.setFrameRateMeter(False)
base.setSceneGraphAnalyzerMeter(False)
base.disableMouse()
self.loadShoes()
self.loadGUI()
"""
If you want to change the default outfit texture (not desat), you can either
change the texture path of the egg model(s) itself, or, alternatively, you can
directly call to load specific textures, e.g.:
self.loadTopTexture("path/to/texture.png")
"""
self.accept('s', self.aspect2d.hide) # Hacky b/c hiding and showing in same method no work
self.accept('s-up', self.saveScreenshot)
self.accept('o', base.oobe)
self.accept('r', self.reloadTextures)
self.accept('e', self.defaultRotation)
self.accept('c', self.toggleOrthoView)
self.accept('q', sys.exit)
self.accept('wheel_up', self.zoomCamera, [0.1])
self.accept('wheel_down', self.zoomCamera, [-0.1])
self.accept('mouse2', self.defaultCam)
self.accept('arrow_left', self.rotateShoesH, [-5])
self.accept('arrow_left-repeat', self.rotateShoesH, [-5])
self.accept('arrow_right', self.rotateShoesH, [5])
self.accept('arrow_right-repeat', self.rotateShoesH, [5])
self.accept('arrow_up', self.rotateShoesP, [5])
self.accept('arrow_up-repeat', self.rotateShoesP, [5])
self.accept('arrow_down', self.rotateShoesP, [-5])
self.accept('arrow_down-repeat', self.rotateShoesP, [-5])
self.accept('1', self.gotoShoes)
self.accept('2', self.gotoMid)
self.accept('3', self.gotoBoots)
self.accept('4', self.toggleLeftShoe)
self.accept('5', self.toggleRightShoe)
self.accept('p', print, ["H = {}, P = {}".format(self.defaultH, self.defaultP)])
# self.accept('b', self.shoeModels.showTightBounds)
# most efficient color to use due to antialiasing.
base.setBackgroundColor(0, 0, 0, 0)
def loadShoes(self): # default: dogM_shorts
self.clearShoes()
self.shoeModels = loader.loadModel("assets/shoes_distanced.egg")
self.shoeModels.reparentTo(render)
self.shoeSmall = self.shoeModels.find("**/shoes_distanced_sm")
self.shoeMedium = self.shoeModels.find("**/shoes_distanced_md")
self.shoeLarge = self.shoeModels.find("**/shoes_distanced_lg")
if self.shoeTex is not None:
self.shoeSmall.setTexture(self.loadedTextures[0], 1)
if self.sBootTex is not None:
self.shoeMedium.setTexture(self.loadedTextures[1], 1)
if self.lBootTex is not None:
self.shoeLarge.setTexture(self.loadedTextures[2], 1)
self.shoeSmall.setX(self.leftMargin)
self.shoeMedium.setX(self.midPointX)
self.shoeLarge.setX(self.rightMargin)
# note: Z-up
self.shoeModels.setPos(0.00, 4.69, -0.235)
self.shoeModels.setH(self.currentH)
self.shoeModels.setP(self.currentP)
self.shoeModels.setTwoSided(True)
def clearShoes(self):
if self.shoeModels:
self.shoeModels.removeNode()
self.shoeModels = None
def loadGUI(self):
# Todo: figure out how to reposition buttons when window changes size
# guiFrame = DirectFrame(frameColor=(0, 0, 0, 1),
# frameSize=(-1, 1, -1, 1),
# pos=(1, -1, -1))
self.topButton = DirectButton(text = ("Change Shoe Texture"),
scale = 0.05, pos = (-1.4, 0, -0.4), command = self.openTop)
self.sleeveButton = DirectButton(text = ("Change Small Boots Texture"),
scale = 0.05, pos = (-1.4, 0, -0.5), command = self.openSleeves)
self.shortsButton = DirectButton(text = ("Change Long Boots Texture"),
scale = 0.05, pos = (-1.4, 0, -0.6), command = self.openBottom)
def saveScreenshot(self):
# intent: Image number would increment if the file already exists just so it doesn't overwrite
self.newfileName = self.fileName
if not (os.path.isfile(self.newfileName)): # wip
self.newfileName = self.fileName + str(self.i)
self.i += 1
filename = self.newfileName + self.fileFormat
base.win.saveScreenshot(Filename(filename))
self.aspect2d.show()
print("Screenshot saved! {}".format(filename))
def reloadTextures(self):
for tex in self.loadedTextures:
if tex:
tex.reload()
def toggleLeftShoe(self):
if not self.hiddenLeftShoe:
for shoe in self.shoeModels.findAllMatches("**/shoe_left"):
shoe.hide()
else:
for shoe in self.shoeModels.findAllMatches("**/shoe_left"):
shoe.show()
self.hiddenLeftShoe = not self.hiddenLeftShoe
def toggleRightShoe(self):
if not self.hiddenRightShoe:
for shoe in self.shoeModels.findAllMatches("**/shoe_right"):
shoe.hide()
else:
for shoe in self.shoeModels.findAllMatches("**/shoe_right"):
shoe.show()
self.hiddenRightShoe = not self.hiddenRightShoe
def gotoShoes(self):
base.cam.setX(self.rightMargin)
def gotoMid(self):
base.cam.setX(self.midPointX)
def gotoBoots(self):
base.cam.setX(self.leftMargin)
# temporary until i have a better way to do this lol
def toggleShoes(self):
if self.shoeModels is None:
return
if (self.SshoesVisible):
self.shoeSmall.hide()
self.shoeSmall.hide()
self.SshoesVisible = False
else:
self.shoeSmall.show()
self.shoeSmall.show()
self.SshoesVisible = True
def toggleSMBoots(self):
if self.shoeModels is None:
return
if (self.MshoesVisible):
self.shoeMedium.hide()
self.shoeMedium.hide()
self.MshoesVisible = False
else:
self.shoeMedium.show()
self.shoeMedium.show()
self.MshoesVisible = True
def toggleLBoots(self):
if self.shoeModels is None:
return
if (self.LshoesVisible):
self.shoeLarge.hide()
self.shoeLarge.hide()
self.LshoesVisible = False
else:
self.shoeLarge.show()
self.shoeLarge.show()
self.LshoesVisible = True
def hideAllVisible(self):
if self.shoeModels is None:
return
if (self.SshoesVisible):
self.shoeSmall.hide()
self.shoeSmall.hide()
self.SshoesVisible = False
if (self.MshoesVisible):
self.shoeMedium.hide()
self.shoeMedium.hide()
self.MshoesVisible = False
if (self.LshoesVisible):
self.shoeLarge.hide()
self.shoeLarge.hide()
self.LshoesVisible = False
# Rotate clothing
def rotateShoesH(self, value):
self.currentH = self.shoeSmall.getH() + value
self.shoeSmall.setH(self.currentH)
self.shoeMedium.setH(self.currentH)
self.shoeLarge.setH(self.currentH)
def rotateShoesP(self, value):
self.currentP = self.shoeSmall.getP() + value
self.shoeSmall.setP(self.currentP)
self.shoeMedium.setP(self.currentP)
self.shoeLarge.setP(self.currentP)
def defaultRotation(self):
self.currentH = self.defaultH
self.shoeSmall.setH(self.currentH)
self.shoeMedium.setH(self.currentH)
self.shoeLarge.setH(self.currentH)
self.currentP = self.defaultP
self.shoeSmall.setP(self.currentP)
self.shoeMedium.setP(self.currentP)
self.shoeLarge.setP(self.currentP)
# Camera Modifiers
def defaultCam(self):
base.cam.setPos(self.defaultCamPos)
self.orthoLens.setFilmSize(self.filmSizeX_BASE, self.filmSizeY_BASE)
def zoomCamera(self, value):
self.filmSizeX, self.filmSizeY = self.orthoLens.getFilmSize()
self.orthoLens.setFilmSize(self.filmSizeX + (value * self.filmSizeX_BASE/2), self.filmSizeY+ (value* self.filmSizeY_BASE/2))
base.cam.setPos(base.cam.getX(), base.cam.getY() + value, base.cam.getZ())
###
def browseForImage(self):
path = Path(askopenfilename(filetypes = (
("Image Files", "*.jpg;*.jpeg;*.png;*.psd;*.tga"),
("JPEG", "*.jpg;*.jpeg"),
("PNG", "*.png"),
("Photoshop File", "*.psd"),
("Targa", "*.tga"))))
return path
def loadTopTexture(self, file: str):
tex = loader.loadTexture(file)
self.shoeTex = file
self.loadedTextures[0] = tex
self.shoeSmall.setTexture(tex, 1)
def loadSleeveTexture(self, file: str):
tex = loader.loadTexture(file)
self.sBootTex = file
self.loadedTextures[1] = tex
self.shoeMedium.setTexture(tex, 1)
def loadBottomTexture(self, file: str):
tex = loader.loadTexture(file)
self.lBootTex = file
self.loadedTextures[2] = tex
self.shoeLarge.setTexture(tex, 1)
def openTop(self):
filename = self.browseForImage()
if str(filename) == ".":
return
try:
self.loadTopTexture(filename)
except:
print(str(filename) + " could not be loaded!")
def openSleeves(self):
filename = self.browseForImage()
if str(filename) == ".":
return
try:
self.loadSleeveTexture(filename)
except:
print(str(filename) + " could not be loaded!")
def openBottom(self):
filename = self.browseForImage()
if str(filename) == ".":
return
try:
self.loadBottomTexture(filename)
except:
print(str(filename) + " could not be loaded!")
def toggleOrthoView(self):
self.isOrthoView = not self.isOrthoView
if self.isOrthoView:
base.cam.node().setLens(self.orthoLens)
else:
base.cam.node().setLens(self.defaultLens)
app = previewShoes()
app.run()