18 Commits

Author SHA1 Message Date
Perfare
1ecf4c8c27 Release 0.8.0 2017-09-06 01:12:55 +08:00
Perfare
3dea2936d7 fixed bug 2017-09-06 01:03:54 +08:00
Perfare
e4533b4ec3 Add json file to read Shader 2017-08-21 22:00:28 +08:00
Perfare
9d87fead21 move glsl file to resource file 2017-08-21 19:51:32 +08:00
Perfare
14bd7f9789 try to read shader after Unity 5.4 2017-08-21 09:20:00 +08:00
Perfare
d02a4ea02e rewrite TextAsset.cs and Shader.cs 2017-08-21 07:10:30 +08:00
Perfare
14829c5e1b update TextureFormat 2017-08-21 06:52:31 +08:00
Perfare
ef29d220e0 Fixes #73 2017-08-21 06:46:46 +08:00
Perfare
14ec7c8259 support Unity 2017.1.0
fixed show "bundle file" original file
2017-07-15 15:27:09 +08:00
Perfare
9687f823fb Add "show original file" right click menu 2017-06-30 16:11:16 +08:00
Perfare
bb36839774 fix bug in export RGB565 format texture 2017-06-22 15:31:38 +08:00
Perfare
b0114520a8 fixed bug 2017-06-22 08:51:20 +08:00
Perfare
8a3af0bfba rewrite export mesh 2017-06-22 06:59:16 +08:00
Perfare
65a13e97c4 Add some simple judgment 2017-06-22 05:29:51 +08:00
Perfare
fe6b7760b0 fixed bug 2017-06-20 17:14:27 +08:00
Perfare
b319e92b3e fixed bug 2017-04-21 11:14:05 +08:00
Perfare
06b8fcea64 fix vertex color 2017-04-13 15:21:57 +08:00
Perfare
100238d232 fixed bug 2017-04-12 14:43:41 +08:00
24 changed files with 1111 additions and 479 deletions

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.0.0")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyVersion("0.8.0.0")]
[assembly: AssemblyFileVersion("0.8.0.0")]

120
Unity Studio/Resource1.Designer.cs generated Normal file
View File

@@ -0,0 +1,120 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Unity_Studio {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resource1 {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resource1() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Unity_Studio.Resource1", typeof(Resource1).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 查找类似 #version 140
///
///in vec3 surfaceNormal;
///in vec3 toLightVector;
///in vec4 color;
///
///out vec4 outputColor;
///
///void main()
///{
/// vec3 lightColor = vec3(0.5, 0.5, 0.5);
///
/// // Ambient
/// float ambientStrength = 0.9;
/// vec3 ambient = ambientStrength * lightColor;
///
/// // Diffuse
/// vec3 unitNormal = normalize(surfaceNormal);
/// vec3 unitLightVector = normalize(toLightVector);
/// float nDotProduct = dot(unitNormal, unitLightVector);
/// float brightness = clamp(nDotProduct, 0, 1); // max(nDotProduct, 0.0);
/// vec3 diffuse [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string fs {
get {
return ResourceManager.GetString("fs", resourceCulture);
}
}
/// <summary>
/// 查找类似 #version 140
///
///in vec3 vertexPosition;
///in vec3 normalDirection;
///in vec4 vertexColor;
///uniform mat4 viewMatrix;
///
///out vec3 surfaceNormal;
///out vec3 toLightVector;
///out vec4 color;
///
///void main()
///{
/// vec3 lightPosition = vec3(200.0, 200.0, 200.0);
/// gl_Position = viewMatrix * vec4(vertexPosition, 1.0);
/// surfaceNormal = normalDirection;
/// toLightVector = lightPosition - vertexPosition;
/// color = vertexColor;
///} 的本地化字符串。
/// </summary>
internal static string vs {
get {
return ResourceManager.GetString("vs", resourceCulture);
}
}
}
}

170
Unity Studio/Resource1.resx Normal file
View File

@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="fs" xml:space="preserve">
<value>#version 140
in vec3 surfaceNormal;
in vec3 toLightVector;
in vec4 color;
out vec4 outputColor;
void main()
{
vec3 lightColor = vec3(0.5, 0.5, 0.5);
// Ambient
float ambientStrength = 0.9;
vec3 ambient = ambientStrength * lightColor;
// Diffuse
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);
float nDotProduct = dot(unitNormal, unitLightVector);
float brightness = clamp(nDotProduct, 0, 1); // max(nDotProduct, 0.0);
vec3 diffuse = brightness * lightColor;
// Output Color
vec4 result = color * vec4((ambient + diffuse/2), 0.0);
outputColor = result;
}</value>
</data>
<data name="vs" xml:space="preserve">
<value>#version 140
in vec3 vertexPosition;
in vec3 normalDirection;
in vec4 vertexColor;
uniform mat4 viewMatrix;
out vec3 surfaceNormal;
out vec3 toLightVector;
out vec4 color;
void main()
{
vec3 lightPosition = vec3(200.0, 200.0, 200.0);
gl_Position = viewMatrix * vec4(vertexPosition, 1.0);
surfaceNormal = normalDirection;
toLightVector = lightPosition - vertexPosition;
color = vertexColor;
}</value>
</data>
</root>

90
Unity Studio/ShaderResource.Designer.cs generated Normal file
View File

