forked from Godlander/objmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjmc.py
More file actions
743 lines (704 loc) · 31.3 KB
/
objmc.py
File metadata and controls
743 lines (704 loc) · 31.3 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
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
import sys
import os
os.system('mode con: cols=60 lines=30')
os.system("title objmc output")
os.system('color')
import math
import json
import argparse
from PIL import Image, ImageOps
from tkinter import ttk
import tkinter as tk
import tkinter.scrolledtext as tkst
import tkinter.filedialog as tkfd
#--------------------------------
#INPUT
#--------------------------------
#objs
objs = [""]
#texture animations not supported yet
texs = [""]
#Output json & png
output = ["potion.json", "block/out.png"]
#Position & Scaling
# just adds & multiplies vertex positions before encoding, so you dont have to re export the model
offset = (0.0,0.0,0.0)
scale = 1.0
#Duration of the animation in ticks
duration = 20
#Animation Easing
# 0: none, 1: linear, 2: in-out cubic, 3: 4-point bezier
easing = 3
#Texture Interpolation
# 0: none, 1: fade
interpolation = 1
#Color Behavior
# defines the behavior of 3 bytes of rgb to rotation and animation frames,
# any 3 chars of 'x', 'y', 'z', 't', 'o' is valid
# 'xyz' = rotate, 't' = animation, 'o' = overlay hue
# multiple rotation bytes increase accuracy on that axis
# for 'ttt', autoplay is automatically on. numbers past 8388608 define paused frame to display (suso's idea)
# auto-play color can be calculated by: ((([time query gametime] % 24000) - starting frame) % total duration)
colorbehavior = 'xyz'
#Auto Rotate
# attempt to estimate rotation with Normals, added to colorbehavior rotation.
# one axis is ok but both is jittery. For display purposes color defined rotation is better.
# 0: none, 1: yaw, 2: pitch, 3: both
autorotate = 1
#Auto Play
# always interpolate frames, colorbehavior='aaa' overrides this.
autoplay = False
#Flip uv
# if your model renders but textures are not right try toggling this
# i find that blockbench ends up flipping uv, but blender does not. dont trust me too much on this tho i have no idea what causes it.
flipuv = False
#No Shadow
# disable face normal shading (lightmap color still applies)
# can be used for models with lighting baked into the texture
noshadow = False
#Visibility
# determins where the model is visible
# 3 bits for: world, hand, gui
visibility = 7
#No power of two textures
# i guess saves a bit of space maybe
# makes it not optifine compatible
nopow = True
#Joining multiple models
join = []
#--------------------------------
#argument parsing by kumitatepazuru
#respects above settings as default
class ArgumentParserError(Exception): pass
class ThrowingArgumentParser(argparse.ArgumentParser):
def error(self, message):
raise ArgumentParserError(message)
parser = ThrowingArgumentParser(description="python script to convert .OBJ files into Minecraft, rendering them in game with a core shader.\nGithub: https://github.com/Godlander/objmc")
parser.add_argument("--objs", help="List of object files", nargs='*', default=objs)
parser.add_argument("--texs", help="Specify a texture file", nargs='*', default=texs)
parser.add_argument("--out", type=str, help="Output json and png", nargs=2, default=output)
parser.add_argument("--offset", type=float, help="Offset of model in xyz", nargs=3, default=offset)
parser.add_argument("--scale", type=float, help="Scale of model", default=scale)
parser.add_argument("--duration", type=int, help="Duration of the animation in ticks", default=duration)
parser.add_argument("--easing", type=int, help="Animation easing, 0: none, 1: linear, 2: in-out cubic, 3: 4-point bezier", default=easing)
parser.add_argument("--interpolation", type=int, help="Texture interpolation, 0: none, 1: fade", default=interpolation)
parser.add_argument("--colorbehavior", type=str, help="Item color overlay behavior, \"xyz\": rotate, 't': animation time offset, 'o': overlay hue", default=colorbehavior)
parser.add_argument("--autorotate", type=int, help="Attempt to estimate rotation with Normals, 0: off, 1: yaw, 2: pitch, 3: both", default=autorotate)
parser.add_argument("--autoplay", action="store_true", dest="autoplay", help="Always interpolate animation, colorbehavior=\"ttt\" overrides this")
parser.add_argument("--visibility", type=int, help="Determines where the model is visible", default=visibility)
parser.add_argument("--flipuv", action="store_true", dest="flipuv", help="Invert the texture to compensate for flipped UV")
parser.add_argument("--noshadow", action="store_true", dest="noshadow", help="Disable shadows from face normals")
parser.add_argument("--nopow", action="store_true", dest="nopow", help="Disable power of two textures")
parser.add_argument("--join", nargs='*', dest="join", help="Joins multiple json models into one")
def getargs(args):
global objs
global texs
global output
global offset
global scale
global duration
global easing
global interpolation
global colorbehavior
global autorotate
global autoplay
global visibility
global flipuv
global noshadow
global nopow
global join
objs = args.objs
texs = args.texs
output = args.out
offset = tuple(args.offset)
scale = args.scale
duration = args.duration
easing = args.easing
interpolation = args.interpolation
colorbehavior = args.colorbehavior
autorotate = args.autorotate
autoplay = args.autoplay
visibility = args.visibility
flipuv = args.flipuv
noshadow = args.noshadow
nopow = args.nopow
join = args.join
getargs(parser.parse_args())
class col:
head = '\033[95m'
blue = '\033[94m'
cyan = '\033[96m'
green = '\033[92m'
warn = '\033[93mWarning: '
err = '\033[91mError: '
end = '\033[0m'
bold = '\033[1m'
underline = '\033[4m'
def quit():
sys.exit()
def exit():
print("Press any key to exit...")
os.system('pause >nul')
sys.exit()
#--------------------------------
count = [0,0]
mem = {"positions":{},"uvs":{}}
data = {"positions":[],"uvs":[],"vertices":[]}
def readobj(name, nfaces):
obj = open(name, "r", encoding="utf-8")
d = {"positions":[],"uvs":[],"faces":[]}
for line in obj:
if line.startswith("v "):
d["positions"].append(tuple([float(i) for i in " ".join(line.split()).split(" ")[1:]]))
if line.startswith("vt "):
d["uvs"].append(tuple([float(i) for i in " ".join(line.split()).split(" ")[1:]]))
if line.startswith("f "):
d["faces"].append(tuple([[int(i)-1 for i in vert.split("/")] for vert in " ".join(line.split()).split(" ")[1:]]))
obj.close()
if nfaces > 0 and len(d["faces"]) != nfaces:
print(col.err+"mismatched obj face count"+col.end)
exit()
return d
#index vertices
def indexvert(o, vert):
global count
global mem
global data
v = []
pos = o["positions"][vert[0]]
uv = o["uvs"][vert[1]]
posh = ','.join([str(i) for i in pos])
uvh =','.join([str(i) for i in uv])
try:
v.append(mem["positions"][posh])
except:
mem["positions"][posh] = count[0]
data["positions"].append(pos)
v.append(count[0])
count[0] += 1
try:
v.append(mem["uvs"][uvh])
except:
mem["uvs"][uvh] = count[1]
data["uvs"].append(uv)
v.append(count[1])
count[1] += 1
data["vertices"].append(v)
#index obj
def indexobj(o, frame, nframes, nfaces):
for face in range(0, len(o["faces"])):
if face % 1000 == 0:
print("\Reading obj ", frame+1, " of ", nframes, "...", "{:>15.2f}".format((frame*nfaces+face)*100/(nframes*nfaces)), "%\033[K", sep="", end="\r")
face = o["faces"][face]
for vert in face:
indexvert(o, vert)
if len(face) == 3:
indexvert(o, face[1])
#unique pixel uv per face with color pointing to topleft
def getheader(out, faceid, x, y, ty):
posx = faceid%x
posy = math.floor(faceid/x)+1
out.putpixel((posx, posy), (int(posx/256)%256, posx%256, int(posy/256)%256, posy%256))
return [(posx+0.1)*16/x, (posy+0.1)*16/ty, (posx+0.9)*16/x, (posy+0.9)*16/ty]
#create elements for model
js = {}
def newelement(out, index, x, y, ty):
cube = {
"from":[8,0,8],
"to":[8.000001,0.000001,8.000001],
"faces":{
"north":{"uv":getheader(out, index, x, y, ty),"texture":"#0","tintindex":0}
}
}
js["elements"].append(cube)
#grab data from the list and convert to rgb
def getposition(i):
x = 8388608+((data["positions"][i][0])*65536)*scale + offset[0]*65536
y = 8388608+((data["positions"][i][1])*65536)*scale + offset[1]*65536
z = 8388608+((data["positions"][i][2])*65536)*scale + offset[2]*65536
rgb = []
rgb.append((int((x/65536)%256), int((x/256)%256), int(x%256), 255))
rgb.append((int((y/65536)%256), int((y/256)%256), int(y%256), 255))
rgb.append((int((z/65536)%256), int((z/256)%256), int(z%256), 255))
return rgb
def getuv(i):
x = (data["uvs"][i][0])*65535
y = (data["uvs"][i][1])*65535
rgb = []
rgb.append((int((x/65536)%256), int((x/256)%256), int(x%256), 255))
rgb.append((int((y/65536)%256), int((y/256)%256), int(y%256), 255))
return rgb
def getvert(i):
poi = (data["vertices"][i][0])
uvi = (data["vertices"][i][1])
rgb = []
rgb.append((int((poi/65536)%256), int((poi/256)%256), int(poi%256), 255))
rgb.append((int((uvi/65536)%256), int((uvi/256)%256), int(uvi%256), 255))
return rgb
def strcontext(objs, texs, output, scale, offset, duration, easing, interpolation, colorbehavior, autorotate, autoplay, flipuv, noshadow, nopow):
s = ""
s += "--objs " + ' '.join(objs)
s += " --texs " + ' '.join(texs)
s += " --out " + ' '.join(output)
s += " --offset " + ' '.join(str(i) for i in offset)
s += " --scale " + str(scale)
s += " --duration " + str(duration)
s += " --easing " + str(easing)
s += " --interpolation " + str(interpolation)
s += " --colorbehavior " + colorbehavior
s += " --autorotate " + str(autorotate)
if autoplay:
s += " --autoplay"
if flipuv:
s += " --flipuv"
if noshadow:
s += " --noshadow"
if nopow:
s += " --nopow"
return s
def getcontext(c):
a = []
try:
a = parser.parse_args(c.split(' '))
except:
print(col.err+"Invalid command: "+col.end+c)
return
getargs(a)
setval()
#--------------------------------
hid = 0
history = []
runtex = ""
def objmc(objs, texs, output, sc, off, duration, easing, interpolation, colorbehavior, autorotate, autoplay, flipuv, noshadow, nopow):
global offset
global scale
offset = off
scale = sc
global count
global mem
global data
count = [0,0]
mem = {"positions":{},"uvs":{}}
data = {"positions":[],"uvs":[],"vertices":[]}
#file extension optional
if (output[0][-5:] != ".json"):
output[0] += ".json"
if (output[1][-4:] != ".png"):
output[1] += ".png"
#input error checking
if duration < 1 or duration > 256:
print(col.err+"duration must be between 1 and 256"+col.end)
exit()
tex = Image.open(texs[0])
x,y = tex.size
if x < 8:
print(col.err+"minimum texture size is 8x"+col.end)
exit()
ntextures = len(texs)
nframes = len(objs)
print("\n"+col.cyan+"objmc start "+runtex+col.end)
#read obj
print("Reading obj 1 of ", nframes, "...", "{:>15.2f}".format(0), "%\033[K", sep="", end="\r")
o = readobj(objs[0], 0)
nfaces = len(o["faces"])
indexobj(o, 0, nframes, nfaces)
if nframes > 1:
for frame in range(1, nframes):
o = readobj(objs[frame], nfaces)
indexobj(o, frame, nframes, nfaces)
nvertices = nfaces*4
texheight = ntextures * y
uvheight = math.ceil(nfaces/x)
vpheight = math.ceil(len(data["positions"])*3/x)
vtheight = math.ceil(len(data["uvs"])*2/x)
vheight = math.ceil(len(data["vertices"])*2/x)
#make height power of 2
ty = 1 + uvheight + texheight + vpheight + vtheight + vheight
if not nopow:
ty = 1<<(ty - 1).bit_length()
if (ty > 4096 and x < 4096) or (ty > 8*x):
print(col.warn+"output height may be too high, consider increasing width of input texture or reducing number of frames to bring the output texture closer to a square."+col. end)
#initial info
print("%\033[K", end="\r")
print("faces: ", nfaces, ", verts: ", nvertices, ", tex: ", (x,y), sep="")
if nframes > 1 or ntextures > 1:
print("objs: ", nframes, ", duration: ", duration,"t", ", ", duration/20, "s", sep="")
print("easing: ", easing, ", interpolation: ", interpolation, ", autoplay: ", autoplay, sep="")
print("uvhead: ", uvheight, ", vph: ", vpheight, ", vth: ", vtheight, ", vh: ", vheight, ", total: ", ty, sep="")
print("colorbehavior: ", colorbehavior, ", flipuv: ", flipuv, ", autorotate: ", autorotate, sep="")
print("offset: ", offset, ", scale: ", scale, ", noshadow: ", noshadow, sep="")
print("visible:", " world" if visibility & 4 > 0 else "", " hand" if visibility & 2 > 0 else "", " gui" if visibility & 1 > 0 else "", sep="")
print("Creating Files...", end="\r")
#write to json model
model = open(output[0], "w")
#create out image with correct dimensions
out = Image.new("RGBA", (x, int(ty)), (0,0,0,0))
#parse color behavior
cbarr = ['x', 'y', 'z', 't', 'o']
ca = [cbarr.index(i) for i in colorbehavior]
cb = (ca[0]<<6) + (ca[1]<<4) + (ca[2])
# header
#| 2^32 | 2^16x2 | 2^32 | 2^24 + 2^8 | 2^24 + \1 2^1 + 2^2 + 2^2 \2| 2^16x2 | 2^1 + 2^2 + 2^3 \2 + 2^8 \16|
#| marker | tex size | nvertices | nobjs, ntexs | duration, autoplay, easing, interp | data heights | noshadow, autorotate, visibility, colorbehavior |
#0: marker
out.putpixel((0,0), (12,34,56,78))
#1: texsize
out.putpixel((1,0), (int(x/256), x%256, int(y/256), y%256))
#2: nvertices
out.putpixel((2,0), (int(nvertices/16777216)%256, int(nvertices/65536)%256, int(nvertices/256)%256, nvertices%256))
#3: nobjs, ntexs
out.putpixel((3,0), (int(nframes/65536)%256, int(nframes/256)%256, nframes%256, ntextures))
#4: duration, autoplay, easing
out.putpixel((4,0), (int(duration/65536)%256, int(duration/256)%256, duration%256, 128+(int(autoplay)<<6)+(easing<<4)+(interpolation<<2)))
#5: data heights
out.putpixel((5,0), (int(vpheight/256)%256, int(vpheight)%256, int(vtheight/256)%256, vtheight%256))
#6: noshadow, autorotate, visibility, colorbehavior
out.putpixel((6,0), ((int(noshadow)<<7)+(autorotate<<5)+(visibility<<2), cb, 0, 255))
#actual texture
for i in range (0,len(texs)):
tex = Image.open(texs[i])
nx,ny = tex.size
if nx != x or ny != y:
print(col.err+"mismatched texture sizes"+col.end)
exit()
if flipuv:
out.paste(tex, (0,1+uvheight+(i*y)))
else:
out.paste(ImageOps.flip(tex), (0,1+uvheight+(i*y)))
#generate json model elements and uv header
global js
js = {
"textures": {
"0": output[1].split('.')[0]
},
"elements": [],
"display": {
"thirdperson_righthand": {
"rotation": [85, 0, 0]
},
"thirdperson_lefthand": {
"rotation": [85, 0, 0]
}
}
}
for i in range(0, nfaces):
newelement(out, i, x, y, ty)
print("Writing json model...\033[K", end="\r")
model.write(json.dumps(js,separators=(',',':')))
model.close()
print("Writing position data...\033[K", end="\r")
y = 1 + uvheight + texheight
for i in range(0,len(data["positions"])):
a = getposition(i)
for j in range(0,3):
p = i*3+j
out.putpixel((p%x,y+math.floor(p/x)), a[j])
print("Writing uv data...\033[K", end="\r")
y = 1 + uvheight + texheight + vpheight
for i in range(0,len(data["uvs"])):
a = getuv(i)
for j in range(0,2):
p = i*2+j
out.putpixel((p%x,y+math.floor(p/x)), a[j])
print("Writing vertex data...\033[K", end="\r")
y = 1 + uvheight + texheight + vpheight + vtheight
for i in range(0,len(data["vertices"])):
a = getvert(i)
for j in range(0,2):
p = i*2+j
out.putpixel((p%x,y+math.floor(p/x)), a[j])
print("Saving files...\033[K", end="\r")
out.save(output[1].split('/')[-1])
out.close()
print(col.green+"Complete\033[K"+col.end)
#--------------------------------
#gui if no args
path = os.getcwd()
def settext(box,text):
box.configure(state='normal')
box.delete('1.0',tk.END)
box.insert('1.0',text)
box.configure(state='disabled')
def opentex():
f = tkfd.askopenfilenames(initialdir=path,title='Select Texture Files',filetypes=[("Image File", ".png .jpg .jpeg .bmp")])
global texs
texs = list(f)
f = [os.path.basename(f) for f in f]
settext(texlist, "\n".join(f))
def openobjs():
f = tkfd.askopenfilenames(initialdir=path,title='Select Obj Files',filetypes=[("Obj Files", ".obj")])
global objs
objs = list(f)
f = [os.path.basename(f) for f in f]
settext(objlist, "\n".join(f))
class Number(tk.Entry):
def __init__(self, master=None, **kwargs):
self.var = kwargs.pop('textvariable', None)
self.var.set(str(duration))
tk.Entry.__init__(self, master, textvariable=self.var, **kwargs)
self.old_value = ''
self.var.trace('w', self.check)
self.get, self.set = self.var.get, self.var.set
def check(self, *args):
if self.get().isdigit() or self.get() == '':
self.old_value = self.get()
else:
self.set(self.old_value)
def isFloat(string):
if string == '' or string == '-':
return True
try:
float(string)
return True
except ValueError:
return False
class Floatbox(tk.Entry):
def __init__(self, master=None, **kwargs):
self.var = kwargs.pop('textvariable', None)
self.var.set("0.0")
tk.Entry.__init__(self, master, textvariable=self.var, **kwargs)
self.old_value = ''
self.var.trace('w', self.check)
self.get, self.set = self.var.get, self.var.set
def check(self, *args):
if isFloat(self.get()) or self.get() == '':
self.old_value = self.get()
else:
self.set(self.old_value)
if not len(sys.argv) > 1:
window = tk.Tk()
window.title("objmc")
ico = tk.PhotoImage(data="""iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsEAAA7BAbiRa+0AAAxrSURBVHhe7VpbjFZXGf3vMyCdwZbpMIg05c5wM6itxgcT0RalRgOJEsQ0Ro0vhgeNTxKjfa3yQAwBH/ogCQ9K4AESsCRgUjCdwUbKRTpyixmYMhSxFKbM/FfX2v9eZ75/zzkzA8wAiayw+Pb+zj77fGvtfS4zkHqCJ3iCJ/h/RtrHxwpdXV2ZWq02q5pJL8xkMsvS6XQrYiaXTg9k0pnL2Wz2TLVavbxixYqiP+W+8dgY8NbxY09D9IampqbV1Ur1a7lc9ql0Nls/mE7jTzqVRz+bITMpGFDK5XInEA/j2J/L5fLZpUuX1sffAx65AUePHl2YyWVfQ3MdVjZPoVjsFNqObJPpNGP9GOxIZTCuhupdHm2Y0gUTfgMe7OzsrE8+DjwyA/5y+M02iPktCv8+l5disaINwqM2BdOIbN0IFk2jajCkhnaGf9VqbgzcOFGuVH6+cN78t3idsfDQDeh+50Sq/1r/qxC7DeJarGiRORnAmMO2dwaAFC7ir/ou8AbgFkpValV3LJvObB8cHPzZ4sWLh+pXjsdDNWD//v25aq36Rhqrns/nnVBRwhuM8AbwvpcB1gQLiier2BO1ahUJl34Xt8S3FixY8G/Xi8FDM2Dv3r0FPLAOZrLZr+QL+RQedg3CQ/EywD30fD/OBIomMHcULTH2SrFYXAsTTrkBAR6KAfv27csMDQ0dRDEv5ZsKTjx3AOmEhgawz7wXH5oTGhCtPgRXKpWGSGLcDVz/i4sWLbrgS4qAp8bkAk/51MDAwBso6CVs/RRfbXyNSQTjiDaoMRJNE3TbyDyyUCg0UGNIzQcTZuDYm+fOnfukLyvCpBtw9erVzRD/al2ge105gexbqlgnmn087bXacSZY2pyMUV9zwoTncevt7unpadj1k2rA7t275+Eh9D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heixPixoe5pDlt3oqxAsVJRVLBSYWPB+M9V+IeitAkjFWsPX6/plhxj0xoEu5X1FjnPXZC45FK/Q86Wi6snaQZvwAAAABJRU5ErkJggg==""")
window.tk.call('wm', 'iconphoto', window._w, ico)
window.geometry("1x1")
window.minsize(500,400)
window.rowconfigure(0,pad=7)
window.rowconfigure(1,weight=1)
window.rowconfigure(2,pad=7)
window.columnconfigure(0,weight=8)
window.columnconfigure(1,weight=9)
#obj list
tk.Button(window, text='Select Objs', command=openobjs, borderwidth=5).grid(column=0, row=0, sticky='NEW')
objlist = tkst.ScrolledText(window, height=500)
objlist.grid(column=0, row=1, rowspan=3, sticky='NEW', padx=5)
ttk.Separator(window, orient=tk.VERTICAL).grid(column=0, row=0, rowspan=4, sticky='NSE')
#tex list
tk.Button(window, text='Select Textures', command=opentex, borderwidth=5).grid(column=1, row=0, sticky='NEW')
texlist = tk.Text(window, height=1)
texlist.grid(column=1, row=1, sticky='NEW', padx=5)
fu = tk.BooleanVar()
tk.Checkbutton(window, text="Flip UV", variable=fu).grid(column=1, row=1, sticky='NE')
#scale and offset
of = [tk.StringVar() for i in range(3)]
tk.Label(window, text="Offset:").grid(column=1, row=1, sticky='N', padx=(0,110), pady=(32,0))
Floatbox(window, width=5, textvariable=of[0]).grid(column=1, row=1, sticky='N', padx=(0,30), pady=(32,0))
Floatbox(window, width=5, textvariable=of[1]).grid(column=1, row=1, sticky='N', padx=(40,0), pady=(32,0))
Floatbox(window, width=5, textvariable=of[2]).grid(column=1, row=1, sticky='N', padx=(110,0), pady=(32,0))
tk.Label(window, text="Scale:").grid(column=1, row=1, sticky='N', padx=(0,110), pady=(55,0))
sc = tk.StringVar()
Floatbox(window, width=17, textvariable=sc).grid(column=1, row=1, sticky='N', padx=(40,0), pady=(55,0))
#noshadow
ns = tk.BooleanVar()
tk.Checkbutton(window, text="No Shadow", variable=ns).grid(column=1, row=1, sticky='N', pady=(77,0))
#advanced
ttk.Separator(window, orient=tk.HORIZONTAL).grid(column=1, row=0, sticky='NEW')
advanced = tk.Frame(window)
advanced.columnconfigure(0, weight=1)
advanced.columnconfigure(1, weight=1)
advanced.grid(column=1, row=3, sticky='NESW')
tk.Label(advanced, text="Advanced").grid(column=0, row=0, columnspan=2, sticky='EW', pady=(0,5))
ttk.Separator(advanced, orient=tk.HORIZONTAL).grid(column=0, row=0, columnspan=2, sticky='NEW')
ttk.Separator(advanced, orient=tk.HORIZONTAL).grid(column=0, row=0, columnspan=2, sticky='NEW', pady=(25,5))
#duration
tk.Label(advanced, text="Total Duration:").grid(column=0, row=1, sticky='W', padx=(5,0))
dur = tk.StringVar()
Number(advanced, textvariable=dur, width=5).grid(column=1, row=1, sticky='EW', padx=(0,30))
tk.Label(advanced, text="ticks").grid(column=1, row=1, sticky='E', padx=(0,25))
#easing
tk.Label(advanced, text="Easing Method:").grid(column=0, row=2, sticky='W', padx=(5,0), pady=(2,0))
ea = tk.StringVar()
earr = ["None","Linear","Cubic","Bezier"]
ttk.Combobox(advanced, values=earr, textvariable=ea, state='readonly', width=7).grid(column=1, row=2, pady=(2,0), sticky='W')
#autorotate
ar = tk.StringVar()
rarr = ["Off","Yaw","Pitch","Both"]
tk.Label(advanced, text="Auto Rotate:").grid(column=0, row=3, sticky='W', padx=(5,0), pady=(2,0))
ttk.Combobox(advanced, values=rarr, textvariable=ar, state='readonly', width=7,).grid(column=1, row=3, pady=(2,0), sticky='W')
#autoplay
ap = tk.BooleanVar()
tk.Checkbutton(advanced, text="Auto Play", variable=ap).grid(column=0, row=4, columnspan=2, sticky='N')
#color behavior
cblabel = tk.Label(advanced, text="Color Behavior:").grid(column=0, row=5, sticky='W', padx=(5,0))
cbarr = ['x', 'y', 'z', 't']
cbarr2 = ['x', 'y', 'z', 't', 'o']
cb = [tk.StringVar() for i in range(3)]
ttk.Combobox(advanced, values=cbarr, textvariable=cb[0], width=1, state='readonly').grid(column=1, row=5, sticky='W', padx=(0,0))
ttk.Combobox(advanced, values=cbarr, textvariable=cb[1], width=1, state='readonly').grid(column=1, row=5, sticky='W', padx=(28,0))
ttk.Combobox(advanced, values=cbarr2, textvariable=cb[2], width=1, state='readonly').grid(column=1, row=5, sticky='W', padx=(56,0))
#output
ttk.Separator(advanced, orient=tk.HORIZONTAL).grid(column=0, row=6, columnspan=2, sticky='EW', pady=(7,0))
tk.Label(advanced, text="Output:").grid(column=0, row=7, columnspan=2)
outjson = tk.StringVar()
outpng = tk.StringVar()
tk.Entry(advanced, textvariable=outjson, width=10).grid(column=0, row=8, columnspan=2, sticky='NEW', padx=(5,10))
tk.Label(advanced, text=".json").grid(column=1, row=8, sticky='NE')
tk.Entry(advanced, textvariable=outpng, width=10).grid(column=0, row=9, columnspan=2, sticky='NEW', padx=5)
tk.Label(advanced, text=".png").grid(column=1, row=9, sticky='NE')
ttk.Separator(advanced, orient=tk.HORIZONTAL).grid(column=0, row=10, columnspan=2, sticky='NEW', pady=(5,0))
def setval():
settext(objlist, "\n".join(objs))
settext(texlist, "\n".join(texs))
fu.set(flipuv)
for i in range(3):
of[i].set(str(offset[i]))
sc.set(str(scale))
ns.set(noshadow)
for i in range(3):
cb[i].set(colorbehavior[i])
ea.set(earr[easing])
ar.set(rarr[autorotate])
ap.set(autoplay)
outjson.set(output[0].replace(".json", ""))
outpng.set(output[1].replace(".png", ""))
setval()
def gethistory():
global history
global hid
if history:
hlable.config(text=str(hid+1)+"/"+str(len(history)))
getcontext(history[hid])
def next():
global hid
global history
if hid < len(history)-1:
hid += 1
gethistory()
def prev():
global hid
if hid > 0:
hid -= 1
gethistory()
def delhistory():
global history
global hid
history.pop(hid)
if hid >= len(history):
hid-=1
gethistory()
def copyhistory():
global history
window.clipboard_clear()
window.clipboard_append('\n'.join(history))
def savehistory():
global history
hf = open("history.txt",'w')
hf.write('\n'.join(history))
hf.close()
print("Saved "+str(len(history))+" items to history.txt")
def loadhistory():
global history
global hid
f = tkfd.askopenfilename(initialdir=path,title="Select History File")
hf = open(f,'r')
history = hf.read().split('\n')
hf.close()
hid = len(history)-1
print("Loaded "+str(hid+1)+" items")
gethistory()
def pastehistory():
global history
global hid
history = window.clipboard_get().split('\n')
hid = len(history)-1
print("Pasted "+str(hid+1)+" items")
gethistory()
def start():
global history
global hid
if len(objs) == 0 or len(texs) == 0:
print("No files selected")
return
if dur.get().isdigit():
duration = max(int(dur.get()), 1)
else:
duration = 1
offset = (float(of[0].get()), float(of[1].get()), float(of[2].get()))
scale = float(sc.get())
easing = earr.index(ea.get())
flipuv = fu.get()
noshadow = ns.get()
autorotate = rarr.index(ar.get())
autoplay = ap.get()
colorbehavior = cb[0].get() + cb[1].get() + cb[2].get()
output = [outjson.get(), outpng.get()]
objmc(objs, texs, output, scale, offset, duration, easing, interpolation, colorbehavior, autorotate, autoplay, flipuv, noshadow, nopow)
context = strcontext(objs, texs, output, scale, offset, duration, easing, interpolation, colorbehavior, autorotate, autoplay, flipuv, noshadow, nopow)
try:
i = history.index(context)
history.pop(i)
history.append(context)
except:
history.append(context)
hid = len(history)
hlable.config(text=str(hid)+"/"+str(hid))
hid -= 1
def runhistory():
print("Running:")
global runtex
for i in range(0,len(history)):
runtex = str(i+1)+"/"+str(len(history))
getcontext(history[i])
objmc(objs, texs, output, scale, offset, duration, easing, interpolation, colorbehavior, autorotate, autoplay, flipuv, noshadow, nopow)
runtex = ""
#start
tk.Button(window, text="Start", command=start).grid(column=1, row=4, sticky='E', padx=50, pady=5)
#history
hlable = tk.Label(window, text="0/0")
hlable.grid(column=0, row=4, sticky='W', padx=5, pady=5)
tk.Button(window, text="←", command=prev).grid(column=0, columnspan=2, row=4, sticky='W', padx=(60,0), pady=5)
tk.Button(window, text="→", command=next).grid(column=0, columnspan=2, row=4, sticky='W', padx=(80,0), pady=5)
tk.Button(window, text="Save History", command=savehistory).grid(column=0, columnspan=2, row=4, padx=(0,200), pady=5)
tk.Button(window, text="Load History", command=loadhistory).grid(column=0, columnspan=2, row=4, padx=(0,47), pady=5)
tk.Button(window, text="Run History", command=runhistory).grid(column=0, columnspan=2, row=4, padx=(102,0), pady=5)
ttk.Separator(window, orient=tk.HORIZONTAL).grid(column=1, row=1, sticky='NEW', pady=(25,0))
#hotkeys
window.bind('<Return>', lambda e: start())
window.bind('<Escape>', lambda e: quit())
window.bind('<Control-c>', lambda e: copyhistory())
window.bind('<Control-s>', lambda e: savehistory())
window.bind('<Control-d>', lambda e: loadhistory())
window.bind('<Control-v>', lambda e: pastehistory())
window.bind('<Control-r>', lambda e: runhistory())
window.bind('<Control-x>', lambda e: delhistory())
window.mainloop()
elif join:
js = {
"textures": {},
"elements": [],
"display": {
"thirdperson_righthand": {
"rotation": [85, 0, 0]
},
"thirdperson_lefthand": {
"rotation": [85, 0, 0]
}
}
}
tid = 0
out = open(output[0], "w")
for file in join:
model = json.load(open(file))
temp = {}
for key,value in model["textures"].items():
js["textures"][str(tid)] = value
temp[key] = tid
tid += 1
for element in model["elements"]:
for key,value in element["faces"].items():
value["texture"] = "#" + str(temp[value["texture"][1:]])
js["elements"].append(element)
out.write(json.dumps(js,separators=(',',':')))
else:
objmc(objs, texs, output, scale, offset, duration, easing, interpolation, colorbehavior, autorotate, autoplay, flipuv, noshadow, nopow)
#--------------------------------
quit()