-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_product.py
622 lines (553 loc) · 22 KB
/
add_product.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
import argparse
import sys
import bpy
import math
from mathutils import Vector, Matrix, Euler
import json
import re
def rename_scene_object():
"""
统一更改场景 对象名字 防止产品模型导入和原对象重复
"""
objs = bpy.data.objects[:]
for i in objs:
i.name = 'scene.' + i.name
def get_frame_camera(frame):
"""
获取帧绑定的相机标记
"""
all_markers = bpy.context.scene.timeline_markers
for i in all_markers:
if i.frame == frame:
return i.camera
def add_product_old(model_path):
"""
场景添加产品
:param model_path: 产品模型路径
:return:
"""
bpy.ops.import_scene.gltf(filepath=model_path)
model = bpy.context.selected_objects[:]
bpy.context.view_layer.objects.active = model[0]
model[0].name = "product"
bpy.ops.object.join()
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
bpy.ops.object.empty_add(
type="PLAIN_AXES", align="WORLD", location=(0, 0, 0), scale=(1, 1, 1)
)
bpy.context.object.name = "ProductContainer"
pdc = bpy.data.objects["ProductContainer"]
pd = bpy.data.objects["product"]
lp = bpy.data.objects["LocatedCube"]
pd.parent = pdc
k1 = pd.dimensions.x
k2 = pd.dimensions.y
k3 = pd.dimensions.z
dimList = [k1, k2, k3]
k = max(dimList)
v = lp.dimensions.y
pd.scale *= v / k
pdBverts = [pd.matrix_world @ Vector(pdBvert) for pdBvert in pd.bound_box]
lpBverts = [lp.matrix_world @ Vector(lpBvert) for lpBvert in lp.bound_box]
pd.location = lpBverts[3] - pdBverts[3]
pd.select_set(True)
bpy.ops.object.transform_apply(location=True, rotation=False, scale=False)
pdBverts = [pd.matrix_world @ Vector(pdBvert) for pdBvert in pd.bound_box]
lpBverts = [lp.matrix_world @ Vector(lpBvert) for lpBvert in lp.bound_box]
pd.location = lpBverts[3] - pdBverts[3]
pd.select_set(True)
bpy.ops.object.transform_apply(location=True, rotation=False, scale=False)
def remove_empty():
"""
删除空对象
"""
while True:
model = bpy.context.selected_objects[:]
# 删除空物体
objs = [
i
for i in model
if i.type in ["EMPTY", "LIGHT", "CAMERA"] and not i.children
]
bpy.ops.object.delete({"selected_objects": objs})
if not objs:
break
def add_product_old_2(model_path):
"""
场景添加产品
:param model_path: 产品模型路径
:return:
"""
bpy.ops.import_scene.gltf(filepath=model_path)
model = bpy.context.selected_objects[:]
model[0].name = "product"
bpy.context.view_layer.objects.active = model[0]
bpy.ops.object.join()
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
# bpy.ops.object.empty_add(type='PLAIN_AXES', align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
# bpy.context.object.name = "ProductContainer"
#
# pdc = bpy.data.objects['ProductContainer']
# pd = bpy.data.objects['product']
# pd.parent = pdc
def add_product(model_path):
"""
场景添加产品
:param model_path: 产品模型路径
:return:
"""
bpy.ops.import_scene.gltf(filepath=model_path)
# 删除空对象
remove_empty()
# 组合
model = bpy.context.selected_objects[:]
for i in model:
if i.type != "EMPTY":
i.name = "product"
bpy.context.view_layer.objects.active = i
break
bpy.ops.object.join()
# 删除空对象
remove_empty()
# 应用变换
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
# 清除动画
model = bpy.context.selected_objects[:]
for i in model:
i.animation_data_clear()
name_index = 0
while True:
pd = bpy.data.objects['product']
parent = pd.parent
if parent:
name_index += 1
pd.name = 'product.' + str(name_index).zfill(4)
parent.name = 'product'
else:
break
# 建立空的父对象 对父对象进行 变换
bpy.ops.object.empty_add(
type="PLAIN_AXES", align="WORLD", location=(0, 0, 0), scale=(1, 1, 1)
)
bpy.context.object.name = "ProductContainer"
pd = bpy.data.objects["product"]
pdc = bpy.data.objects["ProductContainer"]
pd.parent = pdc
def add_product_new(model_path):
"""
场景添加产品
:param model_path: 产品模型路径
:return:
"""
# 为啥 threejs 导入obj 不会拆分顶点 导入glb 就会拆 命名规范也不一样,glb 会把后面得小数点去掉,obj 就不会。。。
rename_scene_object()
if model_path.endswith('.glb') or model_path.endswith('.gltf'):
file_kind = 'glb'
bpy.ops.import_scene.gltf(filepath=model_path)
elif model_path.endswith('.obj'):
file_kind = 'obj'
bpy.ops.import_scene.obj(filepath=model_path)
else:
raise Exception("不支持得产品模型格式")
# 删除空对象
remove_empty()
# 清除动画
model = bpy.context.selected_objects[:]
rex = re.compile('\.\d+$')
for i in model:
if file_kind == 'glb':
# 去除小数点
old_name = i.name
group = rex.search(old_name)
if group:
index = group.span()[0]
new_name = old_name[:index] + old_name[index + 1:]
i.name = new_name
i.name = i.name.replace(' - ', '_-_')
# 去除动画
i.animation_data_clear()
# 建立空的父对象 对父对象进行 变换
bpy.ops.object.empty_add(
type="PLAIN_AXES", align="WORLD", location=(0, 0, 0), scale=(1, 1, 1)
)
bpy.context.object.name = "ProductContainer"
pdc = bpy.data.objects["ProductContainer"]
for i in model:
if not i.parent:
i.parent = pdc
# 分离顶点组 适配 three js 命名规范
if file_kind == 'glb':
for i in model:
if i.type == 'MESH':
bpy.ops.object.select_all(action='DESELECT')
i.select_set(True)
bpy.context.view_layer.objects.active = i
old_name = i.name
bpy.ops.mesh.separate(type="MATERIAL") # 按材质分离
separate_models = bpy.context.selected_objects[:]
separate_models = list(reversed(separate_models))
if len(separate_models) > 1:
for z, y in enumerate(separate_models):
y.name = old_name + "_%s" % str(z + 1)
def update_transform(location, scale, rotation_euler):
"""
更新变换信息
:param location: 位置
:param scale: 大小比例
:param rotation_euler: 欧拉旋转
:return:
"""
pd = bpy.data.objects["ProductContainer"]
pd.location = location # 更新位置
# pd.delta_location = location # 更新位置
# pd.delta_scale = scale # 更新大小比例
pd.scale = scale # 更新大小比例
pd.rotation_mode = "YZX" # 旋转模式
# pd.delta_rotation_euler = rotation_euler # 更新欧拉旋转
pd.rotation_euler = rotation_euler # 更新欧拉旋转
def update_camera(camera_option):
"""
更新摄像头信息
:param camera_option: 相机信息
:return:
"""
for i in range(len(camera_option)):
try:
# camera = get_frame_camera(camera_option[i]['frame'])
camera = get_frame_camera(i + 1)
# camera = bpy.data.cameras[camera_option[i]["name"]]
except:
continue
if camera:
camera.name = camera_option[i]["name"]
camera.data.sensor_height = 50 # 传感器 适配尺寸 mm 高度
camera.data.sensor_fit = "VERTICAL" # 传感器适配方式 垂直
camera.data.lens_unit = 'FOV' # 镜头单位 焦距
camera.data.angle = math.radians(float(camera_option[i]["fov"]))
camera.data.clip_start = float(camera_option[i]["near"])
camera.data.clip_end = float(camera_option[i]["far"])
camera.location = camera_option[i]["location"]
# 父子级方法 前端传父级角度
# camera.rotation_mode = "YZX"
# YXZ
# camera.rotation_euler = camera_option[i]["rotate"]
# 合并相机父子级 前端传合并好的角度
# rotate = camera_option[i]["rotate"]
# m = Euler((float(rotate[0]), float(rotate[1]), float(rotate[2])),
# 'ZYX').to_matrix()
# b_m = [m[0], -m[2], m[1]]
# matrix = Matrix(b_m)
# euler = matrix.to_euler('XYZ')
# camera.rotation_mode = "XYZ"
# camera.rotation_euler = euler
# 新方法 旋转转换
# "x":(tmp_rotation.x*180/Math.PI + 90).toFixed(3),
# "y":(tmp_rotation.z*180/Math.PI).toFixed(3),
# "z":(tmp_rotation.y*180/Math.PI).toFixed(3)
camera.rotation_mode = "YXZ"
camera.rotation_euler = camera_option[i]["rotate"]
# HEX转linearRGB
def srgb_to_linearrgb(c):
if c < 0:
return 0
elif c < 0.04045:
return c / 12.92
else:
return ((c + 0.055) / 1.055) ** 2.4
def hex2rgb(color, alpha=1):
color = int('0x' + color[1:], 16) # #FFFFFF
r = (color & 0xff0000) >> 16
g = (color & 0x00ff00) >> 8
b = (color & 0x0000ff)
return tuple([srgb_to_linearrgb(c / 0xff) for c in (r, g, b)] + [alpha])
# 基础色
def Basecolor(color, map, baseColorIMG, baseColorRGB, baseColorMix, links, BSDF):
if map:
baseColorIMG.image = bpy.data.images.load(map)
baseColorRGB.outputs[0].default_value = (hex2rgb(color))
links.new(baseColorMix.outputs[0], BSDF.inputs['Base Color'])
else:
baseColorRGB.outputs[0].default_value = (hex2rgb(color))
links.new(baseColorRGB.outputs[0], BSDF.inputs['Base Color'])
# 金属度
def Metallic(metalness, metalnessMap, metallicIMG, metallicFactor, metallicMix, links, BSDF):
if metalnessMap:
metallicIMG.image = bpy.data.images.load(metalnessMap)
metallicIMG.image.colorspace_settings.name = 'Non-Color'
metallicFactor.outputs[0].default_value = 1
links.new(metallicMix.outputs[0], BSDF.inputs['Metallic'])
else:
metallicFactor.outputs[0].default_value = metalness
links.new(metallicFactor.outputs[0], BSDF.inputs['Metallic'])
# 粗糙度
def Roughness(roughness, roughnessMap, roughnessIMG, roughnessFactor, roughnessMix, links, BSDF):
if roughnessMap:
roughnessIMG.image = bpy.data.images.load(roughnessMap)
roughnessIMG.image.colorspace_settings.name = 'Non-Color'
roughnessFactor.outputs[0].default_value = 1
links.new(roughnessMix.outputs[0], BSDF.inputs['Roughness'])
else:
roughnessFactor.outputs[0].default_value = roughness
links.new(roughnessFactor.outputs[0], BSDF.inputs['Roughness'])
# 透射率
# def Transmission(ior, transmission, iorFactor, transmissionFactor, links, BSDF):
# iorFactor.outputs[0].default_value = ior
# transmissionFactor.outputs[0].default_value = transmission
# links.new(iorFactor.outputs[0], BSDF.inputs[14])
# links.new(transmissionFactor.outputs[0], BSDF.inputs[15])
# 透射率
def Transmission(ior, transmission, iorFactor, transmissionFactor, transMix, matOutput, links, BSDF):
iorFactor.outputs[0].default_value = ior
transmissionFactor.outputs[0].default_value = transmission
links.new(iorFactor.outputs[0], BSDF.inputs['IOR'])
links.new(transmissionFactor.outputs[0], BSDF.inputs['Transmission'])
if transmission != 0:
links.new(BSDF.outputs[0], transMix.inputs[1])
links.new(transMix.outputs[0], matOutput.inputs[0])
# 发光
def Emission(emissive, emissiveIntensity, emissiveMap, emissiveIMG, emissiveRGB, emissiveFactor, emissiveMix, links,
BSDF):
if emissiveMap:
emissiveIMG.image = bpy.data.images.load(emissiveMap)
emissiveRGB.outputs[0].default_value = (1, 1, 1, 1)
emissiveFactor.outputs[0].default_value = emissiveIntensity
links.new(emissiveMix.outputs[0], BSDF.inputs['Emission'])
links.new(emissiveFactor.outputs[0], BSDF.inputs['Emission Strength'])
else:
emissiveRGB.outputs[0].default_value = (hex2rgb(emissive))
emissiveFactor.outputs[0].default_value = emissiveIntensity
links.new(emissiveRGB.outputs[0], BSDF.inputs['Emission'])
links.new(emissiveFactor.outputs[0], BSDF.inputs['Emission Strength'])
# 法线/凹凸
def Normal(normalMap, NormalMap, normalIMG, links, BSDF):
if normalMap:
normalIMG.image = bpy.data.images.load(normalMap)
normalIMG.image.colorspace_settings.name = 'Non-Color'
links.new(NormalMap.outputs[0], BSDF.inputs['Normal'])
def update_material(material_option):
"""
更新材质信息
:param material_option: 材质信息
:return:
"""
for j, i in enumerate(material_option):
mat_template = bpy.data.materials['StandardMaterial']
name = i['name']
try:
obj = bpy.data.objects[name]
except:
try:
new_name = name.capitalize()
obj = bpy.data.objects[new_name]
except:
continue
mat = mat_template.copy()
obj.active_material = mat
nodes = mat.node_tree.nodes
links = mat.node_tree.links
BSDF = nodes.get('Principled BSDF')
baseColorIMG = nodes.get('baseColorIMG')
baseColorRGB = nodes.get('baseColorRGB')
baseColorMix = nodes.get('baseColorMix')
metallicMix = nodes.get('metallicMix')
metallicIMG = nodes.get('metallicIMG')
metallicFactor = nodes.get('metallicFactor')
roughnessIMG = nodes.get('roughnessIMG')
roughnessFactor = nodes.get('roughnessFactor')
roughnessMix = nodes.get('roughnessMix')
iorFactor = nodes.get('iorFactor')
transmissionFactor = nodes.get('transmissionFactor')
emissiveIMG = nodes.get('emissiveIMG')
emissiveRGB = nodes.get('emissiveRGB')
emissiveMix = nodes.get('emissiveMix')
emissiveFactor = nodes.get('emissiveFactor')
normalIMG = nodes.get('normalIMG')
normalFactor = nodes.get('normalFactor')
NormalMap = nodes.get('NormalMap')
transBSDF = nodes.get('transBSDF')
transMix = nodes.get('transMix')
matOutput = nodes.get('matOutput')
color = i.get('color')
map = i.get('map')
metalness = i.get('metalness')
metalnessMap = i.get('metalnessMap')
roughness = i.get('roughness')
roughnessMap = i.get('roughnessMap')
ior = i.get('ior')
transmission = i.get('transmission')
emissive = i.get('emissive')
emissiveIntensity = i.get('emissiveIntensity')
emissiveMap = i.get('emissiveMap')
normalMap = i.get('normalMap')
Basecolor(color, map, baseColorIMG, baseColorRGB, baseColorMix, links, BSDF)
Metallic(metalness, metalnessMap, metallicIMG, metallicFactor, metallicMix, links, BSDF)
Roughness(roughness, roughnessMap, roughnessIMG, roughnessFactor, roughnessMix, links, BSDF)
Transmission(ior, transmission, iorFactor, transmissionFactor, transMix, matOutput, links, BSDF)
Emission(emissive, emissiveIntensity, emissiveMap, emissiveIMG, emissiveRGB, emissiveFactor, emissiveMix, links,
BSDF)
Normal(normalMap, NormalMap, normalIMG, links, BSDF)
def update_output(of, pixel):
"""
更新输出选项
:param of: jpeg 或者 mp4
:param pixel: 像素分辨率
:return:
"""
if pixel and pixel != (0, 0):
bpy.context.scene.render.resolution_x = pixel[0] # 分辨率 x
bpy.context.scene.render.resolution_y = pixel[1] # 分辨率 y
if of == "jpeg":
bpy.context.scene.render.image_settings.file_format = "JPEG"
bpy.context.scene.cycles.samples = 64
bpy.context.scene.render.resolution_percentage = 100
elif of == "ffmpeg":
bpy.context.scene.render.image_settings.file_format = "FFMPEG"
bpy.context.scene.render.ffmpeg.constant_rate_factor = "HIGH"
bpy.context.scene.render.ffmpeg.format = "MPEG4"
bpy.context.scene.cycles.samples = 64
bpy.context.scene.render.resolution_percentage = 100
class ArgumentParserForBlender(argparse.ArgumentParser):
"""
获取blender 传给python 脚本的参数
"""
def listRightIndex(self, alist, value):
return len(alist) - alist[-1::-1].index(value) - 1
def _get_argv_after_doubledash(self):
try:
idx = self.listRightIndex(sys.argv, "--")
return sys.argv[idx + 1:] # the list after '--'
except ValueError as e: # '--' not in the list:
return []
def parse_args(self):
return super().parse_args(args=self._get_argv_after_doubledash())
parser = ArgumentParserForBlender()
parser.add_argument(
"-l", "--location", nargs="+", type=float, help="位置", default=[0, 0, 0]
)
parser.add_argument(
"-s", "--scale", nargs="+", type=float, help="比例", default=[1, 1, 1]
)
parser.add_argument(
"-r", "--rotation_euler", nargs="+", type=float, help="旋转", default=[0, 0, 0]
)
parser.add_argument(
"-pl", "--pixel", nargs="+", type=int, help="像素分辨率", default=[0, 0]
)
parser.add_argument(
"-pd",
"--product",
type=str,
help="产品",
default="/data/blender/product/Product1.glb",
)
parser.add_argument("-of", "--output_format", type=str, default="jpeg", help="输出格式")
parser.add_argument(
"-co", "--camera_option", type=json.loads, help="镜头camera 调整", default=[]
)
parser.add_argument(
"-mo", "--material_option", type=json.loads, help="材质material 调整", default=[]
)
try:
args = parser.parse_args()
old_location = tuple(args.location)
old_scale = tuple(args.scale)
old_rotation_euler = tuple(args.rotation_euler)
pixel = tuple(args.pixel)
# blender three.js 轴方向适配
location = (old_location[0], -old_location[2], old_location[1])
scale = (old_scale[0], old_scale[2], old_scale[1])
rotation_euler = (old_rotation_euler[0], -old_rotation_euler[2], old_rotation_euler[1])
camera_option = args.camera_option
for i in camera_option:
pass
# temp_l = tuple(i["location"])
# i['location'] = (float(temp_l[0]), -float(temp_l[2]), float(temp_l[1]))
# temp_r = tuple(i["rotate"])
# i["rotate"] = (float(temp_r[0]), -float(temp_r[2]), float(temp_r[1]))
material_option = args.material_option
of = args.output_format
product = args.product
add_product_new(product)
update_transform(location, scale, rotation_euler)
update_camera(camera_option)
update_material(material_option)
update_output(of, pixel)
except Exception as e:
# import traceback
# traceback.print_exc(file=sys.stdout)
line = e.__traceback__.tb_lineno
print('python 脚本异常 行号 {} 异常消息 {}'.format(line, str(e)))
sys.exit(1)
'''
import bpy
import math
def get_frame_camera(frame):
"""
获取帧绑定的相机标记
"""
all_markers = bpy.context.scene.timeline_markers
for i in all_markers:
if i.frame == frame:
return i.camera
camera_option = [{"name":"default","fov":54.43222611864906,"near":0.10000000149011612,"far":100,"location":["-5.81","2.34","-1.10"],"rotate":["-2.01","-1.15","-2.05"]},{"name":"Camera001_Orientation","fov":41.11209023703316,"near":0.10000000149011612,"far":1000,"location":["-6.73","2.29","7.38"],"rotate":["1.57","-0.01","0.65"]},{"name":"Camera002_Orientation","fov":39.597755335771296,"near":0.10000000149011612,"far":1000,"location":["6.44","3.90","9.29"],"rotate":["1.45","0.06","-0.52"]}]
for i in range(len(camera_option)):
try:
# camera = get_frame_camera(camera_option[i]['frame'])
camera = get_frame_camera(i + 1)
# camera = bpy.data.cameras[camera_option[i]["name"]]
except:
continue
if camera:
temp_l = tuple(camera_option[i]['location'])
temp_r = tuple(camera_option[i]['rotation'])
location = (float(temp_l[0]), -float(temp_l[2]), float(temp_l[1]))
rotation_euler = (float(temp_r[0]), -float(temp_r[2]), float(temp_r[1]))
camera.name = camera_option[i]["name"]
camera.data.sensor_height = 50 # 传感器 适配尺寸 mm 高度
camera.data.sensor_fit = "VERTICAL" # 传感器适配方式 垂直
camera.data.lens_unit = 'FOV' # 镜头单位 焦距
camera.data.angle = math.radians(float(camera_option[i]["fov"]))
camera.data.clip_start = float(camera_option[i]["near"])
camera.data.clip_end = float(camera_option[i]["far"])
camera.location = location
camera.rotation_mode = "YZX"
camera.rotation_euler = rotation_euler
'''
#
# test = {
# "location": "0.02,0.40,-0.23",
# "scale": "0.81,0.81,0.81",
# "rotate": "0,0,0",
# "cameraOption": [
# {
# "name": "Picture003",
# "fov": "22.90",
# "near": "0.10",
# "far": "1000.00",
# "location": [
# "10.17",
# "7.01",
# "13.81"
# ],
# "rotation": [
# "1.50",
# "0.05",
# "-0.63"
# ]
# }
# ]
# }
#
# import bpy
# camera = bpy.data.objects[test['cameraOption']['name']]
# camera.data.sensor_height = 50 # 传感器 适配尺寸 mm 高度
# camera.data.sensor_fit = "VERTICAL" # 传感器适配方式 垂直
# camera.data.lens_unit = 'FOV' # 镜头单位 焦距
# camera.data.angle = math.radians(float(test['cameraOption'][0]["fov"]))
# camera.data.clip_start = float(test['cameraOption'][0]["near"])
# camera.data.clip_end = float(test['cameraOption'][0]["far"])
# temp_l = tuple(test['cameraOption'][0]["location"])
# camera.location = (float(temp_l[0]), -float(temp_l[2]), float(temp_l[1]))
# temp_r = tuple(test['cameraOption'][0]["rotation"])
# camera.rotation_mode = "YZX"
# camera.rotation_euler = (float(temp_r[0]), -float(temp_r[2]), float(temp_r[1]))