@@ -0,0 +1,90 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Unity_Studio {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class ShaderResource {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal ShaderResource() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Unity_Studio.ShaderResource", typeof(ShaderResource).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 查找类似 [{&quot;Level&quot;:0,&quot;Type&quot;:&quot;string&quot;,&quot;Name&quot;:&quot;m_Name&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32769},{&quot;Level&quot;:1,&quot;Type&quot;:&quot;Array&quot;,&quot;Name&quot;:&quot;Array&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:16385},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;int&quot;,&quot;Name&quot;:&quot;size&quot;,&quot;Size&quot;:4,&quot;Flag&quot;:1},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;char&quot;,&quot;Name&quot;:&quot;data&quot;,&quot;Size&quot;:1,&quot;Flag&quot;:1},{&quot;Level&quot;:0,&quot;Type&quot;:&quot;SerializedShader&quot;,&quot;Name&quot;:&quot;m_ParsedForm&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:1,&quot;Type&quot;:&quot;SerializedProperties&quot;,&quot;Name&quot;:&quot;m_PropInfo&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;vector&quot;,&quot;Name&quot;:&quot;m_Props&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:3,&quot;Type&quot;:&quot;Arr... 的本地化字符串。
/// </summary>
internal static string Shader20171 {
get {
return ResourceManager.GetString("Shader20171", resourceCulture);
}
}
/// <summary>
/// 查找类似 [{&quot;Level&quot;:0,&quot;Type&quot;:&quot;string&quot;,&quot;Name&quot;:&quot;m_Name&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32769},{&quot;Level&quot;:1,&quot;Type&quot;:&quot;Array&quot;,&quot;Name&quot;:&quot;Array&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:16385},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;int&quot;,&quot;Name&quot;:&quot;size&quot;,&quot;Size&quot;:4,&quot;Flag&quot;:1},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;char&quot;,&quot;Name&quot;:&quot;data&quot;,&quot;Size&quot;:1,&quot;Flag&quot;:1},{&quot;Level&quot;:0,&quot;Type&quot;:&quot;SerializedShader&quot;,&quot;Name&quot;:&quot;m_ParsedForm&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:1,&quot;Type&quot;:&quot;SerializedProperties&quot;,&quot;Name&quot;:&quot;m_PropInfo&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;vector&quot;,&quot;Name&quot;:&quot;m_Props&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:3,&quot;Type&quot;:&quot;Arr... 的本地化字符串。
/// </summary>
internal static string Shader55 {
get {
return ResourceManager.GetString("Shader55", resourceCulture);
}
}
/// <summary>
/// 查找类似 [{&quot;Level&quot;:0,&quot;Type&quot;:&quot;string&quot;,&quot;Name&quot;:&quot;m_Name&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32769},{&quot;Level&quot;:1,&quot;Type&quot;:&quot;Array&quot;,&quot;Name&quot;:&quot;Array&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:16385},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;int&quot;,&quot;Name&quot;:&quot;size&quot;,&quot;Size&quot;:4,&quot;Flag&quot;:1},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;char&quot;,&quot;Name&quot;:&quot;data&quot;,&quot;Size&quot;:1,&quot;Flag&quot;:1},{&quot;Level&quot;:0,&quot;Type&quot;:&quot;SerializedShader&quot;,&quot;Name&quot;:&quot;m_ParsedForm&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:1,&quot;Type&quot;:&quot;SerializedProperties&quot;,&quot;Name&quot;:&quot;m_PropInfo&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:2,&quot;Type&quot;:&quot;vector&quot;,&quot;Name&quot;:&quot;m_Props&quot;,&quot;Size&quot;:-1,&quot;Flag&quot;:32768},{&quot;Level&quot;:3,&quot;Type&quot;:&quot;Arr... 的本地化字符串。
/// </summary>
internal static string Shader56 {
get {
return ResourceManager.GetString("Shader56", resourceCulture);
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -60,8 +60,8 @@ namespace Unity_Studio
{
int m_Stream = a_Stream.ReadInt32();
m_Size = a_Stream.ReadInt32();
if (m_Stream > 1)
var asize = m_Size % 4 != 0 ? m_Size + 4 - m_Size % 4 : m_Size;
if (m_Stream > 1 && preloadData.Size + preloadData.Offset - a_Stream.Position > asize)
{
m_Offset = a_Stream.ReadInt32();
m_Source = sourceFile.filePath + ".resS";

View File

@@ -40,20 +40,21 @@ namespace Unity_Studio
m_ShaderKeywords[i] = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
}
}
else if (sourceFile.version[0] == 5)
else if (sourceFile.version[0] >= 5)//5.0 and up
{
m_ShaderKeywords = new string[1] { a_Stream.ReadAlignedString(a_Stream.ReadInt32()) };
uint m_LightmapFlags = a_Stream.ReadUInt32();
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 6) || sourceFile.version[0] > 5)//5.6.0 and up
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 6 || sourceFile.version[0] > 5)//5.6.0 and up
{
var m_EnableInstancingVariants = a_Stream.ReadBoolean();
//var m_DoubleSidedGI = a_Stream.ReadBoolean();//2017.x
a_Stream.AlignStream(4);
}
}
if (sourceFile.version[0] > 4 || (sourceFile.version[0] == 4 && sourceFile.version[1] >= 3)) { m_CustomRenderQueue = a_Stream.ReadInt32(); }
if (sourceFile.version[0] > 4 || sourceFile.version[0] == 4 && sourceFile.version[1] >= 3) { m_CustomRenderQueue = a_Stream.ReadInt32(); }
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 1)
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 1 || sourceFile.version[0] > 5)//5.1 and up
{
string[][] stringTagMap = new string[a_Stream.ReadInt32()][];
for (int i = 0; i < stringTagMap.Length; i++)

View File

@@ -333,7 +333,7 @@ namespace Unity_Studio
var version = MeshPD.sourceFile.version;
a_Stream = MeshPD.sourceFile.a_Stream;
a_Stream.Position = MeshPD.Offset;
MeshPD.extension = ".obj";
bool m_Use16BitIndices = true; //3.5.0 and newer always uses 16bit indices
uint m_MeshCompression = 0;

View File

@@ -1,4 +1,10 @@
using System.Text;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using Lz4;
namespace Unity_Studio
{
@@ -6,7 +12,6 @@ namespace Unity_Studio
{
public string m_Name;
public byte[] m_Script;
public string m_PathName;
public Shader(AssetPreloadData preloadData, bool readSwitch)
{
@@ -23,50 +28,159 @@ namespace Unity_Studio
}
m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
if ((sourceFile.version[0] == 5 && sourceFile.version[1] >= 5) || sourceFile.version[0] > 5)
{
if (readSwitch)
{
string str;
if ((str = preloadData.ViewStruct()) != null)
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 5 || sourceFile.version[0] > 5)//5.5.0 and up
{
m_Script = Encoding.UTF8.GetBytes(preloadData.ViewStruct());
}
else
m_Script = Encoding.UTF8.GetBytes("Serialized Shader can't be read");
a_Stream.Position = preloadData.Offset;
var str = (string)ShaderResource.ResourceManager.GetObject($"Shader{sourceFile.version[0]}{sourceFile.version[1]}");
var members = new JavaScriptSerializer().Deserialize<List<ClassMember>>(str);
m_Script = ReadSerializedShader(members, a_Stream);
}
else
{
if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
}
}
else
m_Script = a_Stream.ReadBytes(a_Stream.ReadInt32());
if (sourceFile.version[0] == 5 && sourceFile.version[1] >= 3) //5.3 - 5.4
{
int m_Script_size = a_Stream.ReadInt32();
if (readSwitch) //asset is read for preview or export
{
m_Script = new byte[m_Script_size];
a_Stream.Read(m_Script, 0, m_Script_size);
if (m_Script[0] == 93) { m_Script = SevenZip.Compression.LZMA.SevenZipHelper.Decompress(m_Script); }
if (m_Script[0] == 60 || (m_Script[0] == 239 && m_Script[1] == 187 && m_Script[2] == 191 && m_Script[3] == 60)) { preloadData.extension = ".xml"; }
}
else
{
byte lzmaTest = a_Stream.ReadByte();
a_Stream.Position += m_Script_size - 1;
if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
}
a_Stream.AlignStream(4);
m_PathName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
a_Stream.ReadAlignedString(a_Stream.ReadInt32());//m_PathName
var decompressedSize = a_Stream.ReadUInt32();
var m_SubProgramBlob = a_Stream.ReadBytes(a_Stream.ReadInt32());
var decompressedBytes = new byte[decompressedSize];
using (var mstream = new MemoryStream(m_SubProgramBlob))
{
var decoder = new Lz4DecoderStream(mstream);
decoder.Read(decompressedBytes, 0, (int)decompressedSize);
decoder.Dispose();
}
m_Script = m_Script.Concat(decompressedBytes.ToArray()).ToArray();
}
}
}
else
{
if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
}
}
private static byte[] ReadSerializedShader(List<ClassMember> members, EndianStream a_Stream)
{
var offsets = new List<uint>();
var compressedLengths = new List<uint>();
var decompressedLengths = new List<uint>();
for (int i = 0; i < members.Count; i++)
{
var member = members[i];
var level = member.Level;
var varTypeStr = member.Type;
if (member.Name == "offsets")
{
var offsets_size = a_Stream.ReadInt32();
for (int j = 0; j < offsets_size; j++)
{
offsets.Add(a_Stream.ReadUInt32());
}
var compressedLengths_size = a_Stream.ReadInt32();
for (int j = 0; j < compressedLengths_size; j++)
{
compressedLengths.Add(a_Stream.ReadUInt32());
}
var decompressedLengths_size = a_Stream.ReadInt32();
for (int j = 0; j < decompressedLengths_size; j++)
{
decompressedLengths.Add(a_Stream.ReadUInt32());
}
var compressedBlob = a_Stream.ReadBytes(a_Stream.ReadInt32());
var decompressedStream = new MemoryStream();
for (int j = 0; j < offsets.Count; j++)
{
var compressedBytes = new byte[compressedLengths[j]];
Array.Copy(compressedBlob, offsets[j], compressedBytes, 0, compressedLengths[j]);
var decompressedBytes = new byte[decompressedLengths[j]];
using (var mstream = new MemoryStream(compressedBytes))
{
var decoder = new Lz4DecoderStream(mstream);
decoder.Read(decompressedBytes, 0, (int)decompressedLengths[j]);
decoder.Dispose();
}
decompressedStream.Write(decompressedBytes, 0, decompressedBytes.Length);
}
var decompressedBlob = decompressedStream.ToArray();
return decompressedBlob;
}
var align = (member.Flag & 0x4000) != 0;
if (varTypeStr == "SInt8")//sbyte
{
a_Stream.ReadSByte();
}
else if (varTypeStr == "UInt8")//byte
{
a_Stream.ReadByte();
}
else if (varTypeStr == "short" || varTypeStr == "SInt16")//Int16
{
a_Stream.ReadInt16();
}
else if (varTypeStr == "UInt16" || varTypeStr == "unsigned short")//UInt16
{
a_Stream.ReadUInt16();
}
else if (varTypeStr == "int" || varTypeStr == "SInt32")//Int32
{
a_Stream.ReadInt32();
}
else if (varTypeStr == "UInt32" || varTypeStr == "unsigned int")//UInt32
{
a_Stream.ReadUInt32();
}
else if (varTypeStr == "long long" || varTypeStr == "SInt64")//Int64
{
a_Stream.ReadInt64();
}
else if (varTypeStr == "UInt64" || varTypeStr == "unsigned long long")//UInt64
{
a_Stream.ReadUInt64();
}
else if (varTypeStr == "float")//float
{
a_Stream.ReadSingle();
}
else if (varTypeStr == "double")//double
{
a_Stream.ReadDouble();
}
else if (varTypeStr == "bool")//bool
{
a_Stream.ReadBoolean();
}
else if (varTypeStr == "string")//string
{
a_Stream.ReadAlignedString(a_Stream.ReadInt32());
i += 3;//skip
}
else if (varTypeStr == "Array")//Array
{
if ((members[i - 1].Flag & 0x4000) != 0)
align = true;
var size = a_Stream.ReadInt32();
var array = AssetPreloadData.ReadArray(members, level, i);
for (int j = 0; j < size; j++)
{
ReadSerializedShader(array, a_Stream);
}
i += array.Count + 1;//skip
}
else
{
align = false;
}
if (align)
a_Stream.AlignStream(4);
}
return null;
}
}
}

