-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLegoToR.py
1244 lines (1127 loc) · 54.4 KB
/
LegoToR.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
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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
#
# LegoToR Version 0.5.3.8 - Copyright (c) 2021 by m2m
# based on pyldd2obj Version 0.4.8 - Copyright (c) 2019 by jonnysp
# LegoToR parses LXF files and command line parameters to create a renderman compliant rib file.
#
# Usage: ./LegoToR.py /Users/username/Documents/LEGO\ Creations/Models/mylxffile.lxf -v -np
#
# Updates:
# 0.5.3.8 Improved compatibility with RenderMan 24 by removing (rather commenting out) "float g" parameter in materials
# 0.5.3.7 Improved LDD material handling
# 0.5.3.6 Corrected bug in incorrect parsing of primitive xml file, specifically comments. Add support LDDLIFTREE env var to set location of db.lif. Adjusted logoonstuds to be slightly higher
# 0.5.3.5 Preliminary Linux support
# 0.5.3 Improved brick-seams generation. Implement nocsv switch (-nc) to ignore using csv colors and use LDD build-in colors instead
# 0.5.2.1 Corrected Windows path handling bugs
# 0.5.2 Improved Windows and Python 3 compatibility
# 0.5.1.2 Support new lego colors added in the latest LDD mod.
# 0.5.1.1 Some transparent material improvements.
# 0.5.1 Added reading correct focus distance from lxf file camera, allowing for correct depth-of-field rendering.
# 0.5.0.9 Fixed decorations bug, improved material assignments handling
# 0.5.0.8 Improved custom2DField handling, adjusted logoonstuds height to better accommodate new custom bricks, fixed decorations bug, improved material assignments handling
# 0.5.0.7 DB folder support for modifications (such as custom bricks) in addition to db.lif support
# 0.5.0.6 Seperated chrome and metallic materials. Fixed textures on chrome, metallic, transparent materials
# 0.5.0.5 Added color linearization (Thanks to earlywill !). Corrected metal (chrome) materials. Corrected transparency with added maxspeculardepth.
# 0.5.0.4 Implemented metallic material and updated all other materials. Added top and back light. Fixed bug of placement of groundplane. Changed groundplane mesh to be more photostudio-like.
# 0.5.0.3 Some transparent material changes.
# 0.5.0.2 Some material changes. Fixed zfiltered RenderMan Warning. More logo on studs supported.
# 0.5.0.1 Minor bugs (like fstop parameter) fixed.
# 0.5 Initial logo on studs support.
# 0.4.9 Fixed long outstanding bug of camera positioning similar to LXF file.
# 0.4.8.3 Added brick seams via scale factor of 0.99 for each brick (experimental).
# 0.4.8.2 Added nonormals switch, to ignore normals writing as some parts of LDD have incorrect normals.
# 0.4.8.1 Streamlined logic for flex parts handling. Corrected spelling mistakes.
# 0.4.8 Upgraded pyldd2obj to Version 0.4.8. Added uneveness to materials.
# 0.4.7.1 Changes in transparent materials.
# 0.4.7 Import pyldd2obj by jonnysp - overwrite Materials, Converter class, add other functions.
# 0.4.5 Added changes based on pyldd2obj Version 0.4.7.
# 0.4.4 Complete rewrite based on the great work from jonnysp and pyldd2obj Version 0.4.3. Brings flex parts support.
# 0.3 Support for all parts (except flex parts) and textures.
# 0.2 Support for basic parts without textures.
#
# License: MIT License
#
from pylddlib import *
import numpy as np
import uuid
import csv
import datetime
import shutil
import ParseCommandLine as cl
import random
import posixpath
__version__ = '0.5.3.8'
compression = zipfile.ZIP_DEFLATED
PRMANPATH = '/Applications/Pixar/RenderManProServer-24.1/'
PRMANDIR = os.path.basename(os.path.normpath(PRMANPATH))
class Materials:
def __init__(self, data):
self.MaterialsRi = {}
material_id_dict = {}
with open('lego_colors.csv', 'r') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
next(csvfile) # skip the first row
for row in reader:
material_id_dict[row[0]] = row[6], row[7], row[8], row[9]
xml = minidom.parseString(data)
for node in xml.firstChild.childNodes:
if node.nodeName == 'Material':
usecsvcolors = cl.usecsvcolors
if usecsvcolors == True:
#Using colors from csv
self.MaterialsRi[node.getAttribute('MatID')] = MaterialRi(materialId=node.getAttribute('MatID'), r=int(material_id_dict[node.getAttribute('MatID')][0]), g=int(material_id_dict[node.getAttribute('MatID')][1]), b=int(material_id_dict[node.getAttribute('MatID')][2]), materialType=str(material_id_dict[node.getAttribute('MatID')][3]))
elif usecsvcolors == False:
#print('Using colors from LDD')
materialType = "Solid"
if str(node.getAttribute('MaterialType')) == "shinySteel":
materialType = "Metallic"
if int(node.getAttribute('Alpha')) < 255:
materialType = "Transparent"
self.MaterialsRi[node.getAttribute('MatID')] = MaterialRi(materialId=node.getAttribute('MatID'),r=int(node.getAttribute('Red')), g=int(node.getAttribute('Green')), b=int(node.getAttribute('Blue')), materialType=materialType)
def setLOC(self, loc):
for key in loc.values:
if key in self.MaterialsRi:
self.MaterialsRi[key].name = loc.values[key]
def getMaterialRibyId(self, mid):
return self.MaterialsRi[mid]
class MaterialRi:
def __init__(self, materialId, r, g, b, materialType):
self.name = ''
self.materialType = materialType
self.materialId = materialId
self.r = self.sRGBtoLinear(r)
self.g = self.sRGBtoLinear(g)
self.b = self.sRGBtoLinear(b)
# convert from sRGB luma to linear light: https://entropymine.com/imageworsener/srgbformula/
def sRGBtoLinear(self, rgb):
rgb = float(rgb) / 255
if (rgb <= 0.0404482362771082):
lin = float(rgb / 12.92)
else:
lin = float(pow((rgb + 0.055) / 1.055, 2.4))
return round(lin, 9)
# convert from linear light to sRGB luma
def lineartosRGB(self, linear):
if (linear <= 0.00313066844250063):
rgb = float(linear * 12.92)
else:
rgb = float((1.055 * pow(linear, (1.0 / 2.4)) - 0.055))
return round(rgb, 5)
def string(self, decorationId):
texture_strg = ''
ref_strg = ''
if decorationId != None and decorationId != '0':
# We have decorations
rgb_or_dec_str = '"Blend{0}:resultRGB"'.format(decorationId)
ref_strg = 'reference '
texture_strg = '''Pattern "PxrManifold2D" "PxrManifold2D1"
"float angle" [0]
"float scaleS" [1]
"float scaleT" [1]
"int invertT" [1]
# txmake -t:8 -compression zip -mode clamp -resize up {0}.png {0}.tex
Pattern "PxrTexture" "Texture{0}"
"string filename" ["{0}.tex"]
"int invertT" [0]
"int linearize" [1]
"reference struct manifold" ["PxrManifold2D1:result"]
Pattern "PxrBlend" "Blend{0}"
"int operation" [19]
"reference color topRGB" ["Texture{0}:resultRGB"]
"reference float topA" ["Texture{0}:resultA"]
"color bottomRGB" [{1} {2} {3}]
"float bottomA" [1]
"int clampOutput" [1]\n\n'''.format(decorationId, self.r, self.g, self.b)
else:
# We don't have decorations
rgb_or_dec_str = '{0} {1} {2}'.format(self.r, self.g, self.b)
if self.materialType == 'Transparent':
bxdf_mat_str = texture_strg + '''Pattern "PxrColorCorrect" "Trans_BaseColor{0}"
"{1}color inputRGB" [{2}]
"float inputMask" [1.0]
"int invertMask" [0]
"float mixMask" [1.0]
"vector inputMin" [0. 0. 0.]
"vector inputMax" [1. 1. 1.]
"vector gamma" [2.5 2.5 2.5]
"vector contrast" [0.0 0.0 0.0]
"vector contrastPivot" [0.5 0.5 0.5]
"color rgbGain" [1.2 1.2 1.2]
"vector hsv" [0.0 1.0 1.0]
"float exposure" [0]
"vector outputMin" [0. 0. 0.]
"vector outputMax" [1. 1. 1.]
"int clampOutput" [0]
"vector clampMin" [0. 0. 0.]
"vector clampMax" [1. 1. 1.]
Pattern "PxrFractal" "Unevenness"
"int surfacePosition" [0]
"int layers" [1]
"float frequency" [0.8]
"float lacunarity" [16.0]
"float dimension" [5]
"float erosion" [0.0]
"float variation" [{3}]
"int turbulent" [0]
Pattern "PxrNormalMap" "PxrNormalMap1"
"float bumpScale" [-0.07]
"reference color inputRGB" ["Unevenness:resultRGB"]
#"string filename" ["Body_Normal.tex"]
"normal bumpOverlay" [0 0 0]
"int invertBump" [0]
"int orientation" [2]
"int flipX" [0]
"int flipY" [0]
"int firstChannel" [0]
"int atlasStyle" [0]
"int invertT" [1]
"float blur" [0.0]
"int lerp" [1]
"int filter" [1]
"int reverse" [0]
"float adjustAmount" [0.0]
"float surfaceNormalMix" [0.0]
"int disable" [0]
Bxdf "PxrSurface" "Transparent {0}"
"float diffuseGain" [0]
#"reference color diffuseColor" ["Trans_BaseColor{0}:resultRGB"]
"float diffuseRoughness" [0]
"float diffuseExponent" [1]
"normal diffuseBumpNormal" [0 0 0]
"int diffuseDoubleSided" [1]
"int diffuseBackUseDiffuseColor" [1]
"color diffuseBackColor" [0.18 0.18 0.18]
"float diffuseTransmitGain" [0]
"color diffuseTransmitColor" [0.18 0.18 0.18]
"int specularFresnelMode" [0]
"color specularFaceColor" [0 0 0]
"color specularEdgeColor" [0 0 0]
"float specularFresnelShape" [5]
"color specularIor" [1.585 1.585 1.585] # Polycarbonate IOR = 1.584 - 1.586
"color specularExtinctionCoeff" [0 0 0]
"float specularRoughness" [0.2]
"int specularModelType" [0]
"float specularAnisotropy" [0]
"vector specularAnisotropyDirection" [0 0 0]
"normal specularBumpNormal" [0 0 0]
"int specularDoubleSided" [1]
"int roughSpecularFresnelMode" [0]
"color roughSpecularFaceColor" [0 0 0]
"color roughSpecularEdgeColor" [0 0 0]
"float roughSpecularFresnelShape" [5]
"color roughSpecularIor" [1.585 1.585 1.585] # Polycarbonate IOR = 1.584 - 1.586
"color roughSpecularExtinctionCoeff" [0 0 0]
"float roughSpecularRoughness" [0.6]
"int roughSpecularModelType" [0]
"float roughSpecularAnisotropy" [0]
"vector roughSpecularAnisotropyDirection" [0 0 0]
"normal roughSpecularBumpNormal" [0 0 0]
"int roughSpecularDoubleSided" [1]
"int clearcoatFresnelMode" [0]
"color clearcoatFaceColor" [0 0 0]
"color clearcoatEdgeColor" [0 0 0]
"float clearcoatFresnelShape" [5]
"color clearcoatIor" [1.585 1.585 1.585] # Polycarbonate IOR = 1.584 - 1.586
"color clearcoatExtinctionCoeff" [0 0 0]
"float clearcoatThickness" [0]
"color clearcoatAbsorptionTint" [0 0 0]
"float clearcoatRoughness" [0]
"int clearcoatModelType" [0]
"float clearcoatAnisotropy" [0]
"vector clearcoatAnisotropyDirection" [0 0 0]
"normal clearcoatBumpNormal" [0 0 0]
"int clearcoatDoubleSided" [1]
"float specularEnergyCompensation" [0]
"float clearcoatEnergyCompensation" [0]
"float iridescenceFaceGain" [0]
"float iridescenceEdgeGain" [0]
"float iridescenceFresnelShape" [5]
"int iridescenceMode" [1]
"color iridescencePrimaryColor" [1 0 0]
"color iridescenceSecondaryColor" [0 0 1]
"float iridescenceRoughness" [0.2]
"float iridescenceAnisotropy" [0]
"vector iridescenceAnisotropyDirection" [0 0 0]
"normal iridescenceBumpNormal" [0 0 0]
"float iridescenceCurve" [1]
"float iridescenceScale" [1]
"int iridescenceFlip" [0]
"float iridescenceThickness" [0]
"int iridescenceDoubleSided" [1]
"float fuzzGain" [0]
"color fuzzColor" [1 1 1]
"float fuzzConeAngle" [8]
"normal fuzzBumpNormal" [0 0 0]
"int fuzzDoubleSided" [1]
"int subsurfaceType" [0]
"float subsurfaceGain" [0]
"color subsurfaceColor" [0.823 0.791 0.753]
"float subsurfaceDmfp" [10]
"color subsurfaceDmfpColor" [0.851 0.557 0.395]
"float shortSubsurfaceGain" [0]
"color shortSubsurfaceColor" [0 0.8 0]
"float shortSubsurfaceDmfp" [1]
"float longSubsurfaceGain" [0]
"color longSubsurfaceColor" [0 0 0.8]
"float longSubsurfaceDmfp" [100]
"float subsurfaceDirectionality" [0]
"float subsurfaceBleed" [0]
"float subsurfaceDiffuseBlend" [0]
"int subsurfaceResolveSelfIntersections" [0]
"float subsurfaceIor" [1.4]
"color subsurfacePostTint" [1 1 1]
"float subsurfaceDiffuseSwitch" [1]
"int subsurfaceDoubleSided" [1]
"float subsurfaceTransmitGain" [0]
"int considerBackside" [1]
"int continuationRayMode" [0]
"int maxContinuationHits" [2]
"float followTopology" [0]
"string subsurfaceSubset" [""]
"float singlescatterGain" [0]
"color singlescatterColor" [0.823 0.791 0.753]
"float singlescatterMfp" [10]
"color singlescatterMfpColor" [0.851 0.557 0.395]
"float singlescatterDirectionality" [0]
"float singlescatterIor" [1.3]
"float singlescatterBlur" [0]
"float singlescatterDirectGain" [0]
"color singlescatterDirectGainTint" [1 1 1]
"int singlescatterDoubleSided" [1]
"int singlescatterConsiderBackside" [1]
"int singlescatterContinuationRayMode" [0]
"int singlescatterMaxContinuationHits" [2]
"int singlescatterDirectGainMode" [0]
"string singlescatterSubset" [""]
"color irradianceTint" [1 1 1]
"float irradianceRoughness" [0]
"float unitLength" [0.1]
"float refractionGain" [1.0]
"float reflectionGain" [0.95]
"reference color refractionColor" ["Trans_BaseColor{0}:resultRGB"]
"float glassRoughness" [0.001]
"float glassRefractionRoughness" [-1]
"float glassAnisotropy" [0]
"vector glassAnisotropyDirection" [0 0 0]
"normal glassBumpNormal" [0 0 0]
"float glassIor" [1.585] # Polycarbonate IOR = 1.584 - 1.586
"int mwWalkable" [0]
"float mwIor" [1]
"int thinGlass" [0]
"int ignoreFresnel" [0]
"int ignoreAccumOpacity" [0]
"int blocksVolumes" [0]
"color ssAlbedo" [0 0 0]
"color extinction" [0 0 0]
#"float g" [0]
"int multiScatter" [0]
"int enableOverlappingVolumes" [0]
"float glowGain" [0]
"color glowColor" [0 0 0]
"normal bumpNormal" [0 0 0]
"int shadowBumpTerminator" [0]
"color shadowColor" [0 0 0]
"int shadowMode" [0]
"float presence" [1]
"int presenceCached" [0]
"int mwStartable" [0]
"float roughnessMollificationClamp" [32]
"color userColor" [0 0 0]
"int[1] utilityPattern" [0]
#"string __materialid" ["TransparentSG{0}"]
#"reference normal bumpNormal" ["PxrNormalMap1:resultN"]'''.format(self.materialId, ref_strg, rgb_or_dec_str, round(random.random(), 3))
elif (self.materialType == 'Metallic') or (self.materialType == 'Pearl'):
bxdf_mat_str = texture_strg + '''Pattern "PxrExposure" "Metallic_BaseColor{0}"
"{1}color inputRGB" [{2}]
"float stops" [1.0]
Bxdf "PxrSurface" "Metallic {0}"
"reference color specularFaceColor" ["Metallic_BaseColor{0}:resultRGB"]
"reference color specularEdgeColor" ["Metallic_BaseColor{0}:resultRGB"]
"reference color diffuseColor" ["Metallic_BaseColor{0}:resultRGB"]
"float diffuseGain" [0]
"float diffuseRoughness" [0]
"float diffuseExponent" [1]
"normal diffuseBumpNormal" [0 0 0]
"int diffuseDoubleSided" [0]
"int diffuseBackUseDiffuseColor" [1]
"color diffuseBackColor" [0.18 0.18 0.18]
"float diffuseTransmitGain" [0]
"color diffuseTransmitColor" [0.18 0.18 0.18]
"int specularFresnelMode" [0]
"float specularFresnelShape" [5]
"color specularIor" [1.5 1.5 1.5]
"color specularExtinctionCoeff" [0 0 0]
"float specularRoughness" [0.492000014]
"int specularModelType" [1]
"float specularAnisotropy" [0]
"vector specularAnisotropyDirection" [0 0 0]
"normal specularBumpNormal" [0 0 0]
"int specularDoubleSided" [0]
"int roughSpecularFresnelMode" [0] "color roughSpecularFaceColor" [0 0 0] "color roughSpecularEdgeColor" [0 0 0]
"float roughSpecularFresnelShape" [5] "color roughSpecularIor" [1.5 1.5 1.5] "color roughSpecularExtinctionCoeff" [0 0 0] "float roughSpecularRoughness" [0.600000024] "int roughSpecularModelType" [0] "float roughSpecularAnisotropy" [0] "vector roughSpecularAnisotropyDirection" [0 0 0]
"normal roughSpecularBumpNormal" [0 0 0] "int roughSpecularDoubleSided" [0] "int clearcoatFresnelMode" [0] "color clearcoatFaceColor" [0.0199999996 0.0199999996 0.0199999996] "color clearcoatEdgeColor" [0.25 0.25 0.25] "float clearcoatFresnelShape" [5] "color clearcoatIor" [1.5 1.5 1.5]
"color clearcoatExtinctionCoeff" [0 0 0] "float clearcoatThickness" [0] "color clearcoatAbsorptionTint" [0 0 0] "float clearcoatRoughness" [0.316227764] "int clearcoatModelType" [1] "float clearcoatAnisotropy" [0] "vector clearcoatAnisotropyDirection" [0 0 0]
"normal clearcoatBumpNormal" [0 0 0] "int clearcoatDoubleSided" [0] "float specularEnergyCompensation" [0] "float clearcoatEnergyCompensation" [0] "float iridescenceFaceGain" [0] "float iridescenceEdgeGain" [0] "float iridescenceFresnelShape" [5] "int iridescenceMode" [0] "color iridescencePrimaryColor" [1 0 0]
"color iridescenceSecondaryColor" [0 0 1] "float iridescenceRoughness" [0.200000003] "float iridescenceAnisotropy" [0] "vector iridescenceAnisotropyDirection" [0 0 0] "normal iridescenceBumpNormal" [0 0 0] "float iridescenceCurve" [1]
"float iridescenceScale" [1] "int iridescenceFlip" [0] "float iridescenceThickness" [800] "int iridescenceDoubleSided" [0] "float fuzzGain" [0] "color fuzzColor" [7.05987978 4.76732111 1.23935699] "float fuzzConeAngle" [8] "normal fuzzBumpNormal" [0 0 0] "int fuzzDoubleSided" [0] "int subsurfaceType" [0]
"float subsurfaceGain" [0] "color subsurfaceColor" [0.829999983 0.791000009 0.753000021] "float subsurfaceDmfp" [10] "color subsurfaceDmfpColor" [0.851000011 0.556999981 0.395000011] "float shortSubsurfaceGain" [0] "color shortSubsurfaceColor" [0.899999976 0.899999976 0.899999976]
"float shortSubsurfaceDmfp" [5] "float longSubsurfaceGain" [0] "color longSubsurfaceColor" [0.800000012 0 0] "float longSubsurfaceDmfp" [20] "float subsurfaceDirectionality" [0] "float subsurfaceBleed" [0] "float subsurfaceDiffuseBlend" [0] "int subsurfaceResolveSelfIntersections" [0] "float subsurfaceIor" [1.39999998] "color subsurfacePostTint" [1 1 1]
"float subsurfaceDiffuseSwitch" [1] "int subsurfaceDoubleSided" [0] "float subsurfaceTransmitGain" [0] "int considerBackside" [1] "int continuationRayMode" [0] "int maxContinuationHits" [2] "float followTopology" [0] "string subsurfaceSubset" [""] "float singlescatterGain" [0] "color singlescatterColor" [0.829999983 0.791000009 0.753000021] "float singlescatterMfp" [10] "color singlescatterMfpColor" [0.851000011 0.556999981 0.395000011]
"float singlescatterDirectionality" [0] "float singlescatterIor" [1.29999995] "float singlescatterBlur" [0] "float singlescatterDirectGain" [0] "color singlescatterDirectGainTint" [1 1 1] "int singlescatterDoubleSided" [0] "int singlescatterConsiderBackside" [1] "int singlescatterContinuationRayMode" [0] "int singlescatterMaxContinuationHits" [2] "int singlescatterDirectGainMode" [0] "string singlescatterSubset" [""] "color irradianceTint" [1 1 1]
"float irradianceRoughness" [0] "float unitLength" [0.100000001] "float refractionGain" [0] "float reflectionGain" [0] "color refractionColor" [1 1 1] "float glassRoughness" [0.100000001] "float glassRefractionRoughness" [-1] "float glassAnisotropy" [0] "vector glassAnisotropyDirection" [0 0 0]
"normal glassBumpNormal" [0 0 0]
"float glassIor" [1.5]
"int mwWalkable" [0]
"float mwIor" [-1]
"int thinGlass" [0]
"int ignoreFresnel" [0]
"int ignoreAccumOpacity" [0]
"int blocksVolumes" [0]
"color ssAlbedo" [0 0 0]
"color extinction" [0 0 0]
#"float g" [0]
"int multiScatter" [0]
"int enableOverlappingVolumes" [0]
"float glowGain" [0]
"color glowColor" [1 1 1]
"int shadowBumpTerminator" [0]
"color shadowColor" [0 0 0]
"int shadowMode" [0]
"float presence" [1]
"int presenceCached" [1]
"int mwStartable" [0]
"float roughnessMollificationClamp" [32]
"color userColor" [0 0 0]
"int[1] utilityPattern" [0]
#"string __materialid" ["MetallicSG{0}"]'''.format(self.materialId, ref_strg, rgb_or_dec_str, round(random.random(), 3))
elif (self.materialType == 'Chrome'):
bxdf_mat_str = texture_strg + '''Pattern "PxrExposure" "Chrome_BaseColor{0}"
"{1}color inputRGB" [{2}]
"float stops" [-0.5]
Pattern "PxrExposure" "Chrome_Spec{0}"
"reference color inputRGB" ["Chrome_BaseColor{0}:resultRGB"]
"float stops" [2.0]
Pattern "PxrInvert" "Chrome_PxrInvert{0}"
"reference color inputRGB" ["Chrome_BaseColor{0}:resultRGB"]
"int colorModel" [0]
"int invertChannel0" [1]
"int invertChannel1" [1]
"int invertChannel2" [1]
Bxdf "PxrSurface" "Chrome {0}"
"reference color specularIor" ["Chrome_PxrInvert{0}:resultRGB"]
"float diffuseGain" [0]
"color diffuseColor" [0 0 0]
"float diffuseRoughness" [0]
"float diffuseExponent" [1]
"normal diffuseBumpNormal" [0 0 0]
"int diffuseDoubleSided" [0]
"int diffuseBackUseDiffuseColor" [1]
"color diffuseBackColor" [0.18 0.18 0.18]
"float diffuseTransmitGain" [0]
"color diffuseTransmitColor" [0.18 0.18 0.18]
"int specularFresnelMode" [1]
"color specularFaceColor" [0 0 0]
"color specularEdgeColor" [0.9 0.9 0.9]
"float specularFresnelShape" [5]
"reference color specularExtinctionCoeff" ["Chrome_Spec{0}:resultRGB"]
#"color specularExtinctionCoeff" [3.983 2.38599992 1.603]
"float specularRoughness" [0.2]
"int specularModelType" [1]
"float specularAnisotropy" [0]
"vector specularAnisotropyDirection" [0 0 0]
"normal specularBumpNormal" [0 0 0]
"int specularDoubleSided" [0]
"int roughSpecularFresnelMode" [0]
"color roughSpecularFaceColor" [0 0 0]
"color roughSpecularEdgeColor" [0 0 0]
"float roughSpecularFresnelShape" [5]
"color roughSpecularIor" [1.5 1.5 1.5]
"color roughSpecularExtinctionCoeff" [0 0 0]
"float roughSpecularRoughness" [0.6]
"int roughSpecularModelType" [0]
"float roughSpecularAnisotropy" [0]
"vector roughSpecularAnisotropyDirection" [0 0 0]
"normal roughSpecularBumpNormal" [0 0 0]
"int roughSpecularDoubleSided" [0]
"int clearcoatFresnelMode" [0]
"color clearcoatFaceColor" [0 0 0]
"color clearcoatEdgeColor" [0 0 0]
"float clearcoatFresnelShape" [5]
"color clearcoatIor" [1.5 1.5 1.5]
"color clearcoatExtinctionCoeff" [0 0 0]
"float clearcoatThickness" [0]
"color clearcoatAbsorptionTint" [0 0 0]
"float clearcoatRoughness" [0]
"int clearcoatModelType" [0]
"float clearcoatAnisotropy" [0]
"vector clearcoatAnisotropyDirection" [0 0 0]
"normal clearcoatBumpNormal" [0 0 0]
"int clearcoatDoubleSided" [0]
"float specularEnergyCompensation" [0]
"float clearcoatEnergyCompensation" [0]
"float iridescenceFaceGain" [0]
"float iridescenceEdgeGain" [0]
"float iridescenceFresnelShape" [5]
"int iridescenceMode" [0]
"color iridescencePrimaryColor" [1 0 0]
"color iridescenceSecondaryColor" [0 0 1]
"float iridescenceRoughness" [0.2]
"float iridescenceAnisotropy" [0]
"vector iridescenceAnisotropyDirection" [0 0 0]
"normal iridescenceBumpNormal" [0 0 0]
"float iridescenceCurve" [1]
"float iridescenceScale" [1]
"int iridescenceFlip" [0]
"float iridescenceThickness" [800]
"int iridescenceDoubleSided" [0]
"float fuzzGain" [0]
"color fuzzColor" [1 1 1]
"float fuzzConeAngle" [8]
"normal fuzzBumpNormal" [0 0 0]
"int fuzzDoubleSided" [0]
"int subsurfaceType" [0]
"float subsurfaceGain" [0]
"color subsurfaceColor" [0.823 0.791 0.753]
"float subsurfaceDmfp" [10]
"color subsurfaceDmfpColor" [0.851 0.557 0.395]
"float shortSubsurfaceGain" [0]
"color shortSubsurfaceColor" [0.9 0.9 0.9]
"float shortSubsurfaceDmfp" [5]
"float longSubsurfaceGain" [0]
"color longSubsurfaceColor" [0.8 0 0]
"float longSubsurfaceDmfp" [20]
"float subsurfaceDirectionality" [0]
"float subsurfaceBleed" [0]
"float subsurfaceDiffuseBlend" [0]
"int subsurfaceResolveSelfIntersections" [0]
"float subsurfaceIor" [1.4]
"color subsurfacePostTint" [1 1 1]
"float subsurfaceDiffuseSwitch" [1]
"int subsurfaceDoubleSided" [0]
"float subsurfaceTransmitGain" [0]
"int considerBackside" [1]
"int continuationRayMode" [0]
"int maxContinuationHits" [2]
"float followTopology" [0]
"string subsurfaceSubset" [""]
"float singlescatterGain" [0]
"color singlescatterColor" [0.823 0.791 0.753]
"float singlescatterMfp" [10]
"color singlescatterMfpColor" [0.851 0.557 0.395]
"float singlescatterDirectionality" [0]
"float singlescatterIor" [1.3]
"float singlescatterBlur" [0]
"float singlescatterDirectGain" [0]
"color singlescatterDirectGainTint" [1 1 1]
"int singlescatterDoubleSided" [0]
"int singlescatterConsiderBackside" [1]
"int singlescatterContinuationRayMode" [0]
"int singlescatterMaxContinuationHits" [2]
"int singlescatterDirectGainMode" [0]
"string singlescatterSubset" [""]
"color irradianceTint" [1 1 1]
"float irradianceRoughness" [0]
"float unitLength" [0.1]
"float refractionGain" [0]
"float reflectionGain" [0]
"color refractionColor" [1 1 1]
"float glassRoughness" [0.1]
"float glassRefractionRoughness" [-1]
"float glassAnisotropy" [0]
"vector glassAnisotropyDirection" [0 0 0]
"normal glassBumpNormal" [0 0 0]
"float glassIor" [1.5]
"int mwWalkable" [0]
"float mwIor" [-1]
"int thinGlass" [0]
"int ignoreFresnel" [0]
"int ignoreAccumOpacity" [0]
"int blocksVolumes" [0]
"color ssAlbedo" [0 0 0]
"color extinction" [0 0 0]
#"float g" [0]
"int multiScatter" [0]
"int enableOverlappingVolumes" [0]
"float glowGain" [0]
"color glowColor" [0 0 0]
"normal bumpNormal" [0 0 0]
"int shadowBumpTerminator" [0]
"color shadowColor" [0 0 0]
"int shadowMode" [0]
"float presence" [1]
"int presenceCached" [1]
"int mwStartable" [0]
"float roughnessMollificationClamp" [32]
"color userColor" [0 0 0]
"int[1] utilityPattern" [0]
#"string __materialid" ["ChromeSG{0}"]'''.format(self.materialId, ref_strg, rgb_or_dec_str, round(random.random(), 3))
else:
bxdf_mat_str = texture_strg + '''Pattern "PxrFractal" "PxrFractal_SpecRough{0}"
"int surfacePosition" [0]
"int layers" [6]
"float frequency" [8]
"float lacunarity" [2.5]
"float dimension" [0.2]
"float erosion" [0]
"float variation" [0.35]
"int turbulent" [0]
"color colorScale" [0.5 0.5 0.5]
"color colorOffset" [0.23 0.23 0.23]
"float floatScale" [1]
"float floatOffset" [0]
Pattern "PxrExposure" "Pxr_BaseColor{0}"
"{1}color inputRGB" [{2}]
"float stops" [{3}]
Pattern "PxrColorCorrect" "PxrColorCorrect_SpecRough{0}"
"reference color inputRGB" ["PxrFractal_SpecRough{0}:resultRGB"]
"float inputMask" [1]
"int invertMask" [0]
"float mixMask" [1]
"vector inputMin" [0 0 0]
"vector inputMax" [1 1 1]
"vector gamma" [1 1 1]
"vector contrast" [0.08 0.08 0.08]
"vector contrastPivot" [0.08 0.08 0.08]
"color rgbGain" [1 1 1]
"vector hsv" [0 1 1]
"float exposure" [2.585]
"vector outputMin" [0 0 0]
"vector outputMax" [1 1 1]
"int clampOutput" [0]
"vector clampMin" [0 0 0]
"vector clampMax" [1 1 1]
Pattern "PxrExposure" "PxrExposure_SSS_Color{0}"
"reference color inputRGB" ["Pxr_BaseColor{0}:resultRGB"]
"float stops" [-2.5]
Pattern "PxrToFloat" "PxrToFloat_SpecRough{0}"
"reference color input" ["PxrColorCorrect_SpecRough{0}:resultRGB"]
"int mode" [0]
Bxdf "PxrSurface" "Solid Material {0}"
"reference color diffuseColor" ["Pxr_BaseColor{0}:resultRGB"]
"reference float specularRoughness" ["PxrToFloat_SpecRough{0}:resultF"]
"reference color subsurfaceColor" ["PxrExposure_SSS_Color{0}:resultRGB"]
"reference color clearcoatFaceColor" ["PxrExposure_SSS_Color{0}:resultRGB"]
"reference color clearcoatEdgeColor" ["PxrExposure_SSS_Color{0}:resultRGB"]
"float diffuseGain" [1]
"int diffuseDoubleSided" [1]
"color specularFaceColor" [0.1 0.1 0.15]
"color specularIor" [1.54 1.54 1.54] # ABS Refractive Index, Average value: 1.54
"float specularRoughness" [0.25]
"int specularDoubleSided" [0]
"float presence" [1]
#"reference normal bumpNormal" ["PxrNormalMap1:resultN"]\n'''.format(self.materialId, ref_strg, rgb_or_dec_str, round(random.uniform(-0.1, -0.0), 3))
return bxdf_mat_str
class Converter:
def LoadDBFolder(self, dbfolderlocation):
self.database = DBFolderReader(folder=dbfolderlocation)
if self.database.initok and self.database.fileexist(os.path.join(dbfolderlocation,'Materials.xml')) and self.database.fileexist(MATERIALNAMESPATH + 'EN/localizedStrings.loc'):
self.allMaterials = Materials(data=self.database.filelist[os.path.join(dbfolderlocation,'Materials.xml')].read());
self.allMaterials.setLOC(loc=LOCReader(data=self.database.filelist[MATERIALNAMESPATH + 'EN/localizedStrings.loc'].read()))
def LoadDatabase(self, databaselocation):
self.database = LIFReader(file=databaselocation)
if self.database.initok and self.database.fileexist('/Materials.xml') and self.database.fileexist(MATERIALNAMESPATH + 'EN/localizedStrings.loc'):
self.allMaterials = Materials(data=self.database.filelist['/Materials.xml'].read());
self.allMaterials.setLOC(loc=LOCReader(data=self.database.filelist[MATERIALNAMESPATH + 'EN/localizedStrings.loc'].read()))
def LoadScene(self, filename):
if self.database.initok:
self.scene = Scene(file=filename)
def Export(self, filename):
invert = Matrix3D()
#invert.n33 = -1 #uncomment to invert the Z-Axis
indexOffset = 1
textOffset = 1
usedmaterials = []
geometriecache = {}
writtenribs = []
start_time = time.time()
out = open(filename + ".rib", "w+")
zf = zipfile.ZipFile(filename + "_Bricks_Archive.zip", "w")
zfmat = zipfile.ZipFile(filename + "_Materials_Archive.zip", "w")
total = len(self.scene.Bricks)
current = 0
# miny used for floor plane later
miny = 1000
useplane = cl.useplane
usenormal = cl.usenormal
uselogoonstuds = cl.uselogoonstuds
usecsvcolors = cl.usecsvcolors
fstop = cl.args.fstop
fov = cl.args.fov
out.write('''# Camera Minus One
TransformBegin
Projection "PxrCamera" "float fov" [25] "float fStop" [9.99999968e+37] "float focalLength" [1.3] "float focalDistance" [5.0]
Translate 0 -2 80
Rotate -25 1 0 0
Rotate 45 0 1 0
Camera "Cam--1"
"float shutterOpenTime" [0]
"float shutterCloseTime" [1]
"int apertureNSides" [0]
"float apertureAngle" [0]
"float apertureRoundness" [0]
"float apertureDensity" [0]
"float dofaspect" [1]
"float nearClip" [0.1]
"float farClip" [10000]
TransformEnd\n\n''')
for cam in self.scene.Scenecamera:
# Create numpy matrix from camera matrix to create inverted matrix later
x = np.array([[cam.matrix.n11,cam.matrix.n21,cam.matrix.n31,cam.matrix.n41],[cam.matrix.n12,cam.matrix.n22,cam.matrix.n32,cam.matrix.n42],[cam.matrix.n13,cam.matrix.n23,cam.matrix.n33,cam.matrix.n43],[cam.matrix.n14,cam.matrix.n24,cam.matrix.n34,cam.matrix.n44]])
x_inv = np.linalg.inv(x)
# undoTransformMatrix = inverted matrix
undoTransformMatrix = Matrix3D(n11=x_inv[0][0],n12=x_inv[0][1],n13=x_inv[0][2],n14=x_inv[0][3],n21=x_inv[1][0],n22=x_inv[1][1],n23=x_inv[1][2],n24=x_inv[1][3],n31=x_inv[2][0],n32=x_inv[2][1],n33=x_inv[2][2],n34=x_inv[2][3],n41=x_inv[3][0],n42=x_inv[3][1],n43=x_inv[3][2],n44=x_inv[3][3])
out.write('''# Camera {0}
TransformBegin
Projection "PxrCamera" "float fov" [{19}] "float fStop" [{20}] "float focalLength" [1.3] "float focalDistance" [{18}]
ConcatTransform [{1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15} {16}]
Camera "Cam-{0}"
"float shutterOpenTime" [0]
"float shutterCloseTime" [1]
"int apertureNSides" [0]
"float apertureAngle" [0]
"float apertureRoundness" [0]
"float apertureDensity" [0]
"float dofaspect" [1]
"float nearClip" [0.1]
"float farClip" [10000]
#"float fov" [{17}]
TransformEnd\n'''.format(cam.refID, undoTransformMatrix.n11, undoTransformMatrix.n21, -1 * undoTransformMatrix.n31,
undoTransformMatrix.n41, undoTransformMatrix.n12, undoTransformMatrix.n22, -1 * undoTransformMatrix.n32,
undoTransformMatrix.n42, -1 * undoTransformMatrix.n13, -1 * undoTransformMatrix.n23, undoTransformMatrix.n33,
undoTransformMatrix.n43, undoTransformMatrix.n14, undoTransformMatrix.n24, -1 * undoTransformMatrix.n34, undoTransformMatrix.n44,
cam.fieldOfView, cam.distance, fov, fstop))
out.write('''
Display "{0}{1}{2}.beauty.001.exr" "openexr" "Ci,a,mse,albedo,albedo_var,diffuse,diffuse_mse,specular,specular_mse,zfiltered,zfiltered_var,normal,normal_var,forward,backward" "int asrgba" 1
"string storage" ["scanline"]
"string exrpixeltype" ["half"]
"string compression" ["zips"]
"float compressionlevel" [45]
"string camera" ["Cam-{3}"]\n\n'''.format('.', os.sep, filename, cl.args.camera))
out.write('WorldBegin\n\tScale 1 1 1\n')
out.write('''\tAttributeBegin
Attribute "visibility" "int indirect" [0] "int transmission" [0]
Attribute "visibility" "int camera" [1]
Rotate 50 0 1 0
Rotate -90 1 0 0
Light "PxrDomeLight" "PxrDomeLight1"
"float intensity" [1.0]
"float exposure" [0]
"color lightColor" [1 1 1]
"string lightColorMap" ['islandsun_small.tex'] #Luxo-Jr_4000x2000.tex
"vector colorMapGamma" [1.0 1.0 1.0]
"float colorMapSaturation" [1.0]
"int enableTemperature" [0]
"float temperature" [6500]
"float specular" [1.0]
"float diffuse" [1.0]
"int enableShadows" [1]
"color shadowColor" [0 0 0]
"float shadowDistance" [-1.0]
"float shadowFalloff" [-1.0]
"float shadowFalloffGamma" [1.0]
"string shadowSubset" ['']
"string shadowExcludeSubset" ['']
"int traceLightPaths" [0] #[1]
"int thinShadow" [1]
"int fixedSampleCount" [0]
"string lightGroup" ['']
"float importanceMultiplier" [1.0]
AttributeEnd\n\n''')
for bri in self.scene.Bricks:
current += 1
for pa in bri.Parts:
if pa.designID not in geometriecache:
geo = Geometry(designID=pa.designID, database=self.database)
progress(current ,total , "(" + geo.designID + ") " + geo.Partname, ' ')
geometriecache[pa.designID] = geo
else:
geo = geometriecache[pa.designID]
progress(current ,total , "(" + geo.designID + ") " + geo.Partname ,'-')
# n11=a, n21=d, n31=g, n41=x,
# n12=b, n22=e, n32=h, n42=y,
# n13=c, n23=f, n33=i, n43=z,
# n14=0, n24=0, n34=0, n44=1
# Read out 1st Bone matrix values. Might use later
ind = 0
n11 = pa.Bones[ind].matrix.n11
n12 = pa.Bones[ind].matrix.n12
n13 = pa.Bones[ind].matrix.n13
n14 = pa.Bones[ind].matrix.n14
n21 = pa.Bones[ind].matrix.n21
n22 = pa.Bones[ind].matrix.n22
n23 = pa.Bones[ind].matrix.n23
n24 = pa.Bones[ind].matrix.n24
n31 = pa.Bones[ind].matrix.n31
n32 = pa.Bones[ind].matrix.n32
n33 = pa.Bones[ind].matrix.n33
n34 = pa.Bones[ind].matrix.n34
n41 = pa.Bones[ind].matrix.n41
n42 = pa.Bones[ind].matrix.n42
n43 = pa.Bones[ind].matrix.n43
n44 = pa.Bones[ind].matrix.n44
# Only parts with more then 1 bone are flex parts and for these we need to undo the transformation later
flexflag = 1
uniqueId = str(uuid.uuid4().hex)
material_string = '_' + '_'.join(pa.materials)
written_obj = geo.designID + material_string
if hasattr(pa, 'decoration'):
decoration_string = '_' + '_'.join(pa.decoration)
written_obj = written_obj + decoration_string
if (len(pa.Bones) > flexflag):
# Flex parts are "unique". Ensure they get a unique filename
written_obj = written_obj + "_" + uniqueId
# Create numpy matrix from them and create inverted matrix
x = np.array([[n11,n21,n31,n41],[n12,n22,n32,n42],[n13,n23,n33,n43],[n14,n24,n34,n44]])
x_inv = np.linalg.inv(x)
# undoTransformMatrix not used currently. Might use later
undoTransformMatrix = Matrix3D(n11=x_inv[0][0],n12=x_inv[0][1],n13=x_inv[0][2],n14=x_inv[0][3],n21=x_inv[1][0],n22=x_inv[1][1],n23=x_inv[1][2],n24=x_inv[1][3],n31=x_inv[2][0],n32=x_inv[2][1],n33=x_inv[2][2],n34=x_inv[2][3],n41=x_inv[3][0],n42=x_inv[3][1],n43=x_inv[3][2],n44=x_inv[3][3])
out.write("\tAttributeBegin\n")
if not (len(pa.Bones) > flexflag):
# Flex parts don't need to be moved
# Renderman is lefthanded coordinate system, but LDD is right handed.
out.write("\t\tConcatTransform [{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15}]\n".format(n11, n12, -1 * n13, n14, n21, n22, -1 * n23, n24, -1 * n31, -1 * n32, n33, n34, n41, n42 ,-1 * n43, n44))
# Random Scale for brick seams
scalefact = (geo.maxGeoBounding - 0.025 * random.uniform(0.0, 1.000)) / geo.maxGeoBounding
out.write("\t\tScale {0} {0} {0}\n".format(scalefact))
# miny used for floor plane later
if miny > float(n42):
miny = n42
op = open(written_obj + ".rib", "w+")
op.write("##RenderMan RIB-Structure 1.1 Entity\n")
# transform -------------------------------------------------------
decoCount = 0
for part in geo.Parts:
geo.Parts[part].outpositions = [elem.copy() for elem in geo.Parts[part].positions]
geo.Parts[part].outnormals = [elem.copy() for elem in geo.Parts[part].normals]
# translate / rotate only parts with more then 1 bone. This are flex parts
if (len(pa.Bones) > flexflag):
for i, b in enumerate(pa.Bones):
# positions
for j, p in enumerate(geo.Parts[part].outpositions):
if (geo.Parts[part].bonemap[j] == i):
p.transform( invert * b.matrix)
#transform with inverted values (to undo the transformation)
#geo.Parts[part].outpositions[j].transform(undoTransformMatrix)
# normals
for k, n in enumerate(geo.Parts[part].outnormals):
if (geo.Parts[part].bonemap[k] == i):
n.transformW( invert * b.matrix)
#transform with inverted values (to undo the transformation)
#geo.Parts[part].outnormals[k].transformW(undoTransformMatrix)
#try catch here for possible problems in materials assignment of various g, g1, g2, .. files in lxf file
try:
materialCurrentPart = pa.materials[part]
except IndexError:
print('WARNING: {0}.g{1} has NO material assignment in lxf. Replaced with color 9. Fix {0}.xml faces values.'.format(pa.designID, part))
materialCurrentPart = '9'
lddmatri = self.allMaterials.getMaterialRibyId(materialCurrentPart)
matname = materialCurrentPart
deco = '0'
if hasattr(pa, 'decoration') and len(geo.Parts[part].textures) > 0:
if decoCount <= len(pa.decoration):
#if decoCount < len(pa.decoration):
try:
deco = pa.decoration[decoCount]
#print 'Good DecoCount' + str(decoCount)
#print 'Good len' + str(len(pa.decoration))
except IndexError:
print('Error here')
print(decoCount)
print(pa.decoration)
decoCount += 1
extfile = ''
if not deco == '0':
extfile = deco + '.png'
matname += "_" + deco
decofilename = DECORATIONPATH + deco + '.png'
if not os.path.isfile(deco + '.tex') and self.database.fileexist(decofilename):
with open(extfile, "wb") as f:
f.write(self.database.filelist[decofilename].read())
f.close()
if os.path.exists(FindRmtree()):
txmake_cmd = '"' + FindRmtree() + 'bin' + os.sep + 'txmake" -t:8 -compression zip -mode clamp -resize up {0} {1}.tex'.format(extfile, deco)
os.system(txmake_cmd)
os.remove(extfile)
else:
print('RMANTREE environment variable not set correctly. Set with: \nexport RMANTREE={0}\nexport PATH="$PATH:$RMANTREE/bin"'.format(PRMANPATH))
if not matname in usedmaterials:
usedmaterials.append(matname)
outmat = open("material_" + matname + ".rib", "w+")
if not deco == '0':
outmat.write(lddmatri.string(deco))
else:
outmat.write(lddmatri.string(None))
outmat.close()
zfmat.write("material_" + matname + ".rib", compress_type=compression)
os.remove("material_" + matname + ".rib")
#out.write("usemtl " + matname + '\n')
op.write('AttributeBegin #begin Brick {0}.{1}\nAttribute "identifier" "uniform string name" ["Brick {0}.{1}"]\nAttribute "trace" "int maxspeculardepth" [8] "int maxdiffusedepth" [8]\n'.format(written_obj, part))
op.write('ReadArchive "{0}_Materials_Archive.zip!material_{1}.rib"\n'.format(filename, matname))
for face in geo.Parts[part].faces:
op.write('\tPolygon\n')
# NOTE RENDERMAN is left handed coordinate system, obj is right handed -> z-axis inverted
op.write('\t\t"vertex point P" [ {0} {1} {2} {3} {4} {5} {6} {7} {8} ]\n'.format(geo.Parts[part].outpositions[face.a].x, geo.Parts[part].outpositions[face.a].y, -1 * geo.Parts[part].outpositions[face.a].z, geo.Parts[part].outpositions[face.b].x, geo.Parts[part].outpositions[face.b].y, -1 * geo.Parts[part].outpositions[face.b].z, geo.Parts[part].outpositions[face.c].x, geo.Parts[part].outpositions[face.c].y, -1 * geo.Parts[part].outpositions[face.c].z))
if usenormal == True: # write normals in case flag True
# WARNING: SOME PARTS MAY HAVE BAD NORMALS. FOR EXAMPLE MAYBE PART: (85861) PL.ROUND 1X1 W. THROUGHG. HOLE
op.write('\t\t"vertex normal N" [ {0} {1} {2} {3} {4} {5} {6} {7} {8} ]\n'.format(geo.Parts[part].outnormals[face.a].x, geo.Parts[part].outnormals[face.a].y, -1 * geo.Parts[part].outnormals[face.a].z, geo.Parts[part].outnormals[face.b].x, geo.Parts[part].outnormals[face.b].y, -1 * geo.Parts[part].outnormals[face.b].z, geo.Parts[part].outnormals[face.c].x, geo.Parts[part].outnormals[face.c].y, -1 * geo.Parts[part].outnormals[face.c].z))
if len(geo.Parts[part].textures) > 0:
# NOTE RENDERMAN Maps Textures in the T from top to bottom so we calculate 1.0 - t so the image will map properly
op.write('\t\t"st" [ {0} {1} {2} {3} {4} {5} ]\n'.format(geo.Parts[part].textures[face.a].x, 1 - geo.Parts[part].textures[face.a].y, geo.Parts[part].textures[face.b].x, 1 - geo.Parts[part].textures[face.b].y, geo.Parts[part].textures[face.c].x, 1 - geo.Parts[part].textures[face.c].y))
op.write('AttributeEnd #end Brick {0}.{1}\n\n'.format(written_obj, part))
indexOffset += len(geo.Parts[part].outpositions)
textOffset += len(geo.Parts[part].textures)
#Logo on studs
if uselogoonstuds == True: # write logo on studs in case flag True
a = 0
for studs in geo.studsFields2D:
a += 1
if studs.type == 23:
for i in range(len(studs.custom2DField)):
for j in range(len(studs.custom2DField[0])):
if studs.custom2DField[i][j] in LOGOONSTUDSCONNTYPE: #Valid connection type which are "allowed" for logo on stud
if not "logoonstuds" in writtenribs:
writtenribs.append("logoonstuds")
zf.write('logoonstuds.rib', compress_type=compression)
op.write('AttributeBegin #begin Brick {0}.{1} stud{2}_{3}_{4}\nAttribute "identifier" "uniform string name" ["Brick {0}.{1} stud{2}_{3}_{4}"]\n'.format(written_obj, part, a, i, j))
op.write('\t\tConcatTransform [{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15}]\n'.format(studs.matrix.n11, studs.matrix.n12, 1 * studs.matrix.n13, studs.matrix.n14, studs.matrix.n21, studs.matrix.n22, 1 * studs.matrix.n23, studs.matrix.n24, 1 * studs.matrix.n31, 1 * studs.matrix.n32, studs.matrix.n33, studs.matrix.n34, 0, 0, 0, studs.matrix.n44))
op.write('\t\tTranslate {0} {1} {2}\n'.format(-1 * studs.matrix.n41 + j * 0.4 + 0.015, -1 * studs.matrix.n42 + 0.1425, 1 * studs.matrix.n43 + i * -0.4 - 0))
op.write('\t\tRotate 180 0 1 0\n')
op.write("\t\tScale {0} {0} {0}\n".format(0.81))
op.write('ReadArchive "{0}_Materials_Archive.zip!material_{1}.rib"\n'.format(filename, matname))
op.write('ReadArchive "{0}_Bricks_Archive.zip!logoonstuds.rib"\n'.format(filename))
op.write('AttributeEnd #end Brick {0}.{1} stud{2}_{3}_{4}\n\n'.format(written_obj, part, a, i, j))
# -----------------------------------------------------------------
op.close()
# Reset index for each part
indexOffset = 1
textOffset = 1
out.write('\t\tAttribute "identifier" "name" ["{0}"]\n'.format(written_obj))
out.write('\t\tReadArchive "{0}_Bricks_Archive.zip!{1}.rib"\n'.format(filename, written_obj))
out.write('\tAttributeEnd\n\n')
if not written_obj in writtenribs:
writtenribs.append(written_obj)
zf.write(written_obj + '.rib', compress_type=compression)
os.remove(written_obj + '.rib')