Skip to content

Commit

Permalink
Import only the first mesh in each file (#145)
Browse files Browse the repository at this point in the history
Delete all other objects
  • Loading branch information
neverhood311 authored Oct 22, 2021
1 parent 6a7ddd2 commit 4ac238c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

bl_info = {
"name": "Stop motion OBJ",
"description": "Import a sequence of OBJ (or STL or PLY) files and display them each as a single frame of animation. This add-on also supports the .STL and .PLY file formats.",
"description": "Import a sequence of OBJ (or STL or PLY or X3D) files and display them each as a single frame of animation. This add-on also supports the .STL, .PLY, and .X3D file formats.",
"author": "Justin Jensen",
"version": (2, 2, 0, "alpha.11"),
"version": (2, 2, 0, "alpha.12"),
"blender": (2, 83, 0),
"location": "File > Import > Mesh Sequence",
"warning": "",
Expand Down
16 changes: 13 additions & 3 deletions src/stop_motion_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,25 @@ def loadSequenceFromMeshFiles(_obj, _dir, _file):
for file in sortedFiles:
# import the mesh file
mss.fileImporter.load(mss.fileFormat, file)
tmpObject = bpy.context.selected_objects[0]

# get the first object of type MESH
# TODO: eventually, let's pull out all MESH objects and put them into their own individual sequences
tmpObject = next(filter(lambda meshObj: meshObj.type == 'MESH', bpy.context.selected_objects), None)

# IMPORTANT: don't copy it; just copy the pointer. This cuts memory usage in half.
tmpMesh = tmpObject.data
tmpMesh.use_fake_user = True
tmpMesh.inMeshSequence = True

# make a list of the objects we're going to delete
objsToDelete = bpy.context.selected_objects.copy()

# now, delete all selected objects. Yes, even our precious mesh object. We already saved its mesh data
for obj in objsToDelete:
bpy.data.objects.remove(obj, do_unlink=True)

# deselect everything just to be safe
deselectAll()
tmpObject.select_set(state=True)
bpy.ops.object.delete()

# if this is not the first frame, remove any materials and/or images imported with the mesh
if numFrames >= 1 and mss.perFrameMaterial is False:
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# (major, minor, revision, development)
# example dev version: (1, 2, 3, "beta.4")
# example release version: (2, 3, 4)
currentScriptVersion = (2, 2, 0, "alpha.11")
currentScriptVersion = (2, 2, 0, "alpha.12")
legacyScriptVersion = (2, 0, 2, "legacy")

0 comments on commit 4ac238c

Please sign in to comment.