- [Core] Combine ModelConverter options.

- [Core] Fix bug with loading `.zip` files
- [Core] Added new entry [UnityCN]
This commit is contained in:
Razmoth
2023-11-30 10:23:47 +04:00
parent 6945bff896
commit 7321cf9780
6 changed files with 106 additions and 45 deletions

View File

@@ -335,9 +335,17 @@ namespace AssetStudio.CLI
exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx"); exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx");
} }
var m_Animator = (Animator)item.Asset; var m_Animator = (Animator)item.Asset;
var options = new ModelConverter.Options()
{
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
var convert = animationList != null var convert = animationList != null
? new ModelConverter(m_Animator, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations, animationList.Select(x => (AnimationClip)x.Asset).ToArray()) ? new ModelConverter(m_Animator, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
: new ModelConverter(m_Animator, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations); : new ModelConverter(m_Animator, options);
ExportFbx(convert, exportFullPath); ExportFbx(convert, exportFullPath);
return true; return true;
} }
@@ -351,9 +359,17 @@ namespace AssetStudio.CLI
public static bool ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null) public static bool ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null)
{ {
var options = new ModelConverter.Options()
{
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
var convert = animationList != null var convert = animationList != null
? new ModelConverter(gameObject, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations, animationList.Select(x => (AnimationClip)x.Asset).ToArray()) ? new ModelConverter(gameObject, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
: new ModelConverter(gameObject, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations); : new ModelConverter(gameObject, options);
if (convert.MeshList.Count == 0) if (convert.MeshList.Count == 0)
{ {

View File

@@ -334,9 +334,17 @@ namespace AssetStudio.GUI
exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx"); exportFullPath = Path.Combine(exportPath, item.Text + item.UniqueID, item.Text + ".fbx");
} }
var m_Animator = (Animator)item.Asset; var m_Animator = (Animator)item.Asset;
var options = new ModelConverter.Options()
{
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
var convert = animationList != null var convert = animationList != null
? new ModelConverter(m_Animator, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations, animationList.Select(x => (AnimationClip)x.Asset).ToArray()) ? new ModelConverter(m_Animator, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
: new ModelConverter(m_Animator, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations); : new ModelConverter(m_Animator, options);
ExportFbx(convert, exportFullPath); ExportFbx(convert, exportFullPath);
return true; return true;
} }
@@ -355,9 +363,17 @@ namespace AssetStudio.GUI
public static void ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null) public static void ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null)
{ {
var options = new ModelConverter.Options()
{
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
var convert = animationList != null var convert = animationList != null
? new ModelConverter(gameObject, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations, animationList.Select(x => (AnimationClip)x.Asset).ToArray()) ? new ModelConverter(gameObject, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
: new ModelConverter(gameObject, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations); : new ModelConverter(gameObject, options);
exportPath = exportPath + FixFileName(gameObject.m_Name) + ".fbx"; exportPath = exportPath + FixFileName(gameObject.m_Name) + ".fbx";
ExportFbx(convert, exportPath); ExportFbx(convert, exportPath);
} }
@@ -365,9 +381,17 @@ namespace AssetStudio.GUI
public static void ExportGameObjectMerge(List<GameObject> gameObject, string exportPath, List<AssetItem> animationList = null) public static void ExportGameObjectMerge(List<GameObject> gameObject, string exportPath, List<AssetItem> animationList = null)
{ {
var rootName = Path.GetFileNameWithoutExtension(exportPath); var rootName = Path.GetFileNameWithoutExtension(exportPath);
var options = new ModelConverter.Options()
{
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
var convert = animationList != null var convert = animationList != null
? new ModelConverter(rootName, gameObject, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations, animationList.Select(x => (AnimationClip)x.Asset).ToArray()) ? new ModelConverter(rootName, gameObject, options, animationList.Select(x => (AnimationClip)x.Asset).ToArray())
: new ModelConverter(rootName, gameObject, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, Properties.Settings.Default.collectAnimations); : new ModelConverter(rootName, gameObject, options);
ExportFbx(convert, exportPath); ExportFbx(convert, exportPath);
} }

View File

@@ -1290,12 +1290,28 @@ namespace AssetStudio.GUI
private void PreviewGameObject(GameObject m_GameObject) private void PreviewGameObject(GameObject m_GameObject)
{ {
var model = new ModelConverter(m_GameObject, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, false, Array.Empty<AnimationClip>()); var options = new ModelConverter.Options()
{
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
var model = new ModelConverter(m_GameObject, options, Array.Empty<AnimationClip>());
PreviewModel(model); PreviewModel(model);
} }
private void PreviewAnimator(Animator m_Animator) private void PreviewAnimator(Animator m_Animator)
{ {
var model = new ModelConverter(m_Animator, Properties.Settings.Default.convertType, Properties.Settings.Default.texs, Properties.Settings.Default.uvs, Studio.Game, false, Array.Empty<AnimationClip>()); var options = new ModelConverter.Options()
{
imageFormat = Properties.Settings.Default.convertType,
game = Studio.Game,
collectAnimations = Properties.Settings.Default.collectAnimations,
uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(Properties.Settings.Default.uvs),
texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.texs),
};
var model = new ModelConverter(m_Animator, options, Array.Empty<AnimationClip>());
PreviewModel(model); PreviewModel(model);
} }

View File

@@ -15,8 +15,7 @@ namespace AssetStudio
public List<ImportedKeyframedAnimation> AnimationList { get; protected set; } = new List<ImportedKeyframedAnimation>(); public List<ImportedKeyframedAnimation> AnimationList { get; protected set; } = new List<ImportedKeyframedAnimation>();
public List<ImportedMorph> MorphList { get; protected set; } = new List<ImportedMorph>(); public List<ImportedMorph> MorphList { get; protected set; } = new List<ImportedMorph>();
private Game Game; private Options options;
private ImageFormat imageFormat;
private Avatar avatar; private Avatar avatar;
private HashSet<AnimationClip> animationClipHashSet = new HashSet<AnimationClip>(); private HashSet<AnimationClip> animationClipHashSet = new HashSet<AnimationClip>();
private Dictionary<AnimationClip, string> boundAnimationPathDic = new Dictionary<AnimationClip, string>(); private Dictionary<AnimationClip, string> boundAnimationPathDic = new Dictionary<AnimationClip, string>();
@@ -24,19 +23,15 @@ namespace AssetStudio
private Dictionary<Texture2D, string> textureNameDictionary = new Dictionary<Texture2D, string>(); private Dictionary<Texture2D, string> textureNameDictionary = new Dictionary<Texture2D, string>();
private Dictionary<Transform, ImportedFrame> transformDictionary = new Dictionary<Transform, ImportedFrame>(); private Dictionary<Transform, ImportedFrame> transformDictionary = new Dictionary<Transform, ImportedFrame>();
Dictionary<uint, string> morphChannelNames = new Dictionary<uint, string>(); Dictionary<uint, string> morphChannelNames = new Dictionary<uint, string>();
Dictionary<string, (bool, int)> uvs = new Dictionary<string, (bool, int)>();
Dictionary<string, int> texs = new Dictionary<string, int>();
public ModelConverter(GameObject m_GameObject, ImageFormat imageFormat, string texs, string uvs, Game game, bool collectAnimations, AnimationClip[] animationList = null) public ModelConverter(GameObject m_GameObject, Options options, AnimationClip[] animationList = null)
{ {
Game = game; this.options = options;
this.imageFormat = imageFormat;
this.texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(texs);
this.uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(uvs);
if (m_GameObject.m_Animator != null) if (m_GameObject.m_Animator != null)
{ {
InitWithAnimator(m_GameObject.m_Animator); InitWithAnimator(m_GameObject.m_Animator);
if (animationList == null && collectAnimations) if (animationList == null && this.options.collectAnimations)
{ {
CollectAnimationClip(m_GameObject.m_Animator); CollectAnimationClip(m_GameObject.m_Animator);
} }
@@ -55,16 +50,14 @@ namespace AssetStudio
ConvertAnimations(); ConvertAnimations();
} }
public ModelConverter(string rootName, List<GameObject> m_GameObjects, ImageFormat imageFormat, string texs, string uvs, Game game, bool collectAnimations, AnimationClip[] animationList = null) public ModelConverter(string rootName, List<GameObject> m_GameObjects, Options options, AnimationClip[] animationList = null)
{ {
Game = game; this.options = options;
this.imageFormat = imageFormat;
this.texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(texs);
this.uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(uvs);
RootFrame = CreateFrame(rootName, Vector3.Zero, new Quaternion(0, 0, 0, 0), Vector3.One); RootFrame = CreateFrame(rootName, Vector3.Zero, new Quaternion(0, 0, 0, 0), Vector3.One);
foreach (var m_GameObject in m_GameObjects) foreach (var m_GameObject in m_GameObjects)
{ {
if (m_GameObject.m_Animator != null && animationList == null && collectAnimations) if (m_GameObject.m_Animator != null && animationList == null && this.options.collectAnimations)
{ {
CollectAnimationClip(m_GameObject.m_Animator); CollectAnimationClip(m_GameObject.m_Animator);
} }
@@ -88,14 +81,12 @@ namespace AssetStudio
ConvertAnimations(); ConvertAnimations();
} }
public ModelConverter(Animator m_Animator, ImageFormat imageFormat, string texs, string uvs, Game game, bool collectAnimations, AnimationClip[] animationList = null) public ModelConverter(Animator m_Animator, Options options, AnimationClip[] animationList = null)
{ {
Game = game; this.options = options;
this.imageFormat = imageFormat;
this.texs = JsonConvert.DeserializeObject<Dictionary<string, int>>(texs);
this.uvs = JsonConvert.DeserializeObject<Dictionary<string, (bool, int)>>(uvs);
InitWithAnimator(m_Animator); InitWithAnimator(m_Animator);
if (animationList == null && collectAnimations) if (animationList == null && this.options.collectAnimations)
{ {
CollectAnimationClip(m_Animator); CollectAnimationClip(m_Animator);
} }
@@ -313,8 +304,8 @@ namespace AssetStudio
for (int uv = 0; uv < 8; uv++) for (int uv = 0; uv < 8; uv++)
{ {
var key = $"UV{uv}"; var key = $"UV{uv}";
iMesh.hasUV[uv] = mesh.GetUV(uv)?.Length > 0 && uvs[key].Item1; iMesh.hasUV[uv] = mesh.GetUV(uv)?.Length > 0 && options.uvs[key].Item1;
iMesh.uvType[uv] = uvs[key].Item2; iMesh.uvType[uv] = options.uvs[key].Item2;
} }
iMesh.hasTangent = mesh.m_Tangents != null && mesh.m_Tangents.Length == mesh.m_VertexCount * 4; iMesh.hasTangent = mesh.m_Tangents != null && mesh.m_Tangents.Length == mesh.m_VertexCount * 4;
iMesh.hasColor = mesh.m_Colors?.Length > 0; iMesh.hasColor = mesh.m_Colors?.Length > 0;
@@ -720,7 +711,7 @@ namespace AssetStudio
iMat.Textures.Add(texture); iMat.Textures.Add(texture);
int dest = -1; int dest = -1;
if (texs.TryGetValue(texEnv.Key, out var targetDest)) if (options.texs.TryGetValue(texEnv.Key, out var targetDest))
dest = targetDest; dest = targetDest;
else if (texEnv.Key == "_MainTex") else if (texEnv.Key == "_MainTex")
dest = 0; dest = 0;
@@ -733,7 +724,7 @@ namespace AssetStudio
texture.Dest = dest; texture.Dest = dest;
var ext = $".{imageFormat.ToString().ToLower()}"; var ext = $".{options.imageFormat.ToString().ToLower()}";
if (textureNameDictionary.TryGetValue(m_Texture2D, out var textureName)) if (textureNameDictionary.TryGetValue(m_Texture2D, out var textureName))
{ {
texture.Name = textureName; texture.Name = textureName;
@@ -779,7 +770,7 @@ namespace AssetStudio
return; return;
} }
var stream = m_Texture2D.ConvertToStream(imageFormat, true); var stream = m_Texture2D.ConvertToStream(options.imageFormat, true);
if (stream != null) if (stream != null)
{ {
using (stream) using (stream)
@@ -909,9 +900,9 @@ namespace AssetStudio
var m_ClipBindingConstant = animationClip.m_ClipBindingConstant ?? m_Clip.ConvertValueArrayToGenericBinding(); var m_ClipBindingConstant = animationClip.m_ClipBindingConstant ?? m_Clip.ConvertValueArrayToGenericBinding();
var m_ACLClip = m_Clip.m_ACLClip; var m_ACLClip = m_Clip.m_ACLClip;
var aclCount = m_ACLClip.CurveCount; var aclCount = m_ACLClip.CurveCount;
if (m_ACLClip.IsSet && !Game.Type.IsSRGroup()) if (m_ACLClip.IsSet && !options.game.Type.IsSRGroup())
{ {
m_ACLClip.Process(Game, out var values, out var times); m_ACLClip.Process(options.game, out var values, out var times);
for (int frameIndex = 0; frameIndex < times.Length; frameIndex++) for (int frameIndex = 0; frameIndex < times.Length; frameIndex++)
{ {
var time = times[frameIndex]; var time = times[frameIndex];
@@ -931,7 +922,7 @@ namespace AssetStudio
for (int curveIndex = 0; curveIndex < frame.keyList.Count;) for (int curveIndex = 0; curveIndex < frame.keyList.Count;)
{ {
var index = frame.keyList[curveIndex].index; var index = frame.keyList[curveIndex].index;
if (!Game.Type.IsSRGroup()) if (!options.game.Type.IsSRGroup())
index += (int)aclCount; index += (int)aclCount;
ReadCurveData(iAnim, m_ClipBindingConstant, index, frame.time, streamedValues, 0, ref curveIndex); ReadCurveData(iAnim, m_ClipBindingConstant, index, frame.time, streamedValues, 0, ref curveIndex);
} }
@@ -945,14 +936,14 @@ namespace AssetStudio
for (int curveIndex = 0; curveIndex < m_DenseClip.m_CurveCount;) for (int curveIndex = 0; curveIndex < m_DenseClip.m_CurveCount;)
{ {
var index = streamCount + curveIndex; var index = streamCount + curveIndex;
if (!Game.Type.IsSRGroup()) if (!options.game.Type.IsSRGroup())
index += (int)aclCount; index += (int)aclCount;
ReadCurveData(iAnim, m_ClipBindingConstant, (int)index, time, m_DenseClip.m_SampleArray, (int)frameOffset, ref curveIndex); ReadCurveData(iAnim, m_ClipBindingConstant, (int)index, time, m_DenseClip.m_SampleArray, (int)frameOffset, ref curveIndex);
} }
} }
if (m_ACLClip.IsSet && Game.Type.IsSRGroup()) if (m_ACLClip.IsSet && options.game.Type.IsSRGroup())
{ {
m_ACLClip.Process(Game, out var values, out var times); m_ACLClip.Process(options.game, out var values, out var times);
for (int frameIndex = 0; frameIndex < times.Length; frameIndex++) for (int frameIndex = 0; frameIndex < times.Length; frameIndex++)
{ {
var time = times[frameIndex]; var time = times[frameIndex];
@@ -1174,5 +1165,14 @@ namespace AssetStudio
return null; return null;
} }
} }
public record Options
{
public ImageFormat imageFormat;
public Game game;
public bool collectAnimations;
public Dictionary<string, (bool, int)> uvs;
public Dictionary<string, int> texs;
}
} }
} }

View File

@@ -402,6 +402,7 @@ namespace AssetStudio
streamReader.Position = 0; streamReader.Position = 0;
FileReader entryReader = new FileReader(dummyPath, streamReader); FileReader entryReader = new FileReader(dummyPath, streamReader);
entryReader = entryReader.PreProcessing(Game);
LoadFile(entryReader); LoadFile(entryReader);
if (entryReader.FileType == FileType.ResourceFile) if (entryReader.FileType == FileType.ResourceFile)
{ {

View File

@@ -82,5 +82,9 @@
{ {
"Name": "Frostpunk: Beyond the Ice", "Name": "Frostpunk: Beyond the Ice",
"Key": "7368756978696E673838383838383838" "Key": "7368756978696E673838383838383838"
},
{
"Name": "Cat Fantasy",
"Key": "43614461566637323538576877363433"
} }
] ]