View File

@@ -10,7 +10,6 @@ namespace Unity_Studio
{
public string m_Name;
public byte[] m_Script;
public string m_PathName;
public TextAsset(AssetPreloadData preloadData, bool readSwitch)
{
@@ -28,36 +27,16 @@ namespace Unity_Studio
m_Name = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
int m_Script_size = a_Stream.ReadInt32();
if (readSwitch) //asset is read for preview or export
if (readSwitch)
{
m_Script = new byte[m_Script_size];
a_Stream.Read(m_Script, 0, m_Script_size);
if (m_Script[0] == 93)
{
try
{
m_Script = SevenZip.Compression.LZMA.SevenZipHelper.Decompress(m_Script);
}
catch { }
}
if (m_Script[0] == 60 || (m_Script[0] == 239 && m_Script[1] == 187 && m_Script[2] == 191 && m_Script[3] == 60)) { preloadData.extension = ".xml"; }
m_Script = a_Stream.ReadBytes(a_Stream.ReadInt32());
}
else
{
byte lzmaTest = a_Stream.ReadByte();
a_Stream.Position += m_Script_size - 1;
if (m_Name != "") { preloadData.Text = m_Name; }
else { preloadData.Text = preloadData.TypeString + " #" + preloadData.uniqueID; }
preloadData.SubItems.AddRange(new[] { preloadData.TypeString, preloadData.Size.ToString() });
}
a_Stream.AlignStream(4);
m_PathName = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
}
}
}

