fix config file type conversion

test-headless
ink-soul 2024-04-19 18:08:16 +08:00
parent ecc00b6fd2
commit 683d94a8d7
9 changed files with 152 additions and 22 deletions

View File

@ -22,13 +22,13 @@ private:
void updateViewMatrix() void updateViewMatrix()
{ {
glm::mat4 rotM = glm::mat4(1.0f); glm::mat4 rotM = glm::mat4(rotationMatrix);
glm::mat4 transM; glm::mat4 transM;
/*
rotM = glm::rotate(rotM, glm::radians(rotation.x * (flipY ? -1.0f : 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f)); rotM = glm::rotate(rotM, glm::radians(rotation.x * (flipY ? -1.0f : 1.0f)), glm::vec3(1.0f, 0.0f, 0.0f));
rotM = glm::rotate(rotM, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)); rotM = glm::rotate(rotM, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
rotM = glm::rotate(rotM, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f)); rotM = glm::rotate(rotM, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
*/
glm::vec3 translation = position; glm::vec3 translation = position;
if (flipY) { if (flipY) {
translation.y *= -1.0f; translation.y *= -1.0f;
@ -58,6 +58,7 @@ public:
float rotationSpeed = 1.0f; float rotationSpeed = 1.0f;
float movementSpeed = 1.0f; float movementSpeed = 1.0f;
glm::mat3 rotationMatrix = glm::mat3();
bool updated = false; bool updated = false;
bool flipY = false; bool flipY = false;
@ -114,9 +115,9 @@ public:
updateViewMatrix(); updateViewMatrix();
} }
void setRotation(glm::vec3 rotation) void setRotation(glm::mat3 rotaionMatrix)
{ {
this->rotation = rotation; rotaionMatrix = rotaionMatrix;
updateViewMatrix(); updateViewMatrix();
} }

View File

@ -2,7 +2,7 @@
void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string configFilePath) void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string configFilePath,Settings& settings)
{ {
auto config = toml::parse(configFilePath); auto config = toml::parse(configFilePath);
@ -17,12 +17,51 @@ void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string
settings.startFrameIndex = toml::find<uint32_t>(tomlSettings, "startFrameIndex"); settings.startFrameIndex = toml::find<uint32_t>(tomlSettings, "startFrameIndex");
settings.endFrameIndex = toml::find<uint32_t>(tomlSettings, "endFrameIndex"); settings.endFrameIndex = toml::find<uint32_t>(tomlSettings, "endFrameIndex");
settings.videoFrameRate = toml::find<uint32_t>(tomlSettings, "videoFrameRate"); settings.videoFrameRate = toml::find<uint32_t>(tomlSettings, "videoFrameRate");
auto& camera = toml::find(tomlSettings, "camera");
settings.fovX = toml::find<float>(camera, "fovX");
settings.fovY = toml::find<float>(camera, "fovY");
std::string cX = toml::find<std::string>(camera, "cX");
std::string cY = toml::find<std::string>(camera, "cY");
std::vector<float> bottomCenter = toml::find<std::vector<float>>(camera, "bottomCenter");
std::vector<float> bottomNormal = toml::find<std::vector<float>>(camera, "bottomNormal");
std::vector<std::vector<float>> cameraTracks = toml::find<std::vector<std::vector<float>>>(camera, "cameraTracks");
std::vector<std::vector<std::vector<float>>> cameraAngle = toml::find<std::vector<std::vector<std::vector<float>>>>(camera, "cameraAngle");
auto& debug = toml::find(tomlSettings, "debug");
settings.validation = toml::find<bool>(debug, "validation");
settings.vsync = toml::find<bool>(debug, "vsync");
settings.headless = toml::find<bool>(debug, "headless");
settings.outputPNGimage = toml::find<bool>(debug, "outputPNGimage");
settings.debugMode = toml::find<bool>(debug, "debugMode");
//settings.cleanUpImageSequece = toml::find_or<bool>(debug, "cleanUpImageSequece");
/*
conversion
*/
size_t sz;
settings.cX = std::stof(cX, &sz);
settings.cY = std::stof(cY, &sz);
settings.bottomCenter = glm::vec3(bottomCenter[0], bottomCenter[1], bottomCenter[2]);
settings.bottomNormal = glm::vec3(bottomNormal[0], bottomNormal[1], bottomNormal[2]);
auto cameraTracksAndAngleSize = std::min(cameraTracks.size(), cameraAngle.size());
settings.cameraTracks.resize(cameraTracksAndAngleSize);
settings.cameraAngle.resize(cameraTracksAndAngleSize);
for (uint64_t i = 0; i < cameraTracksAndAngleSize; i++)
{
settings.cameraTracks[i] = glm::vec3(cameraTracks[i][0], cameraTracks[i][1], cameraTracks[i][2]);
settings.cameraAngle[i] = glm::mat3(glm::vec3(cameraAngle[i][0][0], cameraAngle[i][0][1], cameraAngle[i][0][2]),
glm::vec3(cameraAngle[i][1][0], cameraAngle[i][1][1], cameraAngle[i][1][2]),
glm::vec3(cameraAngle[i][2][0], cameraAngle[i][2][1], cameraAngle[i][2][2]));
}
} }
PlumageConfig::PlumageConfiguration::PlumageConfiguration() PlumageConfig::PlumageConfiguration::PlumageConfiguration()
{ {
readConfigurationFromToml(filePath.configFilePath, settings);
} }
PlumageConfig::PlumageConfiguration::~PlumageConfiguration() PlumageConfig::PlumageConfiguration::~PlumageConfiguration()

