比如眼睛嘴巴重叠,贴图扭曲乱飞,有大佬知道怎么回事吗?有办法整好吗?
是按照站里大佬解天下布魔的方法解包的同公司的新世界狂欢
贴图按照atlas文件的分辨率改,记事本打开atlas文件看分辨率
大佬,很多个眼睛叠在一起这个情况怎么搞呀?
能问你要一份你这个软件吗?
重叠是正常的。如果播放动作的时候还有重叠就是插槽没绑定动作(我也忘了怎么说了)。
总之就是手动关闭多余插槽。
import os
import re
import cv2
import numpy as np
import concurrent.futures
import multiprocessing
def process_atlas_file(atlas_path, target_dir):
"""处理单个atlas文件,读取其中的图片信息并调整对应图片大小"""
try:
with open(atlas_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
except Exception as e:
print(f"无法读取文件 {atlas_path}: {e}")
return
image_size_map = {}
current_image = None
# 解析atlas文件,建立图片与size的映射关系
for i, line in enumerate(lines):
line = line.strip()
# 检查是否是图片名称行(.png结尾)
if line.endswith('.png'):
current_image = line
# 检查下一行是否存在且包含size信息
if i + 1 < len(lines):
next_line = lines[i + 1].strip()
size_match = re.search(r'size:\s*(\d+),\s*(\d+)', next_line)
if size_match:
width = int(size_match.group(1))
height = int(size_match.group(2))
image_size_map[current_image] = (width, height)
else:
print(f"警告: 在图片 {current_image} 后未找到对应的size信息")
else:
print(f"警告: 在图片 {current_image} 后未找到对应的size信息")
if not image_size_map:
print(f"在文件 {atlas_path} 中未找到有效的图片-size映射")
return
# 获取atlas文件所在目录
atlas_dir = os.path.dirname(atlas_path)
# 处理每个图片
for image_name, (width, height) in image_size_map.items():
# 构建图片的完整路径
image_path = os.path.join(atlas_dir, image_name)
# 检查图片文件是否存在
if not os.path.exists(image_path):
print(f"图片文件不存在: {image_path}")
continue
try:
# 使用支持中文路径的方法读取图片
with open(image_path, 'rb') as f:
img_array = np.asarray(bytearray(f.read()), dtype=np.uint8)
img = cv2.imdecode(img_array, cv2.IMREAD_UNCHANGED)
if img is None:
print(f"无法读取图片: {image_path}")
continue
# 获取原始图片尺寸
original_height, original_width = img.shape[:2]
# 如果图片尺寸与atlas中指定的尺寸不一致,则调整大小
if original_width != width or original_height != height:
print(f"调整图片大小: {image_name} 从 {original_width}x{original_height} 到 {width}x{height}")
# 使用高质量的调整方法
resized_img = cv2.resize(img, (width, height), interpolation=cv2.INTER_AREA)
# 使用支持中文路径的方法保存图片
success, encoded_img = cv2.imencode('.png', resized_img)
if success:
with open(image_path, 'wb') as f:
f.write(encoded_img)
print(f"成功调整并保存图片: {image_path}")
else:
print(f"无法保存图片: {image_path}")
else:
print(f"图片尺寸已符合要求: {image_path}")
except Exception as e:
print(f"处理图片 {image_path} 时出错: {e}")
def main():
while True:
"""主函数:获取用户输入的文件夹路径,遍历处理所有atlas文件"""
# 获取用户输入的文件夹路径
folder_path = input("请输入要处理的文件夹路径(输入 'q' 退出): ").strip()
if folder_path.lower() == 'q':
break
# 检查路径是否存在
if not os.path.exists(folder_path):
print(f"错误:路径不存在 - {folder_path}")
continue
# 检查是否是文件夹
if not os.path.isdir(folder_path):
print(f"错误:{folder_path} 不是一个文件夹")
continue
# 遍历文件夹中的所有文件,找出所有.atlas文件
atlas_files = []
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith('.atlas'):
atlas_path = os.path.join(root, file)
atlas_files.append(atlas_path)
# 获取 CPU 核心数
num_cpus = multiprocessing.cpu_count()
# 使用线程池并行处理.atlas文件
with concurrent.futures.ThreadPoolExecutor(max_workers=num_cpus) as executor:
futures = [executor.submit(process_atlas_file, atlas_path, folder_path) for atlas_path in atlas_files]
for future in concurrent.futures.as_completed(futures):
try:
future.result()
except Exception as e:
print(f"处理过程中出现异常: {e}")
print("\n处理完成!")
if __name__ == "__main__":
try:
# 检查是否安装了OpenCV库
import cv2
print("OpenCV库已安装,版本:", cv2.__version__)
except ImportError:
print("错误:未安装OpenCV库。请先安装:pip install opencv-python")
else:
main()
也是站内一个大佬做的。
GitHub - ww-rm/SpineViewer: 一个简单好用的 spine 文件查看&导出工具。A simple and easy-to-use spine file viewer and exporter.
好的,谢谢大佬