-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMesh.cs
More file actions
45 lines (37 loc) · 1.11 KB
/
Mesh.cs
File metadata and controls
45 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Assimp;
using System.Collections.Generic;
using Unity.Mathematics;
namespace OpenGL_Demo
{
public class Mesh
{
public struct Vertex
{
public float3 position;
public float2 coord;
}
public uint[] Indices;
public Vertex[] Vertices;
public static Mesh Load(string path)
{
var assimp = new AssimpContext();
var scene = assimp.ImportFile(path);
var mesh = scene.Meshes[0];
var indices = mesh.GetUnsignedIndices();
var vertices = new Vertex[mesh.VertexCount];
for (int i = 0; i < mesh.VertexCount; i++)
{
var vertex = mesh.Vertices[i];
vertices[i].position = new float3(vertex.X, vertex.Y, vertex.Z);
var coord = mesh.TextureCoordinateChannels[0][i];
vertices[i].coord = new float2(coord.X, coord.Y);
}
assimp.Dispose();
return new Mesh()
{
Indices = indices,
Vertices = vertices
};
}
}
}