Skip to content

Commit 9d77d95

Browse files
authored
Add Convert To Mesh Sequence button to Stop Motion OBJ object properties panel (#155)
* Add Convert to Sequence button to Stop Motion OBJ panel Still doesn't work * Code cleanup I guess it works
1 parent d75ca03 commit 9d77d95

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ##### BEGIN GPL LICENSE BLOCK #####
22
#
33
# Stop motion OBJ: A Mesh sequence importer for Blender
4-
# Copyright (C) 2016-2021 Justin Jensen
4+
# Copyright (C) 2016-2022 Justin Jensen
55
#
66
# This program is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -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.17"),
28+
"version": (2, 2, 0, "alpha.18"),
2929
"blender": (2, 83, 0),
3030
"location": "File > Import > Mesh Sequence",
3131
"warning": "",

src/panels.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ##### BEGIN GPL LICENSE BLOCK #####
22
#
33
# Stop motion OBJ: A Mesh sequence importer for Blender
4-
# Copyright (C) 2016-2021 Justin Jensen
4+
# Copyright (C) 2016-2022 Justin Jensen
55
#
66
# This program is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -36,10 +36,13 @@ class SMO_PT_MeshSequencePanel(bpy.types.Panel):
3636

3737
@classmethod
3838
def poll(cls, context):
39-
return context.object.mesh_sequence_settings.initialized == True
39+
return context.object.type == 'MESH'
4040

4141
def draw(self, context):
42-
pass
42+
if context.object.type == 'MESH' and context.object.mesh_sequence_settings.initialized == False:
43+
# show button to convert the object into a mesh sequence
44+
self.layout.operator(ConvertToMeshSequence.bl_idname, icon="ONIONSKIN_ON")
45+
4346

4447

4548
class SMO_PT_MeshSequencePlaybackPanel(bpy.types.Panel):
@@ -237,7 +240,7 @@ def execute(self, context):
237240
if self.sequenceSettings.showAsSingleMesh:
238241
seqObj = newMeshSequence('SingleMesh')
239242
else:
240-
seqObj = newMeshSequence('EmptyMesh')
243+
seqObj = newMeshSequence('emptyMesh')
241244

242245
global_matrix = axis_conversion(from_forward=b_axis_forward,from_up=b_axis_up).to_4x4()
243246
seqObj.matrix_world = global_matrix
@@ -432,10 +435,16 @@ def execute(self, context):
432435
return {'CANCELLED'}
433436

434437
# hijack the mesh from the selected object and add it to a new mesh sequence
435-
msObj = newMeshSequence()
438+
msObj = newMeshSequence('emptyMesh')
436439
msObj.mesh_sequence_settings.isImported = False
437440
addMeshToSequence(msObj, obj.data)
438441

442+
# make sure the new mesh sequence has the same transform (especially the location) as context.object
443+
msObj.location = obj.location
444+
msObj.scale = obj.scale
445+
msObj.rotation_euler = obj.rotation_euler
446+
msObj.rotation_quaternion = obj.rotation_quaternion
447+
439448
objName = obj.name
440449
msObj.name = objName + '_sequence'
441450

src/stop_motion_obj.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ##### BEGIN GPL LICENSE BLOCK #####
22
#
33
# Stop motion OBJ: A Mesh sequence importer for Blender
4-
# Copyright (C) 2016-2021 Justin Jensen
4+
# Copyright (C) 2016-2022 Justin Jensen
55
#
66
# This program is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -448,12 +448,11 @@ def deleteLinkedMeshMaterials(mesh, maxMaterialUsers=1, maxImageUsers=0):
448448

449449

450450
def newMeshSequence(meshName):
451-
bpy.ops.object.add(type='MESH')
451+
theMesh = bpy.data.meshes.new(createUniqueName(meshName, bpy.data.meshes))
452+
theObj = bpy.data.objects.new(createUniqueName('sequence', bpy.data.objects), theMesh)
453+
bpy.context.collection.objects.link(theObj)
454+
452455
# this new object should be the currently-selected object
453-
theObj = bpy.context.object
454-
theObj.name = 'sequence'
455-
theMesh = theObj.data
456-
theMesh.name = createUniqueName(meshName, bpy.data.meshes)
457456
theMesh.use_fake_user = True
458457
theMesh.inMeshSequence = True
459458

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.17")
5+
currentScriptVersion = (2, 2, 0, "alpha.18")
66
legacyScriptVersion = (2, 0, 2, "legacy")

0 commit comments

Comments
 (0)