Skip to content

Commit

Permalink
gzip option
Browse files Browse the repository at this point in the history
  • Loading branch information
nokonoko1203 committed Oct 23, 2024
1 parent 3da4084 commit 4215f82
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
25 changes: 20 additions & 5 deletions nusamai/src/sink/cesiumtiles/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::io::Write;

use ahash::{HashMap, HashSet};
use byteorder::{ByteOrder, LittleEndian};
use flate2::{write::GzEncoder, Compression};
use indexmap::IndexSet;
use nusamai_gltf_json::extensions::mesh::ext_mesh_features;

Expand All @@ -24,6 +25,7 @@ pub fn write_gltf_glb<W: Write>(
primitives: Primitives,
num_features: usize,
metadata_encoder: MetadataEncoder,
gzip_compress: bool,
) -> Result<(), PipelineError> {
use nusamai_gltf_json::*;

Expand Down Expand Up @@ -281,12 +283,25 @@ pub fn write_gltf_glb<W: Write>(
..Default::default()
};

// Write glb to the writer
nusamai_gltf::glb::Glb {
json: serde_json::to_vec(&gltf).unwrap().into(),
bin: Some(bin_content.into()),
if gzip_compress {
// Write glb to the writer with gzip compression
let mut encoder = GzEncoder::new(writer, Compression::default());

nusamai_gltf::glb::Glb {
json: serde_json::to_vec(&gltf).unwrap().into(),
bin: Some(bin_content.into()),
}
.to_writer_with_alignment(&mut encoder, 8)?;

Check warning on line 294 in nusamai/src/sink/cesiumtiles/gltf.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/cesiumtiles/gltf.rs#L288-L294

Added lines #L288 - L294 were not covered by tests

encoder.finish()?;

Check warning on line 296 in nusamai/src/sink/cesiumtiles/gltf.rs

View check run for this annotation

Codecov / codecov/patch

nusamai/src/sink/cesiumtiles/gltf.rs#L296

Added line #L296 was not covered by tests
} else {
// Write glb to the writer
nusamai_gltf::glb::Glb {
json: serde_json::to_vec(&gltf).unwrap().into(),
bin: Some(bin_content.into()),
}
.to_writer_with_alignment(writer, 8)?;
}
.to_writer_with_alignment(writer, 8)?;

Ok(())
}
16 changes: 16 additions & 0 deletions nusamai/src/sink/cesiumtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ impl DataSinkProvider for CesiumTilesSinkProvider {
},
});
params.define(limit_texture_resolution_parameter(false));
params.define(ParameterDefinition {
key: "gzip".into(),
entry: ParameterEntry {
description: "gzip compress".into(),
required: false,
parameter: ParameterType::Boolean(BooleanParameter { value: Some(false) }),
label: Some("gzipで圧縮する".into()),
},
});

params
}
Expand All @@ -112,12 +121,14 @@ impl DataSinkProvider for CesiumTilesSinkProvider {
let max_z = get_parameter_value!(params, "max_z", Integer).unwrap() as u8;
let limit_texture_resolution =
*get_parameter_value!(params, "limit_texture_resolution", Boolean);
let gzip_compress = *get_parameter_value!(params, "gzip", Boolean);
let transform_settings = self.transformer_options();

Box::<CesiumTilesSink>::new(CesiumTilesSink {
output_path: output_path.as_ref().unwrap().into(),
transform_settings,
limit_texture_resolution,
gzip_compress,
min_z,
max_z,
})
Expand All @@ -128,6 +139,7 @@ struct CesiumTilesSink {
output_path: PathBuf,
transform_settings: TransformerRegistry,
limit_texture_resolution: Option<bool>,
gzip_compress: Option<bool>,
min_z: u8,
max_z: u8,
}
Expand Down Expand Up @@ -157,6 +169,7 @@ impl DataSink for CesiumTilesSink {
let max_zoom = self.max_z;

let limit_texture_resolution = self.limit_texture_resolution;
let gzip_compress = self.gzip_compress;

// TODO: refactoring

Expand Down Expand Up @@ -205,6 +218,7 @@ impl DataSink for CesiumTilesSink {
tile_id_conv,
schema,
limit_texture_resolution,
gzip_compress,
) {
feedback.fatal_error(error);
}
Expand Down Expand Up @@ -327,6 +341,7 @@ fn tile_writing_stage(
tile_id_conv: TileIdMethod,
schema: &Schema,
limit_texture_resolution: Option<bool>,
gzip_compress: Option<bool>,
) -> Result<()> {
let ellipsoid = nusamai_projection::ellipsoid::wgs84();
let contents: Arc<Mutex<Vec<TileContent>>> = Default::default();
Expand Down Expand Up @@ -707,6 +722,7 @@ fn tile_writing_stage(
primitives,
features.len(),
metadata_encoder,
gzip_compress.unwrap_or_default(),
)?;

Ok::<(), PipelineError>(())
Expand Down
2 changes: 1 addition & 1 deletion nusamai/src/sink/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn limit_texture_resolution_parameter(default_value: bool) -> ParameterDefin
parameter: ParameterType::Boolean(BooleanParameter {
value: Some(default_value),
}),
label: Some("距離(メートル)あたりのテクスチャの解像度を制限する".into()),
label: Some("距離あたりの解像度を制限する".into()),
},
}
}

0 comments on commit 4215f82

Please sign in to comment.