3232forceMeshLoad = False
3333loadingSequenceLock = False
3434inRenderMode = False
35+ lockFrameSwitch = False
3536
3637def alphanumKey (string ):
3738 """ Turn a string into a list of string and number chunks.
@@ -42,6 +43,9 @@ def alphanumKey(string):
4243def 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
4650def 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
100119def 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
206225def 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 )
0 commit comments