@@ -81,7 +81,7 @@ def apply_transformation(meshio_mesh, obj, depsgraph):
81
81
# evaluate the rigid body transformations (only relevant for .bin format)
82
82
rigid_body_transformation = mathutils .Matrix .Identity (4 )
83
83
if meshio_mesh is not None :
84
- if meshio_mesh . field_data . get ( "transformation_matrix" ) is not None :
84
+ if "transformation_matrix" in meshio_mesh . field_data :
85
85
rigid_body_transformation = meshio_mesh .field_data ["transformation_matrix" ]
86
86
87
87
# multiply everything together (with custom transform matrix)
@@ -142,11 +142,10 @@ def update_mesh(meshio_mesh, mesh):
142
142
mesh .validate ()
143
143
144
144
# copy attributes
145
- attributes = mesh .attributes
146
145
for k , v in meshio_mesh .point_data .items ():
147
146
k = "bseq_" + k
148
147
attribute = None
149
- if k not in attributes :
148
+ if k not in mesh . attributes :
150
149
if len (v .shape ) == 1 :
151
150
# one dimensional attribute
152
151
attribute = mesh .attributes .new (k , "FLOAT" , "POINT" )
@@ -165,7 +164,7 @@ def update_mesh(meshio_mesh, mesh):
165
164
show_message_box ('more than 2 dimensional tensor, ignored' )
166
165
continue
167
166
else :
168
- attribute = attributes [k ]
167
+ attribute = mesh . attributes [k ]
169
168
name_string = None
170
169
if attribute .data_type == "FLOAT" :
171
170
name_string = "value"
@@ -174,10 +173,36 @@ def update_mesh(meshio_mesh, mesh):
174
173
175
174
attribute .data .foreach_set (name_string , v .ravel ())
176
175
177
- # set as split norm
178
- if mesh .BSEQ .split_norm_att_name and mesh .BSEQ .split_norm_att_name == k :
179
- mesh .use_auto_smooth = True
180
- mesh .normals_split_custom_set_from_vertices (v )
176
+ # # set as split norm
177
+ # if mesh.BSEQ.split_norm_att_name and mesh.BSEQ.split_norm_att_name == k:
178
+ # mesh.use_auto_smooth = True
179
+ # mesh.normals_split_custom_set_from_vertices(v)
180
+
181
+ # I want to set normals if the scene property use_imported_normals is true and the normals are either in point_data["obj:vn"] or field_data["obj:vn"]
182
+ if bpy .context .scene .BSEQ .use_imported_normals :
183
+ print ("use_imported_normals" )
184
+ # print all the keys in point_data, field_data, cell_data
185
+ print ("point_data" , meshio_mesh .point_data .keys ())
186
+ print ("field_data" , meshio_mesh .field_data .keys ())
187
+ print ("cell_data" , meshio_mesh .cell_data .keys ())
188
+
189
+ mesh .use_auto_smooth = True
190
+
191
+
192
+ if "obj:vn" in meshio_mesh .point_data and len (meshio_mesh .point_data ["obj:vn" ]) == len (mesh .vertices ):
193
+ print ("obj:vn in point_data" , len (mesh .loops ))
194
+ # vert_norms = [tuple(x) for x in meshio_mesh.point_data["obj:vn"]]
195
+
196
+ mesh .normals_split_custom_set_from_vertices (meshio_mesh .point_data ["obj:vn" ])
197
+
198
+ for i in range (len (mesh .vertices )):
199
+ print (mesh .vertices [i ].normal )
200
+ elif "obj:vn" in meshio_mesh .field_data and "obj:vn_face_idx" in meshio_mesh .cell_data :
201
+ print ("obj:vn in field_data" )
202
+ indices = meshio_mesh .cell_data ["obj:vn_face_idx" ][0 ]
203
+ indices = [item for sublist in indices for item in sublist ]
204
+ vert_norms = [meshio_mesh .field_data ["obj:vn" ][i - 1 ] for i in indices ]
205
+ mesh .normals_split_custom_set (vert_norms )
181
206
182
207
# function to create a single meshio object
183
208
def create_meshio_obj (filepath ):
@@ -188,27 +213,7 @@ def create_meshio_obj(filepath):
188
213
show_message_box ("Error when reading: " + filepath + ",\n " + traceback .format_exc (),
189
214
"Meshio Loading Error" + str (e ),
190
215
icon = "ERROR" )
191
-
192
- # if filepath.endswith(".obj"):
193
- # # Save all current objects
194
- # objs = set(bpy.context.scene.objects)
195
- # # Reload the object
196
- # bpy.ops.import_scene.obj(filepath=filepath)
197
- # # Substract all previous items from the current items and print their names
198
- # imported_objs = set(bpy.context.scene.objects) - objs
199
-
200
- # # Check if the imported object worked correctly
201
- # if len(imported_objs) == 1:
202
- # obj = imported_objs.pop()
203
- # else:
204
- # show_message_box("Error when reading: " + filepath + ",\n" + traceback.format_exc(),
205
- # "obj. Loading Error in create_meshio_obj",
206
- # icon="ERROR")
207
- # return
208
-
209
- # obj.name = os.path.basename(filepath)
210
- # return
211
-
216
+ return
212
217
# create the object
213
218
name = os .path .basename (filepath )
214
219
mesh = bpy .data .meshes .new (name )
@@ -224,38 +229,6 @@ def create_obj(fileseq, root_path, transform_matrix=Matrix([[1, 0, 0, 0], [0, 1,
224
229
current_frame = bpy .context .scene .frame_current
225
230
filepath = fileseq [current_frame % len (fileseq )]
226
231
227
- #.obj sequences have to be handled differently
228
- # is_obj_seq = filepath.endswith(".obj")
229
- # if is_obj_seq and bpy.context.scene.BSEQ.use_blender_obj_import:
230
-
231
- # # Save all current objects
232
- # objs = set(bpy.context.scene.objects)
233
- # # Reload the object
234
- # bpy.ops.import_scene.obj(filepath=filepath)
235
- # # Substract all previous items from the current items and print their names
236
- # imported_objs = set(bpy.context.scene.objects) - objs
237
-
238
- # # Check if the imported object worked correctly
239
- # if len(imported_objs) == 1:
240
- # tmp_obj = imported_objs.pop()
241
- # else:
242
- # show_message_box("Error when reading: " + filepath + ",\n" + traceback.format_exc(),
243
- # "obj. Loading Error in create_obj",
244
- # icon="ERROR")
245
- # return
246
-
247
- # name = fileseq.basename() + "@" + fileseq.extension()
248
-
249
- # # Create object with empty mesh
250
- # object = bpy.data.objects.new(name, bpy.data.meshes.new(name))
251
- # object.data = tmp_obj.data
252
-
253
- # # Delete tmp_obj with data
254
- # bpy.data.objects.remove(tmp_obj, do_unlink=True)
255
-
256
- # enabled = True
257
-
258
- # else:
259
232
meshio_mesh = None
260
233
enabled = True
261
234
try :
@@ -284,13 +257,12 @@ def create_obj(fileseq, root_path, transform_matrix=Matrix([[1, 0, 0, 0], [0, 1,
284
257
object .matrix_world = transform_matrix
285
258
driver = object .driver_add ("BSEQ.frame" )
286
259
driver .driver .expression = 'frame'
287
- if enabled : # and not is_obj_seq:
260
+ if enabled :
288
261
update_mesh (meshio_mesh , object .data )
289
262
bpy .context .collection .objects .link (object )
290
263
bpy .ops .object .select_all (action = "DESELECT" )
291
264
bpy .context .view_layer .objects .active = object
292
265
293
-
294
266
def update_obj (scene , depsgraph = None ):
295
267
296
268
for obj in bpy .data .objects :
@@ -320,49 +292,6 @@ def update_obj(scene, depsgraph=None):
320
292
# in case the blender file was created on windows system, but opened in linux system
321
293
pattern = bpy .path .native_pathsep (pattern )
322
294
fs = fileseq .FileSequence (pattern )
323
-
324
- # if pattern.endswith(".obj") and scene.BSEQ.use_blender_obj_import:
325
- # filepath = fs[current_frame % len(fs)]
326
-
327
- # # Save all current objects
328
- # objs = set(scene.objects)
329
-
330
- # # Reload the object
331
- # bpy.ops.import_scene.obj(filepath=filepath)
332
-
333
- # # Substract all previous items from the current items and print their names
334
- # imported_objs = set(scene.objects) - objs
335
-
336
- # # Check if the imported object worked correctly
337
- # if len(imported_objs) == 1:
338
- # new_tmp_obj = imported_objs.pop()
339
- # else:
340
- # show_message_box("Error when reading: " + filepath + ",\n" + traceback.format_exc(),
341
- # "obj. Loading Error in update_obj",
342
- # icon="ERROR")
343
- # continue
344
-
345
- # # Copy the data except for material
346
- # if obj.data.materials:
347
- # # assign to 1st material slot
348
- # new_tmp_obj.data.materials[0] = obj.data.materials[0]
349
- # else:
350
- # # no slots
351
- # new_tmp_obj.data.materials.append(obj.data.materials[0])
352
-
353
- # obj.data = new_tmp_obj.data
354
-
355
- # # Delete the temporary object with the data
356
- # bpy.data.objects.remove(new_tmp_obj, do_unlink=True)
357
-
358
- # # purge old meshes
359
- # bpy.ops.outliner.orphans_purge(do_recursive=True)
360
-
361
- # apply_transformation(meshio_mesh, obj, depsgraph)
362
-
363
- # end_time = time.perf_counter()
364
- # obj.BSEQ.last_benchmark = (end_time - start_time) * 1000
365
- # continue
366
295
367
296
if obj .BSEQ .use_advance and obj .BSEQ .script_name :
368
297
script = bpy .data .texts [obj .BSEQ .script_name ]
0 commit comments