From 464fab1dd5cc1a7b1b47a1776e7ceb25ae899aea Mon Sep 17 00:00:00 2001 From: osaka-yu Date: Thu, 7 Nov 2024 09:25:02 +0900 Subject: [PATCH 1/5] =?UTF-8?q?wip:=20=E3=83=9D=E3=83=AA=E3=82=B4=E3=83=B3?= =?UTF-8?q?=E3=81=AE=E9=A0=82=E7=82=B9=E3=82=92=E3=82=BF=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E5=A2=83=E7=95=8C=E3=81=AB=E3=82=B9=E3=83=8A=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/cesium/3dtiles.html | 3 +- nusamai/Cargo.toml | 4 +-- nusamai/src/sink/cesiumtiles/slice.rs | 47 ++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/demo/cesium/3dtiles.html b/demo/cesium/3dtiles.html index 074832c8c..ab22bf03a 100644 --- a/demo/cesium/3dtiles.html +++ b/demo/cesium/3dtiles.html @@ -71,7 +71,8 @@ viewer.scene.globe.depthTestAgainstTerrain = true; const tileset = await Cesium.Cesium3DTileset.fromUrl( - "/examples/3dtiles/tileset.json" + "/examples/3dtiles_textured", + { enableDebugWireframe: true } ); viewer.scene.primitives.add(tileset); viewer.zoomTo(tileset); diff --git a/nusamai/Cargo.toml b/nusamai/Cargo.toml index 907c305e0..f0d78f5d2 100644 --- a/nusamai/Cargo.toml +++ b/nusamai/Cargo.toml @@ -51,8 +51,8 @@ chrono = "0.4.35" kv-extsort = { git = "https://github.com/MIERUNE/kv-extsort-rs.git" } bytemuck = { version = "1.16.0", features = ["derive"] } dda-voxelize = "0.2.0-alpha.1" -atlas-packer = { git = "https://github.com/MIERUNE/atlas-packer.git" } -# atlas-packer = { path = "../atlas_packer" }; +# atlas-packer = { git = "https://github.com/MIERUNE/atlas-packer.git" } +atlas-packer = { path = "../atlas-packer" } tempfile = "3.10.1" glam = "0.29.0" diff --git a/nusamai/src/sink/cesiumtiles/slice.rs b/nusamai/src/sink/cesiumtiles/slice.rs index 8a2aab043..682187b1c 100644 --- a/nusamai/src/sink/cesiumtiles/slice.rs +++ b/nusamai/src/sink/cesiumtiles/slice.rs @@ -15,7 +15,12 @@ use serde::{Deserialize, Serialize}; use super::{material::Material, tiling}; use crate::sink::cesiumtiles::{material::Texture, tiling::zxy_from_lng_lat}; - +struct TileBounds { + min_x: f64, + max_x: f64, + min_y: f64, + max_y: f64, +} #[derive(Serialize, Deserialize)] pub struct SlicedFeature { // polygons [x, y, z, u, v] @@ -398,6 +403,27 @@ fn slice_polygon( poly_buf.add_ring(ring_buffer.drain(..)) } + let tile_bounds = TileBounds { + min_x: 0.0, + max_x: 1.0, + min_y: 0.0, + max_y: 1.0, + }; + + let rings: Vec<_> = poly_buf.rings().collect(); + + for ring in rings { + if ring.raw_coords().is_empty() { + continue; + } + + ring_buffer.clear(); + + for vertex in &ring { + let snapped_vertex = snap_to_tile_boundary(vertex, &tile_bounds); + ring_buffer.push(snapped_vertex); + } + } send_polygon(key, &poly_buf); } @@ -433,3 +459,22 @@ fn should_process_entry(entry_lod: u8, geom_error: f64, available_lods: &HashSet entry_lod == selected_lod } } + +fn snap_to_tile_boundary(vertex: [f64; 5], tile_bounds: &TileBounds) -> [f64; 5] { + let mut snapped_vertex = vertex; + + if vertex[0] < tile_bounds.min_x { + snapped_vertex[0] = tile_bounds.min_x; + } else if vertex[0] > tile_bounds.max_x { + snapped_vertex[0] = tile_bounds.max_x; + } + + // Snap y coordinate + if vertex[1] < tile_bounds.min_y { + snapped_vertex[1] = tile_bounds.min_y; + } else if vertex[1] > tile_bounds.max_y { + snapped_vertex[1] = tile_bounds.max_y; + } + + snapped_vertex +} From 8b4acaedbde12091bf66a49018f89dd0c97e0ea3 Mon Sep 17 00:00:00 2001 From: osaka-yu Date: Thu, 7 Nov 2024 10:55:25 +0900 Subject: [PATCH 2/5] fix: tileset path --- demo/cesium/3dtiles.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/cesium/3dtiles.html b/demo/cesium/3dtiles.html index ab22bf03a..6f4df7cfe 100644 --- a/demo/cesium/3dtiles.html +++ b/demo/cesium/3dtiles.html @@ -71,7 +71,7 @@ viewer.scene.globe.depthTestAgainstTerrain = true; const tileset = await Cesium.Cesium3DTileset.fromUrl( - "/examples/3dtiles_textured", + "./examples/3dtiles_textured/tileset.json", { enableDebugWireframe: true } ); viewer.scene.primitives.add(tileset); From 78f90be13c727f6a48f7c507a15e4acc24880912 Mon Sep 17 00:00:00 2001 From: osaka-yu Date: Thu, 7 Nov 2024 13:04:47 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E3=82=B9=E3=83=8A=E3=83=83=E3=83=97?= =?UTF-8?q?=E5=87=A6=E7=90=86=E5=BE=8C=E3=81=AE=E9=A0=82=E7=82=B9=E3=81=8C?= =?UTF-8?q?poly=5Fbuf=E3=81=AB=E5=8F=8D=E6=98=A0=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nusamai/src/sink/cesiumtiles/slice.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/nusamai/src/sink/cesiumtiles/slice.rs b/nusamai/src/sink/cesiumtiles/slice.rs index 874682685..d78dae62b 100644 --- a/nusamai/src/sink/cesiumtiles/slice.rs +++ b/nusamai/src/sink/cesiumtiles/slice.rs @@ -263,7 +263,7 @@ fn slice_polygon( // todo?: check interior bbox to optimize for (ri, (ring, uv_ring)) in poly.rings().zip_eq(poly_uv.rings()).enumerate() { - if ring.raw_coords().is_empty() { + if ring.is_empty() { continue; } @@ -350,7 +350,7 @@ fn slice_polygon( poly_buf.clear(); for ring in y_sliced_poly.rings() { - if ring.raw_coords().is_empty() { + if ring.is_empty() { continue; } @@ -410,19 +410,21 @@ fn slice_polygon( max_y: 1.0, }; - let rings: Vec<_> = poly_buf.rings().collect(); + let rings: Vec<_> = poly_buf.rings().map(|r| r.raw_coords().to_vec()).collect(); - for ring in rings { - if ring.raw_coords().is_empty() { + for ring in rings.iter() { + if ring.is_empty() { continue; } ring_buffer.clear(); - for vertex in &ring { - let snapped_vertex = snap_to_tile_boundary(vertex, &tile_bounds); + for vertex in ring { + let snapped_vertex = snap_to_tile_boundary(*vertex, &tile_bounds); ring_buffer.push(snapped_vertex); } + let drained_ring: Vec<_> = ring_buffer.drain(..).collect(); + poly_buf.add_ring(drained_ring); } send_polygon(key, &poly_buf); From 256084191007f42f627af1696fa860de795f3c8f Mon Sep 17 00:00:00 2001 From: osaka-yu Date: Thu, 21 Nov 2024 09:08:31 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20ring=5Fbuffer=E3=81=AE=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E3=82=92std::mem::take=E3=82=92=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=81=97=E3=81=A6drain=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nusamai/src/sink/cesiumtiles/slice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nusamai/src/sink/cesiumtiles/slice.rs b/nusamai/src/sink/cesiumtiles/slice.rs index d78dae62b..e73279bc0 100644 --- a/nusamai/src/sink/cesiumtiles/slice.rs +++ b/nusamai/src/sink/cesiumtiles/slice.rs @@ -423,7 +423,7 @@ fn slice_polygon( let snapped_vertex = snap_to_tile_boundary(*vertex, &tile_bounds); ring_buffer.push(snapped_vertex); } - let drained_ring: Vec<_> = ring_buffer.drain(..).collect(); + let drained_ring: Vec<_> = std::mem::take(&mut ring_buffer).drain(..).collect(); poly_buf.add_ring(drained_ring); } From 656b736545d391e75ff1be9c2cfe074b2ffa5b41 Mon Sep 17 00:00:00 2001 From: osaka-yu Date: Tue, 31 Dec 2024 12:22:16 +0900 Subject: [PATCH 5/5] refactor: remove unused TileBounds struct and snap_to_tile_boundary function --- nusamai/src/sink/cesiumtiles/slice.rs | 57 ++------------------------- 1 file changed, 3 insertions(+), 54 deletions(-) diff --git a/nusamai/src/sink/cesiumtiles/slice.rs b/nusamai/src/sink/cesiumtiles/slice.rs index e73279bc0..00575b9c3 100644 --- a/nusamai/src/sink/cesiumtiles/slice.rs +++ b/nusamai/src/sink/cesiumtiles/slice.rs @@ -15,12 +15,7 @@ use tinymvt::TileZXY; use super::{material::Material, tiling}; use crate::sink::cesiumtiles::{material::Texture, tiling::zxy_from_lng_lat}; -struct TileBounds { - min_x: f64, - max_x: f64, - min_y: f64, - max_y: f64, -} + #[derive(Serialize, Deserialize)] pub struct SlicedFeature { // polygons [x, y, z, u, v] @@ -260,10 +255,8 @@ fn slice_polygon( for yi in y_range.clone() { let (k1, k2) = tiling::y_slice_range(zoom, yi); - // todo?: check interior bbox to optimize - for (ri, (ring, uv_ring)) in poly.rings().zip_eq(poly_uv.rings()).enumerate() { - if ring.is_empty() { + if ring.raw_coords().is_empty() { continue; } @@ -340,8 +333,6 @@ fn slice_polygon( for (xi, xs) in x_iter { let (k1, k2) = tiling::x_slice_range(zoom, xi, xs); - // todo?: check interior bbox to optimize ... - let key = ( zoom, xi.rem_euclid(1 << zoom) as u32, // handling geometry crossing the antimeridian @@ -350,7 +341,7 @@ fn slice_polygon( poly_buf.clear(); for ring in y_sliced_poly.rings() { - if ring.is_empty() { + if ring.raw_coords().is_empty() { continue; } @@ -403,29 +394,6 @@ fn slice_polygon( poly_buf.add_ring(ring_buffer.drain(..)) } - let tile_bounds = TileBounds { - min_x: 0.0, - max_x: 1.0, - min_y: 0.0, - max_y: 1.0, - }; - - let rings: Vec<_> = poly_buf.rings().map(|r| r.raw_coords().to_vec()).collect(); - - for ring in rings.iter() { - if ring.is_empty() { - continue; - } - - ring_buffer.clear(); - - for vertex in ring { - let snapped_vertex = snap_to_tile_boundary(*vertex, &tile_bounds); - ring_buffer.push(snapped_vertex); - } - let drained_ring: Vec<_> = std::mem::take(&mut ring_buffer).drain(..).collect(); - poly_buf.add_ring(drained_ring); - } send_polygon(key, &poly_buf); } @@ -461,22 +429,3 @@ fn should_process_entry(entry_lod: u8, geom_error: f64, available_lods: &HashSet entry_lod == selected_lod } } - -fn snap_to_tile_boundary(vertex: [f64; 5], tile_bounds: &TileBounds) -> [f64; 5] { - let mut snapped_vertex = vertex; - - if vertex[0] < tile_bounds.min_x { - snapped_vertex[0] = tile_bounds.min_x; - } else if vertex[0] > tile_bounds.max_x { - snapped_vertex[0] = tile_bounds.max_x; - } - - // Snap y coordinate - if vertex[1] < tile_bounds.min_y { - snapped_vertex[1] = tile_bounds.min_y; - } else if vertex[1] > tile_bounds.max_y { - snapped_vertex[1] = tile_bounds.max_y; - } - - snapped_vertex -}