View File

@ -12,6 +12,7 @@
namespace PlumageConfig namespace PlumageConfig
{ {
class PlumageConfiguration class PlumageConfiguration
{ {
public: public:
@ -44,13 +45,16 @@ namespace PlumageConfig
float fovY = 1.f; float fovY = 1.f;
float cX = 2.f; float cX = 2.f;
float cY = 0.f; float cY = 0.f;
std::vector<float> bottomCenter = { 0.f,0.f,-6.f }; glm::vec3 bottomCenter = { 0.f,0.f,-6.f };
std::vector<float> bottomNormal = { 0.f,1.0f,0.f }; //std::vector<float> bottomCenter = { 0.f,0.f,-6.f };
std::vector<std::vector<float>> cameraTracks = { {0.f,0.f,-6.f},{1.f,0.f,-3.f} }; glm::vec3 bottomNormal = { 0.f,1.0f,0.f };
std::vector<std::vector<float>> cameraAngle = { {0.f,0.f,0.f},{45.f,0.f,0.f} }; std::vector<glm::vec3> cameraTracks = { {0.f,0.f,-6.f},{1.f,0.f,-3.f} };
std::vector<glm::mat3> cameraAngle = { {{0.f,0.f,0.f},{45.f,0.f,0.f},{0.f,0.f,0.f}},{{0.f,0.f,0.f},{45.f,0.f,0.f},{0.f,0.f,0.f}} };
}settings; }settings;
struct RenderSettings struct RenderSettings
{ {
uint32_t width = 1280; uint32_t width = 1280;
@ -122,13 +126,14 @@ namespace PlumageConfig
std::string hdr2ktxBatFilePath = getAssetPath() + "script/hdr2ktxBatFilePath.bat"; std::string hdr2ktxBatFilePath = getAssetPath() + "script/hdr2ktxBatFilePath.bat";
std::string hdr2ktxShFilePath = getAssetPath() + "script/hdr2ktxShFilePath.sh"; std::string hdr2ktxShFilePath = getAssetPath() + "script/hdr2ktxShFilePath.sh";
// 配置文件路径,命令行传入后保存在这 // 配置文件路径,命令行传入后保存在这
std::string configFilePath = getAssetPath() + "config/config.toml"; //std::string configFilePath = getAssetPath() + "config/guanzi.toml";
std::string configFilePath = getAssetPath() + "config/fangshai_traj1_matrix.toml";
} filePath; } filePath;
void writrConfigurationToJson(); void writrConfigurationToJson();
void readConfigurationFromToml(std::string configFilePath); void readConfigurationFromToml(std::string configFilePath,Settings& settings);
void convertIntToVkSampleCount(uint32_t sampleCount); void convertIntToVkSampleCount(uint32_t sampleCount);

View File

@ -331,11 +331,24 @@ void VulkanExampleBase::renderFrame()
void VulkanExampleBase::renderLoop() void VulkanExampleBase::renderLoop()
{ {
uint32_t currentFrame = 0;
while (!signal.imageSequenceToVideoComplete) while (!signal.imageSequenceToVideoComplete)
{ {
camera.setPosition(settings.cameraTracks[currentFrame]);
camera.setRotation(settings.cameraAngle[currentFrame]);
renderFrame(); renderFrame();
if (currentFrame = settings.cameraTracks.size() )
{
currentFrame = settings.cameraTracks.size()-1;
} }
renderingFrameIndex++; else
{
currentFrame++;
}
}
// Flush device to make sure all resources can be freed // Flush device to make sure all resources can be freed
vkDeviceWaitIdle(device); vkDeviceWaitIdle(device);
} }

View File

@ -89,6 +89,7 @@ public:
PlumageConfig::PlumageConfiguration setter; PlumageConfig::PlumageConfiguration setter;
PlumageConfig::PlumageConfiguration::Settings settings = setter.settings; PlumageConfig::PlumageConfiguration::Settings settings = setter.settings;
PlumageConfig::PlumageConfiguration::FilePath filePath = setter.filePath; PlumageConfig::PlumageConfiguration::FilePath filePath = setter.filePath;
uint32_t selectedPhysicalDeviceIndex = 0; uint32_t selectedPhysicalDeviceIndex = 0;
bool prepared = false; bool prepared = false;

View File

@ -24,12 +24,14 @@ vsync = false
headless = false headless = false
outputPNGimage = false outputPNGimage = false
debugMode = true debugMode = true
cleanUpImageSequence = true
configFilePath ="./data/config/config.toml"
[FilePath] [FilePath]
glTFModelFilePath ="./data/models/DamagedHelmet/DamagedHelmet.gltf" glTFModelFilePath ="./data/models/DamagedHelmet/DamagedHelmet.gltf"
envMapFilePath ="./data/environments/metro_noord_4k_hdr16f_cube.ktx" envMapFilePath ="./data/environments/metro_noord_4k_hdr16f_cube.ktx"
imageOutputPath ="./data/output/imageSequence" imageOutputPath ="./data/output/imageSequence"
videoOutputPath ="./data/output/video" videoOutputPath ="./data/output/video"
configFilePath ="./data/config/config.toml"
[FilePath.ui] [FilePath.ui]
uiVertShaderPath ="./data/shaders/ui.vert.spv" uiVertShaderPath ="./data/shaders/ui.vert.spv"
uiFragShaderPath ="./data/shaders/ui.frag.spv" uiFragShaderPath ="./data/shaders/ui.frag.spv"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -203,8 +203,8 @@ PlumageRender::PlumageRender()
models.scene.loadFromFile(filename, vulkanDevice, queue); models.scene.loadFromFile(filename, vulkanDevice, queue);
auto tFileLoad = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - tStart).count(); auto tFileLoad = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - tStart).count();
std::cout << "Loading took " << tFileLoad << " ms" << std::endl; std::cout << "Loading took " << tFileLoad << " ms" << std::endl;
camera.setPosition({ 0.0f, 0.0f, -2.0f }); camera.setPosition(settings.cameraTracks[0]);
camera.setRotation({ 0.0f, 0.0f, 0.0f }); camera.setRotation(settings.cameraAngle[0]);
} }
void PlumageRender::loadEnvironment(std::string filename) void PlumageRender::loadEnvironment(std::string filename)
@ -1495,7 +1495,7 @@ PlumageRender::PlumageRender()
float scale = (1.0f / modelSize ) * 0.5f; float scale = (1.0f / modelSize ) * 0.5f;
glm::vec3 translate = -glm::vec3(models.scene.aabb[3][0], models.scene.aabb[3][1], models.scene.aabb[3][2]); glm::vec3 translate = -glm::vec3(models.scene.aabb[3][0], models.scene.aabb[3][1], models.scene.aabb[3][2]);
translate += -0.5f * glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]); translate += -0.5f * glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]);
translate += -0.5f * settings.bottomCenter;
//camera.setPosition(glm::vec3(0, 0, -modelSize - 2)); //camera.setPosition(glm::vec3(0, 0, -modelSize - 2));
shaderDataScene.model = glm::mat4(1.0f); shaderDataScene.model = glm::mat4(1.0f);
@ -1990,8 +1990,7 @@ PlumageRender::PlumageRender()
//outputImageSequeue(swapChainImage,filePath.imageSequenceFilePath); //outputImageSequeue(swapChainImage,filePath.imageSequenceFilePath);
outputImageSequence();
imageSequenceToVideo();
VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[frameIndex], VK_TRUE, UINT64_MAX)); VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[frameIndex], VK_TRUE, UINT64_MAX));
@ -2030,6 +2029,8 @@ PlumageRender::PlumageRender()
submitInfo.commandBufferCount = 1; submitInfo.commandBufferCount = 1;
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[frameIndex])); VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[frameIndex]));
outputImageSequence();
imageSequenceToVideo();
//显示队列 //显示队列
/* /*
VkResult present = swapChain.queuePresent(queue, currentBuffer, renderCompleteSemaphores[frameIndex]); VkResult present = swapChain.queuePresent(queue, currentBuffer, renderCompleteSemaphores[frameIndex]);
@ -2302,7 +2303,7 @@ PlumageRender::PlumageRender()
for (int32_t i = 0; i < argc; i++) { PlumageRender::args.push_back(argv[i]); }; for (int32_t i = 0; i < argc; i++) { PlumageRender::args.push_back(argv[i]); };
PlumageConfig::PlumageConfiguration config; PlumageConfig::PlumageConfiguration config;
//config.writrConfigurationToJson(); //config.writrConfigurationToJson();
//config.readConfigurationFromJson(config.filePath.configFilePath); //config.readConfigurationFromToml(config.filePath.configFilePath,config.settings);
plumageRender = new PlumageRender(); plumageRender = new PlumageRender();
std::cout << "start to init vulkan" << std::endl; std::cout << "start to init vulkan" << std::endl;
plumageRender->initVulkan(); plumageRender->initVulkan();