mirror of
https://github.com/PrimeDecomp/retrotool.git
synced 2026-07-12 18:18:58 -07:00
Minor GUI fixes & cleanup
This commit is contained in:
@@ -18,13 +18,14 @@ use retrolib::format::{
|
||||
ETextureAnisotropicRatio, ETextureFilter, ETextureMipFilter, ETextureWrap,
|
||||
STextureSamplerData,
|
||||
},
|
||||
CColor4f,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
use wgpu_types::{AddressMode, Face, FilterMode};
|
||||
|
||||
use crate::{
|
||||
loaders::texture::TextureAsset, material::CustomMaterial, render::model::MESH_FLAG_OPAQUE,
|
||||
loaders::texture::TextureAsset,
|
||||
material::CustomMaterial,
|
||||
render::{convert_color, model::MESH_FLAG_OPAQUE},
|
||||
AssetRef,
|
||||
};
|
||||
|
||||
@@ -192,11 +193,6 @@ impl ModelAsset {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn convert_color(value: &CColor4f) -> Color {
|
||||
Color::rgba_linear(value.r, value.g, value.b, value.a)
|
||||
}
|
||||
|
||||
fn build_material(
|
||||
key: &MaterialKey,
|
||||
materials: &[CMaterialCache],
|
||||
|
||||
@@ -189,7 +189,7 @@ fn texture_to_image(
|
||||
fn wgpu_format(format: ETextureFormat) -> Option<TextureFormat> {
|
||||
use wgpu_types::{AstcBlock::*, AstcChannel::*, TextureFormat::*};
|
||||
Some(match format {
|
||||
ETextureFormat::R8Unorm => Rgba8Unorm,
|
||||
ETextureFormat::R8Unorm => R8Unorm,
|
||||
ETextureFormat::R8Snorm => R8Snorm,
|
||||
ETextureFormat::R8Uint => R8Uint,
|
||||
ETextureFormat::R8Sint => R8Sint,
|
||||
|
||||
@@ -15,7 +15,7 @@ use bevy::{
|
||||
},
|
||||
renderer::{RenderContext, RenderDevice},
|
||||
texture::BevyDefault,
|
||||
view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms},
|
||||
view::{ExtractedView, ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms},
|
||||
RenderApp, RenderSet,
|
||||
},
|
||||
};
|
||||
@@ -99,10 +99,9 @@ impl Node for GridCameraDriver {
|
||||
render_context: &mut RenderContext,
|
||||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let clear_res = world.resource::<ClearColor>();
|
||||
let pipeline_res = world.resource::<GridPipeline>();
|
||||
let pipeline_cache = world.resource::<PipelineCache>();
|
||||
let uniforms = world.resource::<ViewUniforms>();
|
||||
let view_uniforms = world.resource::<ViewUniforms>();
|
||||
|
||||
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
|
||||
let Ok((
|
||||
@@ -119,7 +118,7 @@ impl Node for GridCameraDriver {
|
||||
Some(resource),
|
||||
) = (
|
||||
pipeline_cache.get_render_pipeline(pipeline_ids.id),
|
||||
uniforms.uniforms.binding(),
|
||||
view_uniforms.uniforms.binding(),
|
||||
) else { return Ok(()); };
|
||||
|
||||
render_context.command_encoder().push_debug_group("grid");
|
||||
@@ -131,17 +130,20 @@ impl Node for GridCameraDriver {
|
||||
entries: &[wgpu::BindGroupEntry { binding: 0, resource }],
|
||||
});
|
||||
|
||||
let color_attachment = target.get_color_attachment(wgpu::Operations {
|
||||
load: match settings.clear_color {
|
||||
ClearColorConfig::Default => {
|
||||
wgpu::LoadOp::Clear(world.resource::<ClearColor>().0.into())
|
||||
}
|
||||
ClearColorConfig::Custom(color) => wgpu::LoadOp::Clear(color.into()),
|
||||
ClearColorConfig::None => wgpu::LoadOp::Load,
|
||||
},
|
||||
store: true,
|
||||
});
|
||||
let mut render_pass =
|
||||
render_context.begin_tracked_render_pass(wgpu::RenderPassDescriptor {
|
||||
label: Some("grid_render_pass"),
|
||||
color_attachments: &[Some(target.get_color_attachment(wgpu::Operations {
|
||||
load: match settings.clear_color {
|
||||
ClearColorConfig::Default => wgpu::LoadOp::Clear(clear_res.0.into()),
|
||||
ClearColorConfig::Custom(color) => wgpu::LoadOp::Clear(color.into()),
|
||||
ClearColorConfig::None => wgpu::LoadOp::Load,
|
||||
},
|
||||
store: true,
|
||||
}))],
|
||||
color_attachments: &[Some(color_attachment)],
|
||||
depth_stencil_attachment: None,
|
||||
});
|
||||
if let Some(viewport) = &camera.viewport {
|
||||
@@ -169,6 +171,7 @@ pub struct GridPipeline {
|
||||
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||
pub struct GridPipelineKey {
|
||||
pub msaa_samples: u32,
|
||||
pub texture_format: wgpu::TextureFormat,
|
||||
}
|
||||
|
||||
impl FromWorld for GridPipeline {
|
||||
@@ -212,9 +215,9 @@ impl SpecializedRenderPipeline for GridPipeline {
|
||||
shader_defs: vec![],
|
||||
entry_point: "fragment".into(),
|
||||
targets: vec![Some(wgpu::ColorTargetState {
|
||||
format: wgpu::TextureFormat::bevy_default(),
|
||||
format: key.texture_format,
|
||||
blend: Some(wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING),
|
||||
write_mask: wgpu::ColorWrites::ALL,
|
||||
write_mask: wgpu::ColorWrites::COLOR,
|
||||
})],
|
||||
}),
|
||||
primitive: wgpu::PrimitiveState {
|
||||
@@ -237,12 +240,17 @@ pub fn prepare_grid_pipeline(
|
||||
pipeline_cache: Res<PipelineCache>,
|
||||
mut pipelines: ResMut<SpecializedRenderPipelines<GridPipeline>>,
|
||||
pipeline: Res<GridPipeline>,
|
||||
views: Query<(Entity, &GridSettings)>,
|
||||
views: Query<(Entity, &ExtractedView), With<GridSettings>>,
|
||||
msaa: Res<Msaa>,
|
||||
) {
|
||||
for (entity, _settings) in &views {
|
||||
for (entity, view) in &views {
|
||||
let pipeline_id = pipelines.specialize(&pipeline_cache, &pipeline, GridPipelineKey {
|
||||
msaa_samples: msaa.samples(),
|
||||
texture_format: if view.hdr {
|
||||
ViewTarget::TEXTURE_FORMAT_HDR
|
||||
} else {
|
||||
wgpu::TextureFormat::bevy_default()
|
||||
},
|
||||
});
|
||||
commands.entity(entity).insert(GridPipelineIds { id: pipeline_id });
|
||||
}
|
||||
@@ -253,6 +261,10 @@ pub struct GridSettings {
|
||||
pub clear_color: ClearColorConfig,
|
||||
}
|
||||
|
||||
impl Default for GridSettings {
|
||||
fn default() -> Self { Self { clear_color: ClearColorConfig::None } }
|
||||
}
|
||||
|
||||
// noinspection RsSortImplTraitMembers
|
||||
impl ExtractComponent for GridSettings {
|
||||
type Filter = ();
|
||||
|
||||
@@ -2,7 +2,26 @@ pub mod camera;
|
||||
pub mod grid;
|
||||
pub mod model;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::{prelude::*, render::primitives::Aabb};
|
||||
use retrolib::format::{CAABox, CColor4f, CTransform4f};
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct TemporaryLabel;
|
||||
|
||||
#[inline]
|
||||
pub fn convert_aabb(aabb: &CAABox) -> Aabb {
|
||||
let min = mint::Vector3::from(aabb.min);
|
||||
let max = mint::Vector3::from(aabb.max);
|
||||
Aabb::from_min_max(min.into(), max.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn convert_transform(xf: &CTransform4f) -> Transform {
|
||||
let mtx = mint::ColumnMatrix4::from(*xf);
|
||||
Transform::from_matrix(mtx.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn convert_color(value: &CColor4f) -> Color {
|
||||
Color::rgba_linear(value.r, value.g, value.b, value.a)
|
||||
}
|
||||
|
||||
@@ -12,12 +12,9 @@ use bit_set::BitSet;
|
||||
use half::prelude::*;
|
||||
use retrolib::{
|
||||
array_ref,
|
||||
format::{
|
||||
cmdl::{
|
||||
CMaterialCache, EBufferType, EVertexComponent, EVertexDataFormat, ModelData,
|
||||
SVertexDataComponent,
|
||||
},
|
||||
CAABox, CTransform4f,
|
||||
format::cmdl::{
|
||||
CMaterialCache, EBufferType, EVertexComponent, EVertexDataFormat, ModelData,
|
||||
SVertexDataComponent,
|
||||
},
|
||||
};
|
||||
use wgpu_types::PrimitiveTopology;
|
||||
@@ -27,6 +24,7 @@ use crate::{
|
||||
material::{
|
||||
ATTRIBUTE_TANGENT_1, ATTRIBUTE_TANGENT_2, ATTRIBUTE_UV_1, ATTRIBUTE_UV_2, ATTRIBUTE_UV_3,
|
||||
},
|
||||
render::convert_aabb,
|
||||
};
|
||||
|
||||
pub const MESH_FLAG_OPAQUE: u16 = 1;
|
||||
@@ -136,19 +134,6 @@ pub fn load_model(asset: &ModelAsset, meshes: &mut Assets<Mesh>) -> Result<Built
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn convert_aabb(aabb: &CAABox) -> Aabb {
|
||||
let min = mint::Vector3::from(aabb.min);
|
||||
let max = mint::Vector3::from(aabb.max);
|
||||
Aabb::from_min_max(min.into(), max.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn convert_transform(xf: &CTransform4f) -> Transform {
|
||||
let mtx = mint::ColumnMatrix4::from(*xf);
|
||||
Transform::from_matrix(mtx.into())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
struct VertexBufferInfo {
|
||||
pub attributes: Vec<(MeshVertexAttribute, VertexAttributeValues)>,
|
||||
|
||||
@@ -19,9 +19,7 @@ use crate::{
|
||||
},
|
||||
material::CustomMaterial,
|
||||
render::{
|
||||
camera::ModelCamera,
|
||||
grid::GridSettings,
|
||||
model::{convert_transform, load_model},
|
||||
camera::ModelCamera, convert_transform, grid::GridSettings, model::load_model,
|
||||
TemporaryLabel,
|
||||
},
|
||||
tabs::{model::ModelTab, SystemTab, TabState, TabType},
|
||||
@@ -120,8 +118,8 @@ impl SystemTab for ModConTab {
|
||||
SRes<AssetServer>,
|
||||
SRes<Assets<ModelAsset>>,
|
||||
SRes<Assets<ModConAsset>>,
|
||||
SQuery<&'static Parent, With<Intersection<ModConRaycastSet>>>,
|
||||
SQuery<&'static ModelLabel>,
|
||||
SQuery<Read<Parent>, With<Intersection<ModConRaycastSet>>>,
|
||||
SQuery<Read<ModelLabel>>,
|
||||
);
|
||||
|
||||
fn load(&mut self, _ctx: &mut EguiContext, query: SystemParamItem<'_, '_, Self::LoadParam>) {
|
||||
@@ -236,8 +234,12 @@ impl SystemTab for ModConTab {
|
||||
let mut min = Vec3A::splat(f32::MAX);
|
||||
let mut max = Vec3A::splat(f32::MIN);
|
||||
for info in &self.models {
|
||||
min = info.aabb.min().min(min);
|
||||
max = info.aabb.max().max(max);
|
||||
let m_min = Vec3::from(info.aabb.min());
|
||||
let m_max = Vec3::from(info.aabb.max());
|
||||
for &xf in &info.transforms {
|
||||
min = min.min(Vec3A::from(xf * m_min));
|
||||
max = max.max(Vec3A::from(xf * m_max));
|
||||
}
|
||||
}
|
||||
let aabb = Aabb::from_min_max(min.into(), max.into());
|
||||
self.camera.init(&aabb, true);
|
||||
|
||||
@@ -24,8 +24,9 @@ use crate::{
|
||||
material::CustomMaterial,
|
||||
render::{
|
||||
camera::ModelCamera,
|
||||
convert_aabb,
|
||||
grid::GridSettings,
|
||||
model::{convert_aabb, load_model, ModelLod},
|
||||
model::{load_model, ModelLod},
|
||||
TemporaryLabel,
|
||||
},
|
||||
tabs::{
|
||||
|
||||
Reference in New Issue
Block a user