Skip to content

Commit

Permalink
fix bug where shared materials disappear after the first frame change (
Browse files Browse the repository at this point in the history
…#29)

* fix bug where shared materials disappear after the first frame change

* updated the readme
  • Loading branch information
neverhood311 authored Oct 31, 2019
1 parent 254de4d commit e5961f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A Blender add-on for importing a sequence of meshes as frames

Stop motion OBJ allows you to import a sequence of OBJ (or STL or PLY) files and render them as individual frames. Have a RealFlow animation but want to render it in Blender? This addon is for you! There are now two versions:
- [v2.0.0](https://github.com/neverhood311/Stop-motion-OBJ/releases/tag/v2.0.0) for **Blender 2.80+**
- [v2.0.1](https://github.com/neverhood311/Stop-motion-OBJ/releases/tag/v2.0.1) for **Blender 2.80+**
- [r1.1.1](https://github.com/neverhood311/Stop-motion-OBJ/releases/tag/0.2.79.2) for Blender 2.79 (also tested for 2.77 and 2.78). This version is now deprecated and will no longer be supported

If you find this add-on helpful, please consider donating to support development:
Expand Down
29 changes: 17 additions & 12 deletions stop_motion_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"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.",
"author": "Justin Jensen",
"version": (2, 0, 0),
"version": (2, 0, 1),
"blender": (2, 80, 0),
"location": "View 3D > Add > Mesh > Mesh Sequence",
"warning": "",
Expand Down Expand Up @@ -343,18 +343,23 @@ def getMeshIdxFromFrame(self, _obj, _frameNum):
return idx

def setFrameObj(self, _obj, _frameNum):
idx = self.getMeshIdxFromFrame(_obj, _frameNum)
#store the current mesh for grabbing the material later
# store the current mesh for grabbing the material later
prev_mesh = _obj.data
#swap the meshes
_obj.data = self.getMesh(_obj, idx)
# If this object doesn't have materials for each frame
if(_obj.mesh_sequence_settings.perFrameMaterial == False):
#if the previous mesh had a material, copy it to the new one
if(len(prev_mesh.materials) > 0):
prev_material = prev_mesh.materials[0]
_obj.data.materials.clear()
_obj.data.materials.append(prev_material)
idx = self.getMeshIdxFromFrame(_obj, _frameNum)
next_mesh = self.getMesh(_obj, idx)

# if the new frame is not the same as the old one
if (next_mesh != prev_mesh):
# swap the meshes
_obj.data = next_mesh

# If this object doesn't have materials for each frame
if(_obj.mesh_sequence_settings.perFrameMaterial == False):
# if the previous mesh had a material, copy it to the new one
if(len(prev_mesh.materials) > 0):
_obj.data.materials.clear()
for material in prev_mesh.materials:
_obj.data.materials.append(material)

#iterate over the meshes in the sequence and set their shading to smooth or flat
def shadeSequence(self, _obj, _smooth):
Expand Down

0 comments on commit e5961f8

Please sign in to comment.