View File

@@ -136,7 +136,11 @@ namespace Unity_Studio
m_Aniso = a_Stream.ReadInt32();
m_MipBias = a_Stream.ReadSingle();
m_WrapMode = a_Stream.ReadInt32();
if (sourceFile.version[0] == 2017)//2017.x
{
int m_WrapV = a_Stream.ReadInt32();
int m_WrapW = a_Stream.ReadInt32();
}
if (sourceFile.version[0] >= 3)
{
m_LightmapFormat = a_Stream.ReadInt32();
@@ -986,9 +990,26 @@ namespace Unity_Studio
private Bitmap RGB565ToBitmap()
{
var hObject = GCHandle.Alloc(image_data, GCHandleType.Pinned);
//stride = m_Width * 2 + m_Width * 2 % 4
//所以m_Width * 2不为4的倍数时需要在每行补上相应的像素
byte[] buff;
var padding = m_Width * 2 % 4;
var stride = m_Width * 2 + padding;
if (padding != 0)
{
buff = new byte[stride * m_Height];
for (int i = 0; i < m_Height; i++)
{
Array.Copy(image_data, i * m_Width * 2, buff, i * stride, m_Width * 2);
}
}
else
{
buff = image_data;
}
var hObject = GCHandle.Alloc(buff, GCHandleType.Pinned);
var pObject = hObject.AddrOfPinnedObject();
var bitmap = new Bitmap(m_Width, m_Height, m_Width * 2, PixelFormat.Format16bppRgb565, pObject);
var bitmap = new Bitmap(m_Width, m_Height, stride, PixelFormat.Format16bppRgb565, pObject);
hObject.Free();
return bitmap;
}
@@ -1075,6 +1096,7 @@ public enum TextureFormat
RGFloat,
RGBAFloat,
YUY2,
RGB9e5Float,
BC4 = 26,
BC5,
BC6H = 24,
@@ -1108,7 +1130,9 @@ public enum TextureFormat
ASTC_RGBA_10x10,
ASTC_RGBA_12x12,
ETC_RGB4_3DS,
ETC_RGBA8_3DS
ETC_RGBA8_3DS,
RG16,
R8
}
public static class KTXHeader

View File

@@ -127,7 +127,7 @@ namespace Unity_Studio
}
}
private static List<ClassMember> ReadArray(List<ClassMember> members, int level, int index)
public static List<ClassMember> ReadArray(List<ClassMember> members, int level, int index)
{
var member2 = new List<ClassMember>();
for (int i = index + 2; i < members.Count; i++)//skip int size

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Unity_Studio
{
@@ -9,8 +11,10 @@ namespace Unity_Studio
{
public EndianStream a_Stream;
public string filePath;
public string bundlePath;
public string fileName;
public int fileGen;
public bool valid;
public string m_Version = "2.5.0f5";
public int[] version = new int[4] { 0, 0, 0, 0 };
public string[] buildType;
@@ -31,7 +35,6 @@ namespace Unity_Studio
private List<int[]> classIDs = new List<int[]>();//use for 5.5.0
public static string[] buildTypeSplit = { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
public static string[] strverSplit = { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n", "-", "_" };
#region cmmon string
private static Dictionary<int, string> baseStrings = new Dictionary<int, string>()
@@ -148,12 +151,11 @@ namespace Unity_Studio
public AssetsFile(string fullName, EndianStream fileStream)
{
//if (memFile != null) { Stream = new EndianStream(memFile, endianType); }
//else { Stream = new EndianStream(File.OpenRead(fileName), endianType); }
a_Stream = fileStream;
filePath = fullName;
fileName = Path.GetFileName(fullName);
try
{
int tableSize = a_Stream.ReadInt32();
int dataEnd = a_Stream.ReadInt32();
fileGen = a_Stream.ReadInt32();
@@ -162,20 +164,20 @@ namespace Unity_Studio
switch (fileGen)
{
case 6://2.5.0 - 2.6.1
case 6: //2.5.0 - 2.6.1
{
a_Stream.Position = (dataEnd - tableSize);
a_Stream.Position += 1;
break;
}
case 7://3.0.0 beta
case 7: //3.0.0 beta
{
a_Stream.Position = (dataEnd - tableSize);
a_Stream.Position += 1;
m_Version = a_Stream.ReadStringToNull();
break;
}
case 8://3.0.0 - 3.4.2
case 8: //3.0.0 - 3.4.2
{
a_Stream.Position = (dataEnd - tableSize);
a_Stream.Position += 1;
@@ -183,19 +185,19 @@ namespace Unity_Studio
platform = a_Stream.ReadInt32();
break;
}
case 9://3.5.0 - 4.6.x
case 9: //3.5.0 - 4.6.x
{
a_Stream.Position += 4;//azero
a_Stream.Position += 4; //azero
m_Version = a_Stream.ReadStringToNull();
platform = a_Stream.ReadInt32();
break;
}
case 14://5.0.0 beta and final
case 15://5.0.1 - 5.4
case 16://??.. no sure
case 17://5.5.0 and up
case 14: //5.0.0 beta and final
case 15: //5.0.1 - 5.4
case 16: //??.. no sure
case 17: //5.5.0 and up
{
a_Stream.Position += 4;//azero
a_Stream.Position += 4; //azero
m_Version = a_Stream.ReadStringToNull();
platform = a_Stream.ReadInt32();
baseDefinitions = a_Stream.ReadBoolean();
@@ -219,20 +221,51 @@ namespace Unity_Studio
switch (platform)
{
case -2: platformStr = "Unity Package"; break;
case 4: platformStr = "OSX"; break;
case 5: platformStr = "PC"; break;
case 6: platformStr = "Web"; break;
case 7: platformStr = "Web streamed"; break;
case 9: platformStr = "iOS"; break;
case 10: platformStr = "PS3"; break;
case 11: platformStr = "Xbox 360"; break;
case 13: platformStr = "Android"; break;
case 16: platformStr = "Google NaCl"; break;
case 21: platformStr = "WP8"; break;
case 25: platformStr = "Linux"; break;
case 29: platformStr = "Wii U"; break;
default: platformStr = "Unknown Platform"; break;
case -2:
platformStr = "Unity Package";
break;
case 4:
platformStr = "OSX";
break;
case 5:
platformStr = "PC";
break;
case 6:
platformStr = "Web";
break;
case 7:
platformStr = "Web streamed";
break;
case 9:
platformStr = "iOS";
break;
case 10:
platformStr = "PS3";
break;
case 11:
platformStr = "Xbox 360";
break;
case 13:
platformStr = "Android";
break;
case 16:
platformStr = "Google NaCl";
break;
case 19:
platformStr = "CollabPreview";
break;
case 21:
platformStr = "WP8";
break;
case 25:
platformStr = "Linux";
break;
case 29:
platformStr = "Wii U";
break;
default:
platformStr = "Unknown Platform";
break;
}
int baseCount = a_Stream.ReadInt32();
@@ -247,16 +280,25 @@ namespace Unity_Studio
int memberCount = a_Stream.ReadInt32();
var cb = new List<ClassMember>();
for (int m = 0; m < memberCount; m++) { readBase(cb, 1); }
for (int m = 0; m < memberCount; m++)
{
readBase(cb, 1);
}
var aClass = new ClassStruct() { ID = classID, Text = (baseType + " " + baseName), members = cb };
aClass.SubItems.Add(classID.ToString());
ClassStructures.Add(classID, aClass);
}
else { readBase5(); }
else
{
readBase5();
}
}
if (fileGen >= 7 && fileGen < 14) { a_Stream.Position += 4; }//azero
if (fileGen >= 7 && fileGen < 14)
{
a_Stream.Position += 4; //azero
}
int assetCount = a_Stream.ReadInt32();
@@ -266,11 +308,20 @@ namespace Unity_Studio
for (int i = 0; i < assetCount; i++)
{
//each table entry is aligned individually, not the whole table
if (fileGen >= 14) { a_Stream.AlignStream(4); }
if (fileGen >= 14)
{
a_Stream.AlignStream(4);
}
AssetPreloadData asset = new AssetPreloadData();
if (fileGen < 14) { asset.m_PathID = a_Stream.ReadInt32(); }
else { asset.m_PathID = a_Stream.ReadInt64(); }
if (fileGen < 14)
{
asset.m_PathID = a_Stream.ReadInt32();
}
else
{
asset.m_PathID = a_Stream.ReadInt64();
}
asset.Offset = a_Stream.ReadUInt32();
asset.Offset += dataOffset;
asset.Size = a_Stream.ReadInt32();
@@ -329,9 +380,15 @@ namespace Unity_Studio
#endregion
buildType = m_Version.Split(buildTypeSplit, StringSplitOptions.RemoveEmptyEntries);
var strver = m_Version.Split(strverSplit, StringSplitOptions.RemoveEmptyEntries);
version = Array.ConvertAll(strver, int.Parse);
var strver = from Match m in Regex.Matches(m_Version, @"[0-9]") select m.Value;
version = Array.ConvertAll(strver.ToArray(), int.Parse);
if (version[0] == 2 && version[1] == 0 && version[2] == 1 && version[3] == 7)//2017.x
{
var nversion = new int[version.Length - 3];
nversion[0] = 2017;
Array.Copy(version, 4, nversion, 1, version.Length - 4);
version = nversion;
}
if (fileGen >= 14)
{
//this looks like a list of assets that need to be preloaded in memory before anytihng else
@@ -354,6 +411,11 @@ namespace Unity_Studio
shared.fileName = sharedFileName.Replace("/", "\\");
sharedAssetsList.Add(shared);
}
valid = true;
}
catch
{
}
}
private void readBase(List<ClassMember> cb, int level)

View File

@@ -149,7 +149,7 @@ namespace Unity_Studio
{
var bytes = new List<byte>();
byte b;
while ((b = ReadByte()) != 0)
while (BaseStream.Position != BaseStream.Length && (b = ReadByte()) != 0)
bytes.Add(b);
return Encoding.UTF8.GetString(bytes.ToArray());
}

View File

@@ -7,7 +7,6 @@ using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Drawing.Imaging;
using System.Web.Script.Serialization;
using ManagedFbx;
namespace Unity_Studio
@@ -131,35 +130,20 @@ namespace Unity_Studio
foreach (var memFile in b_File.MemoryAssetsFileList) //filter unity files
{
bool validAssetsFile = false;
switch (Path.GetExtension(memFile.fileName))
{
case ".assets":
case ".sharedAssets":
validAssetsFile = true;
break;
case "":
validAssetsFile = (memFile.fileName == "mainData" ||
Regex.IsMatch(memFile.fileName, "level.*?") ||
Regex.IsMatch(memFile.fileName, "CustomAssetBundle-.*?") ||
Regex.IsMatch(memFile.fileName, "CAB-.*?") ||
Regex.IsMatch(memFile.fileName, "BuildPlayer-.*?"));
break;
}
StatusStripUpdate("Loading " + memFile.fileName);
//create dummy path to be used for asset extraction
memFile.fileName = Path.GetDirectoryName(bundleFileName) + "\\" + memFile.fileName;
AssetsFile assetsFile = new AssetsFile(memFile.fileName, new EndianStream(memFile.memStream, EndianType.BigEndian));
if (assetsFile.valid)
{
assetsFile.bundlePath = bundleFileName;
if (assetsFile.fileGen == 6 && Path.GetFileName(bundleFileName) != "mainData") //2.6.x and earlier don't have a string version before the preload table
{
//make use of the bundle file version
assetsFile.m_Version = b_File.versionEngine;
assetsFile.version = Array.ConvertAll((b_File.versionEngine.Split(AssetsFile.strverSplit, StringSplitOptions.RemoveEmptyEntries)), int.Parse);
assetsFile.version = Array.ConvertAll((from Match m in Regex.Matches(assetsFile.m_Version, @"[0-9]") select m.Value).ToArray(), int.Parse);
assetsFile.buildType = b_File.versionEngine.Split(AssetsFile.buildTypeSplit, StringSplitOptions.RemoveEmptyEntries);
}
if (validAssetsFile)
{
b_assetsfileList.Add(assetsFile);
}
assetsfileandstream[assetsFile.fileName] = assetsFile.a_Stream;
@@ -381,7 +365,10 @@ namespace Unity_Studio
{
var replacename = ab?.m_Container.Find(y => y.second.asset.m_PathID == x.m_PathID)?.first;
if (!string.IsNullOrEmpty(replacename))
x.Text = replacename.Replace(Path.GetExtension(replacename), "");
{
var ex = Path.GetExtension(replacename);
x.Text = !string.IsNullOrEmpty(ex) ? replacename.Replace(ex, "") : replacename;
}
});
}
exportableAssets.AddRange(assetsFile.exportableAssets);
@@ -1304,16 +1291,29 @@ namespace Unity_Studio
//ob.Append(string.Join(",", m_Mesh.m_Colors));
lineSplit = ob.Length;
if (m_Mesh.m_Colors.Length == m_Mesh.m_VertexCount * 3)
{
for (int i = 0; i < m_Mesh.m_VertexCount; i++)
{
ob.AppendFormat("{0},{1},{2},{3},", m_Mesh.m_Colors[i * 2], m_Mesh.m_Colors[i * 2 + 1], m_Mesh.m_Colors[i * 2 + 2], m_Mesh.m_Colors[i * 2 + 3]);
ob.AppendFormat("{0},{1},{2},{3},", m_Mesh.m_Colors[i * 3], m_Mesh.m_Colors[i * 3 + 1], m_Mesh.m_Colors[i * 3 + 2], 1.0f);
if (ob.Length - lineSplit > 2000)
{
ob.Append("\n");
lineSplit = ob.Length;
}
}
}
else
{
for (int i = 0; i < m_Mesh.m_VertexCount; i++)
{
ob.AppendFormat("{0},{1},{2},{3},", m_Mesh.m_Colors[i * 4], m_Mesh.m_Colors[i * 4 + 1], m_Mesh.m_Colors[i * 4 + 2], m_Mesh.m_Colors[i * 4 + 3]);
if (ob.Length - lineSplit > 2000)
{
ob.Append("\n");
lineSplit = ob.Length;
}
}
}
ob.Length--;//remove last comma
@@ -1753,127 +1753,63 @@ namespace Unity_Studio
public static void ExportMesh(Mesh m_Mesh, string exportPath)
{
Scene m_scene = Scene.CreateScene("Scene");
SceneNode root = m_scene.RootNode;
SceneNode meshnode = Scene.CreateNode(m_scene, m_Mesh.m_Name);
SceneNode.AddChild(root, meshnode);
ManagedFbx.Mesh mesh = Scene.CreateMesh(m_scene, meshnode, "Mesh");
if (m_Mesh.m_VertexCount > 0)
{
var sb = new StringBuilder();
sb.AppendLine("g " + m_Mesh.m_Name);
#region Vertices
int count = 3;
int c = 3;
if (m_Mesh.m_Vertices.Length == m_Mesh.m_VertexCount * 4)
{
count = 4;
c = 4;
}
var vertices = new Vector3[m_Mesh.m_VertexCount];
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
{
vertices[v] = new Vector3(
m_Mesh.m_Vertices[v * count],
m_Mesh.m_Vertices[v * count + 1],
m_Mesh.m_Vertices[v * count + 2]);
sb.AppendFormat("v {0} {1} {2}\r\n", -m_Mesh.m_Vertices[v * c], m_Mesh.m_Vertices[v * c + 1], m_Mesh.m_Vertices[v * c + 2]);
}
mesh.Vertices = vertices;
#endregion
#region Indicies
List<int> indices = new List<int>();
for (int i = 0; i < m_Mesh.m_Indices.Count; i = i + 3)
#region UV
if (m_Mesh.m_UV1 != null && m_Mesh.m_UV1.Length == m_Mesh.m_VertexCount * 2)
{
indices.Add((int)m_Mesh.m_Indices[i]);
indices.Add((int)m_Mesh.m_Indices[i + 1]);
indices.Add((int)m_Mesh.m_Indices[i + 2]);
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
{
sb.AppendFormat("vt {0} {1}\r\n", m_Mesh.m_UV1[v * 2], m_Mesh.m_UV1[v * 2 + 1]);
}
}
else if (m_Mesh.m_UV2 != null && m_Mesh.m_UV2.Length == m_Mesh.m_VertexCount * 2)
{
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
{
sb.AppendFormat("vt {0} {1}\r\n", m_Mesh.m_UV2[v * 2], m_Mesh.m_UV2[v * 2 + 1]);
}
}
mesh.AddPolygons(indices, 0);
#endregion
#region Normals
if (m_Mesh.m_Normals != null && m_Mesh.m_Normals.Length > 0)
{
if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 3)
{
count = 3;
c = 3;
}
else if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 4)
{
count = 4;
c = 4;
}
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
{
sb.AppendFormat("vn {0} {1} {2}\r\n", -m_Mesh.m_Normals[v * c], m_Mesh.m_Normals[v * c + 1], m_Mesh.m_Normals[v * c + 2]);
}
}
#endregion
var normals = new Vector3[m_Mesh.m_VertexCount];
for (int n = 0; n < m_Mesh.m_VertexCount; n++)
#region Face
for (int f = 0; f < m_Mesh.m_Indices.Count / 3; f++)
{
normals[n] = new Vector3(
m_Mesh.m_Normals[n * count],
m_Mesh.m_Normals[n * count + 1],
m_Mesh.m_Normals[n * count + 2]);
}
mesh.Normals = normals;
sb.AppendFormat("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\r\n", m_Mesh.m_Indices[f * 3 + 2] + 1, m_Mesh.m_Indices[f * 3 + 1] + 1, m_Mesh.m_Indices[f * 3] + 1);
}
#endregion
#region Colors
if (m_Mesh.m_Colors == null)
{
var colors = new Colour[m_Mesh.m_VertexCount];
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
colors[c] = new Colour(
0.5f, 0.5f, 0.5f, 1.0f);
}
mesh.VertexColours = colors;
}
else if (m_Mesh.m_Colors.Length == m_Mesh.m_VertexCount * 3)
{
var colors = new Colour[m_Mesh.m_VertexCount];
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
colors[c] = new Colour(
m_Mesh.m_Colors[c * 4],
m_Mesh.m_Colors[c * 4 + 1],
m_Mesh.m_Colors[c * 4 + 2],
1.0f);
}
mesh.VertexColours = colors;
}
else
{
var colors = new Colour[m_Mesh.m_VertexCount];
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
colors[c] = new Colour(
m_Mesh.m_Colors[c * 4],
m_Mesh.m_Colors[c * 4 + 1],
m_Mesh.m_Colors[c * 4 + 2],
m_Mesh.m_Colors[c * 4 + 3]);
}
mesh.VertexColours = colors;
}
#endregion
#region UV
if (m_Mesh.m_UV1 != null && m_Mesh.m_UV1.Length == m_Mesh.m_VertexCount * 2)
{
var uv = new Vector2[m_Mesh.m_VertexCount];
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
uv[c] = new Vector2(m_Mesh.m_UV1[c * 2], m_Mesh.m_UV1[c * 2 + 1]);
}
mesh.TextureCoords = uv;
}
else if (m_Mesh.m_UV2 != null && m_Mesh.m_UV2.Length == m_Mesh.m_VertexCount * 2)
{
var uv = new Vector2[m_Mesh.m_VertexCount];
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
uv[c] = new Vector2(m_Mesh.m_UV2[c * 2], m_Mesh.m_UV2[c * 2 + 1]);
}
mesh.TextureCoords = uv;
}
#endregion
}
SceneNode.AddMesh(meshnode, mesh);
//m_scene.Save(exportPath); //default is .fbx
//m_scene.Save(exportPath + ".fbx");
m_scene.Save(exportPath + ".obj");
//m_scene.Save(exportPath + ".dae");
File.WriteAllText(exportPath, sb.ToString());
}
public static bool ExportFileExists(string filename)

