From b7b9f1673ac843c8b3789a947351ae18cb3d31e2 Mon Sep 17 00:00:00 2001 From: sevendev Date: Tue, 13 May 2025 16:22:05 +0900 Subject: [PATCH 1/6] =?UTF-8?q?FBX=20export=E6=99=82=E3=81=AE=E8=BB=B8?= =?UTF-8?q?=E5=A4=89=E6=8F=9B=E5=87=A6=E7=90=86=E3=82=92=E3=81=AA=E3=81=8F?= =?UTF-8?q?=E3=81=99=EF=BC=882=E9=87=8D=E5=A4=89=E6=8F=9B=E3=81=AB?= =?UTF-8?q?=E3=81=AA=E3=81=A3=E3=81=A6=E3=81=97=E3=81=BE=E3=81=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mesh_writer/fbx_writer.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/src/mesh_writer/fbx_writer.cpp b/src/mesh_writer/fbx_writer.cpp index 63b33c9f..70eabbbe 100644 --- a/src/mesh_writer/fbx_writer.cpp +++ b/src/mesh_writer/fbx_writer.cpp @@ -44,34 +44,6 @@ namespace plateau::meshWriter { ios->SetBoolProp(EXP_FBX_GLOBAL_SETTINGS, true); ios->SetBoolProp(EXP_ASCIIFBX, options.file_format == FbxFileFormat::ASCII); const auto fbx_scene = FbxScene::Create(manager_, ""); - FbxAxisSystem axis_system; - switch (options.coordinate_system) { - case geometry::CoordinateSystem::ENU: - axis_system = FbxAxisSystem( - FbxAxisSystem::EUpVector::eZAxis, - FbxAxisSystem::EFrontVector::eParityEven, - FbxAxisSystem::eRightHanded); - break; - case geometry::CoordinateSystem::ESU: - axis_system = FbxAxisSystem( - FbxAxisSystem::EUpVector::eZAxis, - FbxAxisSystem::EFrontVector::eParityEven, - FbxAxisSystem::eLeftHanded); - break; - case geometry::CoordinateSystem::WUN: - axis_system = FbxAxisSystem( - FbxAxisSystem::EUpVector::eYAxis, - FbxAxisSystem::EFrontVector::eParityEven, - FbxAxisSystem::eRightHanded); - break; - case geometry::CoordinateSystem::EUN: - axis_system = FbxAxisSystem( - FbxAxisSystem::EUpVector::eYAxis, - FbxAxisSystem::EFrontVector::eParityEven, - FbxAxisSystem::eLeftHanded); - break; - } - axis_system.ConvertScene(fbx_scene); // create scene info FbxDocumentInfo* SceneInfo = FbxDocumentInfo::Create(manager_, "SceneInfo"); From 9404c41e35ec8378c715f3e1e82c4af9f63b6303 Mon Sep 17 00:00:00 2001 From: Linoal <1321932+linoal@users.noreply.github.com> Date: Wed, 14 May 2025 23:21:21 +0900 Subject: [PATCH 2/6] =?UTF-8?q?(=E8=A9=A6=E9=A8=93=E7=9A=84)=20fbx?= =?UTF-8?q?=E5=86=85=E3=81=AB=E5=BA=A7=E6=A8=99=E8=BB=B8=E3=82=92=E6=9B=B8?= =?UTF-8?q?=E3=81=8D=E8=BE=BC=E3=82=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mesh_writer/fbx_writer.cpp | 29 +++++++++++++++++++ .../CSharpPLATEAU/MeshWriter/FbxWriter.cs | 5 +++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/mesh_writer/fbx_writer.cpp b/src/mesh_writer/fbx_writer.cpp index 70eabbbe..69ced3ac 100644 --- a/src/mesh_writer/fbx_writer.cpp +++ b/src/mesh_writer/fbx_writer.cpp @@ -45,6 +45,35 @@ namespace plateau::meshWriter { ios->SetBoolProp(EXP_ASCIIFBX, options.file_format == FbxFileFormat::ASCII); const auto fbx_scene = FbxScene::Create(manager_, ""); + FbxAxisSystem axis_system; + switch (options.coordinate_system) { + case geometry::CoordinateSystem::ENU: + axis_system = FbxAxisSystem( + FbxAxisSystem::EUpVector::eZAxis, + FbxAxisSystem::EFrontVector::eParityEven, + FbxAxisSystem::eRightHanded); + break; + case geometry::CoordinateSystem::ESU: + axis_system = FbxAxisSystem( + FbxAxisSystem::EUpVector::eZAxis, + FbxAxisSystem::EFrontVector::eParityEven, + FbxAxisSystem::eLeftHanded); + break; + case geometry::CoordinateSystem::WUN: + axis_system = FbxAxisSystem( + FbxAxisSystem::EUpVector::eYAxis, + FbxAxisSystem::EFrontVector::eParityOdd, + FbxAxisSystem::eLeftHanded); + break; + case geometry::CoordinateSystem::EUN: + axis_system = FbxAxisSystem( + FbxAxisSystem::EUpVector::eYAxis, + FbxAxisSystem::EFrontVector::eParityEven, + FbxAxisSystem::eLeftHanded); + break; + } + fbx_scene->GetGlobalSettings().SetAxisSystem(axis_system); + // create scene info FbxDocumentInfo* SceneInfo = FbxDocumentInfo::Create(manager_, "SceneInfo"); fbx_scene->SetSceneInfo(SceneInfo); diff --git a/wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/MeshWriter/FbxWriter.cs b/wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/MeshWriter/FbxWriter.cs index d024e37c..8d1728e2 100644 --- a/wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/MeshWriter/FbxWriter.cs +++ b/wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/MeshWriter/FbxWriter.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using PLATEAU.Geometries; using PLATEAU.Interop; using PLATEAU.PolygonMesh; @@ -9,10 +10,12 @@ namespace PLATEAU.MeshWriter public struct FbxWriteOptions { public FbxFileFormat FileFormat; + public CoordinateSystem CoordinateSystem; - public FbxWriteOptions(FbxFileFormat fileFormat) + public FbxWriteOptions(FbxFileFormat fileFormat, CoordinateSystem coordinateSystem) { this.FileFormat = fileFormat; + this.CoordinateSystem = coordinateSystem; } } From 46be5194bc55b06b1d393ebad6647517ecd53d48 Mon Sep 17 00:00:00 2001 From: Linoal <1321932+linoal@users.noreply.github.com> Date: Thu, 15 May 2025 01:10:20 +0900 Subject: [PATCH 3/6] wun fix --- src/mesh_writer/fbx_writer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh_writer/fbx_writer.cpp b/src/mesh_writer/fbx_writer.cpp index 69ced3ac..704d1b6e 100644 --- a/src/mesh_writer/fbx_writer.cpp +++ b/src/mesh_writer/fbx_writer.cpp @@ -63,7 +63,7 @@ namespace plateau::meshWriter { axis_system = FbxAxisSystem( FbxAxisSystem::EUpVector::eYAxis, FbxAxisSystem::EFrontVector::eParityOdd, - FbxAxisSystem::eLeftHanded); + FbxAxisSystem::eRightHanded); break; case geometry::CoordinateSystem::EUN: axis_system = FbxAxisSystem( From 1f036ddf4543197191eb9e607c8485410fb7cd74 Mon Sep 17 00:00:00 2001 From: Linoal <1321932+linoal@users.noreply.github.com> Date: Tue, 27 May 2025 02:22:39 +0900 Subject: [PATCH 4/6] =?UTF-8?q?fbx=E5=87=BA=E5=8A=9B=E3=81=AE=E5=BA=A7?= =?UTF-8?q?=E6=A8=99=E8=BB=B8=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/geometry/geo_reference.cpp | 2 +- src/mesh_writer/fbx_writer.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/geometry/geo_reference.cpp b/src/geometry/geo_reference.cpp index 8c04eba3..81479fd4 100644 --- a/src/geometry/geo_reference.cpp +++ b/src/geometry/geo_reference.cpp @@ -86,7 +86,7 @@ namespace plateau::geometry { // WUN → ENU の式は 逆変換 ENU → WUN と同じです。 return { -vertex.x, vertex.z, vertex.y }; case CoordinateSystem::ESU: - // EUN → ESU の式は 逆変換 ESU → EUN と同じです。 + // ENU → ESU の式は 逆変換 ESU → ENU と同じです。 return { vertex.x, -vertex.y, vertex.z }; case CoordinateSystem::EUN: // EUN → ENU の式は 逆変換 ENU → EUN と同じです。 diff --git a/src/mesh_writer/fbx_writer.cpp b/src/mesh_writer/fbx_writer.cpp index 704d1b6e..6fef3b75 100644 --- a/src/mesh_writer/fbx_writer.cpp +++ b/src/mesh_writer/fbx_writer.cpp @@ -46,17 +46,19 @@ namespace plateau::meshWriter { const auto fbx_scene = FbxScene::Create(manager_, ""); FbxAxisSystem axis_system; + // FBXのデファクトは右手座標系です。 + // 左手座標系ではUnityやUEで正しく読み込めないことがあるため非推奨です。 switch (options.coordinate_system) { case geometry::CoordinateSystem::ENU: axis_system = FbxAxisSystem( FbxAxisSystem::EUpVector::eZAxis, - FbxAxisSystem::EFrontVector::eParityEven, + FbxAxisSystem::EFrontVector::eParityOdd, FbxAxisSystem::eRightHanded); break; case geometry::CoordinateSystem::ESU: axis_system = FbxAxisSystem( FbxAxisSystem::EUpVector::eZAxis, - FbxAxisSystem::EFrontVector::eParityEven, + FbxAxisSystem::EFrontVector::eParityOdd, FbxAxisSystem::eLeftHanded); break; case geometry::CoordinateSystem::WUN: @@ -68,7 +70,7 @@ namespace plateau::meshWriter { case geometry::CoordinateSystem::EUN: axis_system = FbxAxisSystem( FbxAxisSystem::EUpVector::eYAxis, - FbxAxisSystem::EFrontVector::eParityEven, + FbxAxisSystem::EFrontVector::eParityOdd, FbxAxisSystem::eLeftHanded); break; } From db884868ae8ea96742a643ef833ea833fad26e0f Mon Sep 17 00:00:00 2001 From: Linoal <1321932+linoal@users.noreply.github.com> Date: Tue, 27 May 2025 03:08:27 +0900 Subject: [PATCH 5/6] unit test fix --- .../CSharpPLATEAU.Test/MeshWriter/FbxWriterTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/MeshWriter/FbxWriterTest.cs b/wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/MeshWriter/FbxWriterTest.cs index d0b7672b..3a5b52cd 100644 --- a/wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/MeshWriter/FbxWriterTest.cs +++ b/wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/MeshWriter/FbxWriterTest.cs @@ -1,5 +1,6 @@ using System.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; +using PLATEAU.Geometries; using PLATEAU.MeshWriter; using PLATEAU.Test.CityGML; using PLATEAU.Test.GeometryModel; @@ -19,7 +20,7 @@ public void WriteGenerateFbxFile() string gmlPath = TestUtil.GetGmlPath(TestUtil.GmlFileCase.Simple); string fbxFileName = Path.GetFileNameWithoutExtension(gmlPath) + ".fbx"; string fbxPath = Path.Combine(testDir, fbxFileName); - var option = new FbxWriteOptions(FbxFileFormat.Binary); + var option = new FbxWriteOptions(FbxFileFormat.Binary, CoordinateSystem.ENU); bool isSucceed = FbxWriter.Write(fbxPath, model, option); From ff1ecbf18f8ebf63c6a7a574f991f5afbc5b7397 Mon Sep 17 00:00:00 2001 From: Linoal <1321932+linoal@users.noreply.github.com> Date: Tue, 27 May 2025 03:24:33 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E8=BF=BD=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mesh_writer/fbx_writer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mesh_writer/fbx_writer.cpp b/src/mesh_writer/fbx_writer.cpp index 6fef3b75..856ff927 100644 --- a/src/mesh_writer/fbx_writer.cpp +++ b/src/mesh_writer/fbx_writer.cpp @@ -52,8 +52,8 @@ namespace plateau::meshWriter { case geometry::CoordinateSystem::ENU: axis_system = FbxAxisSystem( FbxAxisSystem::EUpVector::eZAxis, - FbxAxisSystem::EFrontVector::eParityOdd, - FbxAxisSystem::eRightHanded); + FbxAxisSystem::EFrontVector::eParityOdd, // X,Y,ZからUp軸を除いて、残った2軸のうち前者ならParityEven, 後者ならParityOdd + FbxAxisSystem::eRightHanded); // フレミングの法則の要領で中指を折ったとき、親指がX、人差し指がY、中指がZ。左右どちらの手に合うか。 break; case geometry::CoordinateSystem::ESU: axis_system = FbxAxisSystem( @@ -74,6 +74,11 @@ namespace plateau::meshWriter { FbxAxisSystem::eLeftHanded); break; } + // 座標軸の向きをFBXファイルに書き込みます。 + // これを確認するには、FBXをASCIIフォーマットで出力してテキストエディタで開き、 + // GlobalSettingsのPropertiesのAxis系プロパティを確認します。 + // これにより、どの座標軸で書き出したとしてもアプリケーションにFBXをインポートするときに向き補正が働き、 + // 同じ向きに読み込めるはずです(非推奨の左手座標系は除く)。 fbx_scene->GetGlobalSettings().SetAxisSystem(axis_system); // create scene info