-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
テクスチャ付き最大LODを出力するオプションを追加 #647
Changes from all commits
1ffdbcd
b357792
9d719bc
9caed2a
a98779a
29b55ce
e43f931
e9b5eb2
9051f2d
e0fb5e1
c8b4e06
a4e6dc0
3079c22
59589cf
1e80a45
0907cc1
72ff456
a7d9f36
dc6e722
b7006e7
dd99cee
d7070ca
d4a4b85
498bcff
cbfd15c
4c8c0e2
456d5c9
8fc3108
3891dc9
87a21ff
ae55b39
05bc85d
22ee821
6026bd1
c449bf8
7aa6864
56e083d
209fedc
9755944
f3c5812
d66377d
d3b2c6b
0fbb379
c905271
78b291f
1506f6d
f7b3a84
8ed6320
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,18 @@ pub fn use_lod_config(default_value: &str) -> TransformerConfig { | |
TransformerConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q) 前提がよく理解できていなかったんですが、 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. option.rsが transformerフォルダに属していないのが気になりました。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo) optionなのか、configなのか、settingなのか…表記が揺れていて、かつどれも異なる意味を持っていそうで、理解に時間がかかっちゃいそうです…! |
||
key: "use_lod".to_string(), | ||
label: "出力LODの選択".to_string(), | ||
parameter: transformer::ParameterType::Selection(LodSelection::create_lod_selection( | ||
default_value, | ||
)), | ||
parameter: transformer::ParameterType::Selection( | ||
LodSelection::lod_selection_without_texture(default_value), | ||
), | ||
} | ||
} | ||
|
||
pub fn use_texture_config(default_value: bool) -> TransformerConfig { | ||
pub fn use_textured_lod_config(default_value: &str) -> TransformerConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q) |
||
TransformerConfig { | ||
key: "use_texture".to_string(), | ||
label: "テクスチャの使用".to_string(), | ||
parameter: transformer::ParameterType::Boolean(default_value), | ||
key: "use_lod".to_string(), | ||
label: "出力LODの選択".to_string(), | ||
parameter: transformer::ParameterType::Selection(LodSelection::lod_selection_with_texture( | ||
default_value, | ||
)), | ||
satoshi7190 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,8 @@ | |||||
pub enum LodFilterMode { | ||||||
Highest, | ||||||
Lowest, | ||||||
TexturedHighest, | ||||||
All, | ||||||
} | ||||||
|
||||||
#[derive()] | ||||||
|
@@ -29,16 +31,68 @@ | |||||
/// Transform to filter and split the LODs | ||||||
impl Transform for FilterLodTransform { | ||||||
fn transform(&mut self, _feedback: &Feedback, mut entity: Entity, out: &mut Vec<Entity>) { | ||||||
let lods = find_lods(&entity.root) & self.mask; | ||||||
|
||||||
let target_lod = match self.mode { | ||||||
LodFilterMode::Highest => lods.highest_lod(), | ||||||
LodFilterMode::Lowest => lods.lowest_lod(), | ||||||
}; | ||||||
|
||||||
if let Some(target_lod) = target_lod { | ||||||
edit_tree(&mut entity.root, target_lod); | ||||||
out.push(entity); | ||||||
match self.mode { | ||||||
LodFilterMode::TexturedHighest => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo) テクスチャが付いた最大のLODを抽出する。テクスチャがない場合は最大のLODを抽出する。 |
||||||
// TODO: Processing needs to be optimised | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nits) |
||||||
let original_lods = find_lods(&entity.root) & self.mask; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi) シンプルに、こんな感じではいかがでしょう。 let available_lods = find_lods(&entity.root) & self.mask;
let mut highest_textured_lod = None;
// 「最大のLOD」は初めから決まっている。テクスチャが存在しなければ、即座に最大LODを返却できる
let highest_available_lod = available_lods.highest_lod().unwrap_or(0);
// revで逆順イテレータを作成
for lod in (0..=highest_available_lod).rev() {
if available_lods.0 & (1 << lod) != 0 {
edit_tree(&mut entity.root, lod);
let has_textures = {
let appearance = entity.appearance_store.read().unwrap();
!appearance.textures.is_empty()
};
// テクスチャが存在するLODが見つかれば、それを保存して終了
if has_textures {
highest_textured_lod = Some(lod);
break;
}
}
}
// highest_textured_lodがNoneではないならhighest_textured_lodを利用
// Noneならhighest_available_lodを利用
if let Some(lod) = highest_textured_lod.or(Some(highest_available_lod)) {
edit_tree(&mut entity.root, lod);
out.push(entity);
}
Suggested change
|
||||||
let mut current_lods = original_lods; | ||||||
let mut highest_lod_entity = None; | ||||||
|
||||||
while current_lods.0 != 0 { | ||||||
let target_lod = current_lods.highest_lod(); | ||||||
|
||||||
if let Some(lod) = target_lod { | ||||||
// Create a copy of the entity | ||||||
let mut entity_copy = entity.clone(); | ||||||
edit_tree(&mut entity_copy.root, lod); | ||||||
|
||||||
let has_textures = { | ||||||
let appearance = entity_copy.appearance_store.read().unwrap(); | ||||||
!appearance.textures.is_empty() | ||||||
}; | ||||||
satoshi7190 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
if has_textures { | ||||||
out.push(entity_copy); | ||||||
return; | ||||||
} else { | ||||||
// Save the highest LOD entity | ||||||
if highest_lod_entity.is_none() { | ||||||
highest_lod_entity = Some(entity_copy); | ||||||
} | ||||||
// Exclude the current LOD and try the next LOD | ||||||
current_lods.0 &= !(1 << lod); | ||||||
} | ||||||
} else { | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
// If no texture is found, push entity with highest LOD | ||||||
if let Some(highest_entity) = highest_lod_entity { | ||||||
out.push(highest_entity); | ||||||
} | ||||||
satoshi7190 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
LodFilterMode::Highest => { | ||||||
let lods = find_lods(&entity.root) & self.mask; | ||||||
let target_lod = lods.highest_lod(); | ||||||
|
||||||
if let Some(target_lod) = target_lod { | ||||||
edit_tree(&mut entity.root, target_lod); | ||||||
out.push(entity); | ||||||
} | ||||||
} | ||||||
LodFilterMode::Lowest => { | ||||||
let lods = find_lods(&entity.root) & self.mask; | ||||||
let target_lod = lods.lowest_lod(); | ||||||
|
||||||
if let Some(target_lod) = target_lod { | ||||||
edit_tree(&mut entity.root, target_lod); | ||||||
out.push(entity); | ||||||
} | ||||||
} | ||||||
LodFilterMode::All => { | ||||||
out.push(entity); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -92,7 +146,7 @@ | |||||
mask | ||||||
} | ||||||
|
||||||
#[derive(Default, Clone, Copy)] | ||||||
#[derive(Default, Clone, Copy, Debug)] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nits) Debugは消しときましょうか! |
||||||
pub struct LodMask( | ||||||
u8, // lods bit mask | ||||||
); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q) 結局ここのCloneは除去できなかった感じですかね…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
僕が提案したコードを適用すると、除去できる気はしています!