-
Notifications
You must be signed in to change notification settings - Fork 29
/
FotogrametriaOpenMVGWinWSL.py
520 lines (346 loc) · 21.7 KB
/
FotogrametriaOpenMVGWinWSL.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
import bpy
import subprocess
import platform
from os.path import expanduser
import shutil
import tempfile
from os import listdir
from os.path import isfile, join
import multiprocessing
import exifread
import re
import os
# MENSAGENS
class MessageFaltaFotos(bpy.types.Operator):
bl_idname = "object.dialog_operator_falta_foto"
bl_label = "Doesn't have photo path!"
def execute(self, context):
message = ("Doesn't have photo path!")
self.report({'INFO'}, message)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
bpy.utils.register_class(MessageFaltaFotos)
'''
# ERROS
def ERROruntimeFotosDef(self, context):
self.layout.label("Doesn't have photo path!")
def ERROTermFoto():
CRED = '\033[91m'
CEND = '\033[0m'
print(CRED + "Doesn't have photo path!" + CEND)
'''
# PREPARA CENA
def PreparaCenaFotogramDef(self, context):
try:
bpy.ops.object.select_all(action='SELECT')
objetos_selecionados = [ o for o in bpy.context.scene.objects if o.select_get() == True ]
for i in objetos_selecionados:
i.hide_viewport = True
except:
print("Cena já preparada.")
class PreparaCenaFotogram(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.prepara_cena_fotogram"
bl_label = "Photogrammetry Scene Setup"
def execute(self, context):
PreparaCenaFotogramDef(self, context)
return {'FINISHED'}
bpy.utils.register_class(PreparaCenaFotogram)
# MODELOS
def GeraModeloFotoDef(self, context):
scn = context.scene
#CRIA OU SETA DIRETÓRIO TEMPORÁRIO
# if platform.system() == "Linux":
tmpdir = tempfile.mkdtemp()
# else:
# tmpdir = tempfile.gettempdir()
dFactor = scn.d_factor
smoothFactor = scn.smooth_factor
homeall = expanduser("~")
# TESTA ARQUIVOS
mypath = scn.my_tool.path_photo
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
FotoTeste = onlyfiles[1]
TestaHEIC = ".HEIC" in FotoTeste
if TestaHEIC == True:
if platform.system() == "Linux":
subprocess.call('mkdir '+tmpdir+'/JPG && cd '+mypath+' && for i in *; do heif-convert $i $i.jpg; done && mv *.jpg '+tmpdir+'/JPG/', shell=True)
scn.my_tool.path_photo = tmpdir+'/JPG/'
if platform.system() == "Darwin":
subprocess.call('mkdir '+tmpdir+'/JPG && cd '+mypath+' && mogrify -format jpg *.HEIC && mv *.jpg '+tmpdir+'/JPG/', shell=True)
scn.my_tool.path_photo = tmpdir+'/JPG/'
Testajpeg = ".jpeg" in FotoTeste
if Testajpeg == True:
if platform.system() == "Linux" or platform.system() == "Darwin":
subprocess.call('mkdir '+tmpdir+'/JPG && cd '+mypath+' && for i in *; do cp $i $i.jpg; done && mv *.jpg '+tmpdir+'/JPG/', shell=True)
scn.my_tool.path_photo = tmpdir+'/JPG/'
if platform.system() == "Windows" :
subprocess.call('mkdir '+tmpdir+'\JPG & cd '+mypath+' & for %f in (*) do copy %f %f.jpg & move *.jpg '+tmpdir+'\JPG', shell=True)
scn.my_tool.path_photo = tmpdir+'\JPG\\' # Se não colocar as duas barras não funciona!
TestaJPEG = ".JPEG" in FotoTeste
if TestaJPEG == True:
if platform.system() == "Linux" or platform.system() == "Darwin":
subprocess.call('mkdir '+tmpdir+'/JPG && cd '+mypath+' && for i in *; do cp $i $i.jpg; done && mv *.jpg '+tmpdir+'/JPG/', shell=True)
scn.my_tool.path_photo = tmpdir+'/JPG/'
if platform.system() == "Windows" :
subprocess.call('mkdir '+tmpdir+'\JPG & cd '+mypath+' & for %f in (*) do copy %f %f.jpg & move *.jpg '+tmpdir+'\JPG', shell=True)
scn.my_tool.path_photo = tmpdir+'\JPG\\' # Se não colocar as duas barras não funciona!
# REDUZ FOTOS
print("REDUZ FOTOS")
print("bpy.context.scene.my_tool.path_photo", bpy.context.scene.my_tool.path_photo)
tmpdirFotos = tempfile.mkdtemp()
Origem = bpy.context.scene.my_tool.path_photo
# Copia imagens para temporário
ListaImagens = sorted(os.listdir(Origem))
ImagContador = 0
for ImagemAtual in ListaImagens:
shutil.copyfile(Origem+ImagemAtual, tmpdirFotos+"/"+str(ImagContador)+".jpg")
ImagContador += 1
print("Copiando:", Origem+ImagemAtual, "para:", tmpdirFotos+"/"+str(ImagContador)+".jpg")
bpy.context.scene.my_tool.path_photo = Origem
# Reduz imagens
ListaArquivos = sorted(os.listdir(tmpdirFotos))
# print("ORIGEM:", Origem)
print("FOOOOOOOOOOOOOOOOI")
tmpdirIMagemgick = tempfile.mkdtemp()
for ArquivoAtual in ListaArquivos:
print("Reduzindo",ArquivoAtual)
bpy.ops.image.open(filepath=tmpdirFotos+ArquivoAtual, directory=tmpdirFotos, files=[{"name":ArquivoAtual, "name":ArquivoAtual}], relative_path=False, show_multiview=False)
ImgDim0 = bpy.data.images[ArquivoAtual].size[0]
ImgDim1 = bpy.data.images[ArquivoAtual].size[1]
LadoMaior = max(ImgDim0, ImgDim1)
CpuNum = multiprocessing.cpu_count()
if CpuNum >= 8:
FatorPixel = 2536
if CpuNum == 6:
FatorPixel = 2536
if CpuNum == 4:
FatorPixel = 2536
if CpuNum == 2:
FatorPixel = 2200
if CpuNum == 1:
FatorPixel = 2200
if LadoMaior > FatorPixel:
print("Maior que "+str(FatorPixel)+"!")
FatorDivisao = LadoMaior/FatorPixel
# bpy.data.images[ArquivoAtual].scale( int(ImgDim0/FatorDivisao), int(ImgDim1/FatorDivisao) )
if platform.system() == "Linux" or platform.system() == "Darwin":
subprocess.call('convert -resize '+str(100/FatorDivisao)+'% '+tmpdirFotos+"/"+ArquivoAtual+' '+tmpdirIMagemgick+"/"+ArquivoAtual, shell=True)
#bpy.data.images[ArquivoAtual].save()
bpy.context.scene.my_tool.path_photo = tmpdirIMagemgick+"/"
if platform.system() == "Windows":
#subprocess.call('C:\OrtogOnBlender\ImageMagick\convert -resize '+str(100/FatorDivisao)+'% '+tmpdirFotos+'\\'+ArquivoAtual+' '+tmpdirIMagemgick+'\\'+ArquivoAtual, shell=True) # O convert zoa os dados do EXIF no Windows!
FotosAtual = str(tmpdirFotos+"/"+ArquivoAtual).replace("\\", "/").replace('\\', "/").replace("C:", "/mnt/c")
MagickAtual = str(tmpdirIMagemgick+"/"+ArquivoAtual).replace("\\", "/").replace('\\', "/").replace("C:", "/mnt/c")
subprocess.call("wsl \"convert\" -resize \""+str(100/FatorDivisao)+"%\" \""+FotosAtual+"\" \""+MagickAtual+"\"", shell=True)
print("Reduzido com convert")
#bpy.data.images[ArquivoAtual].save()
bpy.context.scene.my_tool.path_photo = tmpdirIMagemgick+"/"
# TESTA CAMERA
# if platform.system() == "Windows":
if bpy.context.scene.my_tool.path_photo == "":
bpy.ops.object.dialog_operator_falta_foto('INVOKE_DEFAULT')
else:
mypath = scn.my_tool.path_photo # Tem que ter o / no final
# mypathFotos = mypath+'*'
# print("Caminho:"+mypathFotos)
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
FotoTeste = onlyfiles[1]
try:
with open(mypath + FotoTeste, 'rb') as f_jpg:
tags = exifread.process_file(f_jpg, details=True)
print (tags['Image Model'])
CamModel = str(tags['Image Model'])
#print("CamModel:", CamModel)
except:
print("Não rolou!")
# subprocess.call([os.system('cd'+mypath), '&&', homeall+'/Programs/OrtogOnBlender/openMVG/ExifTool.sh'])
if platform.system() == "Linux":
os.system('cd '+mypath+' && '+homeall+'/Programs/OrtogOnBlender/openMVG/ExifTool.sh')
if platform.system() == "Darwin":
os.system('cd '+mypath+' && '+homeall+'/Programs/OrtogOnBlender/openMVGMACelcap/ExifTool.sh')
if platform.system() == "Windows":
print(mypath)
#subprocess.call(['C:\OrtogOnBlender\ExitTool\exiftool.exe', '-all=', mypath]) # Necessário pq o convert zoa os dados do EXIF no Windows!
#print("Exif apagado tudo!")
subprocess.call(['C:\OrtogOnBlender\ExitTool\exiftool.exe', '-overwrite_original', '-Model=Z00AD', '-FocalLength=4', mypath+'*']) # Solução colocando o 4 sem as aspas duplas!
# CASO SEJA NECESSARIO EXIFTOOL WINDOWS
tmpdirNovo = str(tmpdir).replace("\\", "/").replace('\\', "/").replace("C:", "/mnt/c")
print("COMANDO EXIFTOOL")
print("wsl \"exiftool \" -overwrite_original -Model=\"Z00AD\" -FocalLength=\"3.8 mm\" \""+tmpdirNovo+"/*\"")
subprocess.call("wsl \"exiftool \" -overwrite_original -Model=\"Z00AD\" -FocalLength=\"3.8 mm\" \""+tmpdirNovo+"/*\"" , shell=True)
print("Resolvido!")
with open(mypath + FotoTeste, 'rb') as f_jpg:
tags = exifread.process_file(f_jpg, details=True)
print (tags['Image Model'])
CamModel = str(tags['Image Model'])+";"
# TESTA MODELO CAMERA
if platform.system() == "Linux":
camDatabase = homeall+"/Programs/OrtogOnBlender/openMVG/sensor_width_camera_database.txt"
if platform.system() == "Darwin":
camDatabase = homeall+"/Programs/OrtogOnBlender/openMVGMACelcap/sensor_width_camera_database.txt"
if platform.system() == "Windows":
camDatabase = "C:/OrtogOnBlender/openMVGWIN/sensor_width_camera_database.txt"
infile = open(camDatabase, "r")
numlines = 0
found = 0
for line in infile:
numlines += 1
while 1:
str_found_at = line.find(CamModel)
if str_found_at == -1:
# string not found in line ...
# go to next (ie break out of the while loop)
break
else:
# string found in line
found += 1
# more than once in this line?
# lets strip string and anything prior from line and
# then go through the testing loop again
line = line[str_found_at + len(CamModel):]
infile.close()
print(CamModel, "was found", found, "times in", numlines, "lines")
if found == 0:
print("Nao apareceu!")
with open(camDatabase, 'a') as file:
inputCam = CamModel, " 3.80"
print(inputCam)
# if platform.system() == "Darwin" or platform.system() == "Windows":
# file.write("\n")
file.write("\n")
file.writelines(inputCam) # Escreve o modelo de camera no arquivo
# GERA FOTOGRAMETRIA
# try:
# if scn.my_tool.path_photo == "":
# ERROTermFoto()
# bpy.context.window_manager.popup_menu(ERROruntimeFotosDef, title="Attention!", icon='INFO')
# else:
OpenMVGtmpDir = tmpdir+'/OpenMVG'
tmpOBJface = tmpdir+'/MVS/scene_dense_mesh_texture.obj'
if platform.system() == "Linux":
OpenMVGPath = homeall+'/Programs/OrtogOnBlender/openMVG/software/SfM/SfM_SequentialPipeline.py'
OpenMVSPath = homeall+'/Programs/OrtogOnBlender/openMVS/OpenMVS'
print("É Linux")
if platform.system() == "Windows":
OpenMVGPath = 'C:/OrtogOnBlender/openMVGWin/software/SfM/SfM_SequentialPipeline.py'
OpenMVSPath = 'C:/OrtogOnBlender/openMVSWin/OpenMVS.bat'
if platform.system() == "Darwin":
# if platform.release() == '15.6.0':
# OpenMVGPath = '/OrtogOnBlender/openMVGMACelcap/SfM_SequentialPipeline.py'
# OpenMVSPath = '/OrtogOnBlender/openMVSMACelcap/openMVSMAC.sh'
# if platform.release() == '17.5.0':
# OpenMVGPath = '/OrtogOnBlender/openMVGMACelcap/SfM_SequentialPipeline.py'
# OpenMVSPath = '/OrtogOnBlender/openMVSMACelcap/openMVSMAC.sh'
# else:
# OpenMVGPath = '/OrtogOnBlender/openMVGMAC/SfM_SequentialPipeline.py'
# OpenMVSPath = '/OrtogOnBlender/openMVSMAC/openMVSMAC.sh'
OpenMVGPath = homeall+'/Programs/OrtogOnBlender/openMVGMACelcap/SfM_SequentialPipeline.py'
OpenMVSPath = homeall+'/Programs/OrtogOnBlender/openMVSMACelcap/openMVSMAC.sh'
shutil.rmtree(tmpdir+'/OpenMVG', ignore_errors=True)
shutil.rmtree(tmpdir+'/MVS', ignore_errors=True)
# if os.name=='posix':
# shutil.rmtree(tmpdir+'/OpenMVG')
# shutil.rmtree(tmpdir+'/MVS')
# if os.name=='nt':
# subprocess.call(['rmdir', '/Q', '/S', tmpdir+'/OpenMVG'])
# subprocess.call(['rmdir', '/Q', '/S', tmpdir+'/MVS'])
if platform.system() == "Linux":
subprocess.call(['python', OpenMVGPath , scn.my_tool.path_photo , OpenMVGtmpDir])
if platform.system() == "Windows":
OpenMVGtmpDir = tmpdir+'/OpenMVG/'
Fotos = str(scn.my_tool.path_photo).replace("\\", "/").replace('\\', "/").replace("C:", "/mnt/c")
Saida = str(OpenMVGtmpDir).replace("\\", "/").replace('\\', "/").replace("C:", "/mnt/c")
subprocess.call("wsl \"python\" \"/mnt/c/OrtogOnBlender/OpenMVGLinux/openMVG/software/SfM/SfM_SequentialPipeline.py\" \""+Fotos+"\" \""+Saida+"\"" , shell=True)
#subprocess.call(['C:/OrtogOnBlender/Python27/python', OpenMVGPath , scn.my_tool.path_photo , OpenMVGtmpDir])
if platform.system() == "Darwin":
subprocess.call(['python', OpenMVGPath , scn.my_tool.path_photo , OpenMVGtmpDir])
#subprocess.call(OpenMVSPath , shell=True)
if platform.system() == "Linux":
subprocess.call('cd '+tmpdir+' && mkdir MVS && ~/Programs/OrtogOnBlender/openMVG/./openMVG_main_openMVG2openMVS -i '+tmpdir+'/OpenMVG/reconstruction_sequential/sfm_data.bin -o '+tmpdir+'/MVS/scene.mvs && ~/Programs/OrtogOnBlender/openMVS/./DensifyPointCloud --estimate-normals 1 '+tmpdir+'/MVS/scene.mvs && ~/Programs/OrtogOnBlender/openMVS/./ReconstructMesh -d '+dFactor+' --smooth '+smoothFactor+' '+tmpdir+'/MVS/scene_dense.mvs && ~/Programs/OrtogOnBlender/openMVS/./TextureMesh --export-type obj '+tmpdir+'/MVS/scene_dense_mesh.mvs', shell=True)
if platform.system() == "Darwin":
subprocess.call('cd '+tmpdir+' && mkdir MVS && '+homeall+'/Programs/OrtogOnBlender/openMVGMACelcap/openMVG_main_openMVG2openMVS -i '+tmpdir+'/OpenMVG/reconstruction_sequential/sfm_data.bin -o '+tmpdir+'/MVS/scene.mvs && '+homeall+'/Programs/OrtogOnBlender/openMVSMACelcap/./DensifyPointCloud --estimate-normals 1 '+tmpdir+'/MVS/scene.mvs && '+homeall+'/Programs/OrtogOnBlender/openMVSMACelcap/./ReconstructMesh -d '+dFactor+' --smooth '+smoothFactor+' '+tmpdir+'/MVS/scene_dense.mvs && '+homeall+'/Programs/OrtogOnBlender/openMVSMACelcap/./TextureMesh --export-type obj '+tmpdir+'/MVS/scene_dense_mesh.mvs', shell=True)
if platform.system() == "Windows":
#subprocess.call('cd '+tmpdir+' && mkdir MVS && C:\OrtogOnBlender\openMVGWin\openMVG_main_openMVG2openMVS -i '+tmpdir+'/OpenMVG/reconstruction_sequential/sfm_data.bin -o '+tmpdir+'/MVS/scene.mvs && C:\OrtogOnBlender\openMVSWin\DensifyPointCloud --estimate-normals 1 '+tmpdir+'/MVS/scene.mvs && C:\OrtogOnBlender\openMVSWin\ReconstructMesh -d '+dFactor+' --smooth '+smoothFactor+' '+tmpdir+'/MVS/scene_dense.mvs && C:\OrtogOnBlender\openMVSWin\TextureMesh --export-type obj '+tmpdir+'/MVS/scene_dense_mesh.mvs', shell=True)
#print("CONVERTE WINDOWS!!!")
#subprocess.call('cd '+tmpdir+' && mkdir MVS && C:\OrtogOnBlender\openMVGWin\openMVG_main_openMVG2openMVS -i '+tmpdir+'/OpenMVG/reconstruction_sequential/sfm_data.bin -o '+tmpdir+'/MVS/scene.mvs', shell = True)
tmpdirNovo = str(tmpdir).replace("\\", "/").replace('\\', "/").replace("C:", "/mnt/c")
subprocess.call("wsl \"mkdir\" "+tmpdirNovo+"\"/MVS\"", shell=True)
os.chdir(tmpdir) # Se não trocar o diretóri ele gera os distrts e demais dentro do dir do Blender e dá erro!
subprocess.call("wsl \"/mnt/c/OrtogOnBlender/OpenMVGLinux/openMVG/./openMVG_main_openMVG2openMVS\" -i \""+tmpdirNovo+"/OpenMVG/reconstruction_sequential/sfm_data.bin\" -o \""+tmpdirNovo+"/MVS/scene.mvs\"", shell=True)
subprocess.call("wsl \"/mnt/c/OrtogOnBlender/OpenMVGLinux/openMVS/./DensifyPointCloud\" --estimate-normals \"1\" \""+tmpdirNovo+"/MVS/scene.mvs\"", shell=True)
subprocess.call("wsl \"/mnt/c/OrtogOnBlender/OpenMVGLinux/openMVS/./ReconstructMesh\" -d \""+dFactor+"\" --smooth "+smoothFactor+" "+tmpdirNovo+"/MVS/scene_dense.mvs", shell=True)
subprocess.call("wsl \"/mnt/c/OrtogOnBlender/OpenMVGLinux/openMVS/./TextureMesh\" --export-type \"obj\" \""+tmpdirNovo+"/MVS/scene_dense_mesh.mvs\"" , shell=True)
#print("MVS WINDOWS!!!")
#print("DENSIFY")
#subprocess.call('C:\OrtogOnBlender\openMVSWin\DensifyPointCloud --estimate-normals 1 '+tmpdir+'/MVS/scene.mvs', shell=True)
#print("RECONMESH")
#subprocess.call('C:\OrtogOnBlender\openMVSWin\ReconstructMesh -d '+dFactor+' --smooth '+smoothFactor+' '+tmpdir+'/MVS/scene_dense.mvs', shell=True)
#print("TEXTURING")
#subprocess.call('C:\OrtogOnBlender\openMVSWin\TextureMesh --export-type obj '+tmpdir+'/MVS/scene_dense_mesh.mvs', shell=True)
# subprocess.call("wsl \"cd "+tmpdirNovo+" && mkdir MVS && /mnt/c/OrtogOnBlender/OpenMVGLinux/openMVG/./openMVG_main_openMVG2openMVS -i "+tmpdirNovo+"/OpenMVG/reconstruction_sequential/sfm_data.bin -o "+tmpdirNovo+"/MVS/scene.mvs && /mnt/c/OrtogOnBlender/OpenMVGLinux/openMVS/./DensifyPointCloud --estimate-normals 1 "+tmpdirNovo+"/MVS/scene.mvs && /mnt/c/OrtogOnBlender/OpenMVGLinux/openMVS/./ReconstructMesh -d "+dFactor+" --smooth "+smoothFactor+" "+tmpdirNovo+"/MVS/scene_dense.mvs && /mnt/c/OrtogOnBlender/OpenMVGLinux/openMVS/./TextureMesh --export-type obj "+tmpdirNovo+"/MVS/scene_dense_mesh.mvs\"" , shell=True)
# else:
# subprocess.call(OpenMVSPath , shell=True)
#subprocess.call([ 'meshlabserver', '-i', tmpdir+'scene_dense_mesh_texture.ply', '-o', tmpdir+'scene_dense_mesh_texture.obj', '-om', 'vn', 'wt' ])
bpy.ops.import_scene.obj(filepath=tmpOBJface, filter_glob="*.obj;*.mtl")
scene_dense_mesh_texture = bpy.data.objects['scene_dense_mesh_texture']
bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.objects.active = scene_dense_mesh_texture
bpy.data.objects['scene_dense_mesh_texture'].select_set(True)
bpy.context.object.data.use_auto_smooth = False
# bpy.context.object.active_material.specular_hardness = 60
# bpy.context.object.active_material.diffuse_intensity = 0.6
# bpy.context.object.active_material.specular_intensity = 0.3
bpy.context.object.active_material.specular_color = (0.233015, 0.233015, 0.233015)
# bpy.ops.object.modifier_add(type='SMOOTH')
# bpy.context.object.modifiers["Smooth"].factor = 2
# bpy.context.object.modifiers["Smooth"].iterations = 3
# bpy.ops.object.convert(target='MESH')
# bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Smooth")
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN')
#bpy.ops.view3d.view_all(center=False)
# Centraliza zoom
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'WINDOW':
override = {'area': area, 'region': region, 'edit_object': bpy.context.edit_object}
bpy.ops.view3d.view_all(override)
bpy.ops.file.pack_all()
bpy.ops.object.modifier_add(type='SMOOTH')
bpy.context.object.modifiers["Smooth"].factor = 2
bpy.context.object.modifiers["Smooth"].iterations = 3
bpy.context.object.modifiers["Smooth"].show_viewport = False
#bpy.ops.object.convert(target='MESH')
# MultRes
bpy.ops.object.modifier_add(type='MULTIRES')
bpy.context.object.modifiers["Multires"].show_viewport = False
bpy.ops.object.multires_subdivide(modifier="Multires")
context = bpy.context
obj = context.active_object
heightTex = bpy.data.textures.new('Texture name', type='IMAGE')
# heightTex.image = bpy.data.images['scene_dense_mesh_texture_material_0_map_Kd.jpg']
heightTex.image = bpy.data.images['scene_dense_mesh_texture_material_0_map_Kd.jpg']
dispMod = obj.modifiers.new("Displace", type='DISPLACE')
dispMod.texture = heightTex
bpy.context.object.modifiers["Displace"].texture_coords = 'UV'
bpy.context.object.modifiers["Displace"].strength = 3.2
bpy.context.object.modifiers["Displace"].mid_level = 0.5
bpy.context.object.modifiers["Displace"].show_viewport = False
#Comprime modificadores
bpy.context.object.modifiers["Smooth"].show_expanded = False
bpy.context.object.modifiers["Multires"].show_expanded = False
bpy.context.object.modifiers["Displace"].show_expanded = False
bpy.ops.object.shade_smooth()
bpy.context.space_data.shading.type = 'SOLID'
bpy.context.space_data.shading.color_type = 'TEXTURE'
class GeraModeloFoto(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.gera_modelo_foto_win"
bl_label = "Gera Modelos Foto Win"
def execute(self, context):
GeraModeloFotoDef(self, context)
return {'FINISHED'}
bpy.utils.register_class(GeraModeloFoto)