宣武深圳网站建设公司,百度竞价设不同网站,附近网络维修,网络推广中心MOV导出序列帧并在Unity中播放 前言项目将MOV变成序列帧使用TexturePacker打成一个图集将Json格式精灵表转换为tpsheet格式精灵表导入Unity并播放总结 鸣谢 前言
收集到一批还不错的MG动画#xff0c;想要在Unity中当特效播放出来#xff0c;那首先就得把MOV变成序列帧… MOV导出序列帧并在Unity中播放 前言项目将MOV变成序列帧使用TexturePacker打成一个图集将Json格式精灵表转换为tpsheet格式精灵表导入Unity并播放总结 鸣谢 前言
收集到一批还不错的MG动画想要在Unity中当特效播放出来那首先就得把MOV变成序列帧然后使用TexturePacker打成一个图集最后再导入Unity中制作Animation Clip播放。
项目
将MOV变成序列帧 需要提前安装FFmpeg 创建一个Cut.txt文本文件将下面内容复制到文本文件中把Cut.txt改成Cut.bat就可以将代码中设置的mov视频导出成序列帧并存储在同级目录下。
echo off
setlocal enabledelayedexpansion:: 设置输入视频文件和输出图片文件夹路径
set input_videoEle.mov
set output_folderoutput_images:: 创建输出文件夹
mkdir %output_folder%:: 使用FFmpeg抓取视频帧并保存为透明图片
ffmpeg -i %input_video% -vf selecteq(n\,0)eq(pict_type\,I) -vsync vfr -q:v 2 %output_folder%\frame%%04d.png:: 完成后的消息
echo 透明图片已经生成到 %output_folder% 文件夹中。:: 按任意键退出
pause使用TexturePacker打成一个图集
这里我只找到了TexturePacker3.0.9的版本(pj方法就是用里面带的两个exe替换原始的两个exe) 链接https://pan.baidu.com/s/1C04rikUgbdlstwBJV_Ch7g?pwdupvu 提取码upvu 但是这里有一个问题3.0.9版本只能导出json格式的图集表Unity2021以上只能使用tpsheet格式的精灵表 所以需要下面的步骤
将Json格式精灵表转换为tpsheet格式精灵表
创建一个Python脚本写入以下内容
import json
import osdef convert_texture_packer_to_unity(json_file, output_file):with open(json_file, r) as f:data json.load(f)frames data[frames]meta data[meta]texture_size meta[size]with open(output_file, w) as f:f.write(#\n)f.write(# Sprite sheet data for Unity.\n)f.write(#\n)f.write(f:format40300\n)f.write(f:texture{meta[image]}\n)f.write(f:size{texture_size[w]}x{texture_size[h]}\n)f.write(:pivotpointsenabled\n)f.write(:bordersdisabled\n)f.write(:alphahandlingClearTransparentPixels\n)f.write(\n)for frame_name, frame_data in frames.items():frame frame_data[frame]source_size frame_data[sourceSize]sprite_source_size frame_data[spriteSourceSize]x frame[x]y texture_size[h] - frame[y] - frame[h]w frame[w]h frame[h]pivot_x sprite_source_size[x] / source_size[w]pivot_y 1 - (sprite_source_size[y] / source_size[h])f.write(f{frame_name.replace(.png, )};{x};{y};{w};{h}; {pivot_x};{pivot_y}; 0;0;0;0\n)if __name__ __main__:json_file link.txt # Replace with your JSON file nameoutput_file link.tpsheet # Replace with your desired output file nameconvert_texture_packer_to_unity(json_file, output_file)
正确填入json_file和output_file的名称j运行即可得到转换后的tpsheet精灵表
导入Unity并播放
需要提前导入TexturePacker的读取工具 再将之前转换的tpsheet和png格式图片放入工程中 之后使用Animation Clip播放序列帧即可
总结
比较难的问题只有如何将Json格式精灵表转换为tpsheet格式精灵表
鸣谢
ChatGPT 4