Add custom material for Retro's PBR

This commit is contained in:
Luke Street
2023-03-10 21:56:15 -05:00
parent 8ec27a0d8f
commit 01aabb65f9
7 changed files with 1019 additions and 47 deletions
Generated
+4 -9
View File
@@ -3061,7 +3061,7 @@ dependencies = [
"image",
"log",
"memmap2",
"tegra_swizzle 0.3.0 (git+https://github.com/ScanMountGoat/tegra_swizzle?rev=f0cf2c61b78b929381f09dd224ca27fe6929e176)",
"tegra_swizzle",
"uuid",
]
@@ -3083,7 +3083,7 @@ dependencies = [
"png",
"retrolib",
"serde_json",
"tegra_swizzle 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tegra_swizzle",
"uuid",
]
@@ -3412,14 +3412,9 @@ dependencies = [
[[package]]
name = "tegra_swizzle"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "898709aaa04e72af51fafa032802e0dee931eee066894478ac0000b4525d30bf"
[[package]]
name = "tegra_swizzle"
version = "0.3.0"
source = "git+https://github.com/ScanMountGoat/tegra_swizzle?rev=f0cf2c61b78b929381f09dd224ca27fe6929e176#f0cf2c61b78b929381f09dd224ca27fe6929e176"
checksum = "d5a696f1997cdcb21949d259b95ccfad64fe5207897c4a4aa34faa4c34bc1678"
[[package]]
name = "termcolor"
+1 -1
View File
@@ -20,5 +20,5 @@ flate2 = "1.0.25"
image = "0.24.5"
log = "0.4.17"
memmap2 = "0.5.9"
tegra_swizzle = { git = "https://github.com/ScanMountGoat/tegra_swizzle", rev = "f0cf2c61b78b929381f09dd224ca27fe6929e176" }
tegra_swizzle = "0.3.1"
uuid = "1.3.0"
+11 -3
View File
@@ -62,7 +62,7 @@ impl PartialEq<[u8; 4]> for FourCC {
pub fn peek_four_cc(data: &[u8]) -> FourCC { FourCC(*array_ref!(data, 0, 4)) }
#[binrw]
#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug)]
pub struct CVector3f {
pub x: f32,
pub y: f32,
@@ -70,7 +70,7 @@ pub struct CVector3f {
}
#[binrw]
#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug)]
pub struct CColor4f {
pub r: f32,
pub g: f32,
@@ -78,8 +78,16 @@ pub struct CColor4f {
pub a: f32,
}
impl CColor4f {
#[inline]
pub fn to_array(self) -> [f32; 4] { [self.r, self.g, self.b, self.a] }
}
impl From<CColor4f> for [f32; 4] {
fn from(value: CColor4f) -> Self { value.to_array() }
}
#[binrw]
#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug)]
pub struct CVector4i {
pub x: i32,
pub y: i32,
File diff suppressed because it is too large Load Diff
+11 -4
View File
@@ -1,5 +1,6 @@
mod icon;
mod loaders;
mod material;
mod tabs;
use std::path::PathBuf;
@@ -16,7 +17,8 @@ use crate::{
package_loader_system, MaterialAssetLoader, ModelAssetLoader, PackageAssetLoader,
PackageDirectory, RetroAssetIoPlugin, TextureAssetLoader,
},
tabs::{load_tab, model::TemporaryTag, project::ProjectTab, TabState, TabType, TabViewer},
material::CustomMaterial,
tabs::{load_tab, model::TemporaryLabel, project::ProjectTab, TabState, TabType, TabViewer},
};
#[derive(Default, Resource)]
@@ -29,12 +31,16 @@ fn main() {
}
App::new()
.insert_resource(ClearColor(Color::rgb(0.05, 0.05, 0.05)))
.insert_resource(Msaa { samples: 4 })
// .insert_resource(Msaa { samples: 4 })
.insert_resource(bevy::render::settings::WgpuSettings {
features: bevy::render::settings::WgpuFeatures::TEXTURE_COMPRESSION_BC,
..default()
})
.insert_resource(bevy::winit::WinitSettings::desktop_app())
// .insert_resource(AmbientLight {
// color: Color::rgb(1.0, 1.0, 1.0),
// brightness: 0.6,
// })
.insert_resource(file_open)
.init_resource::<UiState>()
.init_resource::<Packages>()
@@ -53,6 +59,7 @@ fn main() {
})
.add_before::<AssetPlugin, _>(RetroAssetIoPlugin),
)
.add_plugin(MaterialPlugin::<CustomMaterial>::default())
.add_plugin(PackageAssetLoader)
.add_plugin(TextureAssetLoader)
.add_plugin(ModelAssetLoader)
@@ -165,7 +172,7 @@ fn ui_system(world: &mut World) {
// Remove all temporary entities
let mut to_remove = vec![];
for (entity, _) in world.query::<(Entity, With<TemporaryTag>)>().iter(world) {
for (entity, _) in world.query::<(Entity, With<TemporaryLabel>)>().iter(world) {
to_remove.push(entity);
}
for entity in to_remove {
@@ -191,7 +198,7 @@ fn ui_system(world: &mut World) {
if viewer.state.render_layer == 0 {
// Spawn a camera to just clear the screen
world.spawn((Camera3dBundle::default(), TemporaryTag));
world.spawn((Camera3dBundle::default(), TemporaryLabel));
}
});
});
+183
View File
@@ -0,0 +1,183 @@
use bevy::{
pbr::*,
prelude::*,
reflect::TypeUuid,
render::{mesh::*, render_resource::*},
};
// A "high" random id should be used for custom attributes to ensure consistent sorting and avoid collisions with other attributes.
// See the MeshVertexAttribute docs for more info.
const ATTRIBUTE_UV_1: MeshVertexAttribute =
MeshVertexAttribute::new("Vertex_Uv_1", 988540917, VertexFormat::Float32x2);
const ATTRIBUTE_UV_2: MeshVertexAttribute =
MeshVertexAttribute::new("Vertex_Uv_2", 988540918, VertexFormat::Float32x2);
const ATTRIBUTE_UV_3: MeshVertexAttribute =
MeshVertexAttribute::new("Vertex_Uv_3", 988540919, VertexFormat::Float32x2);
const ATTRIBUTE_TANGENT_1: MeshVertexAttribute =
MeshVertexAttribute::new("Vertex_Tangent_1", 988540920, VertexFormat::Float32x4);
const ATTRIBUTE_TANGENT_2: MeshVertexAttribute =
MeshVertexAttribute::new("Vertex_Tangent_2", 988540921, VertexFormat::Float32x4);
// This is the struct that will be passed to your shader
#[derive(AsBindGroup, Debug, Clone, TypeUuid)]
#[uuid = "f690fdae-d598-45ab-8225-97e2a3f056e0"]
pub struct CustomMaterial {
#[uniform(0)]
pub base_color: Color,
#[texture(1)]
#[sampler(2)]
pub base_color_texture_0: Option<Handle<Image>>,
#[texture(3)]
#[sampler(4)]
pub base_color_texture_1: Option<Handle<Image>>,
#[texture(5)]
#[sampler(6)]
pub base_color_texture_2: Option<Handle<Image>>,
#[uniform(0)]
pub base_color_uv_0: u32,
#[uniform(0)]
pub base_color_uv_1: u32,
#[uniform(0)]
pub base_color_uv_2: u32,
#[uniform(0)]
pub base_color_l0: Color,
#[uniform(0)]
pub base_color_l1: Color,
#[uniform(0)]
pub base_color_l2: Color,
// pub ican_color: Color,
// pub ican_unmasked_color: Color,
#[texture(7)]
#[sampler(8)]
pub normal_map_texture_0: Option<Handle<Image>>,
#[texture(9)]
#[sampler(10)]
pub normal_map_texture_1: Option<Handle<Image>>,
#[texture(11)]
#[sampler(12)]
pub normal_map_texture_2: Option<Handle<Image>>,
#[uniform(0)]
pub normal_map_uv_0: u32,
#[uniform(0)]
pub normal_map_uv_1: u32,
#[uniform(0)]
pub normal_map_uv_2: u32,
#[uniform(0)]
pub normal_map_l0: Color,
#[uniform(0)]
pub normal_map_l1: Color,
#[uniform(0)]
pub normal_map_l2: Color,
#[texture(13)]
#[sampler(14)]
pub metallic_map_texture_0: Option<Handle<Image>>,
#[texture(15)]
#[sampler(16)]
pub metallic_map_texture_1: Option<Handle<Image>>,
#[texture(17)]
#[sampler(18)]
pub metallic_map_texture_2: Option<Handle<Image>>,
#[uniform(0)]
pub metallic_map_uv_0: u32,
#[uniform(0)]
pub metallic_map_uv_1: u32,
#[uniform(0)]
pub metallic_map_uv_2: u32,
#[uniform(0)]
pub metallic_map_l0: Color,
#[uniform(0)]
pub metallic_map_l1: Color,
#[uniform(0)]
pub metallic_map_l2: Color,
#[texture(19)]
#[sampler(20)]
pub emissive_texture: Option<Handle<Image>>,
#[uniform(0)]
pub emissive_uv: u32,
#[uniform(0)]
pub emissive_color: Color,
}
impl Default for CustomMaterial {
fn default() -> Self {
Self {
base_color: Color::WHITE,
base_color_texture_0: None,
base_color_texture_1: None,
base_color_texture_2: None,
base_color_uv_0: 0,
base_color_uv_1: 0,
base_color_uv_2: 0,
base_color_l0: Color::NONE,
base_color_l1: Color::NONE,
base_color_l2: Color::NONE,
normal_map_texture_0: None,
normal_map_texture_1: None,
normal_map_texture_2: None,
normal_map_uv_0: 0,
normal_map_uv_1: 0,
normal_map_uv_2: 0,
normal_map_l0: Color::NONE,
normal_map_l1: Color::NONE,
normal_map_l2: Color::NONE,
metallic_map_texture_0: None,
metallic_map_texture_1: None,
metallic_map_texture_2: None,
metallic_map_uv_0: 0,
metallic_map_uv_1: 0,
metallic_map_uv_2: 0,
metallic_map_l0: Color::NONE,
metallic_map_l1: Color::NONE,
metallic_map_l2: Color::NONE,
emissive_texture: None,
emissive_uv: 0,
emissive_color: Color::BLACK,
}
}
}
impl Material for CustomMaterial {
fn vertex_shader() -> ShaderRef { "custom_material.wgsl".into() }
fn fragment_shader() -> ShaderRef { "custom_material.wgsl".into() }
fn specialize(
_pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
layout: &MeshVertexBufferLayout,
_key: MaterialPipelineKey<Self>,
) -> Result<(), SpecializedMeshPipelineError> {
let mut shader_defs = Vec::new();
let mut vertex_attributes = Vec::new();
let mut add_attribute = |attr: MeshVertexAttribute, location: u32, define: &str| {
if layout.contains(attr.clone()) {
shader_defs.push(String::from(define));
vertex_attributes.push(attr.at_shader_location(location));
}
};
add_attribute(Mesh::ATTRIBUTE_POSITION, 0, "VERTEX_POSITIONS");
add_attribute(Mesh::ATTRIBUTE_NORMAL, 1, "VERTEX_NORMALS");
add_attribute(Mesh::ATTRIBUTE_UV_0, 2, "VERTEX_UVS_0");
add_attribute(ATTRIBUTE_UV_1, 3, "VERTEX_UVS_1");
add_attribute(ATTRIBUTE_UV_2, 4, "VERTEX_UVS_2");
add_attribute(ATTRIBUTE_UV_3, 5, "VERTEX_UVS_3");
add_attribute(Mesh::ATTRIBUTE_TANGENT, 6, "VERTEX_TANGENTS_0");
add_attribute(ATTRIBUTE_TANGENT_1, 7, "VERTEX_TANGENTS_1");
add_attribute(ATTRIBUTE_TANGENT_2, 8, "VERTEX_TANGENTS_2");
add_attribute(Mesh::ATTRIBUTE_COLOR, 9, "VERTEX_COLORS");
if layout.contains(Mesh::ATTRIBUTE_JOINT_INDEX)
&& layout.contains(Mesh::ATTRIBUTE_JOINT_WEIGHT)
{
shader_defs.push(String::from("SKINNED"));
vertex_attributes.push(Mesh::ATTRIBUTE_JOINT_INDEX.at_shader_location(10));
vertex_attributes.push(Mesh::ATTRIBUTE_JOINT_WEIGHT.at_shader_location(11));
}
let vertex_buffer_layout = layout.get_layout(&vertex_attributes)?;
descriptor.vertex.buffers = vec![vertex_buffer_layout];
descriptor.vertex.shader_defs.append(&mut shader_defs.clone());
descriptor.fragment.as_mut().unwrap().shader_defs.append(&mut shader_defs);
Ok(())
}
}
+232 -30
View File
@@ -1,4 +1,4 @@
use std::{borrow::Cow, ops::Range};
use std::{borrow::Cow, num::NonZeroU8, ops::Range};
use bevy::{
asset::LoadState,
@@ -18,6 +18,7 @@ use bevy::{
},
utils::HashMap,
};
use bevy::core_pipeline::bloom::BloomSettings;
use bevy_egui::EguiContext;
use egui::{Id, PointerButton, Sense};
use half::f16;
@@ -26,13 +27,17 @@ use retrolib::format::{
CMaterialDataInner, EBufferType, EMaterialDataId, EVertexComponent, EVertexDataFormat,
ModelData, STextureUsageInfo, SVertexDataComponent,
},
txtr::{ETextureFormat, ETextureType},
txtr::{
ETextureAnisotropicRatio, ETextureFilter, ETextureFormat, ETextureMipFilter, ETextureType,
ETextureWrap, STextureSamplerData,
},
};
use uuid::Uuid;
use crate::{
icon,
loaders::{ModelAsset, TextureAsset},
material::CustomMaterial,
tabs::SystemTab,
AssetRef, TabState,
};
@@ -100,7 +105,7 @@ fn convert_component(
Normal => Mesh::ATTRIBUTE_NORMAL,
Tangent0 => Mesh::ATTRIBUTE_TANGENT,
TexCoord0 => Mesh::ATTRIBUTE_UV_0,
// Color => Mesh::ATTRIBUTE_COLOR,
Color => Mesh::ATTRIBUTE_COLOR,
// BoneIndices => Mesh::ATTRIBUTE_JOINT_INDEX,
// BoneWeights => Mesh::ATTRIBUTE_JOINT_WEIGHT,
_ => return None,
@@ -126,7 +131,7 @@ fn convert_component(
})),
_ => Unorm8x4(copy_direct(input, component)),
},
Rgba8Uint => Uint8x4(copy_direct(input, component)),
Rgba8Uint => Uint16x4(copy_converting(input, component, |v: [u8; 4]| v.map(|n| n as u16))),
Rgba8Snorm => Snorm8x4(copy_direct(input, component)),
Rgba8Sint => Sint8x4(copy_direct(input, component)),
Rg32Uint => Uint32x2(copy_direct(input, component)),
@@ -225,53 +230,92 @@ enum IndicesSlice<'a> {
}
#[derive(Component)]
pub struct TemporaryTag;
pub struct TemporaryLabel;
fn sampler_descriptor_from_usage<'a>(usage: &STextureUsageInfo) -> SamplerDescriptor<'a> {
fn texture_wrap(wrap: ETextureWrap) -> AddressMode {
match wrap {
ETextureWrap::ClampToEdge => AddressMode::ClampToEdge,
ETextureWrap::Repeat => AddressMode::Repeat,
ETextureWrap::MirroredRepeat => AddressMode::MirrorRepeat,
ETextureWrap::MirrorClamp => todo!("Mirror clamp"),
ETextureWrap::ClampToBorder => AddressMode::ClampToBorder,
ETextureWrap::Clamp => todo!("Clamp"),
}
}
fn sampler_descriptor_from_usage<'a>(
usage: &STextureUsageInfo,
data: Option<&STextureSamplerData>,
) -> SamplerDescriptor<'a> {
SamplerDescriptor {
label: None,
address_mode_u: match usage.wrap_x {
0 | u32::MAX => AddressMode::ClampToEdge,
0 => AddressMode::ClampToEdge,
1 => AddressMode::Repeat,
2 => AddressMode::MirrorRepeat,
3 => todo!("Mirror clamp"),
4 => AddressMode::ClampToBorder,
5 => todo!("Clamp"),
u32::MAX => data.map_or(AddressMode::Repeat, |d| texture_wrap(d.wrap_x)),
n => todo!("wrap {n}"),
},
address_mode_v: match usage.wrap_y {
0 | u32::MAX => AddressMode::ClampToEdge,
0 => AddressMode::ClampToEdge,
1 => AddressMode::Repeat,
2 => AddressMode::MirrorRepeat,
3 => todo!("Mirror clamp"),
4 => AddressMode::ClampToBorder,
5 => todo!("Clamp"),
u32::MAX => data.map_or(AddressMode::Repeat, |d| texture_wrap(d.wrap_y)),
n => todo!("wrap {n}"),
},
address_mode_w: match usage.wrap_z {
0 | u32::MAX => AddressMode::ClampToEdge,
0 => AddressMode::ClampToEdge,
1 => AddressMode::Repeat,
2 => AddressMode::MirrorRepeat,
3 => todo!("Mirror clamp"),
4 => AddressMode::ClampToBorder,
5 => todo!("Clamp"),
u32::MAX => data.map_or(AddressMode::Repeat, |d| texture_wrap(d.wrap_z)),
n => todo!("wrap {n}"),
},
mag_filter: match usage.filter {
0 | u32::MAX => FilterMode::Nearest,
0 => FilterMode::Nearest,
1 => FilterMode::Linear,
u32::MAX => data.map_or(FilterMode::Nearest, |d| match d.filter {
ETextureFilter::Nearest => FilterMode::Nearest,
ETextureFilter::Linear => FilterMode::Linear,
}),
n => todo!("Filter {n}"),
},
min_filter: match usage.filter {
0 | u32::MAX => FilterMode::Nearest,
0 => FilterMode::Nearest,
1 => FilterMode::Linear,
u32::MAX => data.map_or(FilterMode::Nearest, |d| match d.filter {
ETextureFilter::Nearest => FilterMode::Nearest,
ETextureFilter::Linear => FilterMode::Linear,
}),
n => todo!("Filter {n}"),
},
mipmap_filter: FilterMode::Linear, // TODO?
mipmap_filter: data.map_or(FilterMode::Nearest, |d| match d.mip_filter {
ETextureMipFilter::Nearest => FilterMode::Nearest,
ETextureMipFilter::Linear => FilterMode::Linear,
}),
lod_min_clamp: 0.0,
lod_max_clamp: 0.0,
lod_max_clamp: f32::MAX,
compare: None,
anisotropy_clamp: None,
anisotropy_clamp: NonZeroU8::new(
data.map(|d| match d.aniso {
ETextureAnisotropicRatio::None => 0,
ETextureAnisotropicRatio::_1 => 1,
ETextureAnisotropicRatio::_2 => 2,
ETextureAnisotropicRatio::_4 => 4,
ETextureAnisotropicRatio::_8 => 8,
ETextureAnisotropicRatio::_16 => 16,
})
.unwrap_or_default(),
),
// anisotropy_clamp: NonZeroU8::new(8),
border_color: None,
}
}
@@ -280,7 +324,7 @@ impl SystemTab for ModelTab {
type LoadParam = (
SCommands,
SResMut<Assets<Mesh>>,
SResMut<Assets<StandardMaterial>>,
SResMut<Assets<CustomMaterial>>,
SResMut<Assets<ModelAsset>>,
SResMut<Assets<TextureAsset>>,
SResMut<Assets<Image>>,
@@ -327,15 +371,27 @@ impl SystemTab for ModelTab {
match &data.data {
CMaterialDataInner::Texture(texture) => {
if let Some(usage) = &texture.usage {
sampler_descriptors
.insert(texture.id, sampler_descriptor_from_usage(usage));
let sampler_data = textures
.get(&texture.id)
.and_then(|handle| texture_assets.get(handle))
.map(|txtr| &txtr.inner.head.sampler_data);
sampler_descriptors.insert(
texture.id,
sampler_descriptor_from_usage(usage, sampler_data),
);
}
}
CMaterialDataInner::LayeredTexture(textures) => {
for texture in &textures.textures {
CMaterialDataInner::LayeredTexture(layers) => {
for texture in &layers.textures {
if let Some(usage) = &texture.usage {
sampler_descriptors
.insert(texture.id, sampler_descriptor_from_usage(usage));
let sampler_data = textures
.get(&texture.id)
.and_then(|handle| texture_assets.get(handle))
.map(|txtr| &txtr.inner.head.sampler_data);
sampler_descriptors.insert(
texture.id,
sampler_descriptor_from_usage(usage, sampler_data),
);
}
}
}
@@ -494,14 +550,18 @@ impl SystemTab for ModelTab {
// Build materials
let mut material_handles = Vec::with_capacity(mtrl.materials.len());
for mat in &mtrl.materials {
let mut out_mat = StandardMaterial::default();
let mut out_mat = CustomMaterial::default();
println!("Shader {}, unk {}", mat.shader_id, mat.unk_guid);
let _ = server.load_untyped(format!("{}.MTRL", mat.shader_id));
for data in &mat.data {
match data.data_id {
EMaterialDataId::DIFT | EMaterialDataId::BCLR => match &data.data {
CMaterialDataInner::Texture(texture) => {
out_mat.base_color_texture = texture_handles.get(&texture.id).cloned();
out_mat.base_color_l0 = Color::WHITE;
out_mat.base_color_texture_0 =
texture_handles.get(&texture.id).cloned();
out_mat.base_color_uv_0 =
texture.usage.as_ref().map(|u| u.flags).unwrap_or_default();
}
_ => {
log::warn!(
@@ -510,6 +570,41 @@ impl SystemTab for ModelTab {
);
}
},
EMaterialDataId::BCRL => match &data.data {
CMaterialDataInner::LayeredTexture(layers) => {
// println!("CREATING BCRL!!!");
out_mat.base_color_l0 = layers.base.colors[0].to_array().into();
out_mat.base_color_l1 = layers.base.colors[1].to_array().into();
out_mat.base_color_l2 = layers.base.colors[2].to_array().into();
out_mat.base_color_texture_0 =
texture_handles.get(&layers.textures[0].id).cloned();
out_mat.base_color_texture_1 =
texture_handles.get(&layers.textures[1].id).cloned();
out_mat.base_color_texture_2 =
texture_handles.get(&layers.textures[2].id).cloned();
out_mat.base_color_uv_0 = layers.textures[0]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
out_mat.base_color_uv_1 = layers.textures[1]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
out_mat.base_color_uv_2 = layers.textures[2]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
}
_ => {
log::warn!(
"Unsupported material data type for BCRL {:?}",
data.data_type
);
}
},
EMaterialDataId::DIFC => match &data.data {
CMaterialDataInner::Color(color) => {
out_mat.base_color = Color::rgba(color.r, color.g, color.b, color.a);
@@ -520,8 +615,10 @@ impl SystemTab for ModelTab {
),
},
EMaterialDataId::ICAN => match &data.data {
CMaterialDataInner::Texture(_texture) => {
// out_mat.emissive_texture = texture_handles.get(&texture.id).cloned();
CMaterialDataInner::Texture(texture) => {
out_mat.emissive_texture = texture_handles.get(&texture.id).cloned();
out_mat.emissive_uv =
texture.usage.as_ref().map(|u| u.flags).unwrap_or_default();
}
_ => log::warn!(
"Unsupported material data type for ICAN {:?}",
@@ -529,14 +626,113 @@ impl SystemTab for ModelTab {
),
},
EMaterialDataId::ICNC => match &data.data {
CMaterialDataInner::Color(_color) => {
// out_mat.emissive = Color::rgba(color.r, color.g, color.b, color.a);
CMaterialDataInner::Color(color) => {
out_mat.emissive_color =
Color::rgba(color.r, color.g, color.b, color.a);
}
_ => log::warn!(
"Unsupported material data type for ICNC {:?}",
data.data_type
),
},
EMaterialDataId::NMAP => match &data.data {
CMaterialDataInner::Texture(texture) => {
out_mat.normal_map_l0 = Color::WHITE;
out_mat.normal_map_texture_0 =
texture_handles.get(&texture.id).cloned();
out_mat.normal_map_uv_0 = texture.usage.as_ref().unwrap().flags;
}
_ => {
log::warn!(
"Unsupported material data type for NMAP {:?}",
data.data_type
);
}
},
EMaterialDataId::NRML => match &data.data {
CMaterialDataInner::LayeredTexture(layers) => {
// println!("CREATING NRML!!!");
out_mat.normal_map_l0 = layers.base.colors[0].to_array().into();
out_mat.normal_map_l1 = layers.base.colors[1].to_array().into();
out_mat.normal_map_l2 = layers.base.colors[2].to_array().into();
out_mat.normal_map_texture_0 =
texture_handles.get(&layers.textures[0].id).cloned();
out_mat.normal_map_texture_1 =
texture_handles.get(&layers.textures[1].id).cloned();
out_mat.normal_map_texture_2 =
texture_handles.get(&layers.textures[2].id).cloned();
out_mat.normal_map_uv_0 = layers.textures[0]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
out_mat.normal_map_uv_1 = layers.textures[1]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
out_mat.normal_map_uv_2 = layers.textures[2]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
}
_ => {
log::warn!(
"Unsupported material data type for NRML {:?}",
data.data_type
);
}
},
EMaterialDataId::METL => match &data.data {
CMaterialDataInner::Texture(texture) => {
out_mat.metallic_map_l0 = Color::WHITE;
out_mat.metallic_map_texture_0 =
texture_handles.get(&texture.id).cloned();
out_mat.metallic_map_uv_0 = texture.usage.as_ref().unwrap().flags;
}
_ => {
log::warn!(
"Unsupported material data type for METL {:?}",
data.data_type
);
}
},
EMaterialDataId::MTLL => match &data.data {
CMaterialDataInner::LayeredTexture(layers) => {
// println!("CREATING MTLL!!!");
out_mat.metallic_map_l0 = layers.base.colors[0].to_array().into();
out_mat.metallic_map_l1 = layers.base.colors[1].to_array().into();
out_mat.metallic_map_l2 = layers.base.colors[2].to_array().into();
out_mat.metallic_map_texture_0 =
texture_handles.get(&layers.textures[0].id).cloned();
out_mat.metallic_map_texture_1 =
texture_handles.get(&layers.textures[1].id).cloned();
out_mat.metallic_map_texture_2 =
texture_handles.get(&layers.textures[2].id).cloned();
out_mat.metallic_map_uv_0 = layers.textures[0]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
out_mat.metallic_map_uv_1 = layers.textures[1]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
out_mat.metallic_map_uv_2 = layers.textures[2]
.usage
.as_ref()
.map(|u| u.flags)
.unwrap_or_default();
}
_ => {
log::warn!(
"Unsupported material data type for MTLL {:?}",
data.data_type
);
}
},
id => {
log::warn!("Unsupported material data ID {id:?}");
}
@@ -574,7 +770,7 @@ impl SystemTab for ModelTab {
}
entities.push((
commands
.spawn(PbrBundle {
.spawn(MaterialMeshBundle {
mesh: meshes.add(out_mesh),
material: material_handles[in_mesh.material_idx as usize].clone(),
transform: Transform::from_translation((-aabb.center).into()),
@@ -712,13 +908,19 @@ impl SystemTab for ModelTab {
camera: Camera {
viewport: Some(viewport),
priority: state.render_layer as isize,
// TOOD bevy 0.10
// hdr: true,
..default()
},
// TOOD bevy 0.10
// tonemapping: Tonemapping::TonyMcMapFace,
transform: loaded.camera_xf,
..default()
},
// TOOD bevy 0.10
// BloomSettings::default(),
RenderLayers::layer(state.render_layer),
TemporaryTag,
TemporaryLabel,
));
commands.spawn((
DirectionalLightBundle {
@@ -728,7 +930,7 @@ impl SystemTab for ModelTab {
..default()
},
RenderLayers::layer(state.render_layer),
TemporaryTag,
TemporaryLabel,
));
egui::Frame::group(ui.style()).show(ui, |ui| {