Added new function signatures in `assimp-vc143-mt.lib` for improved logging, parsing, and vector operations. Added new metadata and configuration information in `assimp-vc143-mt.dll` for versioning and licensing compliance. Added Sobol sequence generation in `Sobol.c` for quasi-random sampling. Added window message handling in `Window.c` for rendering graphics. Added ray-triangle intersection tests in `RayIntersection.c` for collision detection. Added functions for loading mesh data in `Mesh.c` to support 3D model import. Added functions for managing triangle collections in `Triangle.c` to enhance geometric data handling. Added light evaluation functions in `LightEvaluation.c` and `SkyLight.c` for realistic rendering. Added sampling and evaluation functions for simple lit materials in `SimpleLit.c`. Changed various header files to include copyright and licensing information. Changed existing functions in multiple files to improve performance and clarity. Removed unused code in several files to streamline the library.
86 lines
3.0 KiB
C
86 lines
3.0 KiB
C
#include "Geometry/Mesh.h"
|
|
#include "Geometry/Triangle.h"
|
|
#include "assimp/cimport.h"
|
|
#include "assimp/scene.h"
|
|
#include "assimp/postprocess.h"
|
|
|
|
mesh_entity_t mesh_load(const char* filename, uint8_t material_id, triangle_collection_t* triangles, material_collection_t* materials)
|
|
{
|
|
mesh_entity_t entity = {0};
|
|
|
|
const C_STRUCT aiScene* scene = NULL;
|
|
scene = aiImportFile(filename,aiProcessPreset_TargetRealtime_MaxQuality);
|
|
if (scene == NULL)
|
|
{
|
|
// fprintf(stderr, "Error loading mesh: %s\n", aiGetErrorString());
|
|
return entity;
|
|
}
|
|
|
|
for (uint32_t i = 0; i < scene->mNumMeshes; i++)
|
|
{
|
|
const struct aiMesh* mesh = scene->mMeshes[i];
|
|
|
|
//TODO: Handle all mesh types, not just triangles
|
|
if (mesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE)
|
|
{
|
|
// fprintf(stderr, "Mesh %llu is not a triangle mesh\n", i);
|
|
continue;
|
|
}
|
|
|
|
for (uint32_t j = 0; j < mesh->mNumFaces; j++)
|
|
{
|
|
const struct aiFace* face = &mesh->mFaces[j];
|
|
if (face->mNumIndices != 3)
|
|
{
|
|
// fprintf(stderr, "Face %llu in mesh %llu does not have 3 indices\n", j, i);
|
|
continue;
|
|
}
|
|
|
|
vec3s point1 = {
|
|
mesh->mVertices[face->mIndices[0]].x,
|
|
mesh->mVertices[face->mIndices[0]].y,
|
|
mesh->mVertices[face->mIndices[0]].z
|
|
};
|
|
vec3s point2 = {
|
|
mesh->mVertices[face->mIndices[1]].x,
|
|
mesh->mVertices[face->mIndices[1]].y,
|
|
mesh->mVertices[face->mIndices[1]].z
|
|
};
|
|
vec3s point3 = {
|
|
mesh->mVertices[face->mIndices[2]].x,
|
|
mesh->mVertices[face->mIndices[2]].y,
|
|
mesh->mVertices[face->mIndices[2]].z
|
|
};
|
|
|
|
vec3s normal1 = {
|
|
mesh->mNormals[face->mIndices[0]].x,
|
|
mesh->mNormals[face->mIndices[0]].y,
|
|
mesh->mNormals[face->mIndices[0]].z
|
|
};
|
|
vec3s normal2 = {
|
|
mesh->mNormals[face->mIndices[1]].x,
|
|
mesh->mNormals[face->mIndices[1]].y,
|
|
mesh->mNormals[face->mIndices[1]].z
|
|
};
|
|
vec3s normal3 = {
|
|
mesh->mNormals[face->mIndices[2]].x,
|
|
mesh->mNormals[face->mIndices[2]].y,
|
|
mesh->mNormals[face->mIndices[2]].z
|
|
};
|
|
|
|
//TODO: Handle materials, we use OpenPBR standard for parameter naming
|
|
|
|
// uint32_t properties_count = scene->mMaterials[mesh->mMaterialIndex]->mNumProperties;
|
|
// C_STRUCT aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
|
|
// for (uint32_t p = 0; p < properties_count; p++)
|
|
// {
|
|
// material->mProperties[p]->mKey;
|
|
// }
|
|
|
|
triangle_create_with_normals(point1, point2, point3, normal1, normal2, normal3, material_id, triangles);
|
|
}
|
|
}
|
|
|
|
return entity;
|
|
}
|