-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPPE7.py
1134 lines (895 loc) · 52.3 KB
/
PPE7.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
#=============================================================================
# Simplified BSD License, see http://www.opensource.org/licenses/
#-----------------------------------------------------------------------------
# Copyright (c) 2011-2012, HEB Ventures, LLC
# Copyright (c) 2020, Ronald Jensen
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================
###################################################
#
# Poser Prop Exporter Version 6
# 7/26/2011
# www.blender3dclub.com
#
###################################################
import bpy
import os, sys, inspect
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
print ('\n--- Starting Poser Prop Exporter Version 6 ---')
print (sys.platform)
bpy.PoserPropPath = "k:\\content\\runtime\\"
bpy.PoserTexturePath = "k:\\content\\runtime\\textures\\"
bpy.PoserGeometryPath = "k:\\content\\runtime\\geometries\\"
if sys.platform.startswith('win') is False:
bpy.PoserPropPath = bpy.PoserPropPath.replace('\\', '/')
bpy.PoserTexturePath = bpy.PoserTexturePath.replace('\\', '/')
bpy.PoserGeometryPath = bpy.PoserGeometryPath.replace('\\', '/')
print (bpy.PoserPropPath)
print (bpy.PoserTexturePath)
print (bpy.PoserGeometryPath)
# ---------- path finder --------------------
def execution_path(filename):
return os.path.join(os.path.dirname(inspect.getfile(sys._getframe(1))), filename)
bpy.ImageType = ['PNG', '.png']
def offCalc(obj):
tempobj = obj
xtemp = 0
ytemp = 0
ztemp = 0
parent_check = True
while parent_check is True:
if tempobj.parent != None:
xtemp = xtemp + (tempobj.location[0] - tempobj.parent.location[0])
else:
xtemp = xtemp + tempobj.location[0]
if tempobj.parent != None:
ytemp = ytemp + (tempobj.location[1] - tempobj.parent.location[1])
else:
ytemp = ytemp + tempobj.location[1]
if tempobj.parent != None:
ztemp = ztemp + (tempobj.location[2] - tempobj.parent.location[2])
else:
ztemp = ztemp + tempobj.location[2]
if tempobj.parent == None:
parent_check = False
else:
tempobj = tempobj.parent
return(xtemp, ytemp, ztemp)
def store_dir():
# Save Directory Locations
# Get blender path and store in PT2 Directory
# Find PT2 Folder:
############################################
#propsdir = '\\PT2\\props_dirs.pt2'
#if sys.platform.startswith('win'):
# pass
#else:
# propsdir = propsdir.replace('\\', '/')
#outstr = os.path.abspath(execution_path('sample.txt'))
outstr = bpy.PT2path
outstr = outstr + 'prop_dirs.pt2'
#print (outstr)
############################################
file = open(outstr, 'w')
outtext = bpy.PoserPropPath + '\n'
file.write(outtext)
outtext = bpy.PoserGeometryPath + '\n'
file.write(outtext)
outtext = bpy.PoserTexturePath + '\n'
file.write(outtext)
file.close()
def read_dir():
# Find PT2 Folder:
############################################
#print ('\n---------------------------')
# get the absolute path of PT2
outstr = os.path.abspath(execution_path('PT2Main.py'))
outstr = outstr.replace('PT2Main.py', '')
#outstr = outstr + '\\PT2\\'
if sys.platform.startswith('win'):
pass
else:
outstr = outstr.replace('\\', '/')
#print ('145 outstr:', outstr)
bpy.PT2path = outstr
outstr = outstr + 'prop_dirs.pt2'
file = open(outstr, 'r')
line = []
for x in file:
line.append(x)
file.close()
bpy.PoserPropPath = line[0].strip()
bpy.PoserGeometryPath = line[1].strip()
bpy.PoserTexturePath = line[2].strip()
return
class NoRender(bpy.types.Operator):
bl_idname = "object.missing_render"
label = "Error Message: "
bl_label = label
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self, width=250)
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
col = row.column()
col.label(text="Render image not created. Please create a")
col.label(text="render at 91px x 91px to save as a thumbnail.")
bpy.utils.register_class(NoRender)
class NotMesh(bpy.types.Operator):
bl_idname = "object.not_mesh"
label = "Error Message: "
bl_label = label
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self, width=250)
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
col = row.column()
col.label(text="Please select only Mesh Objects for Exporting.")
#col.label(text="render at 91px x 91px to save as a thumbnail.")
bpy.utils.register_class(NotMesh)
class NotPacked(bpy.types.Operator):
bl_idname = "object.not_packed"
label = "Error Message: "
bl_label = label
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self, width=250)
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
col = row.column()
col.label(text="Please pack all images before exporting.")
bpy.utils.register_class(NotPacked)
class OKpup(bpy.types.Operator):
bl_idname = "object.ok_pup"
label = "Export Completed Successfully: "
bl_label = label
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self, width=200)
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
col = row.column()
#col.label(text="Export Comp.")
#col.label(text="render at 91px x 91px to save as a thumbnail.")
bpy.utils.register_class(OKpup)
class noUV(bpy.types.Operator):
bl_idname = "object.no_uv"
label = "No UVMap for this mesh."
bl_label = label
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self, width=200)
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
col = row.column()
#col.label(text="Export Comp.")
#col.label(text="render at 91px x 91px to save as a thumbnail.")
bpy.utils.register_class(noUV)
class PT2_PT_Poser_Prop_Exporter(bpy.types.Panel):
bl_label = "Poser Prop Exporter"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
# bl_category = "Tool"
bl_context = "scene"
def draw(self, context):
# Create Menu:
read_dir()
layout = self.layout
obj = context.object
row = layout.row()
row.operator("export.prop", icon = "DISK_DRIVE", text = 'Save Prop')
row = layout.row()
row.operator("save.thumb", icon = "RENDER_RESULT", text = 'Save Thumb Nail')
box = layout.box()
row = box.row()
row.label(text="Current Prop Path:")
row = box.row()
row.operator("set.proppath", icon = "FILE_FOLDER", text = '')
row.label(text=bpy.PoserPropPath)
box2 = layout.box()
row = box2.row()
row.label(text="Current Geometry Path:")
row = box2.row()
row.operator("set.geometrypath", icon = "FILE_FOLDER", text = '')
row.label(text=bpy.PoserGeometryPath)
box3 = layout.box()
row = box3.row()
row.label(text="Current Texture Path:")
row = box3.row()
row.operator("set.texturepath", icon = "FILE_FOLDER", text = '')
row.label(text=bpy.PoserTexturePath)
class Save_Thumb(bpy.types.Operator):
'''Save last render as a Thumb Nail for this prop'''
bl_idname = "save.thumb"
bl_label = "Save Thumb"
@classmethod
def poll(cls, context):
return context.active_object != None
def execute(self, context):
try:
Thumb = bpy.data.images['Render Result']
print ('Saving Thumb nail...')
print (Thumb)
print (Thumb.file_format)
Thumb.file_format = 'PNG'
obj_name = bpy.context.active_object.name
thumbpath = bpy.PoserPropPath + obj_name + '.png'
Thumb.save_render(thumbpath)
bpy.ops.object.ok_pup('INVOKE_DEFAULT')
except:
print ('No Rendered Image to save')
bpy.ops.object.missing_render('INVOKE_DEFAULT')
#break
return {'FINISHED'}
class SetPropPath(bpy.types.Operator, ExportHelper):
'''Select the Prop Folder where this prop will be saved as a .pp2.'''
bl_idname = "set.proppath" # this is important since its how bpy.ops.export.some_data is constructed
bl_label = "Select Folder"
# ExportHelper mixin class uses this
filename_ext = ".txt"
filter_glob : StringProperty(default="*.txt", options={'HIDDEN'})
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
@classmethod
def poll(cls, context):
return context.active_object != None
def execute(self, context):
path = self.filepath
if sys.platform.startswith('win'):
path = path.split('\\')
else:
path = path.split('/')
path.pop()
temppath = ''
for x in path:
if sys.platform.startswith('win'):
temppath = temppath + x + '\\'
else:
temppath = temppath + x + '/'
print (temppath)
bpy.PoserPropPath = temppath
store_dir()
return {'FINISHED'}
class SetGeometryPath(bpy.types.Operator, ExportHelper):
'''Select the Geometry Folder where this prop will save it's .obj file.'''
bl_idname = "set.geometrypath" # this is important since its how bpy.ops.export.some_data is constructed
bl_label = "Select Folder"
# ExportHelper mixin class uses this
filename_ext = ".pp2"
filter_glob : StringProperty(default="*.pp2", options={'HIDDEN'})
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
@classmethod
def poll(cls, context):
return context.active_object != None
def execute(self, context):
path = self.filepath
if sys.platform.startswith('win'):
path = path.split('\\')
else:
path = path.split('/')
path.pop()
temppath = ''
for x in path:
if sys.platform.startswith('win'):
temppath = temppath + x + '\\'
else:
temppath = temppath + x + '/'
print (temppath)
bpy.PoserGeometryPath = temppath
store_dir()
return {'FINISHED'}
class SetTexturePath(bpy.types.Operator, ExportHelper):
'''Select the Texture Folder where this prop will save it's texture files.'''
bl_idname = "set.texturepath" # this is important since its how bpy.ops.export.some_data is constructed
bl_label = "Select Folder"
# ExportHelper mixin class uses this
filename_ext = ".txt"
filter_glob : StringProperty(default="*.txt", options={'HIDDEN'})
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
@classmethod
def poll(cls, context):
return context.active_object != None
def execute(self, context):
path = self.filepath
if sys.platform.startswith('win'):
path = path.split('\\')
else:
path = path.split('/')
path.pop()
temppath = ''
for x in path:
if sys.platform.startswith('win'):
temppath = temppath + x + '\\'
else:
temppath = temppath + x + '/'
print (temppath)
bpy.PoserTexturePath = temppath
store_dir()
return {'FINISHED'}
#################################################
#
# Save Prop
#
#################################################
class SaveProp(bpy.types.Operator):
bl_idname = "export.prop"
bl_label = "Export Prop"
def execute(self, context):
print ('Saving Prop...')
print ('\n-------------------')
print (bpy.context.selected_objects)
objs = bpy.context.selected_objects
def fw(text):
file.write(text)
file.write('\n')
return
def fwnr(text):
file.write(text)
#file.write('\n')
return
print ('\nOBJ List:')
print (objs)
print ('------------------------')
fail_check = False
for x in objs:
print (x.type)
# Check for all mesh type:
fail_check = False
if x.type != 'MESH':
print ('Please select only Mesh Objects')
#############
# error pup
#############
bpy.ops.object.not_mesh('INVOKE_DEFAULT')
fail_check = True
if fail_check == False:
geom_path = bpy.PoserGeometryPath
tex_path = bpy.PoserTexturePath
print ('Len of OBJS:', str(len(objs)))
for obj in objs:
print ('\n\nWorking obj:', obj.name)
###########################################
#
# Save geometry to geometry folder
#
# External OBJS:
#
###########################################
bpy.ops.object.mode_set(mode='OBJECT')
###########################################
# Apply Scale, location and Rotation First.
###########################################
# Rotate X-90, apply, save, then reverse. to
# compensate for Poser Difference
'''
Removed because of Blender 2.58
'''
#bpy.ops.object.scale_apply()
#bpy.ops.object.rotation_apply()
bpy.ops.object.transform_apply(rotation=True)
#break
obj.rotation_euler[0] = -1.57
bpy.ops.object.transform_apply(rotation=True)
mesh = obj.data
mesh.update()
#break
###########################################
print ('obj name:', obj.name)
geom_file = geom_path + obj.name + '.obj'
file = open(geom_file, 'w')
fw('# File Created with Poser Tools 2 for Blender')
fw('# www.blender3dclub.com')
fw('')
###########################################
# Verts
# Must add in offset to verts
offset = offCalc(obj)
verts = obj.data.vertices
for vert in verts:
xyz = 'v ' + str(vert.co[0]+offset[0]) + ' ' + str(vert.co[1]+offset[2]) + ' ' + str(vert.co[2]-offset[1])
fw(xyz)
fw('')
###########################################
# UV Verts:
# Check first:
mesh = obj.data
try:
uv = mesh.uv_textures[0].data
for face in uv:
for vertex in face.uv:
xy = 'vt ' + str(vertex[0]) + ' ' + str(vertex[1])
fw(xy)
fw('')
except:
bpy.ops.object.no_uv('INVOKE_DEFAULT')
pass
###########################################
# Faces
faces = obj.data.polygons
facecounter = 0
vertcounter = 0
matlist = mesh.materials
###########################################
# Mat name space fix:
for mat in matlist:
mat.name = mat.name.replace(' ','_')
currentmat = ''
for face in faces:
#######################################
# 'usemtl' here
#
#print ('len:', len(matlist))
if len(matlist) > 0 and matlist[face.material_index].name != currentmat:
print ('usemtl', matlist[face.material_index].name)
usemat = '\nusemtl ' + str(matlist[face.material_index].name)
fw(usemat)
currentmat = matlist[face.material_index].name
facetext = 'f '
vertlen = len(face.vertices)
for verts in range(0,vertlen):
###################
# V:
facetext = facetext + str(face.vertices[verts]+1)
###################
# VT:
facetext = facetext + '/' + str(vertcounter+1)
###################
#VN:
vertcounter += 1
facetext = facetext + ' '
facecounter +=1
fw(facetext)
#########################################
# Return to original rotation:
obj.rotation_euler[0] = 1.57
bpy.ops.object.transform_apply(rotation=True)
mesh.update()
#break
#########################################
file.close()
###########################################
#
# Save images to texture folder
#
###########################################
mats = mesh.materials
for mat in mats:
print (mat.name)
this_mat = bpy.data.materials[mat.name]
textures = this_mat.texture_slots
for tex_slot in textures:
if tex_slot != None:
texture = tex_slot.texture
image = texture.image
###########################
#
# Check if packed first:
#
if image.packed_file == None:
bpy.ops.object.not_packed('INVOKE_DEFAULT')
print ('Image not packed')
fail_check = True
print (dir(image))
print ('Pack check:', image.packed_file)
#except:
#bpy.ops.object.not_packed('INVOKE_DEFAULT')
tex_path = bpy.PoserTexturePath
###################################
#
# Keep format fix
#
file_ext = ''
if image.file_format == 'JPEG':
file_ext = '.jpg'
elif image.file_format == 'PNG':
file_ext = '.png'
tex_file = tex_path + image.name + file_ext
image.filepath = tex_file
###############################
# User Select type via toggles
print (image.name, image.file_format)
#image.file_format = bpy.ImageType[0]
image.save()
###########################################
#
# Save prop to prop folder
#
###########################################
bpy.ops.object.mode_set(mode='OBJECT')
obj = bpy.context.active_object
obj_list = bpy.context.selected_objects
############
# cycle through all meshes materials
#############
mesh = obj.data
mats = mesh.materials
prop_name = bpy.context.active_object.name
prop_file = bpy.PoserPropPath + prop_name + '.pp2'
pt2path = bpy.PT2path
#file = open(prop_file, 'w')
####################
#
# Version 4 stuff:
#
####################
print ('\n\n Saving Prop...')
#print (bpy.PT2path)
template = bpy.PT2path + 'PropTemplate.pt2'
templfile = open(template, 'r')
print('prop file', prop_file)
file = open(prop_file, 'w')
# Get obj path
if sys.platform.startswith('win'):
geo_path = bpy.PoserGeometryPath.split('\\')
else:
geo_path = bpy.PoserGeometryPath.split('/')
check = 0
gp = ''
for path in geo_path:
if check == 1:
gp = gp + ':' + path
elif path == 'geometries' or path == 'Geometries':
check = 1
gp = ':Runtime:geometries' + gp
print ('gp:', gp)
geometry_path = gp
# Get texture path
if sys.platform.startswith('win'):
image_path = bpy.PoserTexturePath.split('\\')
else:
image_path = bpy.PoserTexturePath.split('/')
check = 0
tp = ''
for path in image_path:
if check == 1:
tp = tp + ':' + path
elif path == 'textures' or path == 'Textures':
check = 1
tp = ':Runtime:Textures' + tp
print ('tp:', tp)
texture_path = tp
#print ('image_path:', image_path)
for line in templfile:
#print (line)
if line.startswith('[version]') is True:
outstr = '\tversion 4'
fw(outstr)
elif line.startswith('[prop]') is True:
outstr = 'prop ' + obj.name
fw(outstr)
elif line.startswith('[prop name]') is True:
outstr = '\tname ' + obj.name
fw(outstr)
elif line.startswith('[objfile]') is True:
# cycle through multiple objs
for this_obj in obj_list:
outstr = 'prop ' + this_obj.name
fw(outstr)
outstr = '\t{\n\tstorageOffset 0 0.3487 0'
fw(outstr)
outstr = '\tobjFileGeom 0 0 ' + geometry_path + this_obj.name + '.obj'
fw(outstr)
outstr = '\t}'
fw(outstr)
elif line.startswith('[prop details]') is True:
print ('Starting prop details')
# add details for each prop
details = bpy.PT2path + 'PropDetails4.pt2'
for this_obj in obj_list:
#
#origin = this_obj.location
#print ('origin:', origin)
#bpy.ops.object.location_apply()
#print ('origin2:', origin)
file3 = open(details, 'r')
outstr = 'prop ' + this_obj.name
fw(outstr)
for Dline in file3:
if Dline.startswith('[prop name]') is True:
outstr = '\tname ' + this_obj.name
fw(outstr)
elif Dline.startswith('[origin]') is True:
#outstr = '\torigin ' + str(this_obj.location[0])+ ' ' + str(this_obj.location[2]) + ' ' + str(this_obj.location[1]*-1)
#fw(outstr)
#print ('origin', outstr)
#############################
# Must change to offset amount
x = offCalc(this_obj)[0]
y = offCalc(this_obj)[2]
z = offCalc(this_obj)[1]
outstr = '\torigin ' + str(x) + ' ' + str(y) + ' ' + str(z*-1)
fw(outstr)
elif Dline.startswith('[parent]') is True:
this_parent = this_obj.parent
if this_parent == None:
this_parent = 'UNIVERSE'
else:
this_parent = this_parent.name
outstr = '\tparent ' + this_parent
fw(outstr)
elif Dline.startswith('[xOffA]') is True:
outstr = '\t\t\tinitValue'
xoff = offCalc(this_obj)[0]
outstr = outstr + ' ' + str(xoff)
#print (this_obj.name, outstr)
#print (outstr)
fw(outstr)
elif Dline.startswith('[xOffB]') is True:
outstr = '\t\t\tinitValue'
xoff = offCalc(this_obj)[0]
outstr = outstr + ' ' + str((xoff)*-1)
#print (this_obj.name, outstr)
#print (outstr)
fw(outstr)
elif Dline.startswith('[yOffA]') is True:
outstr = '\t\t\tinitValue'
yoff = offCalc(this_obj)[2]
outstr = outstr + ' ' + str(yoff)
#print (this_obj.name, outstr)
#print (outstr)
fw(outstr)
elif Dline.startswith('[yOffB]') is True:
outstr = '\t\t\tinitValue'
yoff = offCalc(this_obj)[2]
outstr = outstr + ' ' + str((yoff)*-1)
#print (this_obj.name, outstr)
#print (outstr)
fw(outstr)
elif Dline.startswith('[zOffA]') is True:
outstr = '\t\t\tinitValue'
zoff = offCalc(this_obj)[1]
outstr = outstr + ' ' + str(zoff)
#print (this_obj.name, outstr)
#print (outstr)
fw(outstr)
elif Dline.startswith('[zOffB]') is True:
outstr = '\t\t\tinitValue'
zoff = offCalc(this_obj)[1]
outstr = outstr + ' ' + str((zoff)*-1)
#print (this_obj.name, outstr)
#print (outstr)
fw(outstr)
#########################################
#
# Rotation Locks:
#
#########################################
elif Dline.startswith('[xrotlock]') is True:
if this_obj.lock_rotation[0] is True:
outstr = '\t\t\thidden 1'
else:
outstr = '\t\t\thidden 0'
fw(outstr)
elif Dline.startswith('[yrotlock]') is True:
if this_obj.lock_rotation[2] is True:
outstr = '\t\t\thidden 1'
else:
outstr = '\t\t\thidden 0'
fw(outstr)
elif Dline.startswith('[zrotlock]') is True:
if this_obj.lock_rotation[1] is True:
outstr = '\t\t\thidden 1'
else:
outstr = '\t\t\thidden 0'
fw(outstr)
#########################################
#
# Materials:
#
#########################################
elif Dline.startswith('[materials]') is True:
# Cycle though obj materials:
#mesh = obj.data
mats = this_obj.data.materials
for mat in mats:
######################################
#
# Mat name space fix:
#
#mat.name = mat.name.replace(' ','_')
print (mat.name)
outstr = '\tmaterial ' + mat.name
fw(outstr)
outstr = '\t\t{'
fw(outstr)
mat_temp = bpy.PT2path + 'MaterialTemplate.pt2'
mat_file = open(mat_temp, 'r')
for line2 in mat_file:
if line2.startswith('[kd]') is True:
outstr = '\t\tKdColor ' + str(mat.diffuse_color[0]) + ' ' + str(mat.diffuse_color[1]) + ' ' + str(mat.diffuse_color[2]) + ' 1'
fw(outstr)
elif line2.startswith('[ka]') is True:
#outstr = '\t\tkaColor 0 0 0' + str(mat.alpha)
outstr = '\t\tKaColor 0 0 0 1'
fw(outstr)
elif line2.startswith('[ks]') is True:
outstr = '\t\tKsColor ' + str(mat.specular_color[0]) + ' ' + str(mat.specular_color[1]) + ' ' + str(mat.specular_color[2]) + ' 1'
fw(outstr)
elif line2.startswith('[tMax]') is True:
this_mat = bpy.data.materials[mat.name]
textures = this_mat.texture_slots
alphacheck = False
for tex_slot in textures:
if tex_slot != None and tex_slot.use_map_alpha is True:
alphacheck = True
outstr = '\t\ttMax 1.0'
fw(outstr)
if alphacheck == False:
outstr = '\t\ttMax 0'
fw(outstr)
elif line2.startswith('[textureMap]') is True:
this_mat = bpy.data.materials[mat.name]
textures = this_mat.texture_slots
mapcheck = False
for tex_slot in textures:
if tex_slot != None and tex_slot.use_map_color_diffuse is True and tex_slot.use == True:
print (tex_slot.texture.image.name, tex_slot.texture.image.file_format)
###################################
#
# Keep format fix
#
image = tex_slot.texture.image
file_ext = ''
if image.file_format == 'JPEG':
file_ext = '.jpg'
elif image.file_format == 'PNG':
file_ext = '.png'
tex_file = texture_path + tex_slot.texture.image.name + file_ext
outstr = '\t\ttextureMap "' + tex_file + '"\n\t\t\t0 0'
fw(outstr)
mapcheck = True
if mapcheck == False:
outstr = '\t\ttextureMap NO_MAP'
fw(outstr)
elif line2.startswith('[bumpMap]') is True:
this_mat = bpy.data.materials[mat.name]
textures = this_mat.texture_slots