MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ProcessMesh

Function ProcessMesh

Source/Engine/Tools/ModelTool/ModelTool.Assimp.cpp:241–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239}
240
241bool ProcessMesh(ModelData& result, AssimpImporterData& data, const aiMesh* aMesh, MeshData& mesh, String& errorMsg)
242{
243 // Properties
244 mesh.Name = aMesh->mName.C_Str();
245 mesh.MaterialSlotIndex = aMesh->mMaterialIndex;
246
247 // Vertex positions
248 mesh.Positions.Set((const Float3*)aMesh->mVertices, aMesh->mNumVertices);
249
250 // Texture coordinates
251 for (int32 channelIndex = 0; channelIndex < MODEL_MAX_UV && aMesh->mTextureCoords[channelIndex]; channelIndex++)
252 {
253 mesh.UVs.Resize(channelIndex + 1);
254 auto& channel = mesh.UVs[channelIndex];
255 channel.Resize(aMesh->mNumVertices, false);
256 aiVector3D* a = aMesh->mTextureCoords[channelIndex];
257 for (uint32 v = 0; v < aMesh->mNumVertices; v++)
258 {
259 channel.Get()[v] = *(Float2*)a;
260 a++;
261 }
262 }
263
264 // Indices
265 const int32 indicesCount = aMesh->mNumFaces * 3;
266 mesh.Indices.Resize(indicesCount, false);
267 for (unsigned faceIndex = 0, i = 0; faceIndex < aMesh->mNumFaces; faceIndex++)
268 {
269 const auto face = &aMesh->mFaces[faceIndex];
270 if (face->mNumIndices != 3)
271 {
272 errorMsg = TEXT("All faces in a mesh must be triangles!");
273 return true;
274 }
275
276 mesh.Indices[i++] = face->mIndices[0];
277 mesh.Indices[i++] = face->mIndices[1];
278 mesh.Indices[i++] = face->mIndices[2];
279 }
280
281 // Normals
282 if (data.Options.CalculateNormals || !aMesh->mNormals)
283 {
284 // Support generation of normals when using assimp.
285 if (mesh.GenerateNormals(data.Options.SmoothingNormalsAngle))
286 {
287 errorMsg = TEXT("Failed to generate normals.");
288 return true;
289 }
290 }
291 else if (aMesh->mNormals)
292 {
293 mesh.Normals.Set((const Float3*)aMesh->mNormals, aMesh->mNumVertices);
294 }
295
296 // Tangents
297 if (aMesh->mTangents)
298 {

Callers 1

ImportMeshFunction · 0.70

Calls 15

EnumHasAnyFlagsFunction · 0.85
C_StrMethod · 0.80
GenerateNormalsMethod · 0.80
SetLightmapUVsSourceMethod · 0.80
NormalizeBlendWeightsMethod · 0.80
AddOneMethod · 0.80
ToMatrixFunction · 0.70
ToFloat3Function · 0.70
MaxFunction · 0.50
ToStringFunction · 0.50
SetMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected