mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Improve log messages and remove assimp loader
This commit is contained in:
parent
0603d77917
commit
16357675a7
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -16,6 +16,3 @@
|
||||
[submodule "dependencies/VulkanMemoryAllocator"]
|
||||
path = dependencies/VulkanMemoryAllocator
|
||||
url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator
|
||||
[submodule "dependencies/assimp"]
|
||||
path = dependencies/assimp
|
||||
url = https://github.com/assimp/assimp
|
@ -54,7 +54,6 @@ set(SRC_FILES
|
||||
"src/systems/transform.cpp"
|
||||
"src/util/files.cpp"
|
||||
"src/util/gltf_loader.cpp"
|
||||
"src/util/model_loader.cpp"
|
||||
"src/vulkan/device.cpp"
|
||||
"src/vulkan/device.h"
|
||||
"src/vulkan/gpu_allocator.cpp"
|
||||
@ -101,7 +100,6 @@ set(INCLUDE_FILES
|
||||
"include/util.h"
|
||||
"include/util/files.h"
|
||||
"include/util/gltf_loader.h"
|
||||
"include/util/model_loader.h"
|
||||
"include/window.h"
|
||||
)
|
||||
|
||||
@ -182,18 +180,6 @@ endif()
|
||||
# stb
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC dependencies/stb)
|
||||
|
||||
# assimp
|
||||
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
|
||||
set(ASSIMP_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
|
||||
set(ASSIMP_BUILD_ZLIB ON CACHE INTERNAL "" FORCE)
|
||||
set(ASSIMP_NO_EXPORT ON CACHE INTERNAL "" FORCE)
|
||||
set(ASSIMP_INSTALL OFF CACHE INTERNAL "" FORCE)
|
||||
set(ASSIMP_BUILD_COLLADA_IMPORTER ON CACHE INTERNAL "" FORCE)
|
||||
set(ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT OFF CACHE INTERNAL "" FORCE)
|
||||
add_subdirectory(dependencies/assimp)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE dependencies/assimp/include)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE assimp)
|
||||
|
||||
# public libraries:
|
||||
|
||||
# SDL2:
|
||||
|
1
dependencies/assimp
vendored
1
dependencies/assimp
vendored
@ -1 +0,0 @@
|
||||
Subproject commit 6392dbfe4d9b0e23d4e573d0f3e45a198412ece1
|
@ -1,4 +1,5 @@
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||
#ifndef ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||
#define ENGINE_INCLUDE_RESOURCES_MESH_H_
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
@ -26,11 +27,7 @@ namespace engine {
|
||||
class Mesh {
|
||||
public:
|
||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices);
|
||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices,
|
||||
const std::vector<uint32_t>& indices)
|
||||
: gfx_(gfx) {
|
||||
InitMesh(vertices, indices);
|
||||
}
|
||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
|
||||
~Mesh();
|
||||
Mesh(const Mesh&) = delete;
|
||||
Mesh& operator=(const Mesh&) = delete;
|
||||
@ -46,8 +43,7 @@ class Mesh {
|
||||
const gfx::Buffer* ib_;
|
||||
uint32_t count_;
|
||||
|
||||
void InitMesh(const std::vector<Vertex>& vertices,
|
||||
const std::vector<uint32_t>& indices);
|
||||
void InitMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef ENGINE_INCLUDE_UTIL_MODEL_LOADER_H_
|
||||
#define ENGINE_INCLUDE_UTIL_MODEL_LOADER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "scene.h"
|
||||
|
||||
namespace engine {
|
||||
namespace util {
|
||||
|
||||
Entity LoadMeshFromFile(Scene* parent, const std::string& path, bool is_static = false);
|
||||
|
||||
} // namespace util
|
||||
} // namespace engine
|
||||
|
||||
#endif
|
@ -210,8 +210,8 @@ void Application::GameLoop()
|
||||
uint64_t now = window_->GetNanos();
|
||||
if (now - lastTick >= 1000000000LL * 5LL) [[unlikely]] {
|
||||
lastTick = now;
|
||||
LOG_INFO("fps: {}", std::lroundf(avg_fps));
|
||||
// renderer()->GetDevice()->LogPerformanceInfo();
|
||||
LOG_DEBUG("fps: {}", std::lroundf(avg_fps));
|
||||
renderer()->GetDevice()->LogPerformanceInfo();
|
||||
window_->ResetAvgFPS();
|
||||
}
|
||||
|
||||
|
@ -2310,18 +2310,18 @@ void GFXDevice::LogPerformanceInfo()
|
||||
memProps.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
|
||||
vkGetPhysicalDeviceMemoryProperties2(pimpl->device.physicalDevice, &memProps);
|
||||
|
||||
LOG_INFO("GPU Memory Statistics:");
|
||||
LOG_DEBUG("GPU Memory Statistics:");
|
||||
|
||||
for (uint32_t i = 0; i < memProps.memoryProperties.memoryHeapCount; i++) {
|
||||
const VmaStatistics& statistics = pStats.memoryHeap[i].statistics;
|
||||
VkMemoryHeap heap = memProps.memoryProperties.memoryHeaps[i];
|
||||
LOG_INFO("Memory heap {}", i);
|
||||
LOG_DEBUG("Memory heap {}", i);
|
||||
if (heap.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) {
|
||||
LOG_INFO(" DEVICE_LOCAL");
|
||||
LOG_DEBUG(" DEVICE_LOCAL");
|
||||
}
|
||||
LOG_INFO(" Memory blocks allocated: {} ({} MiB)", statistics.blockCount, statistics.allocationBytes / (1024 * 1024));
|
||||
LOG_INFO(" Number of allocations: {} ({} MiB)", statistics.allocationCount, statistics.allocationBytes / (1024 * 1024));
|
||||
LOG_INFO(" Max size: {} MiB", heap.size / (1024 * 1024));
|
||||
LOG_DEBUG(" Memory blocks allocated: {} ({} MiB)", statistics.blockCount, statistics.allocationBytes / (1024 * 1024));
|
||||
LOG_DEBUG(" Number of allocations: {} ({} MiB)", statistics.allocationCount, statistics.allocationBytes / (1024 * 1024));
|
||||
LOG_DEBUG(" Max size: {} MiB", heap.size / (1024 * 1024));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ Font::Font(const std::string& path) {
|
||||
LOG_DEBUG("Created font: {}", path);
|
||||
}
|
||||
|
||||
Font::~Font() { LOG_DEBUG("Destroying font..."); }
|
||||
Font::~Font() { LOG_DEBUG("Destroyed font"); }
|
||||
|
||||
std::unique_ptr<std::vector<uint8_t>> Font::GetTextBitmap(
|
||||
const std::string& text, float height_px, int& width_out, int& height_out) {
|
||||
|
@ -7,9 +7,10 @@ namespace engine {
|
||||
Material::Material(Renderer* renderer, std::shared_ptr<Shader> shader) : shader_(shader), renderer_(renderer)
|
||||
{
|
||||
material_set_ = renderer->GetDevice()->AllocateDescriptorSet(renderer->GetMaterialSetLayout());
|
||||
LOG_DEBUG("Created material");
|
||||
}
|
||||
|
||||
Material::~Material() { renderer_->GetDevice()->FreeDescriptorSet(material_set_); }
|
||||
Material::~Material() { renderer_->GetDevice()->FreeDescriptorSet(material_set_); LOG_DEBUG("Destroyed material"); }
|
||||
|
||||
void Material::SetAlbedoTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
|
@ -5,7 +5,8 @@
|
||||
|
||||
namespace engine {
|
||||
|
||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices) : gfx_(gfx) {
|
||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices) : gfx_(gfx)
|
||||
{
|
||||
std::vector<uint32_t> indices(vertices.size());
|
||||
for (uint32_t i = 0; i < indices.size(); i++) {
|
||||
indices[i] = i;
|
||||
@ -13,10 +14,13 @@ Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices) : gfx_(gfx) {
|
||||
InitMesh(vertices, indices);
|
||||
}
|
||||
|
||||
Mesh::~Mesh() {
|
||||
LOG_DEBUG("Destroying mesh...");
|
||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices) : gfx_(gfx) { InitMesh(vertices, indices); }
|
||||
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
gfx_->DestroyBuffer(ib_);
|
||||
gfx_->DestroyBuffer(vb_);
|
||||
LOG_DEBUG("Destroyed mesh");
|
||||
}
|
||||
|
||||
const gfx::Buffer* Mesh::GetVB() { return vb_; }
|
||||
@ -25,15 +29,12 @@ const gfx::Buffer* Mesh::GetIB() { return ib_; }
|
||||
|
||||
uint32_t Mesh::GetCount() { return count_; }
|
||||
|
||||
void Mesh::InitMesh(const std::vector<Vertex>& vertices,
|
||||
const std::vector<uint32_t>& indices) {
|
||||
vb_ = gfx_->CreateBuffer(gfx::BufferType::kVertex,
|
||||
vertices.size() * sizeof(Vertex), vertices.data());
|
||||
ib_ = gfx_->CreateBuffer(gfx::BufferType::kIndex,
|
||||
indices.size() * sizeof(uint32_t), indices.data());
|
||||
void Mesh::InitMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||
{
|
||||
vb_ = gfx_->CreateBuffer(gfx::BufferType::kVertex, vertices.size() * sizeof(Vertex), vertices.data());
|
||||
ib_ = gfx_->CreateBuffer(gfx::BufferType::kIndex, indices.size() * sizeof(uint32_t), indices.data());
|
||||
count_ = (uint32_t)indices.size();
|
||||
LOG_DEBUG("Created mesh, vertices: {}, indices: {}", vertices.size(),
|
||||
indices.size());
|
||||
LOG_DEBUG("Created mesh, vertices: {}, indices: {}", vertices.size(), indices.size());
|
||||
}
|
||||
|
||||
} // namespace engine
|
||||
|
@ -62,8 +62,8 @@ Shader::Shader(Renderer* renderer, const std::string& vertPath, const std::strin
|
||||
}
|
||||
|
||||
Shader::~Shader() {
|
||||
LOG_DEBUG("Destroying shader... pipeline: {}", static_cast<const void*>(pipeline_));
|
||||
gfx_->DestroyPipeline(pipeline_);
|
||||
LOG_DEBUG("Destroyed shader, pipeline: {}", static_cast<const void*>(pipeline_));
|
||||
}
|
||||
|
||||
const gfx::Pipeline* Shader::GetPipeline() { return pipeline_; }
|
||||
|
@ -24,8 +24,8 @@ Texture::Texture(Renderer* renderer, const uint8_t* bitmap, int width, int heigh
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
LOG_DEBUG("Destroying texture...");
|
||||
gfx_->DestroyImage(image_);
|
||||
LOG_DEBUG("Destroyed texture");
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadTextureFromFile(const std::string& path, gfx::SamplerInfo samplerInfo, Renderer* renderer, bool srgb)
|
||||
|
@ -124,7 +124,7 @@ void CollisionSystem::OnUpdate(float ts)
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO("BUILT BVH!");
|
||||
LOG_DEBUG("BUILT BVH!");
|
||||
|
||||
colliders_size_last_update_ = colliders_size_now_;
|
||||
}
|
||||
|
@ -1,225 +0,0 @@
|
||||
#include "util/model_loader.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "application.h"
|
||||
|
||||
#include "components/transform.h"
|
||||
#include "components/mesh_renderable.h"
|
||||
|
||||
#include "resources/texture.h"
|
||||
#include "resources/material.h"
|
||||
#include "resources/shader.h"
|
||||
#include "resources/mesh.h"
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/LogStream.hpp>
|
||||
#include <assimp/Logger.hpp>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/scene.h>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <filesystem>
|
||||
|
||||
namespace engine::util {
|
||||
|
||||
static void buildGraph(const std::map<int, std::shared_ptr<Texture>>& textures, const std::vector<std::shared_ptr<Mesh>>& meshes,
|
||||
const std::vector<unsigned int>& meshTextureIndices, aiNode* parentNode, Scene* scene, Entity parentObj, bool is_static)
|
||||
{
|
||||
|
||||
// convert to glm column major
|
||||
glm::mat4 transform{};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
transform[i][j] = parentNode->mTransformation[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
// get position
|
||||
glm::vec3 position{transform[3][0], transform[3][1], transform[3][2]};
|
||||
|
||||
// remove position from matrix
|
||||
transform[3][0] = 0.0f;
|
||||
transform[3][1] = 0.0f;
|
||||
transform[3][2] = 0.0f;
|
||||
|
||||
// get scale
|
||||
glm::vec3 scale{};
|
||||
scale.x = sqrt(transform[0][0] * transform[0][0] + transform[0][1] * transform[0][1] + transform[0][2] * transform[0][2]);
|
||||
scale.y = sqrt(transform[1][0] * transform[1][0] + transform[1][1] * transform[1][1] + transform[1][2] * transform[1][2]);
|
||||
scale.z = sqrt(transform[2][0] * transform[2][0] + transform[2][1] * transform[2][1] + transform[2][2] * transform[2][2]);
|
||||
|
||||
// remove scaling from matrix
|
||||
for (int row = 0; row < 3; row++) {
|
||||
transform[0][row] /= scale.x;
|
||||
transform[1][row] /= scale.y;
|
||||
transform[2][row] /= scale.z;
|
||||
}
|
||||
|
||||
// get rotation
|
||||
glm::quat rotation = glm::quat_cast(transform);
|
||||
|
||||
// ASSIMP always makes the root node Y-up
|
||||
// We want Z-up
|
||||
if (parentNode->mParent == nullptr) {
|
||||
// if this is the root node
|
||||
rotation *= glm::angleAxis(glm::half_pi<float>(), glm::vec3{1.0f, 0.0f, 0.0f});
|
||||
}
|
||||
|
||||
// update position, scale, rotation
|
||||
auto parentTransform = scene->GetComponent<TransformComponent>(parentObj);
|
||||
parentTransform->position = position;
|
||||
parentTransform->scale = scale;
|
||||
parentTransform->rotation = rotation;
|
||||
parentTransform->is_static = is_static;
|
||||
|
||||
for (uint32_t i = 0; i < parentNode->mNumMeshes; i++) {
|
||||
// create child node for each mesh
|
||||
auto child = scene->CreateEntity("_mesh" + std::to_string(i), parentObj);
|
||||
scene->GetComponent<TransformComponent>(child)->is_static = is_static;
|
||||
auto childRenderer = scene->AddComponent<MeshRenderableComponent>(child);
|
||||
childRenderer->mesh = meshes[parentNode->mMeshes[i]];
|
||||
childRenderer->material = std::make_shared<Material>(scene->app()->renderer(), scene->app()->GetResource<Shader>("builtin.fancy"));
|
||||
if (textures.contains(meshTextureIndices[parentNode->mMeshes[i]])) {
|
||||
childRenderer->material->SetAlbedoTexture(textures.at(meshTextureIndices[parentNode->mMeshes[i]]));
|
||||
}
|
||||
else {
|
||||
childRenderer->material->SetAlbedoTexture(scene->app()->GetResource<Texture>("builtin.white"));
|
||||
}
|
||||
childRenderer->material->SetNormalTexture(scene->app()->GetResource<Texture>("builtin.normal"));
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < parentNode->mNumChildren; i++) {
|
||||
buildGraph(textures, meshes, meshTextureIndices, parentNode->mChildren[i], scene, scene->CreateEntity("child" + std::to_string(i), parentObj),
|
||||
is_static);
|
||||
}
|
||||
}
|
||||
|
||||
Entity LoadMeshFromFile(Scene* parent, const std::string& path, bool is_static)
|
||||
{
|
||||
|
||||
Assimp::Importer importer;
|
||||
|
||||
class myStream : public Assimp::LogStream {
|
||||
public:
|
||||
void write(const char* message) override
|
||||
{
|
||||
(void)message;
|
||||
LOG_TRACE("ASSIMP: {}", message);
|
||||
}
|
||||
};
|
||||
|
||||
const unsigned int severity = Assimp::Logger::Debugging | Assimp::Logger::Info | Assimp::Logger::Err | Assimp::Logger::Warn;
|
||||
Assimp::DefaultLogger::get()->attachStream(new myStream, severity);
|
||||
|
||||
// remove everything but texcoords, normals, meshes, materials
|
||||
importer.SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, aiComponent_ANIMATIONS | aiComponent_BONEWEIGHTS | aiComponent_CAMERAS | aiComponent_COLORS |
|
||||
aiComponent_LIGHTS | aiComponent_TANGENTS_AND_BITANGENTS | aiComponent_TEXTURES | 0);
|
||||
importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_POINT | aiPrimitiveType_LINE | aiPrimitiveType_POLYGON);
|
||||
|
||||
const aiScene* scene =
|
||||
importer.ReadFile(path,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_RemoveComponent |
|
||||
aiProcess_SplitLargeMeshes | // leave at default maximum
|
||||
aiProcess_ValidateDataStructure | // make sure to log the output
|
||||
aiProcess_ImproveCacheLocality | aiProcess_RemoveRedundantMaterials | aiProcess_FindInvalidData | aiProcess_GenSmoothNormals |
|
||||
aiProcess_GenUVCoords | aiProcess_TransformUVCoords | aiProcess_FlipUVs | // Collada uses bottom-left origin
|
||||
aiProcess_CalcTangentSpace | 0);
|
||||
|
||||
const char* errString = importer.GetErrorString();
|
||||
if (errString[0] != '\0' || scene == nullptr) {
|
||||
throw std::runtime_error("assimp error: " + std::string(errString));
|
||||
}
|
||||
|
||||
if (scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) {
|
||||
throw std::runtime_error("assimp error (incomplete): " + std::string(errString));
|
||||
}
|
||||
|
||||
assert(scene->HasAnimations() == false);
|
||||
assert(scene->HasCameras() == false);
|
||||
assert(scene->HasLights() == false);
|
||||
assert(scene->hasSkeletons() == false);
|
||||
|
||||
LOG_TRACE("material count: {}, mesh count: {}", scene->mNumMaterials, scene->mNumMeshes);
|
||||
|
||||
std::map<int, std::shared_ptr<Texture>> textures{};
|
||||
|
||||
for (uint32_t i = 0; i < scene->mNumMaterials; i++) {
|
||||
const aiMaterial* m = scene->mMaterials[i];
|
||||
LOG_TRACE("Material {}:", i);
|
||||
LOG_TRACE(" Name: {}", m->GetName().C_Str());
|
||||
for (uint32_t j = 0; j < m->mNumProperties; j++) {
|
||||
[[maybe_unused]] const aiMaterialProperty* p = m->mProperties[j];
|
||||
LOG_TRACE(" prop {}, key: {}", j, p->mKey.C_Str());
|
||||
}
|
||||
|
||||
if (aiGetMaterialTextureCount(m, aiTextureType_DIFFUSE) >= 1) {
|
||||
aiString texPath{};
|
||||
aiGetMaterialTexture(m, aiTextureType_DIFFUSE, 0, &texPath);
|
||||
LOG_TRACE(" Diffuse tex: {}", texPath.C_Str());
|
||||
std::filesystem::path absPath = path;
|
||||
absPath = absPath.parent_path();
|
||||
absPath /= texPath.C_Str();
|
||||
try {
|
||||
textures[i] = LoadTextureFromFile(absPath.string(), gfx::SamplerInfo{}, parent->app()->renderer());
|
||||
}
|
||||
catch (const std::runtime_error&) {
|
||||
textures[i] = parent->app()->GetResource<Texture>("builtin.white");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Mesh>> meshes{};
|
||||
std::vector<unsigned int> meshMaterialIndices{};
|
||||
for (uint32_t i = 0; i < scene->mNumMeshes; i++) {
|
||||
const aiMesh* m = scene->mMeshes[i];
|
||||
meshMaterialIndices.push_back(m->mMaterialIndex);
|
||||
std::vector<Vertex> vertices(m->mNumVertices);
|
||||
std::vector<uint32_t> indices((size_t)m->mNumFaces * 3);
|
||||
LOG_TRACE("Mesh {}: vertex count {}", i, vertices.size());
|
||||
LOG_TRACE("Mesh {}: index count {}", i, indices.size());
|
||||
|
||||
if (m->mTangents == nullptr) {
|
||||
throw std::runtime_error("No tangents array found!");
|
||||
}
|
||||
|
||||
for (uint32_t j = 0; j < vertices.size(); j++) {
|
||||
Vertex v{};
|
||||
v.pos.x = m->mVertices[j].x;
|
||||
v.pos.y = m->mVertices[j].y;
|
||||
v.pos.z = m->mVertices[j].z;
|
||||
v.norm.x = m->mNormals[j].x;
|
||||
v.norm.y = m->mNormals[j].y;
|
||||
v.norm.z = m->mNormals[j].z;
|
||||
v.tangent.x = m->mTangents[j].x;
|
||||
v.tangent.y = m->mTangents[j].y;
|
||||
v.tangent.z = m->mTangents[j].z;
|
||||
v.tangent.w = 1.0f;
|
||||
v.uv.x = m->mTextureCoords[0][j].x;
|
||||
v.uv.y = m->mTextureCoords[0][j].y;
|
||||
vertices[j] = v;
|
||||
}
|
||||
|
||||
for (uint32_t j = 0; j < indices.size() / 3; j++) {
|
||||
indices[(size_t)j * 3 + 0] = m->mFaces[j].mIndices[0];
|
||||
indices[(size_t)j * 3 + 1] = m->mFaces[j].mIndices[1];
|
||||
indices[(size_t)j * 3 + 2] = m->mFaces[j].mIndices[2];
|
||||
}
|
||||
meshes.push_back(std::make_shared<Mesh>(parent->app()->renderer()->GetDevice(), vertices, indices));
|
||||
}
|
||||
|
||||
Entity obj = parent->CreateEntity(scene->GetShortFilename(path.c_str()));
|
||||
|
||||
buildGraph(textures, meshes, meshMaterialIndices, scene->mRootNode, parent, obj, is_static);
|
||||
|
||||
LOG_INFO("Loaded model: {}, meshes: {}, textures: {}", scene->GetShortFilename(path.c_str()), meshes.size(), textures.size());
|
||||
|
||||
Assimp::DefaultLogger::kill();
|
||||
return obj;
|
||||
}
|
||||
|
||||
} // namespace engine::util
|
@ -209,11 +209,11 @@ void CameraControllerSystem::OnUpdate(float ts)
|
||||
engine::Raycast cast = scene_->GetSystem<engine::CollisionSystem>()->GetRaycast(ray);
|
||||
|
||||
if (cast.hit) {
|
||||
LOG_INFO("Distance: {} m", cast.distance);
|
||||
LOG_INFO("Location: {} {} {}", cast.location.x, cast.location.y, cast.location.z);
|
||||
LOG_INFO("Normal: {} {} {}", cast.normal.x, cast.normal.y, cast.normal.z);
|
||||
LOG_INFO("Ray direction: {} {} {}", ray.direction.x, ray.direction.y, ray.direction.z);
|
||||
LOG_INFO("Hit Entity: {}", scene_->GetComponent<engine::TransformComponent>(cast.hit_entity)->tag);
|
||||
LOG_TRACE("Distance: {} m", cast.distance);
|
||||
LOG_TRACE("Location: {} {} {}", cast.location.x, cast.location.y, cast.location.z);
|
||||
LOG_TRACE("Normal: {} {} {}", cast.normal.x, cast.normal.y, cast.normal.z);
|
||||
LOG_TRACE("Ray direction: {} {} {}", ray.direction.x, ray.direction.y, ray.direction.z);
|
||||
LOG_TRACE("Hit Entity: {}", scene_->GetComponent<engine::TransformComponent>(cast.hit_entity)->tag);
|
||||
c->perm_lines.clear();
|
||||
c->perm_lines.emplace_back(ray.origin, cast.location, glm::vec3{0.0f, 0.0f, 1.0f});
|
||||
scene_->GetComponent<engine::MeshRenderableComponent>(cast.hit_entity)->visible ^= true;
|
||||
|
Loading…
Reference in New Issue
Block a user