Skip to content

Commit

Permalink
アピアランスをジオメトリに紐づける (#276)
Browse files Browse the repository at this point in the history
AppearanceStore がもつアピアランスの情報を GeometryStore に紐づける。

この処理はパースの時点ではなく、 Transformer stage
において行う。都市モデルは、アピアランスとして複数のテーマを持ちうるため、どのテーマを適用するかは、パースの時点で決められない/決めないほうがよいという考え。

relates: #195

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **新機能**
    - ジオメトリ情報に材質、テクスチャ、UVマッピングのフィールドを追加しました。
    - 外部からアクセス可能にするために、テーマ構造体と外観ストア構造体の特定のフィールドを公開しました。
    - エンティティに材質とテクスチャを適用する新しい外観変換機能を追加しました。
    - CesiumタイルとGLTF出力のための外観解決設定を追加しました。

- **バグ修正**
    - 特定条件下で終了点を削除するロジックを改善しました。

- **リファクタ**
    - ソースコードの整理と、一部のデータ提供者の再配置および削除を行いました。
    - 外観変換の適用ロジックに新しい条件ブロックを追加しました。

- **その他の変更**
    - 新しいモジュールを追加し、モジュール宣言の順序を調整しました。

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
ciscorn authored Feb 15, 2024
1 parent 73a80a7 commit 201c7aa
Show file tree
Hide file tree
Showing 17 changed files with 10,967 additions and 13 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,14 @@ Build:
cd ./app
npx tauri build
```

### Test

#### Coverage

Codecov: https://app.codecov.io/gh/MIERUNE/nusamai

```bash
cargo llvm-cov --workspace --exclude app --html --all-features
```

10 changes: 9 additions & 1 deletion nusamai-citygml/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct GeometryStore {
/// EPSG code of the Coordinate Reference System (CRS) for this geometry
pub epsg: EPSGCode,

/// Shared vertex buffer for all geometries
/// Shared vertex buffer for all geometries in this store
pub vertices: Vec<[f64; 3]>,

/// All polygons, referenced by `GeometryRefs`
Expand All @@ -63,6 +63,13 @@ pub struct GeometryStore {
pub ring_ids: Vec<Option<LocalId>>,
/// List of surface ids and their spans in `multipolygon`
pub surface_spans: Vec<SurfaceSpan>,

/// Assigned materials for each polygon. Empty if appearance resolution is not enabled.
pub polygon_materials: Vec<Option<u32>>,
/// Assigned textures for each polygon. Empty if appearance resolution is not enabled.
pub polygon_textures: Vec<Option<u32>>,
/// Assigned texture UVs for each polygon. Empty if appearance resolution is not enabled.
pub polygon_uvs: MultiPolygon<'static, 2>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -135,6 +142,7 @@ impl GeometryCollector {
multipoint: self.multipoint,
ring_ids: self.ring_ids,
surface_spans: self.surface_spans,
..Default::default()
}
}
}
9 changes: 7 additions & 2 deletions nusamai-citygml/src/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ pub fn wellknown_prefix_from_nsres<'a>(ns: &ResolveResult<'a>) -> &'a [u8] {
} else {
b"unsupported:"
}
} else if name == b"w3.org/1999/xlink" {
} else if http_www == b"w3.org/1999/xlink" {
// xlink
b"xlink:"
} else {
// PLATEAU 1.x
match *name {
match http_www {
b"kantei.go.jp/jp/singi/tiiki/toshisaisei/itoshisaisei/iur/uro/1.4" => {
b"uro:"
}
Expand Down Expand Up @@ -118,6 +118,8 @@ mod tests {
xmlns:urf2ns="https://www.geospatial.jp/iur/urf/3.0"
xmlns:uro15ns="https://www.chisou.go.jp/tiiki/toshisaisei/itoshisaisei/iur/uro/1.5"
xmlns:urf15ns="https://www.chisou.go.jp/tiiki/toshisaisei/itoshisaisei/iur/urf/1.5"
xmlns:uro14ns="http://www.kantei.go.jp/jp/singi/tiiki/toshisaisei/itoshisaisei/iur/uro/1.4"
xmlns:urf14ns="http://www.kantei.go.jp/jp/singi/tiiki/toshisaisei/itoshisaisei/iur/urf/1.4"
xmlns:xAL2ns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
xmlns:xlinkns="http://www.w3.org/1999/xlink"
>
Expand All @@ -144,7 +146,10 @@ mod tests {
<urf2ns:urf />
<uro15ns:uro />
<urf15ns:urf />
<uro14ns:uro />
<urf14ns:urf />
<xAL2ns:xAL />
<xlinkns:xlink />
</core2ns:core>
"#;

Expand Down
18 changes: 18 additions & 0 deletions nusamai-citygml/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,24 @@ impl<'b, R: BufRead> SubTreeReader<'_, 'b, R> {
}
}

if self.state.fp_buf.len() % 2 != 0 {
return Err(ParseError::InvalidValue(
"Length of UV coordinates must be multiple of 2".into(),
));
}

// remove closing point
{
let len = self.state.fp_buf.len();
if len >= 4
&& self.state.fp_buf[0] == self.state.fp_buf[len - 2]
&& self.state.fp_buf[1] == self.state.fp_buf[len - 1]
{
self.state.fp_buf.pop();
self.state.fp_buf.pop();
}
}

coords = Some(mem::take(&mut self.state.fp_buf));
}
Ok(_) => (),
Expand Down
10 changes: 5 additions & 5 deletions nusamai-plateau/src/appearance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::hash::{Hash, Hasher};

#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct Theme {
ring_id_to_texture: HashMap<LocalId, (u32, LineString2<'static>)>,
surface_id_to_material: HashMap<LocalId, u32>,
pub ring_id_to_texture: HashMap<LocalId, (u32, LineString2<'static>)>, // TODO: texture index is redundant
pub surface_id_to_material: HashMap<LocalId, u32>,
}

/// Material (CityGML's X3DMaterial)
Expand Down Expand Up @@ -50,9 +50,9 @@ impl Hash for Material {
}
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct AppearanceStore {
textures: Vec<Texture>,
materials: Vec<Material>,
themes: HashMap<String, Theme>,
pub textures: Vec<Texture>,
pub materials: Vec<Material>,
pub themes: HashMap<String, Theme>,
}

/// Texture (CityGML's ParameterizedTexture)
Expand Down
Loading

0 comments on commit 201c7aa

Please sign in to comment.