Skip to content

Commit c8e4b43

Browse files
authored
Fixed wrong/no export issue (#159)
Note: this only works when a SINGLE mesh sequence is present
1 parent 57e879a commit c8e4b43

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"name": "Stop motion OBJ",
2626
"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.",
2727
"author": "Justin Jensen",
28-
"version": (2, 2, 0, "alpha.20"),
28+
"version": (2, 2, 0, "alpha.21"),
2929
"blender": (2, 83, 0),
3030
"location": "File > Import > Mesh Sequence",
3131
"warning": "",

src/stop_motion_obj.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
forceMeshLoad = False
3333
loadingSequenceLock = False
3434
inRenderMode = False
35+
lockFrameSwitch = False
3536

3637
def alphanumKey(string):
3738
""" Turn a string into a list of string and number chunks.
@@ -42,6 +43,9 @@ def alphanumKey(string):
4243
def clamp(value, minVal, maxVal):
4344
return max(minVal, min(value, maxVal))
4445

46+
def selectOnly(obj):
47+
deselectAll()
48+
obj.select_set(state=True)
4549

4650
def deselectAll():
4751
for ob in bpy.context.scene.objects:
@@ -53,8 +57,10 @@ def checkMeshChangesFrameChangePre(scene):
5357
if inRenderMode == True:
5458
return
5559

60+
obj = bpy.context.object
61+
5662
# if the selected object is not a loaded and initialized mesh sequence, return
57-
mss = bpy.context.object.mesh_sequence_settings
63+
mss = obj.mesh_sequence_settings
5864
if mss.initialized is False or mss.loaded is False:
5965
return
6066

@@ -68,15 +74,19 @@ def checkMeshChangesFrameChangePre(scene):
6874
return
6975

7076
# generate the mesh hash for the current mesh (just before the frame switches)
71-
meshHashStr = getMeshHashStr(bpy.context.object.data)
77+
meshHashStr = getMeshHashStr(obj.data)
7278

7379
# if the generated mesh hash does not match the mesh's stored hash
7480
# for some reason we also have to check whether the meshHash has not been calculated yet
75-
if bpy.context.object.data.meshHash != '' and meshHashStr != bpy.context.object.data.meshHash:
81+
if obj.data.meshHash != '' and meshHashStr != obj.data.meshHash:
82+
# lock frame switching until we're done exporting (so that we export the correct frame beofre the next one is loaded)
83+
global lockFrameSwitch
84+
lockFrameSwitch = True
85+
7686
# update the mesh hash
77-
bpy.context.object.data.meshHash = meshHashStr
87+
obj.data.meshHash = meshHashStr
7888

79-
# export this updated mesh
89+
# export this updated mesh
8090
absDir = ''
8191
if mss.overwriteSrcDir is True:
8292
# writing over the original meshes
@@ -90,12 +100,21 @@ def checkMeshChangesFrameChangePre(scene):
90100
return
91101

92102
filename = os.path.join(absDir, mss.meshNameArray[mss.curVisibleMeshIdx].basename)
103+
104+
# select only this object so that this object is the only one that will be exported
105+
selectOnly(obj)
106+
107+
# actually export the file
93108
mss.fileImporter.export(mss.fileFormat, filename)
94109

95110
# show an unobtrusive message that the mesh has been exported
96111
msg = "Mesh exported: " + filename
97112
bpy.context.workspace.status_text_set(text=msg)
98113

114+
# once the export operation has fully finished, unlock importing/changing meshes, then trigger an updateFrame call
115+
lockFrameSwitch = False
116+
updateFrame(0)
117+
99118

100119
def showError(message=""):
101120
def draw(self, context):
@@ -204,6 +223,10 @@ def lockLoadingSequence(lock):
204223
# set the frame number for all mesh sequence objects
205224
@persistent
206225
def updateFrame(scene):
226+
global lockFrameSwitch
227+
if lockFrameSwitch is True:
228+
# we're not ready to switch frames yet
229+
return
207230
global loadingSequenceLock
208231
if loadingSequenceLock is False:
209232
scn = bpy.context.scene
@@ -985,6 +1008,7 @@ def setFrameObjStreamed(obj, frameNum, forceLoad=False, deleteMaterials=False):
9851008
# if we want to load new meshes as needed and it's not already loaded
9861009
if nextMeshProp.inMemory is False and (mss.streamDuringPlayback is True or forceLoad is True):
9871010
importStreamedFile(obj, idx)
1011+
obj.select_set(state=True)
9881012
if deleteMaterials is True:
9891013
nextMesh = getMeshFromIndex(obj, idx)
9901014
deleteLinkedMeshMaterials(nextMesh)

src/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# (major, minor, revision, development)
33
# example dev version: (1, 2, 3, "beta.4")
44
# example release version: (2, 3, 4)
5-
currentScriptVersion = (2, 2, 0, "alpha.20")
5+
currentScriptVersion = (2, 2, 0, "alpha.21")
66
legacyScriptVersion = (2, 0, 2, "legacy")

0 commit comments

Comments
 (0)