Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/geometry/geo_reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 と同じです。
Expand Down
36 changes: 36 additions & 0 deletions src/mesh_writer/fbx_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,42 @@ namespace plateau::meshWriter {
ios->SetBoolProp(EXP_ASCIIFBX, options.file_format == FbxFileFormat::ASCII);
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::eParityOdd, // X,Y,ZからUp軸を除いて、残った2軸のうち前者ならParityEven, 後者ならParityOdd
FbxAxisSystem::eRightHanded); // フレミングの法則の要領で中指を折ったとき、親指がX、人差し指がY、中指がZ。左右どちらの手に合うか。
break;
case geometry::CoordinateSystem::ESU:
axis_system = FbxAxisSystem(
FbxAxisSystem::EUpVector::eZAxis,
FbxAxisSystem::EFrontVector::eParityOdd,
FbxAxisSystem::eLeftHanded);
break;
case geometry::CoordinateSystem::WUN:
axis_system = FbxAxisSystem(
FbxAxisSystem::EUpVector::eYAxis,
FbxAxisSystem::EFrontVector::eParityOdd,
FbxAxisSystem::eRightHanded);
break;
case geometry::CoordinateSystem::EUN:
axis_system = FbxAxisSystem(
FbxAxisSystem::EUpVector::eYAxis,
FbxAxisSystem::EFrontVector::eParityOdd,
FbxAxisSystem::eLeftHanded);
break;
}
// 座標軸の向きをFBXファイルに書き込みます。
// これを確認するには、FBXをASCIIフォーマットで出力してテキストエディタで開き、
// GlobalSettingsのPropertiesのAxis系プロパティを確認します。
// これにより、どの座標軸で書き出したとしてもアプリケーションにFBXをインポートするときに向き補正が働き、
// 同じ向きに読み込めるはずです(非推奨の左手座標系は除く)。
fbx_scene->GetGlobalSettings().SetAxisSystem(axis_system);

// create scene info
FbxDocumentInfo* SceneInfo = FbxDocumentInfo::Create(manager_, "SceneInfo");
fbx_scene->SetSceneInfo(SceneInfo);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using PLATEAU.Geometries;
using PLATEAU.Interop;
using PLATEAU.PolygonMesh;

Expand All @@ -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;
}
}

Expand Down