完成坐标和法线对齐
parent
d0ae241479
commit
a438e685f3
|
@ -29,12 +29,8 @@ const std::string getAssetPath()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::filesystem::path currentPath = std::filesystem::current_path();
|
|
||||||
dataFilePath = VK_EXAMPLE_DATA_DIR;
|
|
||||||
dataFilePath = dataFilePath.lexically_relative(currentPath);
|
|
||||||
dataFile = dataFilePath.generic_string();
|
|
||||||
|
|
||||||
return dataFile;
|
return VK_EXAMPLE_DATA_DIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,6 +26,7 @@ void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string
|
||||||
std::string cY = toml::find<std::string>(camera, "cY");
|
std::string cY = toml::find<std::string>(camera, "cY");
|
||||||
std::vector<float> bottomCenter = toml::find<std::vector<float>>(camera, "bottomCenter");
|
std::vector<float> bottomCenter = toml::find<std::vector<float>>(camera, "bottomCenter");
|
||||||
std::vector<float> bottomNormal = toml::find<std::vector<float>>(camera, "bottomNormal");
|
std::vector<float> bottomNormal = toml::find<std::vector<float>>(camera, "bottomNormal");
|
||||||
|
std::vector<float> cameraFixation = toml::find<std::vector<float>>(camera, "center");
|
||||||
std::vector<std::vector<float>> cameraTracks = toml::find<std::vector<std::vector<float>>>(camera, "cameraTracks");
|
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");
|
std::vector<std::vector<std::vector<float>>> cameraAngle = toml::find<std::vector<std::vector<std::vector<float>>>>(camera, "cameraAngle");
|
||||||
|
|
||||||
|
@ -38,8 +39,9 @@ void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string
|
||||||
//settings.cleanUpImageSequece = toml::find_or<bool>(debug, "cleanUpImageSequece");
|
//settings.cleanUpImageSequece = toml::find_or<bool>(debug, "cleanUpImageSequece");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
conversion
|
conversion: type and coordinate system(rotation had been converted)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
size_t sz;
|
size_t sz;
|
||||||
settings.fX = std::stof(fX, &sz);
|
settings.fX = std::stof(fX, &sz);
|
||||||
settings.fY = std::stof(fY, &sz);
|
settings.fY = std::stof(fY, &sz);
|
||||||
|
@ -47,6 +49,7 @@ void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string
|
||||||
settings.cY = std::stof(cY, &sz);
|
settings.cY = std::stof(cY, &sz);
|
||||||
settings.bottomCenter = glm::vec3(bottomCenter[0], -bottomCenter[1], -bottomCenter[2]);
|
settings.bottomCenter = glm::vec3(bottomCenter[0], -bottomCenter[1], -bottomCenter[2]);
|
||||||
settings.bottomNormal = glm::vec3(bottomNormal[0], -bottomNormal[1], -bottomNormal[2]);
|
settings.bottomNormal = glm::vec3(bottomNormal[0], -bottomNormal[1], -bottomNormal[2]);
|
||||||
|
settings.cameraFixation = glm::vec3(cameraFixation[0], -cameraFixation[1], -cameraFixation[2]);
|
||||||
auto cameraTracksAndAngleSize = std::min(cameraTracks.size(), cameraAngle.size());
|
auto cameraTracksAndAngleSize = std::min(cameraTracks.size(), cameraAngle.size());
|
||||||
settings.cameraTracks.resize(cameraTracksAndAngleSize);
|
settings.cameraTracks.resize(cameraTracksAndAngleSize);
|
||||||
settings.cameraAngle.resize(cameraTracksAndAngleSize);
|
settings.cameraAngle.resize(cameraTracksAndAngleSize);
|
||||||
|
|
|
@ -51,6 +51,7 @@ namespace PlumageConfig
|
||||||
glm::vec3 bottomCenter = { 0.f,0.f,-6.f };
|
glm::vec3 bottomCenter = { 0.f,0.f,-6.f };
|
||||||
//std::vector<float> bottomCenter = { 0.f,0.f,-6.f };
|
//std::vector<float> bottomCenter = { 0.f,0.f,-6.f };
|
||||||
glm::vec3 bottomNormal = { 0.f,1.0f,0.f };
|
glm::vec3 bottomNormal = { 0.f,1.0f,0.f };
|
||||||
|
glm::vec3 cameraFixation = { -0.5f,1.5f,1.79f };
|
||||||
std::vector<glm::vec3> cameraTracks = { {0.f,0.f,-6.f},{1.f,0.f,-3.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}} };
|
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}} };
|
||||||
|
|
||||||
|
@ -106,7 +107,7 @@ namespace PlumageConfig
|
||||||
std::string brdfVertShaderPath = getAssetPath() + "shaders/genbrdflut.vert.spv";
|
std::string brdfVertShaderPath = getAssetPath() + "shaders/genbrdflut.vert.spv";
|
||||||
std::string brdfFragShaderPath = getAssetPath() + "shaders/genbrdflut.frag.spv";
|
std::string brdfFragShaderPath = getAssetPath() + "shaders/genbrdflut.frag.spv";
|
||||||
// environment map texture
|
// environment map texture
|
||||||
std::string envMapFilePath = getAssetPath() + "environments/brown_photostudio_02_4k_hdr16f_cube.ktx";
|
std::string envMapFilePath = getAssetPath() + "environments/metro_noord_4k_hdr16f_cube.ktx";
|
||||||
std::string emptyEnvmapFilePath = getAssetPath() + "textures/empty.ktx";
|
std::string emptyEnvmapFilePath = getAssetPath() + "textures/empty.ktx";
|
||||||
// pbr shader
|
// pbr shader
|
||||||
std::string pbrVertShaderPath = getAssetPath() + "shaders/pbr.vert.spv";
|
std::string pbrVertShaderPath = getAssetPath() + "shaders/pbr.vert.spv";
|
||||||
|
@ -130,7 +131,7 @@ namespace PlumageConfig
|
||||||
std::string hdr2ktxShFilePath = getAssetPath() + "script/hdr2ktxShFilePath.sh";
|
std::string hdr2ktxShFilePath = getAssetPath() + "script/hdr2ktxShFilePath.sh";
|
||||||
// 配置文件路径,命令行传入后保存在这
|
// 配置文件路径,命令行传入后保存在这
|
||||||
//std::string configFilePath = getAssetPath() + "config/guanzi.toml";
|
//std::string configFilePath = getAssetPath() + "config/guanzi.toml";
|
||||||
std::string configFilePath = getAssetPath() + "config/yukino_traj1_matrix.toml";
|
std::string configFilePath = getAssetPath() + "config/yukino_flat.toml";
|
||||||
|
|
||||||
} filePath;
|
} filePath;
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -1283,4 +1283,12 @@
|
||||||
return nodeFound;
|
return nodeFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void glTFModel::Model::setModelPosition(glm::vec3 position)
|
||||||
|
{
|
||||||
|
|
||||||
|
this->position = position;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -236,6 +236,9 @@ namespace glTFModel
|
||||||
std::vector<Animation> animations;
|
std::vector<Animation> animations;
|
||||||
std::vector<std::string> extensions;
|
std::vector<std::string> extensions;
|
||||||
|
|
||||||
|
glm::vec3 position = glm::vec3();
|
||||||
|
glm::vec3 rotation = glm::vec3();
|
||||||
|
|
||||||
struct Dimensions {
|
struct Dimensions {
|
||||||
glm::vec3 min = glm::vec3(FLT_MAX);
|
glm::vec3 min = glm::vec3(FLT_MAX);
|
||||||
glm::vec3 max = glm::vec3(-FLT_MAX);
|
glm::vec3 max = glm::vec3(-FLT_MAX);
|
||||||
|
@ -266,6 +269,8 @@ namespace glTFModel
|
||||||
void updateAnimation(uint32_t index, float time);
|
void updateAnimation(uint32_t index, float time);
|
||||||
Node* findNode(Node* parent, uint32_t index);
|
Node* findNode(Node* parent, uint32_t index);
|
||||||
Node* nodeFromIndex(uint32_t index);
|
Node* nodeFromIndex(uint32_t index);
|
||||||
|
void setModelPosition(glm::vec3 position);
|
||||||
|
void setModelRotation(glm::vec3 rotation);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1032,10 +1032,11 @@ PlumageRender::PlumageRender()
|
||||||
renderPassBeginInfo.pClearValues = clearValues;
|
renderPassBeginInfo.pClearValues = clearValues;
|
||||||
|
|
||||||
std::vector<glm::mat4> matrices = {
|
std::vector<glm::mat4> matrices = {
|
||||||
|
// posi
|
||||||
glm::rotate(glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
glm::rotate(glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
||||||
glm::rotate(glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(0.0f, 1.0f, 0.0f)), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
glm::rotate(glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(0.0f, 1.0f, 0.0f)), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
||||||
glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
|
||||||
glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
||||||
|
glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
||||||
glm::rotate(glm::mat4(1.0f), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
glm::rotate(glm::mat4(1.0f), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
|
||||||
glm::rotate(glm::mat4(1.0f), glm::radians(180.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
|
glm::rotate(glm::mat4(1.0f), glm::radians(180.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
|
||||||
};
|
};
|
||||||
|
@ -1047,7 +1048,7 @@ PlumageRender::PlumageRender()
|
||||||
viewport.height = (float)dim;
|
viewport.height = (float)dim;
|
||||||
viewport.minDepth = 0.0f;
|
viewport.minDepth = 0.0f;
|
||||||
viewport.maxDepth = 1.0f;
|
viewport.maxDepth = 1.0f;
|
||||||
viewport.x = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1445,9 +1446,11 @@ PlumageRender::PlumageRender()
|
||||||
|
|
||||||
VkViewport viewport{};
|
VkViewport viewport{};
|
||||||
viewport.width = (float)dim;
|
viewport.width = (float)dim;
|
||||||
viewport.height = (float)dim;
|
viewport.height = -(float)dim;
|
||||||
viewport.minDepth = 0.0f;
|
viewport.minDepth = 0.0f;
|
||||||
viewport.maxDepth = 1.0f;
|
viewport.maxDepth = 1.0f;
|
||||||
|
viewport.x = 0;
|
||||||
|
viewport.y = -viewport.height;
|
||||||
|
|
||||||
VkRect2D scissor{};
|
VkRect2D scissor{};
|
||||||
scissor.extent.width = dim;
|
scissor.extent.width = dim;
|
||||||
|
@ -1497,24 +1500,35 @@ PlumageRender::PlumageRender()
|
||||||
|
|
||||||
float modelSize = std::max(models.scene.aabb[0][0], std::max(models.scene.aabb[1][1], models.scene.aabb[2][2]));
|
float modelSize = std::max(models.scene.aabb[0][0], std::max(models.scene.aabb[1][1], models.scene.aabb[2][2]));
|
||||||
// Center and scale model
|
// Center and scale model
|
||||||
float scale = (1.0f / modelSize ) * 2.0f;
|
float scale = (1.0f / modelSize ) * 5.0f;
|
||||||
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 += -2.0f * glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]);
|
//translate += -glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]);
|
||||||
translate += -2.0f * settings.bottomCenter;
|
//translate += -2.0f * settings.bottomCenter;
|
||||||
//camera.setPosition(glm::vec3(0, 0, -modelSize - 2));
|
//camera.setPosition(glm::vec3(0, 0, -modelSize - 2));
|
||||||
|
glm::vec3 aabbMax = glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]);
|
||||||
|
glm::vec3 aabbMin = glm::vec3(models.scene.aabb[3][0], models.scene.aabb[3][1], models.scene.aabb[3][2]);
|
||||||
|
glm::vec3 modelCenter = 0.5f * (aabbMin + aabbMax);
|
||||||
|
|
||||||
shaderDataScene.model = glm::mat4(1.0f);
|
|
||||||
shaderDataScene.model[0][0] = scale;
|
glm::vec3 translate = settings.cameraFixation - modelCenter;
|
||||||
shaderDataScene.model[1][1] = scale;
|
//translate = modelCenter + translate ;
|
||||||
shaderDataScene.model[2][2] = scale;
|
//shaderDataScene.model = glm::translate(glm::mat4(1.0f), translate);
|
||||||
|
//glm::vec3 translate = settings.cameraFixation;
|
||||||
|
shaderDataScene.model = glm::scale(glm::mat4(1.0f), glm::vec3(scale, scale, scale));
|
||||||
|
//glm::mat4 scaleModelMatrix = glm::scale(glm::mat4(1.0f),glm::vec3(scale,scale,scale));
|
||||||
|
//glm::mat4 translateMatrix = glm::translate(glm::mat4(1.0f), translate);
|
||||||
|
shaderDataScene.model = glm::translate(glm::mat4(1.0f), modelCenter);
|
||||||
shaderDataScene.model = glm::translate(shaderDataScene.model, translate);
|
shaderDataScene.model = glm::translate(shaderDataScene.model, translate);
|
||||||
|
//shaderDataScene.model = glm::scale()
|
||||||
|
|
||||||
if (settings.rotateModel)
|
glm::mat4 rotationMatrix = glm::mat4(1.0f);
|
||||||
{
|
glm::vec4 topNormal = glm::vec4(0,1,0,0);
|
||||||
shaderDataScene.model = glm::mat4(1.0f);
|
glm::vec4 modelTopNormal4 = glm::transpose(glm::inverse(shaderDataScene.model)) * topNormal;
|
||||||
shaderDataScene.model = glm::rotate(shaderDataScene.model, glm::radians(modelrot), glm::vec3(0, 1, 0));
|
glm::vec3 modelTopNormal3 = glm::vec3(modelTopNormal4[0], modelTopNormal4[1], modelTopNormal4[2]);
|
||||||
}
|
glm::vec3 rotationAxis = glm::normalize(glm::cross(settings.bottomNormal, modelTopNormal3));
|
||||||
|
float cosTheta = glm::dot(settings.bottomNormal, modelTopNormal3);
|
||||||
|
float angle = acos(cosTheta);
|
||||||
|
shaderDataScene.model = glm::rotate(glm::mat4(1.0f), angle, rotationAxis);
|
||||||
/*
|
/*
|
||||||
shaderDataScene.camPos = glm::vec3(
|
shaderDataScene.camPos = glm::vec3(
|
||||||
-camera.position.z * sin(glm::radians(camera.rotation.y)) * cos(glm::radians(camera.rotation.x)),
|
-camera.position.z * sin(glm::radians(camera.rotation.y)) * cos(glm::radians(camera.rotation.x)),
|
||||||
|
@ -1522,9 +1536,19 @@ PlumageRender::PlumageRender()
|
||||||
camera.position.z * cos(glm::radians(camera.rotation.y)) * cos(glm::radians(camera.rotation.x))
|
camera.position.z * cos(glm::radians(camera.rotation.y)) * cos(glm::radians(camera.rotation.x))
|
||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
|
glm::mat4 selfRotationMatrix = glm::mat4(1.0f);
|
||||||
|
|
||||||
|
if (settings.rotateModel)
|
||||||
|
{
|
||||||
|
|
||||||
|
selfRotationMatrix = glm::rotate(shaderDataScene.model, glm::radians(modelrot), glm::vec3(0, 1, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
//shaderDataScene.model = translateMatrix * rotationMatrix * scaleModelMatrix
|
||||||
|
//shaderDataScene.model = rotationMatrix * scaleModelMatrix;
|
||||||
shaderDataScene.camPos = settings.cameraTracks[currentFrame];
|
shaderDataScene.camPos = settings.cameraTracks[currentFrame];
|
||||||
|
|
||||||
|
shaderDataScene.model = selfRotationMatrix;
|
||||||
// Skybox
|
// Skybox
|
||||||
shaderDataSkybox.projection = camera.matrices.perspective;
|
shaderDataSkybox.projection = camera.matrices.perspective;
|
||||||
shaderDataSkybox.view = camera.matrices.view;
|
shaderDataSkybox.view = camera.matrices.view;
|
||||||
|
@ -1552,7 +1576,7 @@ PlumageRender::PlumageRender()
|
||||||
|
|
||||||
camera.setProjectionMatrix(settings.fX,settings.fY,settings.cX,settings.cY,1.f, 256.f,settings.calibrationWidth,settings.calibrationHeight,false,true);
|
camera.setProjectionMatrix(settings.fX,settings.fY,settings.cX,settings.cY,1.f, 256.f,settings.calibrationWidth,settings.calibrationHeight,false,true);
|
||||||
//camera.setPerspective(settings.fX, settings.fY, settings.cX, settings.cY, 1.0f, 256.0f);
|
//camera.setPerspective(settings.fX, settings.fY, settings.cX, settings.cY, 1.0f, 256.0f);
|
||||||
camera.setTo(settings.bottomCenter);
|
camera.setTo(settings.cameraFixation);
|
||||||
camera.setUp(settings.bottomNormal);
|
camera.setUp(settings.bottomNormal);
|
||||||
camera.rotationSpeed = 0.25f;
|
camera.rotationSpeed = 0.25f;
|
||||||
camera.movementSpeed = 0.1f;
|
camera.movementSpeed = 0.1f;
|
||||||
|
@ -1923,7 +1947,7 @@ PlumageRender::PlumageRender()
|
||||||
std::string commandLineFrameRate = std::to_string(settings.videoFrameRate);
|
std::string commandLineFrameRate = std::to_string(settings.videoFrameRate);
|
||||||
std::filesystem::path image2videoBatFilePath = filePath.image2videoBatFilePath;
|
std::filesystem::path image2videoBatFilePath = filePath.image2videoBatFilePath;
|
||||||
|
|
||||||
filePath.image2videoBatFilePath = image2videoBatFilePath.lexically_proximate(image2videoBatFilePath.root_path()).generic_string();
|
//filePath.image2videoBatFilePath = image2videoBatFilePath.lexically_proximate(image2videoBatFilePath.root_path()).generic_string();
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string commandLine = filePath.image2videoBatFilePath + " " + commandLineFrameRate + " " + commandLineImageSequencePath + " " + resultVideoPath;
|
std::string commandLine = filePath.image2videoBatFilePath + " " + commandLineFrameRate + " " + commandLineImageSequencePath + " " + resultVideoPath;
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue