Skip to content

Commit 0cfa9b3

Browse files
Merge pull request #278 from Synesthesias/exp/fbx_fix
FBXエクスポート時にfbxファイルに座標軸を書き出すように
2 parents 0c0ee5d + ff1ecbf commit 0cfa9b3

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/geometry/geo_reference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace plateau::geometry {
8686
// WUN → ENU の式は 逆変換 ENU → WUN と同じです。
8787
return { -vertex.x, vertex.z, vertex.y };
8888
case CoordinateSystem::ESU:
89-
// EUN → ESU の式は 逆変換 ESU → EUN と同じです。
89+
// ENU → ESU の式は 逆変換 ESU → ENU と同じです。
9090
return { vertex.x, -vertex.y, vertex.z };
9191
case CoordinateSystem::EUN:
9292
// EUN → ENU の式は 逆変換 ENU → EUN と同じです。

src/mesh_writer/fbx_writer.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,42 @@ namespace plateau::meshWriter {
4545
ios->SetBoolProp(EXP_ASCIIFBX, options.file_format == FbxFileFormat::ASCII);
4646
const auto fbx_scene = FbxScene::Create(manager_, "");
4747

48+
FbxAxisSystem axis_system;
49+
// FBXのデファクトは右手座標系です。
50+
// 左手座標系ではUnityやUEで正しく読み込めないことがあるため非推奨です。
51+
switch (options.coordinate_system) {
52+
case geometry::CoordinateSystem::ENU:
53+
axis_system = FbxAxisSystem(
54+
FbxAxisSystem::EUpVector::eZAxis,
55+
FbxAxisSystem::EFrontVector::eParityOdd, // X,Y,ZからUp軸を除いて、残った2軸のうち前者ならParityEven, 後者ならParityOdd
56+
FbxAxisSystem::eRightHanded); // フレミングの法則の要領で中指を折ったとき、親指がX、人差し指がY、中指がZ。左右どちらの手に合うか。
57+
break;
58+
case geometry::CoordinateSystem::ESU:
59+
axis_system = FbxAxisSystem(
60+
FbxAxisSystem::EUpVector::eZAxis,
61+
FbxAxisSystem::EFrontVector::eParityOdd,
62+
FbxAxisSystem::eLeftHanded);
63+
break;
64+
case geometry::CoordinateSystem::WUN:
65+
axis_system = FbxAxisSystem(
66+
FbxAxisSystem::EUpVector::eYAxis,
67+
FbxAxisSystem::EFrontVector::eParityOdd,
68+
FbxAxisSystem::eRightHanded);
69+
break;
70+
case geometry::CoordinateSystem::EUN:
71+
axis_system = FbxAxisSystem(
72+
FbxAxisSystem::EUpVector::eYAxis,
73+
FbxAxisSystem::EFrontVector::eParityOdd,
74+
FbxAxisSystem::eLeftHanded);
75+
break;
76+
}
77+
// 座標軸の向きをFBXファイルに書き込みます。
78+
// これを確認するには、FBXをASCIIフォーマットで出力してテキストエディタで開き、
79+
// GlobalSettingsのPropertiesのAxis系プロパティを確認します。
80+
// これにより、どの座標軸で書き出したとしてもアプリケーションにFBXをインポートするときに向き補正が働き、
81+
// 同じ向きに読み込めるはずです(非推奨の左手座標系は除く)。
82+
fbx_scene->GetGlobalSettings().SetAxisSystem(axis_system);
83+
4884
// create scene info
4985
FbxDocumentInfo* SceneInfo = FbxDocumentInfo::Create(manager_, "SceneInfo");
5086
fbx_scene->SetSceneInfo(SceneInfo);

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU.Test/MeshWriter/FbxWriterTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.IO;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using PLATEAU.Geometries;
34
using PLATEAU.MeshWriter;
45
using PLATEAU.Test.CityGML;
56
using PLATEAU.Test.GeometryModel;
@@ -19,7 +20,7 @@ public void WriteGenerateFbxFile()
1920
string gmlPath = TestUtil.GetGmlPath(TestUtil.GmlFileCase.Simple);
2021
string fbxFileName = Path.GetFileNameWithoutExtension(gmlPath) + ".fbx";
2122
string fbxPath = Path.Combine(testDir, fbxFileName);
22-
var option = new FbxWriteOptions(FbxFileFormat.Binary);
23+
var option = new FbxWriteOptions(FbxFileFormat.Binary, CoordinateSystem.ENU);
2324

2425
bool isSucceed = FbxWriter.Write(fbxPath, model, option);
2526

wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/MeshWriter/FbxWriter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using PLATEAU.Geometries;
34
using PLATEAU.Interop;
45
using PLATEAU.PolygonMesh;
56

@@ -9,10 +10,12 @@ namespace PLATEAU.MeshWriter
910
public struct FbxWriteOptions
1011
{
1112
public FbxFileFormat FileFormat;
13+
public CoordinateSystem CoordinateSystem;
1214

13-
public FbxWriteOptions(FbxFileFormat fileFormat)
15+
public FbxWriteOptions(FbxFileFormat fileFormat, CoordinateSystem coordinateSystem)
1416
{
1517
this.FileFormat = fileFormat;
18+
this.CoordinateSystem = coordinateSystem;
1619
}
1720
}
1821

0 commit comments

Comments
 (0)