A custom mesh with a circular shape. The first step towards a rendering the track as a mesh.
FWAJQITR24VOZGKPU6EPJBQHXXWVCVH3OHAIKM77BYEC3LJFPMZAC use bevy::{math::{cubic_splines::CubicCurve, vec3}, prelude::*};use rand::{Rng, thread_rng};
use bevy::{math::{cubic_splines::CubicCurve, vec3},prelude::*,render::{mesh::{Indices, PrimitiveTopology},render_asset::RenderAssetUsages,},};const PI: f32 = 3.14151;use rand::{thread_rng, Rng};
let mut curve_points= vec![];for _ in 0 .. 10 {let point = vec3((-0.5 + r.gen::<f32>()) * 200.0, (-0.5 + r.gen::<f32>()) * 200.0, (-0.5 + r.gen::<f32>()) * 200.0);
let mut curve_points = vec![];for _ in 0..10 {let point = vec3((-0.5 + r.gen::<f32>()) * 200.0,(-0.5 + r.gen::<f32>()) * 200.0,(-0.5 + r.gen::<f32>()) * 200.0,);
pub struct Track {curve: CubicCurve<Vec3>,points : Vec<Vec3>}
pub struct Track {curve: CubicCurve<Vec3>,points: Vec<Vec3>,}pub fn draw_test_mesh(mut commands: Commands,mut meshes: ResMut<Assets<Mesh>>,mut mat: ResMut<Assets<StandardMaterial>>,) {let center: [f32; 3] = [0.0, 0.0, -20.0];let radius: f32 = 5.0;let circle_segments: u32 = 16;let mut positions = vec![center];let normals = vec![[0.0, 0.0, 1.0]; circle_segments as usize + 1];let mut vertices: Vec<u32> = vec![];let mut uvs = vec![[0.0, 0.0]];for i in 0..circle_segments + 1 {vertices.push(0);vertices.push(circle_segments);vertices.push(1);if i > 0 {vertices.push(0);vertices.push(i);vertices.push(i + 1);}let angle = i as f32 * 2.0 * PI / circle_segments as f32;let x = angle.cos();let y = angle.sin();positions.push([center[0] + x * radius,center[1] + y * radius,center[2] + 0.0,]);//uvs.push([0.5 * (x * 0.5), -0.5 + (y * 0.5)]);uvs.push([0.0, 0.0]);}let mesh = Mesh::new(PrimitiveTopology::TriangleList,RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD,).with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions).with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, uvs).with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals).with_inserted_indices(Indices::U32(vertices));commands.spawn(PbrBundle {mesh: meshes.add(mesh),material: mat.add(StandardMaterial::default()),..default()});}