ADD: Floating origin system
This commit is contained in:
@@ -104,6 +104,32 @@ AsyncAssetLoader::JobID AsyncAssetLoader::load_gltf_async(const std::string &sce
|
||||
return id;
|
||||
}
|
||||
|
||||
AsyncAssetLoader::JobID AsyncAssetLoader::load_gltf_async(const std::string &scene_name,
|
||||
const std::string &model_relative_path,
|
||||
const WorldVec3 &translation_world,
|
||||
const glm::quat &rotation,
|
||||
const glm::vec3 &scale,
|
||||
bool preload_textures)
|
||||
{
|
||||
JobID id = load_gltf_async(scene_name, model_relative_path, glm::mat4(1.0f), preload_textures);
|
||||
if (id == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(_jobs_mutex);
|
||||
auto it = _jobs.find(id);
|
||||
if (it != _jobs.end() && it->second)
|
||||
{
|
||||
Job &job = *it->second;
|
||||
job.has_world_trs = true;
|
||||
job.translation_world = translation_world;
|
||||
job.rotation = rotation;
|
||||
job.scale = scale;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
bool AsyncAssetLoader::get_job_status(JobID id, JobState &out_state, float &out_progress, std::string *out_error)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_jobs_mutex);
|
||||
@@ -234,6 +260,13 @@ void AsyncAssetLoader::pump_main_thread(SceneManager &scene)
|
||||
job->scene->debugName = job->model_relative_path;
|
||||
}
|
||||
scene.addGLTFInstance(job->scene_name, job->scene, job->transform);
|
||||
if (job->has_world_trs)
|
||||
{
|
||||
scene.setGLTFInstanceTRSWorld(job->scene_name,
|
||||
job->translation_world,
|
||||
job->rotation,
|
||||
job->scale);
|
||||
}
|
||||
|
||||
// Optionally preload textures (same logic as addGLTFInstance)
|
||||
if (job->preload_textures && _textures && _engine && _engine->_resourceManager)
|
||||
|
||||
@@ -11,8 +11,11 @@
|
||||
#include <thread>
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "scene/vk_loader.h"
|
||||
#include "core/world.h"
|
||||
#include "core/assets/texture_cache.h"
|
||||
|
||||
class VulkanEngine;
|
||||
@@ -41,6 +44,13 @@ public:
|
||||
const glm::mat4 &transform,
|
||||
bool preload_textures = false);
|
||||
|
||||
JobID load_gltf_async(const std::string &scene_name,
|
||||
const std::string &model_relative_path,
|
||||
const WorldVec3 &translation_world,
|
||||
const glm::quat &rotation,
|
||||
const glm::vec3 &scale,
|
||||
bool preload_textures = false);
|
||||
|
||||
bool get_job_status(JobID id, JobState &out_state, float &out_progress, std::string *out_error = nullptr);
|
||||
|
||||
// Main-thread integration: commit completed jobs into the SceneManager.
|
||||
@@ -66,6 +76,10 @@ private:
|
||||
std::string scene_name;
|
||||
std::string model_relative_path;
|
||||
glm::mat4 transform{1.0f};
|
||||
bool has_world_trs{false};
|
||||
WorldVec3 translation_world{0.0, 0.0, 0.0};
|
||||
glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};
|
||||
glm::vec3 scale{1.0f};
|
||||
bool preload_textures{false};
|
||||
|
||||
std::shared_ptr<LoadedGLTF> scene;
|
||||
|
||||
@@ -533,7 +533,7 @@ void TextureCache::worker_loop()
|
||||
{
|
||||
ktx_size_t off = 0, len = 0;
|
||||
ktxTexture_GetImageOffset(ktxTexture(ktex), mip, 0, 0, &off);
|
||||
ktxTexture_GetImageSize(ktxTexture(ktex), mip, &len);
|
||||
len = ktxTexture_GetImageSize(ktxTexture(ktex), mip);
|
||||
uint32_t w = std::max(1u, baseW >> mip);
|
||||
uint32_t h = std::max(1u, baseH >> mip);
|
||||
out.ktx.levels.push_back({ static_cast<uint64_t>(off), static_cast<uint64_t>(len), w, h });
|
||||
|
||||
Reference in New Issue
Block a user