mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-06-03 00:58:13 -04:00
parent
df45fa9b8e
commit
e19ecf4770
3
Unity Studio/Resource1.Designer.cs
generated
3
Unity Studio/Resource1.Designer.cs
generated
@ -123,6 +123,7 @@ namespace Unity_Studio {
|
|||||||
///in vec3 vertexPosition;
|
///in vec3 vertexPosition;
|
||||||
///in vec3 normalDirection;
|
///in vec3 normalDirection;
|
||||||
///in vec4 vertexColor;
|
///in vec4 vertexColor;
|
||||||
|
///uniform mat4 modelMatrix;
|
||||||
///uniform mat4 viewMatrix;
|
///uniform mat4 viewMatrix;
|
||||||
///
|
///
|
||||||
///out vec3 normal;
|
///out vec3 normal;
|
||||||
@ -130,7 +131,7 @@ namespace Unity_Studio {
|
|||||||
///
|
///
|
||||||
///void main()
|
///void main()
|
||||||
///{
|
///{
|
||||||
/// gl_Position = viewMatrix * vec4(vertexPosition, 1.0);
|
/// gl_Position = viewMatrix * modelMatrix * vec4(vertexPosition, 1.0);
|
||||||
/// normal = normalDirection;
|
/// normal = normalDirection;
|
||||||
/// color = vertexColor;
|
/// color = vertexColor;
|
||||||
///}.
|
///}.
|
||||||
|
@ -164,6 +164,7 @@ void main()
|
|||||||
in vec3 vertexPosition;
|
in vec3 vertexPosition;
|
||||||
in vec3 normalDirection;
|
in vec3 normalDirection;
|
||||||
in vec4 vertexColor;
|
in vec4 vertexColor;
|
||||||
|
uniform mat4 modelMatrix;
|
||||||
uniform mat4 viewMatrix;
|
uniform mat4 viewMatrix;
|
||||||
|
|
||||||
out vec3 normal;
|
out vec3 normal;
|
||||||
@ -171,7 +172,7 @@ out vec4 color;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = viewMatrix * vec4(vertexPosition, 1.0);
|
gl_Position = viewMatrix * modelMatrix * vec4(vertexPosition, 1.0);
|
||||||
normal = normalDirection;
|
normal = normalDirection;
|
||||||
color = vertexColor;
|
color = vertexColor;
|
||||||
}</value>
|
}</value>
|
||||||
|
@ -40,18 +40,21 @@ namespace Unity_Studio
|
|||||||
int attributeVertexPosition;
|
int attributeVertexPosition;
|
||||||
int attributeNormalDirection;
|
int attributeNormalDirection;
|
||||||
int attributeVertexColor;
|
int attributeVertexColor;
|
||||||
|
int uniformModelMatrix;
|
||||||
int uniformViewMatrix;
|
int uniformViewMatrix;
|
||||||
int vao;
|
int vao;
|
||||||
int vboPositions;
|
int vboPositions;
|
||||||
int vboNormals;
|
int vboNormals;
|
||||||
int vboColors;
|
int vboColors;
|
||||||
|
int vboModelMatrix;
|
||||||
int vboViewMatrix;
|
int vboViewMatrix;
|
||||||
int eboElements;
|
int eboElements;
|
||||||
Vector3[] vertexData;
|
Vector3[] vertexData;
|
||||||
Vector3[] normalData;
|
Vector3[] normalData;
|
||||||
Vector3[] normal2Data;
|
Vector3[] normal2Data;
|
||||||
Vector4[] colorData;
|
Vector4[] colorData;
|
||||||
Matrix4[] viewMatrixData;
|
Matrix4 modelMatrixData;
|
||||||
|
Matrix4 viewMatrixData;
|
||||||
int[] indiceData;
|
int[] indiceData;
|
||||||
int wireFrameMode;
|
int wireFrameMode;
|
||||||
int shadeMode;
|
int shadeMode;
|
||||||
@ -335,86 +338,80 @@ namespace Unity_Studio
|
|||||||
// --> Right
|
// --> Right
|
||||||
if (e.KeyCode == Keys.D)
|
if (e.KeyCode == Keys.D)
|
||||||
{
|
{
|
||||||
if (e.Shift && e.KeyCode == Keys.D) //Move
|
if (e.Shift) //Move
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateTranslation(0.1f, 0, 0);
|
viewMatrixData *= Matrix4.CreateTranslation(0.1f, 0, 0);
|
||||||
}
|
}
|
||||||
else //Rotate
|
else //Rotate
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateRotationY(0.1f);
|
viewMatrixData *= Matrix4.CreateRotationY(0.1f);
|
||||||
}
|
}
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// <-- Left
|
// <-- Left
|
||||||
if (e.KeyCode == Keys.A)
|
if (e.KeyCode == Keys.A)
|
||||||
{
|
{
|
||||||
if (e.Shift && e.KeyCode == Keys.A) //Move
|
if (e.Shift) //Move
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateTranslation(-0.1f, 0, 0);
|
viewMatrixData *= Matrix4.CreateTranslation(-0.1f, 0, 0);
|
||||||
}
|
}
|
||||||
else //Rotate
|
else //Rotate
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateRotationY(-0.1f);
|
viewMatrixData *= Matrix4.CreateRotationY(-0.1f);
|
||||||
}
|
}
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Up
|
// Up
|
||||||
if (e.KeyCode == Keys.W)
|
if (e.KeyCode == Keys.W)
|
||||||
{
|
{
|
||||||
if (e.Control && e.KeyCode == Keys.W) //Toggle WireFrame
|
if (e.Control) //Toggle WireFrame
|
||||||
{
|
{
|
||||||
wireFrameMode = (wireFrameMode + 1) % 3;
|
wireFrameMode = (wireFrameMode + 1) % 3;
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
else if (e.Shift && e.KeyCode == Keys.W) //Move
|
else if (e.Shift) //Move
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateTranslation(0, 0.1f, 0);
|
viewMatrixData *= Matrix4.CreateTranslation(0, 0.1f, 0);
|
||||||
}
|
}
|
||||||
else //Rotate
|
else //Rotate
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateRotationX(0.1f);
|
viewMatrixData *= Matrix4.CreateRotationX(0.1f);
|
||||||
}
|
}
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Down
|
// Down
|
||||||
if (e.KeyCode == Keys.S)
|
if (e.KeyCode == Keys.S)
|
||||||
{
|
{
|
||||||
if (e.Control && e.KeyCode == Keys.S) //Toggle Shade
|
if (e.Control) //Toggle Shade
|
||||||
{
|
{
|
||||||
shadeMode = (shadeMode + 1) % 2;
|
shadeMode = (shadeMode + 1) % 2;
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
else if (e.Shift && e.KeyCode == Keys.S) //Move
|
else if (e.Shift) //Move
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateTranslation(0, -0.1f, 0);
|
viewMatrixData *= Matrix4.CreateTranslation(0, -0.1f, 0);
|
||||||
}
|
}
|
||||||
else //Rotate
|
else //Rotate
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateRotationX(-0.1f);
|
viewMatrixData *= Matrix4.CreateRotationX(-0.1f);
|
||||||
}
|
}
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zoom Out
|
// Zoom Out
|
||||||
if (e.KeyCode == Keys.Q)
|
if (e.KeyCode == Keys.Q)
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateScale(0.9f);
|
viewMatrixData *= Matrix4.CreateScale(0.9f);
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zoom In
|
// Zoom In
|
||||||
if (e.KeyCode == Keys.E)
|
if (e.KeyCode == Keys.E)
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateScale(1.1f);
|
viewMatrixData *= Matrix4.CreateScale(1.1f);
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -982,9 +979,8 @@ namespace Unity_Studio
|
|||||||
case 43: //Mesh
|
case 43: //Mesh
|
||||||
{
|
{
|
||||||
glControl1.Visible = true;
|
glControl1.Visible = true;
|
||||||
viewMatrixData = new Matrix4[] {
|
viewMatrixData = Matrix4.CreateRotationY(-(float)Math.PI / 4) * Matrix4.CreateRotationX(-(float)Math.PI / 6);
|
||||||
Matrix4.Identity
|
|
||||||
* Matrix4.CreateRotationY(-90.0f)};
|
|
||||||
var m_Mesh = new Mesh(asset, true);
|
var m_Mesh = new Mesh(asset, true);
|
||||||
if (m_Mesh.m_VertexCount > 0)
|
if (m_Mesh.m_VertexCount > 0)
|
||||||
{
|
{
|
||||||
@ -1003,34 +999,29 @@ namespace Unity_Studio
|
|||||||
min[i] = m_Mesh.m_Vertices[i];
|
min[i] = m_Mesh.m_Vertices[i];
|
||||||
max[i] = m_Mesh.m_Vertices[i];
|
max[i] = m_Mesh.m_Vertices[i];
|
||||||
}
|
}
|
||||||
for (int v = 1; v < m_Mesh.m_VertexCount; v++)
|
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
min[i] = Math.Min(min[i], m_Mesh.m_Vertices[v * count + i]);
|
min[i] = Math.Min(min[i], m_Mesh.m_Vertices[v * count + i]);
|
||||||
max[i] = Math.Max(max[i], m_Mesh.m_Vertices[v * count + i]);
|
max[i] = Math.Max(max[i], m_Mesh.m_Vertices[v * count + i]);
|
||||||
}
|
}
|
||||||
}
|
vertexData[v] = new Vector3(
|
||||||
// Calculate offset & scale to remapping vertex
|
|
||||||
Vector3 scale = Vector3.One, offset = Vector3.Zero;
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
if(min[i] + 1e-5 < max[i])
|
|
||||||
{
|
|
||||||
scale[i] = 1.5f / (max[i] - min[i]);
|
|
||||||
}
|
|
||||||
offset[i] = (max[i] + min[i]) / 2;
|
|
||||||
}
|
|
||||||
float minScale = Math.Min(scale.X, Math.Min(scale.Y, scale.Z));
|
|
||||||
scale = new Vector3(minScale);
|
|
||||||
|
|
||||||
for (int v = 0; v < m_Mesh.m_VertexCount; v++)
|
|
||||||
{
|
|
||||||
vertexData[v] = (new Vector3(
|
|
||||||
m_Mesh.m_Vertices[v * count],
|
m_Mesh.m_Vertices[v * count],
|
||||||
m_Mesh.m_Vertices[v * count + 1],
|
m_Mesh.m_Vertices[v * count + 1],
|
||||||
m_Mesh.m_Vertices[v * count + 2]) - offset) * scale;
|
m_Mesh.m_Vertices[v * count + 2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate modelMatrix
|
||||||
|
Vector3 dist = Vector3.One, offset = Vector3.Zero;
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
dist[i] = max[i] - min[i];
|
||||||
|
offset[i] = (max[i] + min[i]) / 2;
|
||||||
|
}
|
||||||
|
float d = Math.Max(1e-5f, dist.Length);
|
||||||
|
Vector3 scale = new Vector3(2f / d);
|
||||||
|
modelMatrixData = Matrix4.CreateScale(2f / d) * Matrix4.CreateTranslation(-offset);
|
||||||
#endregion
|
#endregion
|
||||||
#region Indicies
|
#region Indicies
|
||||||
indiceData = new int[m_Mesh.m_Indices.Count];
|
indiceData = new int[m_Mesh.m_Indices.Count];
|
||||||
@ -1773,8 +1764,7 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
if (glControl1.Visible == true)
|
if (glControl1.Visible == true)
|
||||||
{
|
{
|
||||||
viewMatrixData[0] *= Matrix4.CreateRotationY(-0.1f);
|
viewMatrixData *= Matrix4.CreateRotationY(-0.1f);
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
|
||||||
glControl1.Invalidate();
|
glControl1.Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1803,7 +1793,7 @@ namespace Unity_Studio
|
|||||||
attributeVertexPosition = GL.GetAttribLocation(pgmID, "vertexPosition");
|
attributeVertexPosition = GL.GetAttribLocation(pgmID, "vertexPosition");
|
||||||
attributeNormalDirection = GL.GetAttribLocation(pgmID, "normalDirection");
|
attributeNormalDirection = GL.GetAttribLocation(pgmID, "normalDirection");
|
||||||
attributeVertexColor = GL.GetAttribLocation(pgmColorID, "vertexColor");
|
attributeVertexColor = GL.GetAttribLocation(pgmColorID, "vertexColor");
|
||||||
var str = GL.GetError();
|
uniformModelMatrix = GL.GetUniformLocation(pgmID, "modelMatrix");
|
||||||
uniformViewMatrix = GL.GetUniformLocation(pgmID, "viewMatrix");
|
uniformViewMatrix = GL.GetUniformLocation(pgmID, "viewMatrix");
|
||||||
glControl1.Visible = false;
|
glControl1.Visible = false;
|
||||||
}
|
}
|
||||||
@ -1842,10 +1832,10 @@ namespace Unity_Studio
|
|||||||
GL.EnableVertexAttribArray(address);
|
GL.EnableVertexAttribArray(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createVBO(out int vboAddress, Matrix4[] data, int address)
|
private void createVBO(out int vboAddress, Matrix4 data, int address)
|
||||||
{
|
{
|
||||||
GL.GenBuffers(1, out vboAddress);
|
GL.GenBuffers(1, out vboAddress);
|
||||||
GL.UniformMatrix4(address, false, ref data[0]);
|
GL.UniformMatrix4(address, false, ref data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createEBO(out int address, int[] data)
|
private void createEBO(out int address, int[] data)
|
||||||
@ -1875,6 +1865,7 @@ namespace Unity_Studio
|
|||||||
createVBO(out vboNormals, normalData, attributeNormalDirection);
|
createVBO(out vboNormals, normalData, attributeNormalDirection);
|
||||||
}
|
}
|
||||||
createVBO(out vboColors, colorData, attributeVertexColor);
|
createVBO(out vboColors, colorData, attributeVertexColor);
|
||||||
|
createVBO(out vboModelMatrix, modelMatrixData, uniformModelMatrix);
|
||||||
createVBO(out vboViewMatrix, viewMatrixData, uniformViewMatrix);
|
createVBO(out vboViewMatrix, viewMatrixData, uniformViewMatrix);
|
||||||
createEBO(out eboElements, indiceData);
|
createEBO(out eboElements, indiceData);
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||||
@ -1897,7 +1888,8 @@ namespace Unity_Studio
|
|||||||
if (wireFrameMode == 0 || wireFrameMode == 2)
|
if (wireFrameMode == 0 || wireFrameMode == 2)
|
||||||
{
|
{
|
||||||
GL.UseProgram(shadeMode == 0 ? pgmID : pgmColorID);
|
GL.UseProgram(shadeMode == 0 ? pgmID : pgmColorID);
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
GL.UniformMatrix4(uniformModelMatrix, false, ref modelMatrixData);
|
||||||
|
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData);
|
||||||
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
|
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
|
||||||
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
|
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
|
||||||
}
|
}
|
||||||
@ -1907,7 +1899,8 @@ namespace Unity_Studio
|
|||||||
GL.Enable(EnableCap.PolygonOffsetLine);
|
GL.Enable(EnableCap.PolygonOffsetLine);
|
||||||
GL.PolygonOffset(-1, -1);
|
GL.PolygonOffset(-1, -1);
|
||||||
GL.UseProgram(pgmBlackID);
|
GL.UseProgram(pgmBlackID);
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData[0]);
|
GL.UniformMatrix4(uniformModelMatrix, false, ref modelMatrixData);
|
||||||
|
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData);
|
||||||
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
|
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
|
||||||
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
|
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
|
||||||
GL.Disable(EnableCap.PolygonOffsetLine);
|
GL.Disable(EnableCap.PolygonOffsetLine);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user