Fix PBRT exporter coordinate system

Was just mirroring the x axis. This uses aiProcess_ConvertToLeftHanded and
rotates the root node to match PBRT.

The problem is apparent when using an environment map texture.
pull/5082/head
Samuel Kogler 2023-05-03 16:49:27 +02:00
parent f32c21e6b3
commit 55cb19f924
3 changed files with 24 additions and 6 deletions

View File

@ -225,7 +225,7 @@ static void setupExporterArray(std::vector<Exporter::ExportFormatEntry> &exporte
#endif
#ifndef ASSIMP_BUILD_NO_PBRT_EXPORTER
exporters.emplace_back("pbrt", "pbrt-v4 scene description file", "pbrt", &ExportScenePbrt, aiProcess_Triangulate | aiProcess_SortByPType);
exporters.emplace_back("pbrt", "pbrt-v4 scene description file", "pbrt", &ExportScenePbrt, aiProcess_ConvertToLeftHanded | aiProcess_Triangulate | aiProcess_SortByPType);
#endif
#ifndef ASSIMP_BUILD_NO_ASSJSON_EXPORTER

View File

@ -111,7 +111,22 @@ PbrtExporter::PbrtExporter(
mScene(pScene),
mIOSystem(pIOSystem),
mPath(path),
mFile(file) {
mFile(file),
mRootTransform(
// rotates the (already left-handed) CRS -90 degrees around the x axis in order to
// make +Z 'up' and +Y 'towards viewer', as in default in pbrt
1.f, 0.f, 0.f, 0.f, //
0.f, 0.f, -1.f, 0.f, //
0.f, 1.f, 0.f, 0.f, //
0.f, 0.f, 0.f, 1.f //
) {
mRootTransform = aiMatrix4x4(
-1.f, 0, 0.f, 0.f, //
0.0f, -1.f, 0.f, 0.f, //
0.f, 0.f, 1.f, 0.f, //
0.f, 0.f, 0.f, 1.f //
) * mRootTransform;
// Export embedded textures.
if (mScene->mNumTextures > 0)
if (!mIOSystem->CreateDirectory("textures"))
@ -260,7 +275,7 @@ aiMatrix4x4 PbrtExporter::GetNodeTransform(const aiString &name) const {
node = node->mParent;
}
}
return m;
return mRootTransform * m;
}
std::string PbrtExporter::TransformAsString(const aiMatrix4x4 &m) {
@ -327,7 +342,7 @@ void PbrtExporter::WriteCamera(int i) {
if (!cameraActive)
mOutput << "# ";
mOutput << "Scale -1 1 1\n"; // right handed -> left handed
mOutput << "Scale 1 1 1\n";
if (!cameraActive)
mOutput << "# ";
mOutput << "LookAt "
@ -383,8 +398,8 @@ void PbrtExporter::WriteWorldDefinition() {
}
mOutput << "# Geometry\n\n";
aiMatrix4x4 worldFromObject;
WriteGeometricObjects(mScene->mRootNode, worldFromObject, meshUses);
WriteGeometricObjects(mScene->mRootNode, mRootTransform, meshUses);
}
void PbrtExporter::WriteTextures() {

View File

@ -100,6 +100,9 @@ private:
// A private set to keep track of which textures have been declared
std::set<std::string> mTextureSet;
// Transform to apply to the root node and all root objects such as cameras, lights, etc.
aiMatrix4x4 mRootTransform;
aiMatrix4x4 GetNodeTransform(const aiString& name) const;
static std::string TransformAsString(const aiMatrix4x4& m);