View File

@@ -55,11 +55,6 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="ManagedFbx, Version=0.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>library\x86\ManagedFbx.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>library\OpenTK.dll</HintPath>
@@ -141,6 +136,16 @@
<Compile Include="AboutBox.Designer.cs">
<DependentUpon>AboutBox.cs</DependentUpon>
</Compile>
<Compile Include="Resource1.Designer.cs">
<DependentUpon>Resource1.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="ShaderResource.Designer.cs">
<DependentUpon>ShaderResource.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Unity Classes\AssetBundle.cs" />
<Compile Include="Unity Studio Classes\AssetPreloadData.cs" />
<Compile Include="Unity Classes\AudioClip.cs" />
@@ -203,14 +208,19 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Resource1.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource1.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="ShaderResource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ShaderResource.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UnityStudioForm.resx">
<DependentUpon>UnityStudioForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="app.config" />
<None Include="fs.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -220,9 +230,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="vs.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

View File

@@ -55,11 +55,6 @@
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="ManagedFbx, Version=0.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>library\x64\ManagedFbx.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>library\OpenTK.dll</HintPath>
@@ -141,6 +136,16 @@
<Compile Include="AboutBox.Designer.cs">
<DependentUpon>AboutBox.cs</DependentUpon>
</Compile>
<Compile Include="Resource1.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resource1.resx</DependentUpon>
</Compile>
<Compile Include="ShaderResource.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>ShaderResource.resx</DependentUpon>
</Compile>
<Compile Include="Unity Classes\AssetBundle.cs" />
<Compile Include="Unity Studio Classes\AssetPreloadData.cs" />
<Compile Include="Unity Classes\AudioClip.cs" />
@@ -203,14 +208,19 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Resource1.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource1.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="ShaderResource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ShaderResource.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UnityStudioForm.resx">
<DependentUpon>UnityStudioForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="app.config" />
<None Include="fs.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -220,9 +230,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="vs.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

