fix collider mesh
This commit is contained in:
@@ -43,7 +43,6 @@ fn create_tile_collider(
|
|||||||
}
|
}
|
||||||
for i in 0..3 {
|
for i in 0..3 {
|
||||||
let off = i * 2;
|
let off = i * 2;
|
||||||
|
|
||||||
indices.push([off + idx, ((off + 1) % 6) + idx, ((off + 2) % 6) + idx]);
|
indices.push([off + idx, ((off + 1) % 6) + idx, ((off + 2) % 6) + idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,8 +79,9 @@ fn create_tile_wall_collider(
|
|||||||
verts.push(pos + HEX_CORNERS[dir]);
|
verts.push(pos + HEX_CORNERS[dir]);
|
||||||
verts.push(pos + HEX_CORNERS[(dir + 1) % 6]);
|
verts.push(pos + HEX_CORNERS[(dir + 1) % 6]);
|
||||||
|
|
||||||
indices.push([idx, idx + 1, idx2]);
|
let off = dir as u32;
|
||||||
indices.push([idx, idx2 + 1, idx2]);
|
indices.push([idx + off, idx + ((off + 1) % 6), idx2 + 1]);
|
||||||
|
indices.push([idx + off, idx2 + 1, idx2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_chunk_mesh(
|
pub fn generate_chunk_mesh(
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ fn main() {
|
|||||||
primary_window: Some(Window {
|
primary_window: Some(Window {
|
||||||
title: "Phos".into(),
|
title: "Phos".into(),
|
||||||
name: Some("phos".into()),
|
name: Some("phos".into()),
|
||||||
resolution: (1920., 1080.).into(),
|
// resolution: (1920., 1080.).into(),
|
||||||
present_mode: PresentMode::AutoNoVsync,
|
present_mode: PresentMode::AutoNoVsync,
|
||||||
// mode: bevy::window::WindowMode::BorderlessFullscreen,
|
mode: bevy::window::WindowMode::BorderlessFullscreen,
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use bevy::{
|
|||||||
use bevy_rapier3d::dynamics::{RigidBody, Velocity};
|
use bevy_rapier3d::dynamics::{RigidBody, Velocity};
|
||||||
use bevy_rapier3d::geometry::{Collider, Restitution};
|
use bevy_rapier3d::geometry::{Collider, Restitution};
|
||||||
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
|
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
|
||||||
|
use bevy_rapier3d::render::RapierDebugRenderPlugin;
|
||||||
use camera_system::prelude::PhosCamera;
|
use camera_system::prelude::PhosCamera;
|
||||||
use camera_system::PhosCameraPlugin;
|
use camera_system::PhosCameraPlugin;
|
||||||
use iyes_perf_ui::prelude::*;
|
use iyes_perf_ui::prelude::*;
|
||||||
@@ -38,7 +39,15 @@ impl Plugin for PhosGamePlugin {
|
|||||||
.add_systems(Startup, (load_textures, load_tiles, create_map).chain());
|
.add_systems(Startup, (load_textures, load_tiles, create_map).chain());
|
||||||
|
|
||||||
//Systems - Update
|
//Systems - Update
|
||||||
app.add_systems(Update, (finalize_texture, spawn_map, spawn_sphere));
|
app.add_systems(
|
||||||
|
Update,
|
||||||
|
(
|
||||||
|
finalize_texture,
|
||||||
|
spawn_map,
|
||||||
|
spawn_sphere,
|
||||||
|
render_distance_system,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
//Perf UI
|
//Perf UI
|
||||||
app.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
|
app.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
|
||||||
@@ -52,7 +61,7 @@ impl Plugin for PhosGamePlugin {
|
|||||||
app.add_plugins(BiomePainterPlugin);
|
app.add_plugins(BiomePainterPlugin);
|
||||||
//Physics
|
//Physics
|
||||||
app.add_plugins(RapierPhysicsPlugin::<NoUserData>::default());
|
app.add_plugins(RapierPhysicsPlugin::<NoUserData>::default());
|
||||||
// .add_plugins(RapierDebugRenderPlugin::default());
|
// app.add_plugins(RapierDebugRenderPlugin::default());
|
||||||
|
|
||||||
app.insert_resource(WireframeConfig {
|
app.insert_resource(WireframeConfig {
|
||||||
global: false,
|
global: false,
|
||||||
@@ -200,6 +209,7 @@ fn create_map(mut commands: Commands) {
|
|||||||
sea_level: 4.,
|
sea_level: 4.,
|
||||||
border_size: 64.,
|
border_size: 64.,
|
||||||
size: UVec2::splat(1024 / Chunk::SIZE as u32),
|
size: UVec2::splat(1024 / Chunk::SIZE as u32),
|
||||||
|
// size: UVec2::splat(1),
|
||||||
},
|
},
|
||||||
4,
|
4,
|
||||||
);
|
);
|
||||||
@@ -276,28 +286,30 @@ fn spawn_sphere(
|
|||||||
let cam_transform = cam.single();
|
let cam_transform = cam.single();
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
MaterialMeshBundle {
|
MaterialMeshBundle {
|
||||||
mesh: meshes.add(Sphere::new(0.5)),
|
mesh: meshes.add(Sphere::new(0.3)),
|
||||||
material: mat.0.clone(),
|
material: mat.0.clone(),
|
||||||
transform: Transform::from_translation(cam_transform.translation),
|
transform: Transform::from_translation(cam_transform.translation),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Collider::ball(0.5),
|
Collider::ball(0.3),
|
||||||
RigidBody::Dynamic,
|
RigidBody::Dynamic,
|
||||||
Velocity::linear(cam_transform.forward() * 100.),
|
Velocity::linear(cam_transform.forward() * 50.),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fn render_distance_system(
|
fn render_distance_system(
|
||||||
// mut chunks: Query<(&PhosChunk, &mut Visibility)>,
|
mut chunks: Query<(&Transform, &mut Visibility), With<PhosChunk>>,
|
||||||
// camera: Query<&Transform, With<PhosCamera>>,
|
camera: Query<&Transform, With<PhosCamera>>,
|
||||||
// ) {
|
) {
|
||||||
// let cam = camera.single();
|
let cam = camera.single();
|
||||||
// for (transform, mut visibility) in chunks.iter_mut() {
|
for (transform, mut visibility) in chunks.iter_mut() {
|
||||||
// let dist = (transform.center - cam.translation).length();
|
let dist = (transform.translation - cam.translation
|
||||||
// if dist > 500. {
|
+ Vec3::new((Chunk::SIZE / 2) as f32, 0., (Chunk::SIZE / 2) as f32))
|
||||||
// *visibility = Visibility::Hidden;
|
.length();
|
||||||
// } else {
|
if dist > 500. {
|
||||||
// *visibility = Visibility::Visible;
|
*visibility = Visibility::Hidden;
|
||||||
// }
|
} else {
|
||||||
// }
|
*visibility = Visibility::Visible;
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user