Prototype animation export

This commit is contained in:
Perfare
2018-04-07 07:51:33 +08:00
parent 4bcbdbc57d
commit 0b111d5f79
33 changed files with 3700 additions and 45 deletions

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9131C403-7FE8-444D-9AF5-5FE5DF76FF24}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AssetStudioUtility</RootNamespace>
<AssemblyName>AssetStudioUtility</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpDX.Mathematics">
<HintPath>..\AssetStudio\Library\SharpDX.Mathematics.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Imported.cs" />
<Compile Include="ObjChildren.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,263 @@
using System;
using System.Collections.Generic;
using System.IO;
using SharpDX;
namespace AssetStudio
{
public interface IImported
{
List<ImportedFrame> FrameList { get; }
List<ImportedMesh> MeshList { get; }
List<ImportedMaterial> MaterialList { get; }
List<ImportedTexture> TextureList { get; }
List<ImportedAnimation> AnimationList { get; }
List<ImportedMorph> MorphList { get; }
}
public class ImportedFrame : ObjChildren<ImportedFrame>, IObjChild
{
public string Name { get; set; }
public Matrix Matrix { get; set; }
public dynamic Parent { get; set; }
}
public class ImportedMesh
{
public string Name { get; set; }
public List<ImportedSubmesh> SubmeshList { get; set; }
public List<ImportedBone> BoneList { get; set; }
}
public class ImportedSubmesh
{
public List<ImportedVertex> VertexList { get; set; }
public List<ImportedFace> FaceList { get; set; }
public string Material { get; set; }
public int Index { get; set; }
public bool WorldCoords { get; set; }
public bool Visible { get; set; }
}
public class ImportedVertex
{
public Vector3 Position { get; set; }
public float[] Weights { get; set; }
public byte[] BoneIndices { get; set; }
public Vector3 Normal { get; set; }
public float[] UV { get; set; }
public Vector4 Tangent { get; set; }
}
public class ImportedVertexWithColour : ImportedVertex
{
public Color4 Colour { get; set; }
}
public class ImportedFace
{
public int[] VertexIndices { get; set; }
}
public class ImportedBone
{
public string Name { get; set; }
public Matrix Matrix { get; set; }
}
public class ImportedMaterial
{
public string Name { get; set; }
public Color4 Diffuse { get; set; }
public Color4 Ambient { get; set; }
public Color4 Specular { get; set; }
public Color4 Emissive { get; set; }
public float Power { get; set; }
public string[] Textures { get; set; }
public Vector2[] TexOffsets { get; set; }
public Vector2[] TexScales { get; set; }
}
public class ImportedTexture
{
public string Name { get; set; }
public byte[] Data { get; set; }
public ImportedTexture(MemoryStream stream, string name)
{
Name = name;
Data = stream.ToArray();
}
}
public interface ImportedAnimation
{
}
public abstract class ImportedAnimationTrackContainer<TrackType> : ImportedAnimation where TrackType : ImportedAnimationTrack
{
public List<TrackType> TrackList { get; set; }
public TrackType FindTrack(string name)
{
return TrackList.Find(track => track.Name == name);
}
}
public class ImportedKeyframedAnimation : ImportedAnimationTrackContainer<ImportedAnimationKeyframedTrack>
{
public string Name { get; set; }
}
public class ImportedSampledAnimation : ImportedAnimationTrackContainer<ImportedAnimationSampledTrack>
{
public string Name { get; set; }
public float SampleRate { get; set; }
}
public abstract class ImportedAnimationTrack
{
public string Name { get; set; }
}
public class ImportedAnimationKeyframedTrack : ImportedAnimationTrack
{
public Dictionary<float, ImportedAnimationKeyframe> Keyframes { get; set; } = new Dictionary<float, ImportedAnimationKeyframe>();
}
public class ImportedKeyframe<T>
{
public float time { get; set; }
public T value { get; set; }
public T inSlope { get; set; }
public T outSlope { get; set; }
public ImportedKeyframe(float time, T value, T inSlope, T outSlope)
{
this.time = time;
this.value = value;
this.inSlope = inSlope;
this.outSlope = outSlope;
}
}
public class ImportedAnimationKeyframe
{
public ImportedKeyframe<Vector3> Scaling { get; set; }
public ImportedKeyframe<Quaternion> Rotation { get; set; }
public ImportedKeyframe<Vector3> Translation { get; set; }
}
public class ImportedAnimationSampledTrack : ImportedAnimationTrack
{
public Vector3?[] Scalings;
public Quaternion?[] Rotations;
public Vector3?[] Translations;
public float?[] Curve;
}
public class ImportedMorph
{
public string Name { get; set; }
public string ClipName { get; set; }
public List<Tuple<float, int, int>> Channels { get; set; }
public List<ImportedMorphKeyframe> KeyframeList { get; set; }
public List<ushort> MorphedVertexIndices { get; set; }
}
public class ImportedMorphKeyframe
{
public string Name { get; set; }
public List<ImportedVertex> VertexList { get; set; }
public List<ushort> MorphedVertexIndices { get; set; }
public float Weight { get; set; }
}
public static class ImportedHelpers
{
public static ImportedFrame FindFrame(String name, ImportedFrame root)
{
ImportedFrame frame = root;
if ((frame != null) && (frame.Name == name))
{
return frame;
}
for (int i = 0; i < root.Count; i++)
{
if ((frame = FindFrame(name, root[i])) != null)
{
return frame;
}
}
return null;
}
public static ImportedMesh FindMesh(String frameName, List<ImportedMesh> importedMeshList)
{
foreach (ImportedMesh mesh in importedMeshList)
{
if (mesh.Name == frameName)
{
return mesh;
}
}
return null;
}
public static ImportedMesh FindMesh(ImportedFrame frame, List<ImportedMesh> importedMeshList)
{
string framePath = frame.Name;
ImportedFrame root = frame;
while (root.Parent != null)
{
root = root.Parent;
framePath = root.Name + "/" + framePath;
}
foreach (ImportedMesh mesh in importedMeshList)
{
if (mesh.Name == framePath)
{
return mesh;
}
}
return null;
}
public static ImportedMaterial FindMaterial(String name, List<ImportedMaterial> importedMats)
{
foreach (ImportedMaterial mat in importedMats)
{
if (mat.Name == name)
{
return mat;
}
}
return null;
}
public static ImportedTexture FindTexture(string name, List<ImportedTexture> importedTextureList)
{
if (string.IsNullOrEmpty(name))
{
return null;
}
foreach (ImportedTexture tex in importedTextureList)
{
if (tex.Name == name)
{
return tex;
}
}
return null;
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace AssetStudio
{
public interface IObjChild
{
dynamic Parent { get; set; }
}
public abstract class ObjChildren<T> : IEnumerable<T> where T : IObjChild
{
protected List<T> children;
public T this[int i]
{
get { return (T)children[i]; }
}
public int Count
{
get { return children.Count; }
}
public void InitChildren(int count)
{
children = new List<T>(count);
}
public void AddChild(T obj)
{
children.Add(obj);
obj.Parent = this;
}
public void InsertChild(int i, T obj)
{
children.Insert(i, obj);
obj.Parent = this;
}
public void RemoveChild(T obj)
{
obj.Parent = null;
children.Remove(obj);
}
public void RemoveChild(int i)
{
children[i].Parent = null;
children.RemoveAt(i);
}
public int IndexOf(T obj)
{
return children.IndexOf(obj);
}
public IEnumerator<T> GetEnumerator()
{
return children.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("AssetStudioUtility")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AssetStudioUtility")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("9131c403-7fe8-444d-9af5-5fe5df76ff24")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]