Skip to content

Commit 3b64e07

Browse files
committed
Added functionality to use from_pydata and objloader now works
1 parent 72a721e commit 3b64e07

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

bseq/importer.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def update_mesh(meshio_mesh, mesh):
120120
faces_loop_start = np.roll(faces_loop_start, 1)
121121
faces_loop_start[0] = 0
122122

123+
start_time = time.perf_counter()
124+
123125
if len(mesh.vertices) == n_verts and len(mesh.polygons) == n_poly and len(mesh.loops) == n_loop:
124126
pass
125127
else:
@@ -128,12 +130,20 @@ def update_mesh(meshio_mesh, mesh):
128130
mesh.loops.add(n_loop)
129131
mesh.polygons.add(n_poly)
130132

133+
131134
mesh.vertices.foreach_set("co", mesh_vertices.ravel())
132135
mesh.loops.foreach_set("vertex_index", loops_vert_idx)
133136
mesh.polygons.foreach_set("loop_start", faces_loop_start)
134137
mesh.polygons.foreach_set("loop_total", faces_loop_total)
135138
mesh.polygons.foreach_set("use_smooth", [shade_scheme] * len(faces_loop_total))
136139

140+
# mesh.clear_geometry()
141+
# mesh.from_pydata(mesh_vertices, [], data)
142+
143+
end_time = time.perf_counter()
144+
print("foreach_set time: ", end_time - start_time)
145+
146+
137147
mesh.update()
138148
mesh.validate()
139149

@@ -208,13 +218,19 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0,
208218

209219
#.obj sequences have to be handled differently
210220
isObj = filepath.endswith(".obj")
211-
if isObj:
221+
if isObj and bpy.context.scene.BSEQ.use_blender_obj_import:
212222
print(str(filepath))
213223
bpy.ops.import_scene.obj(filepath=filepath)
214-
object = bpy.context.selected_objects[-1]
215-
object.name = fileseq.basename() + "@" + fileseq.extension()
216-
# object.data.name = fileseq.basename() + "@" + fileseq.extension()
217224
enabled = True
225+
226+
tmp_obj = bpy.context.selected_objects[-1]
227+
228+
name = fileseq.basename() + "@" + fileseq.extension()
229+
object = bpy.data.objects.new(name, tmp_obj.data)
230+
231+
tmp_obj.select_set(True)
232+
bpy.ops.object.delete()
233+
218234
else:
219235
meshio_mesh = None
220236
enabled = True
@@ -245,9 +261,7 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0,
245261
object.matrix_world = transform_matrix
246262
driver = object.driver_add("BSEQ.frame")
247263
driver.driver.expression = 'frame'
248-
if isObj:
249-
return
250-
if enabled:
264+
if enabled and not isObj:
251265
update_mesh(meshio_mesh, object.data)
252266
bpy.context.collection.objects.link(object)
253267
bpy.ops.object.select_all(action="DESELECT")
@@ -283,21 +297,20 @@ def update_obj(scene, depsgraph=None):
283297
pattern = bpy.path.native_pathsep(pattern)
284298
fs = fileseq.FileSequence(pattern)
285299

286-
if pattern.endswith(".obj"):
300+
if pattern.endswith(".obj") and scene.BSEQ.use_blender_obj_import:
287301
filepath = fs[current_frame % len(fs)]
288302

289303
# Reload the object
290-
tmp_transform = obj.matrix_world
291-
obj.select_set(True)
292-
bpy.ops.object.delete()
293304
bpy.ops.import_scene.obj(filepath=filepath)
294-
obj = bpy.context.selected_objects[-1]
305+
tmp_obj = bpy.context.selected_objects[-1]
295306
print(str(filepath))
296307
print(current_frame % len(fs))
297308
print(obj.name)
298-
obj.name = fs.basename() + "@" + fs.extension()
299-
obj.data.name = fs.basename() + "@" + fs.extension()
300-
obj.matrix_world = tmp_transform
309+
310+
obj.data = tmp_obj.data
311+
tmp_obj.select_set(True)
312+
bpy.ops.object.delete()
313+
301314
apply_transformation(meshio_mesh, obj, depsgraph)
302315

303316
end_time = time.perf_counter()

bseq/panels.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ def draw(self, context):
207207
col1.label(text="Root Directory")
208208
col2.prop(importer_prop, "root_path", text="")
209209

210+
col1.label(text="Use Blender .obj Importer")
211+
col2.prop(importer_prop, "use_blender_obj_import", text="")
212+
210213
layout.operator("sequence.load")
211214

212215
layout.operator("wm.seq_import_batch")

bseq/properties.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class BSEQ_scene_property(bpy.types.PropertyGroup):
7373
size=3,
7474
subtype="COORDINATES",
7575
default=[1,1,1])
76+
77+
use_blender_obj_import: bpy.props.BoolProperty(name='Use Blender Object Import',
78+
description="Whether or not to use Blender's built-in object import function",
79+
default=True)
7680

7781
class BSEQ_obj_property(bpy.types.PropertyGroup):
7882
init: bpy.props.BoolProperty(default=False)

0 commit comments

Comments
 (0)