View File

@@ -105,6 +105,8 @@
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.saveFolderDialog1 = new System.Windows.Forms.SaveFileDialog();
this.treeTip = new System.Windows.Forms.ToolTip(this.components);
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.showOriginalFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
@@ -122,6 +124,7 @@
this.classPreviewPanel.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.tabPage3.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
@@ -498,6 +501,7 @@
this.assetListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.assetListView_ColumnClick);
this.assetListView.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.selectAsset);
this.assetListView.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.assetListView_RetrieveVirtualItem);
this.assetListView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.assetListView_MouseClick);
//
// columnHeaderName
//
@@ -851,6 +855,21 @@
this.saveFolderDialog1.RestoreDirectory = true;
this.saveFolderDialog1.Title = "Browse for folder";
//
// contextMenuStrip1
//
this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.showOriginalFileToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(202, 56);
//
// showOriginalFileToolStripMenuItem
//
this.showOriginalFileToolStripMenuItem.Name = "showOriginalFileToolStripMenuItem";
this.showOriginalFileToolStripMenuItem.Size = new System.Drawing.Size(201, 24);
this.showOriginalFileToolStripMenuItem.Text = "show original file";
this.showOriginalFileToolStripMenuItem.Click += new System.EventHandler(this.showOriginalFileToolStripMenuItem_Click);
//
// UnityStudioForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -891,6 +910,7 @@
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.tabPage3.ResumeLayout(false);
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -973,6 +993,8 @@
private System.Windows.Forms.Label FMODcopyright;
private System.Windows.Forms.ToolStripMenuItem all3DObjectssplitToolStripMenuItem;
private OpenTK.GLControl glControl1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem showOriginalFileToolStripMenuItem;
}
}

View File

