-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Close or Related Issues --> Close #593 #311 #448 #303 ### Description(変更内容) <!-- Please describe the motivation behind this PR and the changes it introduces. --> <!-- 何のために、どのような変更をしますか? --> - #612 を修正 - 以下の事象に対応し、アトラス化されたテクスチャの出力と対応するOBJファイルを出力するように変更 - UV座標をアトラスの座標に差し替え - mtlに書き込むテクスチャのパスと、アトラスの出力パスが不整合を修正 - 不要なcrop処理を入れないように修正 - 全体的にマルチスレッド処理に変更 - 画像のキャッシュサイズを増加 - 一度切り出した`atlas-packer`を一旦nusamaiに戻す - 開発効率の問題 ### Notes(連絡事項) <!-- If manual testing is required, please describe the procedure. --> <!-- 手動の動作確認が必要なら、手順を簡単に伝えてください。その他連絡事項など。 --> ```bash cargo run -- <input_path> --sink obj -o transform=use_texture -o split=true --output <output_path> ```
- Loading branch information
Showing
47 changed files
with
1,911 additions
and
3,673 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ members = [ | |
"nusamai-*", | ||
"nusamai-*/nusamai-*-json", | ||
"nusamai", | ||
"atlas-packer" | ||
] | ||
resolver = "2" | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
### Generated by gibo (https://github.com/simonwhitaker/gibo) | ||
### https://raw.github.com/github/gitignore/e5323759e387ba347a9d50f8b0ddd16502eb71d4/Rust.gitignore | ||
|
||
# Prevent committing example outputs | ||
output.* | ||
out.* | ||
schema.json | ||
|
||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
# llvm-cov | ||
lcov.info | ||
|
||
### Generated by gibo (https://github.com/simonwhitaker/gibo) | ||
### https://raw.github.com/github/gitignore/e5323759e387ba347a9d50f8b0ddd16502eb71d4/Global/macOS.gitignore | ||
|
||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
# emacs buckup files | ||
*~ | ||
|
||
.docs | ||
docs/obj |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "atlas-packer" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
image = { version = "0.25.1", default-features = false, features = ["rayon", "tiff", "jpeg", "webp", "png"] } | ||
thiserror = "1.0.61" | ||
hashbrown = { version = "0.14.5", features = ["rayon"] } | ||
stretto = "0.8.4" | ||
rayon = "1.10.0" | ||
|
||
[dev-dependencies] | ||
tempfile = "3.10.1" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 MIERUNE Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# atlas-packer |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Blender 4.1.1 MTL File: 'dice.blend' | ||
# www.blender.org | ||
|
||
newmtl マテリアル | ||
Ks 0.500000 0.500000 0.500000 | ||
Ke 0.000000 0.000000 0.000000 | ||
Ni 1.500000 | ||
d 1.000000 | ||
illum 2 | ||
Pr 0.500000 | ||
Pm 0.000000 | ||
Ps 0.000000 | ||
Pc 0.000000 | ||
Pcr 0.030000 | ||
aniso 0.000000 | ||
anisor 0.000000 | ||
map_Kd blue_dice.png | ||
|
||
newmtl マテリアル.001 | ||
Ks 0.500000 0.500000 0.500000 | ||
Ke 0.000000 0.000000 0.000000 | ||
Ni 1.500000 | ||
d 1.000000 | ||
illum 2 | ||
Pr 0.500000 | ||
Pm 0.000000 | ||
Ps 0.000000 | ||
Pc 0.000000 | ||
Pcr 0.030000 | ||
aniso 0.000000 | ||
anisor 0.000000 | ||
map_Kd red_dice.png | ||
|
||
newmtl マテリアル.002 | ||
Ks 0.500000 0.500000 0.500000 | ||
Ke 0.000000 0.000000 0.000000 | ||
Ni 1.500000 | ||
d 1.000000 | ||
illum 2 | ||
Pr 0.500000 | ||
Pm 0.000000 | ||
Ps 0.000000 | ||
Pc 0.000000 | ||
Pcr 0.030000 | ||
aniso 0.000000 | ||
anisor 0.000000 | ||
map_Kd yellow_dice.png |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Blender 4.1.1 | ||
# www.blender.org | ||
mtllib dice.mtl | ||
o 立方体 | ||
v -1.000000 -1.000000 1.000000 | ||
v -1.000000 2.426060 1.000000 | ||
v -1.000000 -1.000000 -1.000000 | ||
v -1.000000 2.426060 -1.000000 | ||
v 1.000000 -1.000000 1.000000 | ||
v 1.000000 2.426060 1.000000 | ||
v 1.000000 -1.000000 -1.000000 | ||
v 1.000000 2.426060 -1.000000 | ||
vn -1.0000 -0.0000 -0.0000 | ||
vn -0.0000 -0.0000 -1.0000 | ||
vn 1.0000 -0.0000 -0.0000 | ||
vn -0.0000 -0.0000 1.0000 | ||
vn -0.0000 -1.0000 -0.0000 | ||
vn -0.0000 1.0000 -0.0000 | ||
vt -0.000000 0.628906 | ||
vt 0.316406 0.628906 | ||
vt 0.316406 0.816406 | ||
vt -0.000000 0.816406 | ||
vt 0.816406 1.000000 | ||
vt 0.500000 1.000000 | ||
vt 0.500000 0.816406 | ||
vt 0.816406 0.816406 | ||
vt 0.500000 0.628906 | ||
vt 0.816406 0.628906 | ||
vt 0.500000 0.445312 | ||
vt 0.816406 0.445312 | ||
vt 1.000000 0.816406 | ||
vt 1.000000 0.628906 | ||
s 0 | ||
usemtl マテリアル.002 | ||
f 1/1/1 2/2/1 4/3/1 3/4/1 | ||
f 3/5/2 4/6/2 8/7/2 7/8/2 | ||
f 7/8/3 8/7/3 6/9/3 5/10/3 | ||
f 5/10/4 6/9/4 2/11/4 1/12/4 | ||
f 3/13/5 7/8/5 5/10/5 1/14/5 | ||
f 8/7/6 4/3/6 2/2/6 6/9/6 | ||
o 立方体.001 | ||
v 2.000000 0.000000 4.000000 | ||
v 2.000000 1.053673 4.000000 | ||
v 2.000000 0.000000 2.000000 | ||
v 2.000000 1.053673 2.000000 | ||
v 4.000000 0.000000 4.000000 | ||
v 4.000000 1.053673 4.000000 | ||
v 4.000000 0.000000 2.000000 | ||
v 4.000000 1.053673 2.000000 | ||
vn -1.0000 -0.0000 -0.0000 | ||
vn -0.0000 -0.0000 -1.0000 | ||
vn 1.0000 -0.0000 -0.0000 | ||
vn -0.0000 -0.0000 1.0000 | ||
vn -0.0000 -1.0000 -0.0000 | ||
vn -0.0000 1.0000 -0.0000 | ||
vt 0.327473 0.329309 | ||
vt 0.500000 0.329309 | ||
vt 0.500000 0.656008 | ||
vt 0.327473 0.656008 | ||
vt 0.500000 0.984543 | ||
vt 0.327473 0.984543 | ||
vt 0.999226 0.656008 | ||
vt 0.826699 0.656008 | ||
vt 0.826699 0.329309 | ||
vt 0.999226 0.329309 | ||
vt 0.327473 0.000774 | ||
vt 0.500000 0.000774 | ||
vt 0.000774 0.656008 | ||
vt 0.000774 0.329309 | ||
s 0 | ||
usemtl マテリアル | ||
f 9/15/7 10/16/7 12/17/7 11/18/7 | ||
f 11/18/8 12/17/8 16/19/8 15/20/8 | ||
f 15/21/9 16/22/9 14/23/9 13/24/9 | ||
f 13/25/10 14/26/10 10/16/10 9/15/10 | ||
f 11/18/11 15/27/11 13/28/11 9/15/11 | ||
f 16/22/12 12/17/12 10/16/12 14/23/12 | ||
o 立方体.002 | ||
v -2.895887 -1.239795 6.341527 | ||
v -2.895887 4.526947 6.341527 | ||
v -2.895887 -1.239795 4.341527 | ||
v -2.895887 4.526947 4.341527 | ||
v -0.895887 -1.239795 6.341527 | ||
v -0.895887 4.526947 6.341527 | ||
v -0.895887 -1.239795 4.341527 | ||
v -0.895887 4.526947 4.341527 | ||
vn -1.0000 -0.0000 -0.0000 | ||
vn -0.0000 -0.0000 -1.0000 | ||
vn 1.0000 -0.0000 -0.0000 | ||
vn -0.0000 -0.0000 1.0000 | ||
vn -0.0000 -1.0000 -0.0000 | ||
vn -0.0000 1.0000 -0.0000 | ||
vt -0.000000 0.742188 | ||
vt 0.371094 0.742188 | ||
vt 0.371094 0.871094 | ||
vt -0.000000 0.871094 | ||
vt 0.871094 1.000000 | ||
vt 0.500000 1.000000 | ||
vt 0.500000 0.871094 | ||
vt 0.871094 0.871094 | ||
vt 0.500000 0.742188 | ||
vt 0.871094 0.742188 | ||
vt 0.500000 0.613281 | ||
vt 0.871094 0.613281 | ||
vt 1.000000 0.871094 | ||
vt 1.000000 0.742188 | ||
s 0 | ||
usemtl マテリアル.001 | ||
f 17/29/13 18/30/13 20/31/13 19/32/13 | ||
f 19/33/14 20/34/14 24/35/14 23/36/14 | ||
f 23/36/15 24/35/15 22/37/15 21/38/15 | ||
f 21/38/16 22/37/16 18/39/16 17/40/16 | ||
f 19/41/17 23/36/17 21/38/17 17/42/17 | ||
f 24/35/18 20/31/18 18/30/18 22/37/18 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use std::path::{Path, PathBuf}; | ||
use std::sync::Mutex; | ||
use std::time::Instant; | ||
|
||
use rayon::prelude::*; | ||
|
||
use atlas_packer::{ | ||
export::JpegAtlasExporter, | ||
pack::TexturePacker, | ||
place::{GuillotineTexturePlacer, TexturePlacerConfig}, | ||
texture::{DownsampleFactor, TextureCache}, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
struct Polygon { | ||
id: String, | ||
uv_coords: Vec<(f64, f64)>, | ||
texture_uri: PathBuf, | ||
downsample_factor: DownsampleFactor, | ||
} | ||
|
||
fn main() { | ||
let all_process_start = Instant::now(); | ||
|
||
// 3D Tiles Sink passes the texture path and UV coordinates for each polygon | ||
let mut polygons: Vec<Polygon> = Vec::new(); | ||
let downsample_factor = 1.0; | ||
for i in 0..200 { | ||
for j in 1..11 { | ||
// Specify a polygon to crop around the center of the image | ||
let uv_coords = vec![ | ||
(0.2, 0.3), | ||
(0.3, 0.2), | ||
(0.6, 0.2), | ||
(0.8, 0.3), | ||
(0.8, 0.7), | ||
(0.6, 0.8), | ||
(0.3, 0.8), | ||
(0.2, 0.7), | ||
]; | ||
let path_string: String = format!("examples/assets/{}.png", j); | ||
let image_path = PathBuf::from(path_string.as_str()); | ||
polygons.push(Polygon { | ||
id: format!("texture_{}_{}", i, j), | ||
uv_coords, | ||
texture_uri: image_path, | ||
downsample_factor: DownsampleFactor::new(&downsample_factor), | ||
}); | ||
} | ||
} | ||
|
||
// initialize texture packer | ||
let config = TexturePlacerConfig { | ||
width: 4096, | ||
height: 4096, | ||
padding: 0, | ||
}; | ||
let placer = GuillotineTexturePlacer::new(config.clone()); | ||
let exporter = JpegAtlasExporter::default(); | ||
let packer = Mutex::new(TexturePacker::new(placer, exporter)); | ||
|
||
// Texture cache | ||
let texture_cache = TextureCache::new(100_000_000); | ||
|
||
let start = Instant::now(); | ||
|
||
// Add textures to the atlas | ||
polygons.par_iter().for_each(|polygon| { | ||
let texture = texture_cache.get_or_insert( | ||
&polygon.uv_coords, | ||
&polygon.texture_uri, | ||
&polygon.downsample_factor.value(), | ||
); | ||
let _ = packer | ||
.lock() | ||
.unwrap() | ||
.add_texture(polygon.id.clone(), texture); | ||
// println!("{:?}", info); | ||
}); | ||
|
||
let duration = start.elapsed(); | ||
println!("atlas process {:?}", duration); | ||
|
||
let mut packer = packer.into_inner().unwrap(); | ||
|
||
packer.finalize(); | ||
|
||
let start = Instant::now(); | ||
|
||
let output_dir = Path::new("examples/output/"); | ||
packer.export(output_dir, &texture_cache, config.width(), config.height()); | ||
|
||
let duration = start.elapsed(); | ||
println!("atlas export process {:?}", duration); | ||
|
||
let duration = all_process_start.elapsed(); | ||
println!("all process {:?}", duration); | ||
} |
Oops, something went wrong.