mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-06-03 00:58:13 -04:00
rewrite export mesh
This commit is contained in:
parent
65a13e97c4
commit
8a3af0bfba
@ -333,7 +333,7 @@ namespace Unity_Studio
|
|||||||
var version = MeshPD.sourceFile.version;
|
var version = MeshPD.sourceFile.version;
|
||||||
a_Stream = MeshPD.sourceFile.a_Stream;
|
a_Stream = MeshPD.sourceFile.a_Stream;
|
||||||
a_Stream.Position = MeshPD.Offset;
|
a_Stream.Position = MeshPD.Offset;
|
||||||
|
MeshPD.extension = ".obj";
|
||||||
bool m_Use16BitIndices = true; //3.5.0 and newer always uses 16bit indices
|
bool m_Use16BitIndices = true; //3.5.0 and newer always uses 16bit indices
|
||||||
uint m_MeshCompression = 0;
|
uint m_MeshCompression = 0;
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ namespace Unity_Studio
|
|||||||
}
|
}
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Web.Script.Serialization;
|
using System.Web.Script.Serialization;
|
||||||
using ManagedFbx;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Unity_Studio
|
namespace Unity_Studio
|
||||||
@ -1750,127 +1749,63 @@ namespace Unity_Studio
|
|||||||
|
|
||||||
public static void ExportMesh(Mesh m_Mesh, string exportPath)
|
public static void ExportMesh(Mesh m_Mesh, string exportPath)
|
||||||
{
|
{
|
||||||
Scene m_scene = Scene.CreateScene("Scene");
|
var sb = new StringBuilder();
|
||||||
SceneNode root = m_scene.RootNode;
|
sb.AppendLine("g " + m_Mesh.m_Name);
|
||||||
SceneNode meshnode = Scene.CreateNode(m_scene, m_Mesh.m_Name);
|
#region Vertices
|
||||||
SceneNode.AddChild(root, meshnode);
|
int c = 3;
|
||||||
ManagedFbx.Mesh mesh = Scene.CreateMesh(m_scene, meshnode, "Mesh");
|
if (m_Mesh.m_Vertices.Length == m_Mesh.m_VertexCount * 4)
|
||||||
if (m_Mesh.m_VertexCount > 0)
|
{
|
||||||
|
c = 4;
|
||||||
|
}
|
||||||
|
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
|
||||||
|
{
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region UV
|
||||||
|
if (m_Mesh.m_UV1 != null && m_Mesh.m_UV1.Length == m_Mesh.m_VertexCount * 2)
|
||||||
{
|
{
|
||||||
#region Vertices
|
|
||||||
int count = 3;
|
|
||||||
if (m_Mesh.m_Vertices.Length == m_Mesh.m_VertexCount * 4)
|
|
||||||
{
|
|
||||||
count = 4;
|
|
||||||
}
|
|
||||||
var vertices = new Vector3[m_Mesh.m_VertexCount];
|
|
||||||
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
|
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
|
||||||
{
|
{
|
||||||
vertices[v] = new Vector3(
|
sb.AppendFormat("vt {0} {1}\r\n", m_Mesh.m_UV1[v * 2], m_Mesh.m_UV1[v * 2 + 1]);
|
||||||
m_Mesh.m_Vertices[v * count],
|
|
||||||
m_Mesh.m_Vertices[v * count + 1],
|
|
||||||
m_Mesh.m_Vertices[v * count + 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)
|
|
||||||
{
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
else if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 4)
|
|
||||||
{
|
|
||||||
count = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
var normals = new Vector3[m_Mesh.m_VertexCount];
|
|
||||||
for (int n = 0; n < m_Mesh.m_VertexCount; n++)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
#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 * 3],
|
|
||||||
m_Mesh.m_Colors[c * 3 + 1],
|
|
||||||
m_Mesh.m_Colors[c * 3 + 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);
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
//m_scene.Save(exportPath); //default is .fbx
|
#region Normals
|
||||||
//m_scene.Save(exportPath + ".fbx");
|
if (m_Mesh.m_Normals != null && m_Mesh.m_Normals.Length > 0)
|
||||||
m_scene.Save(exportPath + ".obj");
|
{
|
||||||
//m_scene.Save(exportPath + ".dae");
|
if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 3)
|
||||||
|
{
|
||||||
|
c = 3;
|
||||||
|
}
|
||||||
|
else if (m_Mesh.m_Normals.Length == m_Mesh.m_VertexCount * 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
|
||||||
|
|
||||||
|
#region Face
|
||||||
|
for (int f = 0; f < m_Mesh.m_Indices.Count / 3; f++)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
|
||||||
|
File.WriteAllText(exportPath, sb.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ExportFileExists(string filename)
|
public static bool ExportFileExists(string filename)
|
||||||
|
@ -55,11 +55,6 @@
|
|||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<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">
|
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>library\OpenTK.dll</HintPath>
|
<HintPath>library\OpenTK.dll</HintPath>
|
||||||
|
@ -55,11 +55,6 @@
|
|||||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<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">
|
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>library\OpenTK.dll</HintPath>
|
<HintPath>library\OpenTK.dll</HintPath>
|
||||||
|
@ -1574,7 +1574,7 @@ namespace Unity_Studio
|
|||||||
Mesh m_Mesh = new Mesh(asset, true);
|
Mesh m_Mesh = new Mesh(asset, true);
|
||||||
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
|
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
|
||||||
{
|
{
|
||||||
ExportMesh(m_Mesh, exportpath + asset.Text);
|
ExportMesh(m_Mesh, exportpath + asset.Text + asset.extension);
|
||||||
exportedCount++;
|
exportedCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user