Skip to content

Commit f2fd21b

Browse files
authored
Assimp tutorial cleanup (#1452)
* start of updating assimp usage in tutorial 4.1 * wip * Fix of texcoord
1 parent 6f9d43d commit f2fd21b

File tree

1 file changed

+15
-35
lines changed
  • examples/CSharp/OpenGL Tutorials/Tutorial 4.1 - Model Loading

1 file changed

+15
-35
lines changed

examples/CSharp/OpenGL Tutorials/Tutorial 4.1 - Model Loading/Model.cs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -70,52 +70,31 @@ private unsafe Mesh ProcessMesh(AssimpMesh* mesh, Scene* scene)
7070
Vertex vertex = new Vertex();
7171
vertex.BoneIds = new int[Vertex.MAX_BONE_INFLUENCE];
7272
vertex.Weights = new float[Vertex.MAX_BONE_INFLUENCE];
73-
Vector3 vector = new Vector3(); // we declare a placeholder vector since assimp uses its own vector class that doesn't directly convert to glm's vec3 class so we transfer the data to this placeholder glm::vec3 first.
74-
// positions
75-
vector.X = mesh->MVertices[i].X;
76-
vector.Y = mesh->MVertices[i].Y;
77-
vector.Z = mesh->MVertices[i].Z;
78-
vertex.Position = vector;
73+
74+
vertex.Position = mesh->MVertices[i];
75+
7976
// normals
80-
8177
if (mesh->MNormals != null)
82-
{
83-
vector.X = mesh->MNormals[i].X;
84-
vector.Y = mesh->MNormals[i].Y;
85-
vector.Z = mesh->MNormals[i].Z;
86-
vertex.Normal = vector;
87-
}
78+
vertex.Normal = mesh->MNormals[i];
79+
// tangent
80+
if (mesh->MTangents != null)
81+
vertex.Tangent = mesh->MTangents[i];
82+
// bitangent
83+
if (mesh->MBitangents != null)
84+
vertex.Bitangent = mesh->MBitangents[i];
85+
8886
// texture coordinates
8987
if (mesh->MTextureCoords[0] != null) // does the mesh contain texture coordinates?
9088
{
91-
Vector2 vec = new Vector2();
9289
// a vertex can contain up to 8 different texture coordinates. We thus make the assumption that we won't
9390
// use models where a vertex can have multiple texture coordinates so we always take the first set (0).
94-
vec.X = mesh->MTextureCoords[0][i].X;
95-
vec.Y = mesh->MTextureCoords[0][i].Y;
96-
vertex.TexCoords = vec;
97-
// tangent
98-
if (mesh->MTangents != null)
99-
{
100-
vector.X = mesh->MTangents[i].X;
101-
vector.Y = mesh->MTangents[i].Y;
102-
vector.Z = mesh->MTangents[i].Z;
103-
vertex.Tangent = vector;
104-
}
105-
// bitangent
106-
if (mesh->MBitangents != null)
107-
{
108-
vector.X = mesh->MBitangents[i].X;
109-
vector.Y = mesh->MBitangents[i].Y;
110-
vector.Z = mesh->MBitangents[i].Z;
111-
vertex.Bitangent = vector;
112-
}
91+
Vector3 texcoord3 = mesh->MTextureCoords[0][i];
92+
vertex.TexCoords = new Vector2(texcoord3.X, texcoord3.Y);
11393
}
114-
else
115-
vertex.TexCoords = new Vector2(0.0f, 0.0f);
11694

11795
vertices.Add(vertex);
11896
}
97+
11998
// now wak through each of the mesh's faces (a face is a mesh its triangle) and retrieve the corresponding vertex indices.
12099
for (uint i = 0; i < mesh->MNumFaces; i++)
121100
{
@@ -124,6 +103,7 @@ private unsafe Mesh ProcessMesh(AssimpMesh* mesh, Scene* scene)
124103
for (uint j = 0; j < face.MNumIndices; j++)
125104
indices.Add(face.MIndices[j]);
126105
}
106+
127107
// process materials
128108
Material* material = scene->MMaterials[mesh->MMaterialIndex];
129109
// we assume a convention for sampler names in the shaders. Each diffuse texture should be named

0 commit comments

Comments
 (0)