Repository navigation
Expand file tree
/
Copy pathBEUtils.py
More file actions
686 lines (500 loc) · 24.1 KB
/
Copy pathBEUtils.py
File metadata and controls
686 lines (500 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
import os
import stat
import bpy
import json
from json.decoder import JSONDecodeError
# import numpy as np
# from math import degrees
from mathutils import Color, Vector, Euler
from .. import BESettings
from ..BESettings import BaseStuff, EngineType
# from ..BEStartParams import StartParams
from . import BEUtilsGeo
from . import BEGNInputs
def LoadJSON(bengineInputs_path: str):
with open(bengineInputs_path) as js_file:
try:
js_input_data = json.load(js_file)
except JSONDecodeError:
print("Problem to Open File: " + bengineInputs_path)
js_input_data = None
return js_input_data
def SaveJSON(gn_js_path, js_data):
# Set Writable
if os.path.exists(gn_js_path) and not os.access(gn_js_path, os.W_OK):
os.chmod(gn_js_path, stat.S_IWRITE)
print("File Was Read-Only and Has Been Changed: " + gn_js_path)
# Save JSON
with open(gn_js_path, 'w') as json_file:
json.dump(js_data, json_file)
# Set GN/SV Default/Min/Max Values
# input is either GNNodeInputs or SVNode
def SetBaseInputValues(input_data, input, is_GN: bool):
input_obj = input
# If Blen 3
if bpy.app.version[0] == 3:
if is_GN:
input_obj = input[1]
match input_data['Type']:
case 'VALUE':
if is_GN:
input_data['DefaultValue'] = input_obj.default_value
# input_data['DefaultValue'] = numpy.float32(input_obj.default_value)
input_data['MinValue'] = input_obj.min_value
input_data['MaxValue'] = input_obj.max_value
# input_data['Value'] = geom_mod[input_obj.identifier]
else:
input_data['DefaultValue'] = input_obj['BEFloatDefault']
input_data['MinValue'] = input_obj['BEFloatMin']
input_data['MaxValue'] = input_obj['BEFloatMax']
case 'INT':
if is_GN:
input_data['DefaultValue'] = input_obj.default_value
input_data['MinValue'] = input_obj.min_value
input_data['MaxValue'] = input_obj.max_value
else:
input_data['DefaultValue'] = input_obj['BEIntegerDefault']
input_data['MinValue'] = input_obj['BEIntegerMin']
input_data['MaxValue'] = input_obj['BEIntegerMax']
case 'BOOLEAN':
if is_GN:
input_data['DefaultValue'] = input_obj.default_value
else:
input_data['DefaultValue'] = input_obj['BEBooleanDefault']
case 'STRING':
if is_GN:
input_data['DefaultValue'] = input_obj.default_value
else:
input_data['DefaultValue'] = input_obj['BEStringDefault']
case 'RGBA':
if is_GN:
input_data['DefaultValue'] = list(input_obj.default_value)
else:
input_data['DefaultValue'] = list(input_obj['BEColorDefault'])
case 'VECTOR':
if is_GN:
input_data['DefaultValue'] = list(input_obj.default_value)
input_data['MinValue'] = input_obj.min_value
input_data['MaxValue'] = input_obj.max_value
else:
input_data['DefaultValue'] = list(input_obj['BEVectorDefault'])
input_data['DefaultValue'] = input_obj['BEVectorMin']
input_data['DefaultValue'] = input_obj['BEVectorMax']
def GetSVOutputObjects(node_tree):
sv_out_nodes = []
sv_out_objs = []
for node in node_tree.nodes:
if node.bl_idname == BESettings.TYPE_SV_SCRIPT:
if BESettings.SVConstants.SV_OUTPUT_OBJ in node.script_name:
sv_out_nodes.append(node)
sv_out_nodes.sort(key=lambda x: x.location.y)
sv_out_nodes.reverse()
for node in sv_out_nodes:
try:
socket_objs = node.inputs[0].sv_get(default=None)
sv_out_objs += socket_objs
except:
print("No Objects/Meshes in BEObjectsOutput Node: " + node.name)
return sv_out_objs
def GetSVInputNodes(node_tree):
sv_input_nodes = []
for node in node_tree.nodes:
if node.bl_idname == BESettings.TYPE_SV_SCRIPT:
for in_out_name in BESettings.SVConstants.SV_Inputs:
if in_out_name in node.script_name:
the_name = ''
# Set Type
match in_out_name:
case BESettings.SVConstants.SV_INPUT_BOOL:
the_name = 'BOOLEAN'
case BESettings.SVConstants.SV_INPUT_COLL:
the_name = 'COLLECTION'
case BESettings.SVConstants.SV_INPUT_COLOR:
the_name = 'RGBA'
case BESettings.SVConstants.SV_INPUT_FLOAT:
the_name = 'VALUE'
case BESettings.SVConstants.SV_INPUT_INT:
the_name = 'INT'
case BESettings.SVConstants.SV_INPUT_OBJ:
the_name = 'OBJECT'
case BESettings.SVConstants.SV_INPUT_STR:
the_name = 'STRING'
case BESettings.SVConstants.SV_INPUT_VEC:
the_name = 'VECTOR'
sv_input_nodes.append((the_name, node))
break
sv_input_nodes.sort(key=lambda x: x[1].location.y)
sv_input_nodes.reverse()
return sv_input_nodes
def GetSVInputsData(node_group): # ADD IMAGE AND MATERIAL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sv_inputs_data = []
sv_input_nodes = GetSVInputNodes(node_group)
for sv_node_stuff in sv_input_nodes:
sv_node = sv_node_stuff[1]
input_data = {}
input_data['Name'] = sv_node['BEInputName']
input_data['Identifier'] = sv_node.node_id
input_data['Type'] = sv_node_stuff[0]
# Set Default/Min/Max Values
SetBaseInputValues(input_data, sv_node, False)
sv_inputs_data.append(input_data)
return sv_inputs_data
def GetGNInputsData(node_group):
gn_inputs_data = []
for input in BEGNInputs.GetNodeTreeInputs(node_group):
input_data = {}
input_data['Type'] = BEGNInputs.GetInputType(input)
input_data['Name'] = BEGNInputs.GetInputName(input)
input_data['Identifier'] = BEGNInputs.GetInputIdentifier(input)
# Set Default/Min/Max Values
SetBaseInputValues(input_data, input, True)
gn_inputs_data.append(input_data)
return gn_inputs_data
def LoadNodesTreeFromJSON(context, be_base_stuff: BaseStuff):
bpy.ops.wm.link(filepath=be_base_stuff.filepath, filename=be_base_stuff.filename,
directory=be_base_stuff.directory, link=False)
if (bpy.data.node_groups):
node_tree = bpy.data.node_groups[be_base_stuff.node_sys_name]
process_gn_obj = None
geom_mod = None
# If GN NodeTree
if node_tree.bl_idname == BESettings.TYPE_GN:
# Create New Object
process_mesh = bpy.data.meshes.new('emptyMesh')
process_gn_obj = bpy.data.objects.new("BEngineProcess", process_mesh)
context.collection.objects.link(process_gn_obj)
process_gn_obj.select_set(True)
context.view_layer.objects.active = process_gn_obj
# Add GN Modifier
geom_mod = process_gn_obj.modifiers.new("BEngine", type='NODES')
# geom_mod.show_viewport = False # Modifier is switched off during loading
geom_mod.node_group = node_tree
# else:
# # Switch Off Auto Update
# node_tree.sv_process = False
return process_gn_obj, geom_mod, node_tree
return None, None, None
def SetupInputsFromJSON(context, node_tree, GN_mod, js_input_data,
engine_type: EngineType):
if "BEngineInputs" in js_input_data:
js_inputs = js_input_data["BEngineInputs"]
is_GN = node_tree.bl_idname == BESettings.TYPE_GN
coll_idx = 0
# GN - Inputs
# SV - SVInputNodes
if is_GN:
input_items = BEGNInputs.GetNodeTreeInputs(node_tree)
else:
input_items = GetSVInputNodes(node_tree)
instanced_meshes = {}
for input in input_items:
if is_GN:
node_id = BEGNInputs.GetInputIdentifier(input)
else:
node_id = input[1].node_id
# NEED TO DO THE SAME FOR SVERCHOK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
input_name = BEGNInputs.GetInputName(input)
input_type = BEGNInputs.GetInputType(input)
if node_id in js_inputs.keys():
# Check if the same type
if is_GN:
is_same_type = (input_type == js_inputs[node_id]["Type"])
if not is_same_type:
print("!Input " + input_name + " is not the same type! " + input_type + " " + js_inputs[node_id]["Type"])
continue
else:
is_same_type = (input[0] == js_inputs[node_id]["Type"])
if not is_same_type:
print("!Input " + input[1].name + " is not the same type! " + input[0] + " " + js_inputs[node_id]["Type"])
continue
# Run Main Stuff
js_prop = js_inputs[node_id]
if "Value" in js_prop.keys() and js_prop["Value"] is not None:
match js_prop["Type"]:
case "RGBA":
if is_GN:
GN_mod[node_id][0] = js_prop["Value"][0]
GN_mod[node_id][1] = js_prop["Value"][1]
GN_mod[node_id][2] = js_prop["Value"][2]
GN_mod[node_id][3] = js_prop["Value"][3]
else:
input[1]['BEColor'][0] = js_prop["Value"][0]
input[1]['BEColor'][1] = js_prop["Value"][1]
input[1]['BEColor'][2] = js_prop["Value"][2]
input[1]['BEColor'][3] = js_prop["Value"][3]
case "VECTOR":
if is_GN:
GN_mod[node_id][0] = js_prop["Value"][0]
GN_mod[node_id][1] = js_prop["Value"][1]
GN_mod[node_id][2] = js_prop["Value"][2]
else:
input[1]['BEVector'][0] = js_prop["Value"][0]
input[1]['BEVector'][1] = js_prop["Value"][1]
input[1]['BEVector'][2] = js_prop["Value"][2]
case "IMAGE":
new_img = bpy.data.images.load(js_prop["Value"])
if is_GN:
GN_mod[node_id] = new_img
# case "TEXTURE":
# pass
case "MATERIAL":
mat = bpy.data.materials.new(name="BEMaterial")
if is_GN:
GN_mod[node_id] = mat
case "OBJECT":
js_obj_val = js_prop["Value"]
be_objs, has_mesh = ParseObjectFromJSON(js_obj_val,
js_input_data, instanced_meshes,
engine_type, False, True)
# Join Meshes
be_obj = None
if len(be_objs) > 1:
bpy.ops.object.select_all(action='DESELECT')
be_obj = be_objs[0]
for obj in be_objs:
context.collection.objects.link(obj)
obj.select_set(True)
context.view_layer.objects.active = be_obj
bpy.ops.object.join()
else:
if len(be_objs) == 1:
be_obj = be_objs[0]
context.collection.objects.link(be_objs[0])
if is_GN:
GN_mod[node_id] = be_obj
else:
input[1]['BEObject'] = be_obj.name
case "COLLECTION":
js_coll_val = js_prop["Value"]
be_coll = bpy.data.collections.new('BEngine_' + str(coll_idx))
context.scene.collection.children.link(be_coll)
be_coll_objs, has_mesh = ParseObjectFromJSON(js_coll_val,
js_input_data, instanced_meshes,
engine_type, True, False)
for obj in be_coll_objs:
be_coll.objects.link(obj)
if is_GN:
GN_mod[node_id] = be_coll
else:
input[1]['BECollection'] = be_coll.name
coll_idx += 1
case "VALUE":
if is_GN:
GN_mod[node_id] = float(js_prop["Value"])
else:
input[1]['BEFloat'] = float(js_prop["Value"])
case "INT":
if is_GN:
GN_mod[node_id] = js_prop["Value"]
else:
input[1]['BEInteger'] = js_prop["Value"]
case "STRING":
if is_GN:
GN_mod[node_id] = js_prop["Value"]
else:
input[1]['BEString'] = js_prop["Value"]
case "BOOLEAN":
if is_GN:
GN_mod[node_id] = js_prop["Value"]
else:
input[1]['BEBoolean'] = js_prop["Value"]
case default:
if is_GN:
GN_mod[node_id] = js_prop["Value"]
# else:
# GN_mod[node_id] = prop_value
def ParseObjectFromJSON(js_obj_val, js_input_data, instanced_meshes,
engine_type: EngineType, isCollection: bool,
convert_to_meshes=False):
has_mesh = False
be_objs = []
# Check If it has Mesh
for js_obj in js_obj_val:
if "Mesh" in js_obj or "Terrain" in js_obj:
has_mesh = True
break
# if hasMesh:
for i, js_obj in enumerate(js_obj_val):
be_mesh_obj = None
be_curves_obj = None
be_terr_obj = None
# Import Mesh
if "Mesh" in js_obj:
if js_obj["Mesh"] not in instanced_meshes.keys():
js_mesh = js_input_data["Meshes"][js_obj["Mesh"]]
be_mesh = BEUtilsGeo.MeshFromJSON(js_mesh, engine_type)
instanced_meshes[js_obj["Mesh"]] = be_mesh
else:
be_mesh = instanced_meshes[js_obj["Mesh"]]
be_mesh_obj = ObjectFromJSON(js_obj, be_mesh, engine_type, True)
be_objs.append(be_mesh_obj)
# Import Curves
if "Curves" in js_obj:
if (convert_to_meshes):
be_curves_data = BEUtilsGeo.CurvesFromJSON(js_obj, engine_type, bool(1 - has_mesh))
else:
be_curves_data = BEUtilsGeo.CurvesFromJSON(js_obj, engine_type, True)
be_curves_obj = ObjectFromJSON(js_obj, be_curves_data, engine_type, True)
be_objs.append(be_curves_obj)
# Import Terrain
if "Terrain" in js_obj:
be_terr_mesh = BEUtilsGeo.TerrainMeshFromJSON(js_obj, engine_type)
be_terr_obj = ObjectFromJSON(js_obj, be_terr_mesh, engine_type, False)
be_objs.append(be_terr_obj)
if be_mesh_obj is None and be_curves_obj is None and be_terr_obj is None:
if isCollection:
# Add Empty
empty_obj = bpy.data.objects.new(js_obj["Name"], None )
SetTransformFromJSON(js_obj, empty_obj, engine_type)
be_objs.append(empty_obj)
else:
# Add an Empty Object which will be as a Master Object to Joint all Objects
if i == 0:
be_append_obj = None
if len(js_obj_val) > 1:
if has_mesh:
empty_mesh_data = BEUtilsGeo.CreateEmptyMesh()
be_append_obj = bpy.data.objects.new(js_obj["Name"], empty_mesh_data)
else:
empty_curv_data = bpy.data.curves.new(js_obj["Name"], type='CURVE')
empty_curv_data.dimensions = '3D'
be_append_obj = bpy.data.objects.new(js_obj["Name"], empty_curv_data)
else:
# Empty
be_append_obj = bpy.data.objects.new(js_obj["Name"], None )
SetTransformFromJSON(js_obj, be_append_obj, engine_type)
be_objs.append(be_append_obj)
instanced_meshes = None # Clear Meshes
return be_objs, has_mesh
def ObjectFromJSON(js_obj, mesh, engine_type, do_transform: bool):
be_mesh_obj = bpy.data.objects.new(js_obj["Name"], mesh)
if do_transform:
SetTransformFromJSON(js_obj, be_mesh_obj, engine_type)
return be_mesh_obj
def SetTransformFromJSON(js_obj, be_obj, engine_type: EngineType):
be_obj.location = js_obj["Pos"]
SetRotationFromJSON(be_obj, js_obj["Rot"], engine_type)
be_obj.scale = js_obj["Scale"]
def RecordObjectOutputToJSON(objects_sets_dict, the_object, is_instance: bool,
js_meshes: list, meshes_tmp_list: list,
meshes_tmp_set: set, engine_type: EngineType):
if is_instance:
mesh = the_object.object.data
obj_type = the_object.object.type
true_obj = the_object.object
else:
mesh = the_object.data
obj_type = the_object.type
true_obj = the_object
# Add Default Keys
if mesh not in objects_sets_dict.keys():
objects_sets_dict[mesh] = {}
objects_sets_dict[mesh]["Transforms"] = []
js_object_data = objects_sets_dict[mesh]
# Setup Transforms
inst_pos, inst_rot, inst_scale = the_object.matrix_world.decompose()
js_object_data["Transforms"].append((tuple(inst_pos), tuple(inst_rot.to_euler('XYZ')), tuple(inst_scale)))
# Get Custom Attributes
custom_attribs_dict = GetCustomAttribs("beo_", mesh.attributes)
if custom_attribs_dict:
js_object_data[BESettings.CUSTOM_ATTRIBUTES] = custom_attribs_dict
# Get Mesh or BENGINE_INSTANCE
if obj_type == "MESH":
# Get BENGINE_INSTANCE Value
if BESettings.BENGINE_INSTANCE in mesh.attributes.keys():
if BESettings.BENGINE_INSTANCE not in js_object_data.keys():
if len(mesh.attributes[BESettings.BENGINE_INSTANCE].data) > 0:
be_inst_id = mesh.attributes[BESettings.BENGINE_INSTANCE].data[0].value
if type(be_inst_id) is int:
js_object_data[BESettings.KEYPARAM_BE_INSTANCE] = be_inst_id
else:
print(BESettings.BENGINE_INSTANCE + " Attribute is not Integer!!!")
# Get Mesh to JSON
elif "Mesh" not in js_object_data.keys():
if mesh not in meshes_tmp_set:
js_mesh = BEUtilsGeo.MeshToJSONData(mesh, engine_type)
js_meshes.append(js_mesh)
js_object_data["Mesh"] = len(meshes_tmp_list)
meshes_tmp_list.append(mesh)
meshes_tmp_set.add(mesh)
else:
js_object_data["Mesh"] = meshes_tmp_list.index(mesh)
# Get Custom Instance Attributes
def GetCustomAttribs(custom_attrib_name: str, attributes):
custom_attribs_dict = {}
float_custom_attribs = {}
vector_custom_attribs = {}
color_custom_attribs = {}
for attrib_name in attributes.keys():
if attrib_name.startswith(custom_attrib_name):
attrib = attributes[attrib_name].data[0]
GetCustomAttrib(attrib, float_custom_attribs, vector_custom_attribs, color_custom_attribs, attrib_name)
# Add Custom Attributes
if float_custom_attribs or vector_custom_attribs or color_custom_attribs:
if float_custom_attribs:
custom_attribs_dict[BESettings.CUSTOM_FLOAT_ATTRIBS] = float_custom_attribs
if vector_custom_attribs:
custom_attribs_dict[BESettings.CUSTOM_VECTOR_ATTRIBS] = vector_custom_attribs
if color_custom_attribs:
custom_attribs_dict[BESettings.CUSTOM_COLOR_ATTRIBS] = color_custom_attribs
return custom_attribs_dict
def GetCustomAttrib(attrib, float_attribs: dict, vector_attribs: dict, color_attribs: dict, attrib_name: str):
attrib_type = type(attrib)
attrib_val = None
# Vector
if (attrib_type is bpy.types.FloatVectorAttributeValue or attrib_type is bpy.types.Float2AttributeValue):
attrib_val = attrib.vector
if (attrib_type is bpy.types.FloatVectorAttributeValue):
vector_attribs[attrib_name] = tuple(attrib_val)
else:
vector_attribs[attrib_name] = (attrib_val[0], attrib_val[1], 0)
# Color
elif (attrib_type is bpy.types.FloatColorAttributeValue or attrib_type is bpy.types.ByteColorAttributeValue):
attrib_val = attrib.color
color_attribs[attrib_name] = tuple(attrib_val)
# Float
elif (attrib_type is bpy.types.BoolAttributeValue or attrib_type is bpy.types.IntAttributeValue
or attrib_type is bpy.types.FloatAttributeValue):
attrib_val = attrib.value
float_attribs[attrib_name] = float(attrib_val)
def GetBlenderOutputs(context, process_objs: list, engine_type: EngineType, is_GN: bool):
depsgraph = context.evaluated_depsgraph_get()
# MAIN Data
js_output_data = {} # Output JSON Data
objects_sets_dict = {} # Instances Dictionary
meshes_tmp_list = []
meshes_tmp_set = set()
js_meshes_list = [] # All Parsed JSON Meshes
process_ev_objs = [depsgraph.objects[obj.name] for obj in process_objs]
process_ev_objs_set = set(process_ev_objs)
# GET OBJECS AND MESHES
for obj in process_ev_objs:
# If GeometryNodes main mesh has no points/polygons
if is_GN and len(obj.data.vertices) == 0:
continue
RecordObjectOutputToJSON(objects_sets_dict, obj, False,
js_meshes_list, meshes_tmp_list,
meshes_tmp_set, engine_type)
# GET INSTANCES
for obj_instance in depsgraph.object_instances:
if obj_instance.parent in process_ev_objs_set and obj_instance.is_instance:
RecordObjectOutputToJSON(objects_sets_dict, obj_instance, True,
js_meshes_list, meshes_tmp_list,
meshes_tmp_set, engine_type)
# Record Objects/Instances
if objects_sets_dict:
js_output_data["ObjectsSets"] = list(objects_sets_dict.values())
else:
js_output_data["ObjectsSets"] = []
# Record Meshes
js_output_data["Meshes"] = js_meshes_list
return js_output_data
def SetRotationFromJSON(obj, js_euler, engine_type: EngineType):
if engine_type == EngineType.Unity:
# Set Rotation
rot_YXZ = Euler(js_euler, 'YXZ')
rot_mat = rot_YXZ.to_matrix()
rot_XYZ = rot_mat.to_euler('XYZ')
obj.rotation_euler = rot_XYZ
else:
obj.rotation_euler = Euler(js_euler, 'XYZ')