Skip to content

Commit

Permalink
Improve Sprite Importer
Browse files Browse the repository at this point in the history
Having multiple shapekeys on a Sprite could result in corrupted shapekeys when reimporting sprites.
  • Loading branch information
ndee85 committed Oct 17, 2018
1 parent 63da9dc commit 76f400d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Blender/coa_tools/operators/import_sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def execute(self, context):
if not self.replace or i.name not in bpy.data.objects:
bpy.ops.coa_tools.coa_import_sprite(path=filepath,parent=sprite_object.name,scale=get_addon_prefs(context).sprite_import_export_scale)
else:
bpy.ops.coa_tools.coa_reimport_sprite(filepath=filepath,name=i.name)
bpy.ops.coa_tools.coa_reimport_sprite(filepath=filepath,name=i.name, reposition=False)
else:
data_file = open(self.filepath)
sprite_data = json.load(data_file)
Expand Down Expand Up @@ -357,20 +357,25 @@ class ReImportSprite(bpy.types.Operator, ImportHelper):
pos = FloatVectorProperty(default=Vector((0,0,0)))
scale = FloatProperty(default=.01)
offset = FloatVectorProperty(default=Vector((0,0,0)))
reposition = BoolProperty(default=True)

def move_verts(self,obj,ratio_x,ratio_y):
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.reveal()
bpy.ops.object.mode_set(mode="OBJECT")

data = obj.data.vertices
shapekeys = [obj.data.vertices]
if obj.data.shape_keys != None:
data = obj.data.shape_keys.key_blocks[0].data
shapekeys = []
for shapekey in obj.data.shape_keys.key_blocks:
shapekeys.append(shapekey.data)

for vert in data:
co_x = vert.co[0] * ratio_x
co_y = vert.co[2] * ratio_y
vert.co = Vector((co_x,0,co_y))
for shapekey in shapekeys:
for vert in shapekey:
co_x = vert.co[0] * ratio_x
co_y = vert.co[2] * ratio_y
vert.co = Vector((co_x,0,co_y))


obj.coa_sprite_dimension = Vector((get_local_dimension(obj)[0],0,get_local_dimension(obj)[1]))
obj.coa_tiles_x = self.tiles_x
Expand All @@ -389,8 +394,6 @@ def draw(self,context):

def execute(self, context):



sprite_found = False
for image in bpy.data.images:
if os.path.exists(bpy.path.abspath(image.filepath)) and os.path.exists(self.filepath):
Expand Down Expand Up @@ -429,7 +432,8 @@ def execute(self, context):
obj_dimension[2] /= obj.scale[2]

pos = self.pos
obj.location = Vector((pos[0],pos[1],-pos[2]))*self.scale + Vector((self.offset[0],self.offset[1],self.offset[2]))*self.scale
if self.reposition:
obj.location = Vector((pos[0],pos[1],-pos[2]))*self.scale + Vector((self.offset[0],self.offset[1],self.offset[2]))*self.scale

sprite_dimension = Vector(obj_dimension) * (1/scale)

Expand Down

0 comments on commit 76f400d

Please sign in to comment.