mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-07-16 19:14:15 -04:00
@ -13,9 +13,9 @@ using System.Diagnostics;
|
||||
using System.Drawing.Text;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using ManagedFbx;
|
||||
using static Unity_Studio.UnityStudio;
|
||||
|
||||
|
||||
namespace Unity_Studio
|
||||
{
|
||||
partial class UnityStudioForm : Form
|
||||
@ -50,65 +50,11 @@ namespace Unity_Studio
|
||||
int vboColors;
|
||||
int vboViewMatrix;
|
||||
int eboElements;
|
||||
Vector3[] vertexData =
|
||||
{
|
||||
new Vector3(-0.5f, -0.5f, -0.5f),
|
||||
new Vector3(0.5f, -0.5f, -0.5f),
|
||||
new Vector3(0.5f, 0.5f, -0.5f),
|
||||
new Vector3(-0.5f, 0.5f, -0.5f),
|
||||
new Vector3(-0.5f, -0.5f, 0.5f),
|
||||
new Vector3(0.5f, -0.5f, 0.5f),
|
||||
new Vector3(0.5f, 0.5f, 0.5f),
|
||||
new Vector3(-0.5f, 0.5f, 0.5f)
|
||||
};
|
||||
Vector3[] normalData =
|
||||
{
|
||||
//left
|
||||
new Vector3(-1.0f, 0.0f, 0.0f)
|
||||
//back
|
||||
//new Vector3(0.0f, 0.0f, -1.0f),
|
||||
//right
|
||||
//new Vector3(1.0f, 0.0f, 0.0f),
|
||||
//top
|
||||
//new Vector3(0.0f, 1.0f, 0.0f),
|
||||
//front
|
||||
//new Vector3(0.0f, 0.0f, 1.0f),
|
||||
//bottom
|
||||
//new Vector3(0.0f, -1.0f, 0.0f)
|
||||
};
|
||||
Vector4[] colorData =
|
||||
{
|
||||
new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
|
||||
new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
|
||||
new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
|
||||
new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
|
||||
new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
|
||||
new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
|
||||
new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
|
||||
new Vector4(0.5f, 0.5f, 0.5f, 1.0f)
|
||||
};
|
||||
Matrix4[] viewMatrixData = { Matrix4.Identity };
|
||||
int[] indiceData =
|
||||
{
|
||||
//left
|
||||
0,2,1,
|
||||
0,3,2,
|
||||
//back
|
||||
1,2,6,
|
||||
6,5,1,
|
||||
//right
|
||||
4,5,6,
|
||||
6,7,4,
|
||||
//top
|
||||
2,3,6,
|
||||
6,3,7,
|
||||
//front
|
||||
0,7,3,
|
||||
0,4,7,
|
||||
//bottom
|
||||
0,1,5,
|
||||
0,5,4
|
||||
};
|
||||
OpenTK.Vector3[] vertexData;
|
||||
OpenTK.Vector3[] normalData;
|
||||
OpenTK.Vector4[] colorData;
|
||||
Matrix4[] viewMatrixData;
|
||||
int[] indiceData;
|
||||
bool wireFrameView;
|
||||
#endregion
|
||||
|
||||
@ -1021,24 +967,25 @@ namespace Unity_Studio
|
||||
Matrix4.Identity
|
||||
* Matrix4.CreateTranslation( 0.0f, -1.0f, 0.0f )
|
||||
* Matrix4.CreateRotationY(-90.0f)};
|
||||
|
||||
var m_Mesh = new Mesh(asset);
|
||||
|
||||
var m_Mesh = new Mesh(asset, true);
|
||||
if (m_Mesh.m_VertexCount > 0)
|
||||
{
|
||||
int count = 3;//vertex components
|
||||
//skip last component in vector4
|
||||
if (m_Mesh.m_Vertices.Length == m_Mesh.m_VertexCount * 4) { count = 4; }
|
||||
|
||||
vertexData = new Vector3[m_Mesh.m_VertexCount];
|
||||
#region Vertices
|
||||
int count = 3;
|
||||
if (m_Mesh.m_Vertices.Length == m_Mesh.m_VertexCount * 4)
|
||||
{
|
||||
count = 4;
|
||||
}
|
||||
vertexData = new OpenTK.Vector3[m_Mesh.m_VertexCount];
|
||||
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
|
||||
{
|
||||
vertexData[v] = new Vector3(
|
||||
vertexData[v] = new OpenTK.Vector3(
|
||||
m_Mesh.m_Vertices[v * count],
|
||||
m_Mesh.m_Vertices[v * count + 1],
|
||||
m_Mesh.m_Vertices[v * count + 2]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region Indicies
|
||||
indiceData = new int[m_Mesh.m_Indices.Count];
|
||||
for (int i = 0; i < m_Mesh.m_Indices.Count; i = i + 3)
|
||||
{
|
||||
@ -1046,6 +993,8 @@ namespace Unity_Studio
|
||||
indiceData[i + 1] = (int)m_Mesh.m_Indices[i + 1];
|
||||
indiceData[i + 2] = (int)m_Mesh.m_Indices[i + 2];
|
||||
}
|
||||
#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)
|
||||
@ -1057,40 +1006,53 @@ namespace Unity_Studio
|
||||
count = 4;
|
||||
}
|
||||
|
||||
normalData = new Vector3[m_Mesh.m_VertexCount];
|
||||
normalData = new OpenTK.Vector3[m_Mesh.m_VertexCount];
|
||||
for (int n = 0; n < m_Mesh.m_VertexCount; n++)
|
||||
{
|
||||
normalData[n] = new Vector3(
|
||||
normalData[n] = new OpenTK.Vector3(
|
||||
m_Mesh.m_Normals[n * count],
|
||||
m_Mesh.m_Normals[n * count + 1],
|
||||
m_Mesh.m_Normals[n * count + 2]);
|
||||
}
|
||||
}
|
||||
if (m_Mesh.m_Colors == null || m_Mesh.m_Colors.Length == m_Mesh.m_VertexCount * 3)
|
||||
#endregion
|
||||
#region Colors
|
||||
if (m_Mesh.m_Colors == null)
|
||||
{
|
||||
colorData = new Vector4[m_Mesh.m_VertexCount];
|
||||
colorData = new OpenTK.Vector4[m_Mesh.m_VertexCount];
|
||||
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
|
||||
{
|
||||
colorData[c] = new Vector4(
|
||||
colorData[c] = new OpenTK.Vector4(
|
||||
0.5f, 0.5f, 0.5f, 1.0f);
|
||||
}
|
||||
}
|
||||
else if (m_Mesh.m_Colors.Length == m_Mesh.m_VertexCount * 3)
|
||||
{
|
||||
colorData = new OpenTK.Vector4[m_Mesh.m_VertexCount];
|
||||
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
|
||||
{
|
||||
colorData[c] = new OpenTK.Vector4(
|
||||
m_Mesh.m_Colors[c * 4],
|
||||
m_Mesh.m_Colors[c * 4 + 1],
|
||||
m_Mesh.m_Colors[c * 4 + 2],
|
||||
1.0f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
colorData = new Vector4[m_Mesh.m_VertexCount];
|
||||
colorData = new OpenTK.Vector4[m_Mesh.m_VertexCount];
|
||||
for (int c = 0; c < m_Mesh.m_VertexCount; c++)
|
||||
{
|
||||
colorData[c] = new Vector4(
|
||||
colorData[c] = new OpenTK.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 * 4 + 3]);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
createVAO();
|
||||
|
||||
StatusStripUpdate("Using OpenGL Version: " + GL.GetString(StringName.Version)
|
||||
+ " | 'T'=Start/Stop Rotation | 'WASD'=Manual Rotate | "
|
||||
+ "'Shift WASD'=Move | 'Q/E'=Zoom | 'Ctl W' =Wireframe");
|
||||
@ -1574,9 +1536,10 @@ namespace Unity_Studio
|
||||
}
|
||||
break;
|
||||
case 48:
|
||||
Shader m_Shader = new Shader(asset, true);
|
||||
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
|
||||
{
|
||||
ExportShader(new Shader(asset, true), exportpath + asset.Text + ".txt");
|
||||
ExportShader(m_Shader, exportpath + asset.Text + ".txt");
|
||||
exportedCount++;
|
||||
}
|
||||
break;
|
||||
@ -1603,6 +1566,15 @@ namespace Unity_Studio
|
||||
ExportFont(m_Font, exportpath + asset.Text + asset.extension);
|
||||
exportedCount++;
|
||||
}
|
||||
break;
|
||||
case 43: //Mesh
|
||||
Mesh m_Mesh = new Mesh(asset, true);
|
||||
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
|
||||
{
|
||||
ExportMesh(m_Mesh, exportpath + asset.Text);
|
||||
exportedCount++;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
if (!ExportFileExists(exportpath + asset.Text + asset.extension))
|
||||
@ -1755,24 +1727,24 @@ namespace Unity_Studio
|
||||
GL.DeleteShader(address);
|
||||
}
|
||||
|
||||
private void createVBO(int vboAddress, Vector3[] data, int address)
|
||||
private void createVBO(int vboAddress, OpenTK.Vector3[] data, int address)
|
||||
{
|
||||
GL.GenBuffers(1, out vboAddress);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress);
|
||||
GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
|
||||
(IntPtr)(data.Length * Vector3.SizeInBytes),
|
||||
GL.BufferData<OpenTK.Vector3>(BufferTarget.ArrayBuffer,
|
||||
(IntPtr)(data.Length * OpenTK.Vector3.SizeInBytes),
|
||||
data,
|
||||
BufferUsageHint.StaticDraw);
|
||||
GL.VertexAttribPointer(address, 3, VertexAttribPointerType.Float, false, 0, 0);
|
||||
GL.EnableVertexAttribArray(address);
|
||||
}
|
||||
|
||||
private void createVBO(int vboAddress, Vector4[] data, int address)
|
||||
private void createVBO(int vboAddress, OpenTK.Vector4[] data, int address)
|
||||
{
|
||||
GL.GenBuffers(1, out vboAddress);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vboAddress);
|
||||
GL.BufferData<Vector4>(BufferTarget.ArrayBuffer,
|
||||
(IntPtr)(data.Length * Vector4.SizeInBytes),
|
||||
GL.BufferData<OpenTK.Vector4>(BufferTarget.ArrayBuffer,
|
||||
(IntPtr)(data.Length * OpenTK.Vector4.SizeInBytes),
|
||||
data,
|
||||
BufferUsageHint.StaticDraw);
|
||||
GL.VertexAttribPointer(address, 4, VertexAttribPointerType.Float, false, 0, 0);
|
||||
@ -1802,10 +1774,10 @@ namespace Unity_Studio
|
||||
GL.GenVertexArrays(1, out vao);
|
||||
GL.BindVertexArray(vao);
|
||||
createVBO(vboPositions, vertexData, attributeVertexPosition);
|
||||
createVBO(vboNormals, normalData, attributeNormalDirection);
|
||||
createVBO(vboColors, colorData, attributeVertexColor);
|
||||
createVBO(vboViewMatrix, viewMatrixData, uniformViewMatrix);
|
||||
createEBO(eboElements, indiceData);
|
||||
createVBO(vboNormals, normalData, attributeNormalDirection);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user