@@ -69,6 +69,8 @@ namespace Unity_Studio
private PrivateFontCollection pfc = new PrivateFontCollection();
private AssetPreloadData selectasset;
[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
@@ -876,6 +878,7 @@ namespace Unity_Studio
Shader m_TextAsset = new Shader(asset, true);
string m_Script_Text = Encoding.UTF8.GetString(m_TextAsset.m_Script);
m_Script_Text = Regex.Replace(m_Script_Text, "(?<!\r)\n", "\r\n");
m_Script_Text = m_Script_Text.Replace("\0", "\\0");
textPreviewBox.Text = m_Script_Text;
textPreviewBox.Visible = true;
break;
@@ -997,14 +1000,9 @@ namespace Unity_Studio
if (m_Mesh.m_Normals != null && m_Mesh.m_Normals.Length > 0)
{
if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 3)
{
count = 3;
}
else if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 4)
{
count = 4;
}
normalData = new Vector3[m_Mesh.m_VertexCount];
for (int n = 0; n < m_Mesh.m_VertexCount; n++)
{
@@ -1014,6 +1012,8 @@ namespace Unity_Studio
m_Mesh.m_Normals[n * count + 2]);
}
}
else
normalData = null;
#endregion
#region Colors
if (m_Mesh.m_Colors == null)
@@ -1031,9 +1031,9 @@ namespace Unity_Studio
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
{
colorData[c] = new Vector4(
m_Mesh.m_Colors[c * 4],
m_Mesh.m_Colors[c * 4 + 1],
m_Mesh.m_Colors[c * 4 + 2],
m_Mesh.m_Colors[c * 3],
m_Mesh.m_Colors[c * 3 + 1],
m_Mesh.m_Colors[c * 3 + 2],
1.0f);
}
}
@@ -1401,6 +1401,7 @@ namespace Unity_Studio
//防止主界面假死
ThreadPool.QueueUserWorkItem(delegate
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
sceneTreeView.Invoke(new Action(() =>
{
//挂起控件防止更新
@@ -1508,6 +1509,7 @@ namespace Unity_Studio
ThreadPool.QueueUserWorkItem(delegate
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
var savePath = saveFolderDialog1.FileName;
if (Path.GetFileName(savePath) == "Select folder or write folder name to create")
{ savePath = Path.GetDirectoryName(saveFolderDialog1.FileName); }
@@ -1577,7 +1579,7 @@ namespace Unity_Studio
Mesh m_Mesh = new Mesh(asset, true);
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
{
ExportMesh(m_Mesh, exportpath + asset.Text);
ExportMesh(m_Mesh, exportpath + asset.Text + asset.extension);
exportedCount++;
}
@@ -1711,8 +1713,8 @@ namespace Unity_Studio
GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
GL.ClearColor(Color.CadetBlue);
pgmID = GL.CreateProgram();
loadShader("vs.glsl", ShaderType.VertexShader, pgmID, out vsID);
loadShader("fs.glsl", ShaderType.FragmentShader, pgmID, out fsID);
loadShader("vs", ShaderType.VertexShader, pgmID, out vsID);
loadShader("fs", ShaderType.FragmentShader, pgmID, out fsID);
GL.LinkProgram(pgmID);
GL.UseProgram(pgmID);
attributeVertexPosition = GL.GetAttribLocation(pgmID, "vertexPosition");
@@ -1725,10 +1727,8 @@ namespace Unity_Studio
private void loadShader(string filename, ShaderType type, int program, out int address)
{
address = GL.CreateShader(type);
using (StreamReader sr = new StreamReader(filename))
{
GL.ShaderSource(address, sr.ReadToEnd());
}
var str = (string)Resource1.ResourceManager.GetObject(filename);
GL.ShaderSource(address, str);
GL.CompileShader(address);
GL.AttachShader(program, address);
GL.DeleteShader(address);
@@ -1738,7 +1738,7 @@ namespace Unity_Studio
{
GL.GenBuffers(1, out vboAddress);
GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress);
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
GL.BufferData(BufferTarget.ArrayBuffer,
(IntPtr)(data.Length * Vector3.SizeInBytes),
data,
BufferUsageHint.StaticDraw);
@@ -1750,7 +1750,7 @@ namespace Unity_Studio
{
GL.GenBuffers(1, out vboAddress);
GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress);
GL.BufferData<Vector4>(BufferTarget.ArrayBuffer,
GL.BufferData(BufferTarget.ArrayBuffer,
(IntPtr)(data.Length * Vector4.SizeInBytes),
data,
BufferUsageHint.StaticDraw);
@@ -1781,6 +1781,7 @@ namespace Unity_Studio
GL.GenVertexArrays(1, out vao);
GL.BindVertexArray(vao);
createVBO(out vboPositions, vertexData, attributeVertexPosition);
if (normalData != null)
createVBO(out vboNormals, normalData, attributeNormalDirection);
createVBO(out vboColors, colorData, attributeVertexColor);
createVBO(out vboViewMatrix, viewMatrixData, uniformViewMatrix);
@@ -1858,5 +1859,21 @@ namespace Unity_Studio
FMODreset();
}
private void showOriginalFileToolStripMenuItem_Click(object sender, EventArgs e)
{
var args = $"/select, {selectasset.sourceFile.bundlePath ?? selectasset.sourceFile.filePath}";
var pfi = new ProcessStartInfo("explorer.exe", args);
Process.Start(pfi);
}
private void assetListView_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
selectasset = (AssetPreloadData)assetListView.Items[assetListView.SelectedIndices[0]];
contextMenuStrip1.Show(assetListView, e.X, e.Y);
}
}
}
}

View File

@@ -149,7 +149,7 @@ The quick brown fox jumps over the lazy dog. 1234567890</value>
<value>636, 17</value>
</data>
<data name="openFileDialog1.Filter" xml:space="preserve">
<value>Unity asset files|level*; globalgamemanagers; mainData; CustomAssetBundle-*; CAB-*; BuildPlayer-*; *.assets; *.sharedAssets|Unity bundle files|*.unity3d; *.unity3d.lz4; *.assetbundle; *.bundle; *.bytes|Unity asset files|*.*|Unity bundle files|*.*</value>
<value>Unity asset files|*.*|Unity bundle files|*.*|Unity asset files|level*; globalgamemanagers; mainData; CustomAssetBundle-*; CAB-*; BuildPlayer-*; *.assets; *.sharedAssets|Unity bundle files|*.unity3d; *.unity3d.lz4; *.assetbundle; *.bundle; *.bytes</value>
</data>
<data name="openFolderDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing">
<value>169, 17</value>

View File

@@ -1,27 +0,0 @@
#version 140
in vec3 surfaceNormal;
in vec3 toLightVector;
in vec4 color;
out vec4 outputColor;
void main()
{
vec3 lightColor = vec3(0.5, 0.5, 0.5);
// Ambient
float ambientStrength = 0.9;
vec3 ambient = ambientStrength * lightColor;
// Diffuse
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);
float nDotProduct = dot(unitNormal, unitLightVector);
float brightness = clamp(nDotProduct, 0, 1); // max(nDotProduct, 0.0);
vec3 diffuse = brightness * lightColor;
// Output Color
vec4 result = color * vec4((ambient + diffuse/2), 0.0);
outputColor = result;
}

View File

@@ -1,19 +0,0 @@
#version 140
in vec3 vertexPosition;
in vec3 normalDirection;
in vec4 vertexColor;
uniform mat4 viewMatrix;
out vec3 surfaceNormal;
out vec3 toLightVector;
out vec4 color;
void main()
{
vec3 lightPosition = vec3(200.0, 200.0, 200.0);
gl_Position = viewMatrix * vec4(vertexPosition, 1.0);
surfaceNormal = normalDirection;
toLightVector = lightPosition - vertexPosition;
color = vertexColor;
}