textured_max_lod でテクスチャの無い建物のジオメトリが消える不具合の修正 - #1
Open
kurouna wants to merge 1 commit into
Open
Conversation
TexturedHighest のLOD選択が、探索ループの中で破壊的な edit_tree を呼び、かつテクスチャ判定を エンティティ全体の appearance_store で行っていた(LOD非依存)。このためテクスチャを持たない フィーチャはループの過程でジオメトリが空になり、出力から消えていた。 polygon_textures(ApplyAppearanceTransform が本変換の前に解決する、ポリゴン単位のテクスチャ 割り当て)でLODごとに非破壊で判定し、テクスチャを持つ最上位LOD(無ければ最上位LOD)を選んで edit_tree は一度だけ呼ぶように修正。ユニットテストを追加。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
--sink gltf -t use_lod=textured_max_lodで変換すると、テクスチャを持たない建物(住宅地に多いです)のジオメトリが出力から丸ごと消えてしまいます。テクスチャ付きの建物は問題なく出ます。さいたま市(大宮周辺)のデータを変換していて、住宅街がごっそり抜け落ちることで気づきました。あるメッシュ(
53396479)だと、修正前は約 1,900 頂点しか残らないのに、修正後は約 62,000 頂点になります。衝突判定用に別途 GeoJSON で出しているフットプリント側には建物があるのに、glTF 側だけ消えている、という状態でした。原因
nusamai/src/transformer/transform/lods.rsのLodFilterMode::TexturedHighestです。edit_treeはgeometries.retain(|g| g.lod == target_lod)で対象以外の LOD のジオメトリを破棄します。これを探索ループの中で毎回呼んでいるので、LOD を降りながら順にジオメトリを壊してしまい、あとから戻せません。appearance_store(エンティティ全体が持つテクスチャ画像の有無)で見ていますが、これはedit_treeでは刈られないため、LOD ごとの判定になっていません(実質「このエンティティにテクスチャが 1 枚でもあるか」という、LOD によらない定数になっています)。この結果、テクスチャ付きのエンティティは最初の反復(最上位 LOD)で
breakするのでたまたま正しく動きますが、テクスチャの無いエンティティはループが最後まで回ってジオメトリが空になり、消えてしまいます(本来は「最上位 LOD にフォールバック」したいはずの分岐です)。修正
polygon_textures(ポリゴン単位のテクスチャ割り当て。ApplyAppearanceTransformがFilterLodTransformより前に解決します)を使って、各 LOD にテクスチャ付きのポリゴンがあるかを 非破壊で 判定するようにしました。テクスチャを持つ最上位 LOD を選び、無ければ最上位 LOD にフォールバックして、edit_treeは対象 LOD を決めてから一度だけ呼びます。これでテクスチャの無い建物もジオメトリを保ったまま出力されます。textured_max_lodはset_appearance(true)で appearance を有効化するため、本変換の時点でpolygon_texturesは解決済みです。万一空(appearance 未解決)の場合は最上位 LOD にフォールバックするので、ジオメトリが失われることはありません。テスト
lods.rsにユニットテストを追加しました。動作確認
実データで再変換して確認しました。
53394611): 頂点数は変化なし(元からテクスチャ付きなので影響を受けません)。