This commit is contained in:
1 parent
577d8dcb27
commit
ed21bcc52d
22 files changed
+874
-6
No files matched your search
@@ -112,6 +112,7 @@ pub fn draw_actor_inspector(world: &mut World, ui: &mut egui::Ui, entity: Entity
|
||||
ActorKind::StaticMesh
|
||||
| ActorKind::SkinnedMesh
|
||||
| ActorKind::Brush
|
||||
| ActorKind::Terrain
|
||||
| ActorKind::ImportedModel
|
||||
| ActorKind::Light
|
||||
| ActorKind::Empty
|
||||
@@ -143,6 +144,7 @@ fn actor_icon(kind: ActorKind) -> egui_phosphor_icons::Icon {
|
||||
ActorKind::StaticMesh
|
||||
| ActorKind::SkinnedMesh
|
||||
| ActorKind::Brush
|
||||
| ActorKind::Terrain
|
||||
| ActorKind::ImportedModel => icons::CUBE,
|
||||
ActorKind::Light => icons::LIGHTBULB,
|
||||
ActorKind::PrefabAnchor => icons::PACKAGE,
|
||||
|
||||
@@ -373,6 +373,27 @@ impl Default for EditorComponentRegistry {
|
||||
],
|
||||
hydration_effect: "Hydrates into generated brush mesh children.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_TERRAIN,
|
||||
type_name: "shared::components::TerrainDesc",
|
||||
display_name: "Terrain",
|
||||
category: EditorComponentCategory::Authoring,
|
||||
addable: true,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::MOUNTAINS.as_str(),
|
||||
description: "Creates chunked height-grid terrain with optional collision.",
|
||||
search_terms: &["terrain", "landscape", "heightmap", "ground", "chunk"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[
|
||||
"shared::components::Primitive",
|
||||
"shared::components::BrushDesc",
|
||||
"shared::components::StaticMeshRenderer",
|
||||
"shared::animation::SkinnedMeshRenderer",
|
||||
],
|
||||
hydration_effect: "Hydrates into generated render and collider chunks.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_MATERIAL,
|
||||
type_name: "shared::components::MaterialDesc",
|
||||
|
||||
@@ -205,6 +205,7 @@ fn actor_kind_sort_key(world: &World, entity: Entity) -> u8 {
|
||||
.map(|kind| match kind {
|
||||
ActorKind::Empty => 0,
|
||||
ActorKind::Brush
|
||||
| ActorKind::Terrain
|
||||
| ActorKind::StaticMesh
|
||||
| ActorKind::SkinnedMesh
|
||||
| ActorKind::ImportedModel => 1,
|
||||
@@ -468,6 +469,7 @@ pub fn actor_kind_icon(kind: ActorKind) -> &'static str {
|
||||
match kind {
|
||||
ActorKind::Empty => icons::FOLDER.as_str(),
|
||||
ActorKind::Brush => icons::CUBE.as_str(),
|
||||
ActorKind::Terrain => icons::MOUNTAINS.as_str(),
|
||||
ActorKind::StaticMesh => icons::CUBE.as_str(),
|
||||
ActorKind::SkinnedMesh => icons::PERSON_SIMPLE_RUN.as_str(),
|
||||
ActorKind::ImportedModel => icons::CUBE_TRANSPARENT.as_str(),
|
||||
|
||||
@@ -16,8 +16,8 @@ use shared::{
|
||||
MaterialParameterValue, MaterialRef, MaterialShaderKind, NavigationArea, NavigationBounds,
|
||||
NavigationLink, NavigationObstacle, ObjectiveMarker, PhysicsBody, PlayerSpawn,
|
||||
PostProcessVolumeDesc, PrefabInstance, Primitive, PrimitiveShape, ProjectSun, RigidBodyDesc,
|
||||
SkinnedMeshRenderer, StaticMeshRenderer, StaticMeshRendererEntry, TeamSpawn, TriggerVolume,
|
||||
WeaponSpawn, AUTHORING_DIRECTIONAL_LUX_MAX, AUTHORING_POINT_SPOT_LUMENS_MAX,
|
||||
SkinnedMeshRenderer, StaticMeshRenderer, StaticMeshRendererEntry, TeamSpawn, TerrainDesc,
|
||||
TriggerVolume, WeaponSpawn, AUTHORING_DIRECTIONAL_LUX_MAX, AUTHORING_POINT_SPOT_LUMENS_MAX,
|
||||
COMPONENT_ANIMATION_CONTROLLER_DESC, COMPONENT_AUDIO_LISTENER_DESC,
|
||||
COMPONENT_AUDIO_SOURCE_DESC, COMPONENT_BRUSH_DESC, COMPONENT_COLLIDER_DESC,
|
||||
COMPONENT_LIGHT_DESC, COMPONENT_MATERIAL_DESC, COMPONENT_NAVIGATION_AREA,
|
||||
@@ -25,8 +25,8 @@ use shared::{
|
||||
COMPONENT_OBJECTIVE_MARKER, COMPONENT_PHYSICS_BODY, COMPONENT_PLAYER_SPAWN,
|
||||
COMPONENT_POST_PROCESS_VOLUME, COMPONENT_PREFAB_INSTANCE, COMPONENT_PRIMITIVE,
|
||||
COMPONENT_PROJECT_SUN, COMPONENT_RIGID_BODY_DESC, COMPONENT_SKINNED_MESH_RENDERER,
|
||||
COMPONENT_STATIC_MESH_RENDERER, COMPONENT_TEAM_SPAWN, COMPONENT_TRIGGER_VOLUME,
|
||||
COMPONENT_WEAPON_SPAWN,
|
||||
COMPONENT_STATIC_MESH_RENDERER, COMPONENT_TEAM_SPAWN, COMPONENT_TERRAIN_DESC,
|
||||
COMPONENT_TRIGGER_VOLUME, COMPONENT_WEAPON_SPAWN,
|
||||
};
|
||||
|
||||
use crate::history::{
|
||||
@@ -1110,6 +1110,7 @@ fn draw_authoring_component_by_type(
|
||||
COMPONENT_STATIC_MESH_RENDERER => static_mesh_renderer_ui(world, ui, entity),
|
||||
COMPONENT_SKINNED_MESH_RENDERER => skinned_mesh_renderer_ui(world, ui, entity),
|
||||
COMPONENT_BRUSH_DESC => brush_editor_ui(world, ui, entity),
|
||||
COMPONENT_TERRAIN_DESC => terrain_editor_ui(world, ui, entity),
|
||||
COMPONENT_PRIMITIVE => primitive_editor_ui(world, ui, entity),
|
||||
COMPONENT_MATERIAL_DESC => material_editor_ui(world, ui, entity),
|
||||
COMPONENT_LIGHT_DESC => light_editor_ui(world, ui, entity),
|
||||
@@ -3494,6 +3495,128 @@ fn brush_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
}
|
||||
}
|
||||
|
||||
fn terrain_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let Some(mut terrain) = world.get::<TerrainDesc>(entity).cloned() else {
|
||||
return;
|
||||
};
|
||||
let original = terrain.clone();
|
||||
let mut changed = false;
|
||||
let mut requested_resolution = terrain.resolution;
|
||||
let card = component_card_context(
|
||||
world,
|
||||
entity,
|
||||
ComponentCardOptions::removable(COMPONENT_TERRAIN_DESC, "Terrain", icons::MOUNTAINS),
|
||||
);
|
||||
let card_response = component_card(ui, &card, |ui| {
|
||||
property_row(ui, "Grid", |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut requested_resolution)
|
||||
.range(2..=1025)
|
||||
.suffix(" samples"),
|
||||
);
|
||||
if ui
|
||||
.add_enabled(
|
||||
requested_resolution != terrain.resolution,
|
||||
egui::Button::new("Resize Flat"),
|
||||
)
|
||||
.on_hover_text("Replaces the current height grid with a flat grid")
|
||||
.clicked()
|
||||
{
|
||||
let replacement = TerrainDesc::flat(requested_resolution);
|
||||
terrain.resolution = replacement.resolution;
|
||||
terrain.heights = replacement.heights;
|
||||
terrain.chunk_quads = terrain.chunk_quads.min(terrain.resolution - 1).max(1);
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
property_row(ui, "Sample Spacing", |ui| {
|
||||
changed |= ui
|
||||
.add(
|
||||
egui::DragValue::new(&mut terrain.sample_spacing)
|
||||
.range(0.01..=1000.0)
|
||||
.speed(0.1)
|
||||
.suffix(" m"),
|
||||
)
|
||||
.changed();
|
||||
});
|
||||
property_row(ui, "Height Scale", |ui| {
|
||||
changed |= ui
|
||||
.add(
|
||||
egui::DragValue::new(&mut terrain.height_scale)
|
||||
.range(0.01..=10000.0)
|
||||
.speed(0.1)
|
||||
.suffix(" m"),
|
||||
)
|
||||
.changed();
|
||||
});
|
||||
property_row(ui, "Chunk Size", |ui| {
|
||||
changed |= ui
|
||||
.add(
|
||||
egui::DragValue::new(&mut terrain.chunk_quads)
|
||||
.range(1..=terrain.resolution.saturating_sub(1))
|
||||
.suffix(" quads"),
|
||||
)
|
||||
.changed();
|
||||
});
|
||||
property_row(ui, "Collision", |ui| {
|
||||
changed |= ui
|
||||
.checkbox(&mut terrain.generate_colliders, "Generate")
|
||||
.changed();
|
||||
});
|
||||
property_row(ui, "Shadows", |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
changed |= ui.checkbox(&mut terrain.cast_shadows, "Cast").changed();
|
||||
changed |= ui
|
||||
.checkbox(&mut terrain.receive_shadows, "Receive")
|
||||
.changed();
|
||||
});
|
||||
});
|
||||
property_row(ui, "Base Material", |ui| {
|
||||
ui.label(
|
||||
terrain
|
||||
.base_material
|
||||
.as_ref()
|
||||
.map(|material| material.label.as_str())
|
||||
.filter(|label| !label.is_empty())
|
||||
.unwrap_or("Terrain fallback"),
|
||||
);
|
||||
});
|
||||
match terrain.validate() {
|
||||
Ok(()) => {
|
||||
ui.label(
|
||||
egui::RichText::new(format!(
|
||||
"{} heights • {}×{} chunks",
|
||||
terrain.heights.len(),
|
||||
(terrain.resolution - 1).div_ceil(terrain.chunk_quads),
|
||||
(terrain.resolution - 1).div_ceil(terrain.chunk_quads)
|
||||
))
|
||||
.color(super::theme::SUCCESS),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
ui.label(egui::RichText::new(error).color(super::theme::ERROR));
|
||||
}
|
||||
}
|
||||
});
|
||||
apply_component_card_response(world, entity, card_response);
|
||||
|
||||
if changed && terrain != original {
|
||||
let _ = reflected_component_transaction(
|
||||
world,
|
||||
entity,
|
||||
"Edit Terrain",
|
||||
shared::AUTHORING_COMPONENT_TERRAIN,
|
||||
COMPONENT_TERRAIN_DESC,
|
||||
move |world, entity| {
|
||||
world.entity_mut(entity).insert(terrain);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn brush_validation_ui(ui: &mut egui::Ui, brush: &BrushDesc) {
|
||||
let report = validate_brush(brush);
|
||||
if report.diagnostics.is_empty() {
|
||||
|
||||
Reference in new issue
Block a user